diff options
author | Jeff Layton <jlayton@samba.org> | 2012-11-07 10:19:17 -0500 |
---|---|---|
committer | Jeff Layton <jlayton@samba.org> | 2012-11-07 10:19:17 -0500 |
commit | 6575515e37363b0db04ed13e7d627ef1a7c36ede (patch) | |
tree | 32eee6d96ff60d230a107edb36a3f3f7e577a675 | |
parent | b07c3d72ff27e1818e3c1a38466d027d04a54e04 (diff) | |
download | cifs-utils-6575515e37363b0db04ed13e7d627ef1a7c36ede.tar.gz cifs-utils-6575515e37363b0db04ed13e7d627ef1a7c36ede.tar.bz2 cifs-utils-6575515e37363b0db04ed13e7d627ef1a7c36ede.zip |
setcifsacl: clean up get_numcaces
No need to walk the string twice or to hand-roll our own version of
strchr(). Also, move the check for no argument out into main().
Signed-off-by: Jeff Layton <jlayton@samba.org>
-rw-r--r-- | setcifsacl.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/setcifsacl.c b/setcifsacl.c index 86dca9d..522731f 100644 --- a/setcifsacl.c +++ b/setcifsacl.c @@ -701,22 +701,19 @@ parse_cmdline_aces_ret: return NULL; } +/* How many aces were provided on the command-line? Count the commas. */ static unsigned int -get_numcaces(const char *optarg) +get_numcaces(const char *aces) { int i, len; - unsigned int numcaces = 1; + unsigned int num = 1; + const char *current; - if (!optarg) - return 0; - - len = strlen(optarg); - for (i = 0; i < len; ++i) { - if (*(optarg + i) == ',') - ++numcaces; - } + current = aces; + while((current = strchr(current, ','))) + ++num; - return numcaces; + return num; } static int @@ -831,12 +828,13 @@ main(const int argc, char *const argv[]) } filename = argv[3]; - numcaces = get_numcaces(ace_list); - if (!numcaces) { + if (!ace_list) { printf("%s: No valid ACEs specified\n", __func__); return -1; } + numcaces = get_numcaces(ace_list); + arrptr = parse_cmdline_aces(ace_list, numcaces); if (!arrptr) goto setcifsacl_numcaces_ret; |