diff options
author | Karel Zak <kzak@redhat.com> | 2010-03-22 15:16:01 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2010-03-22 15:16:01 +0100 |
commit | 962496d401dea4a9dd18c3cc5e0fda8b902ff097 (patch) | |
tree | 83dd74b90a6436c5a56ea986463296c7a859d81c /misc-utils/blkid.c | |
parent | 7f152745c33567f49807019fd4f5f72eadfd4fd4 (diff) | |
download | util-linux-old-962496d401dea4a9dd18c3cc5e0fda8b902ff097.tar.gz |
blkid: cleanup -u <list> parsing
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/blkid.c')
-rw-r--r-- | misc-utils/blkid.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index 1a5db550..b2d231bc 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -526,32 +526,41 @@ done: static int list_to_usage(const char *list, int *flag) { int mask = 0; - const char *word, *p = list; + const char *word = NULL, *p = list; if (p && strncmp(p, "no", 2) == 0) { *flag = BLKID_FLTR_NOTIN; p += 2; } - for (word = p; p && *p; p++) { - if (*p == ',' || *(p + 1) == '\0') { - if (!strncmp(word, "filesystem", 10)) - mask |= BLKID_USAGE_FILESYSTEM; - else if (!strncmp(word, "raid", 4)) - mask |= BLKID_USAGE_RAID; - else if (!strncmp(word, "crypto", 6)) - mask |= BLKID_USAGE_CRYPTO; - else if (!strncmp(word, "other", 5)) - mask |= BLKID_USAGE_OTHER; - else { - fprintf(stderr, "unknown usage keyword '%*s'\n", - (int) (p - word), word); - exit(4); - } - word = p + 1; - } + if (!p || !*p) + goto err; + + while(p) { + word = p; + + p = strchr(p, ','); + if (p) + p++; + + if (!strncmp(word, "filesystem", 10)) + mask |= BLKID_USAGE_FILESYSTEM; + else if (!strncmp(word, "raid", 4)) + mask |= BLKID_USAGE_RAID; + else if (!strncmp(word, "crypto", 6)) + mask |= BLKID_USAGE_CRYPTO; + else if (!strncmp(word, "other", 5)) + mask |= BLKID_USAGE_OTHER; + else + goto err; } return mask; + +err: + *flag = 0; + fprintf(stderr, "unknown kerword in -u <list> argument: '%s'\n", + word ? word : list); + exit(4); } int main(int argc, char **argv) |