diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-12-22 03:38:28 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-12-22 03:38:28 +0000 |
commit | 5b6c40f2258c3058707b6ba56114b25e9beec372 (patch) | |
tree | 7025cee90b5c93588d42bd35c2e8da86156d84d0 /usr.bin | |
parent | 15dfe78baaefd19ac569500360e645c1b595ece6 (diff) | |
download | FreeBSD-src-5b6c40f2258c3058707b6ba56114b25e9beec372.zip FreeBSD-src-5b6c40f2258c3058707b6ba56114b25e9beec372.tar.gz |
Fix -W long option handling.
In particular:
-W excl=text
fails because "excl" is a prefix of both "exclude" and "exclude-from". But,
-W exclude=text
is okay because it matches "exclude" exactly.
Thanks to: Jose F Nieves
MFC after: 7 days
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tar/bsdtar.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c index bf99464..852d4b8 100644 --- a/usr.bin/tar/bsdtar.c +++ b/usr.bin/tar/bsdtar.c @@ -120,6 +120,10 @@ static const char *tar_opts = "+Bb:C:cF:f:HhI:jkLlmnOoPprtT:UuvW:wX:xyZz"; #define OPTION_TOTALS 28 #define OPTION_VERSION 30 +/* + * If you add anything, be very careful + * to keep this list properly sorted. + */ static const struct option tar_longopts[] = { { "absolute-paths", no_argument, NULL, 'P' }, { "append", no_argument, NULL, 'r' }, @@ -753,12 +757,18 @@ bsdtar_getopt(struct bsdtar *bsdtar, const char *optstring, *poption = option; opt = option->val; - /* Check if there's another match. */ - option++; - while (option->name != NULL && - (strlen(option->name) < option_length || - strncmp(p, option->name, option_length) != 0)) { + /* If the first match was exact, we're done. */ + if (strncmp(p, option->name, strlen(option->name)) == 0) { + while (option->name != NULL) + option++; + } else { + /* Check if there's another match. */ option++; + while (option->name != NULL && + (strlen(option->name) < option_length || + strncmp(p, option->name, option_length) != 0)) { + option++; + } } if (option->name != NULL) bsdtar_errc(bsdtar, 1, 0, |