From: Karel Zak Date: Mon, 22 Mar 2010 14:16:01 +0000 (+0100) Subject: blkid: cleanup -u parsing X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=962496d401dea4a9dd18c3cc5e0fda8b902ff097;p=util-linux blkid: cleanup -u parsing Signed-off-by: Karel Zak --- 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 argument: '%s'\n", + word ? word : list); + exit(4); } int main(int argc, char **argv)