diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2011-03-07 09:03:04 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2011-03-07 09:03:04 +0200 |
commit | e0ddd282033b23fdcef47f8cbdfcae5c87892797 (patch) | |
tree | d472263d69109f26613a71b67537d07abe48a83a | |
parent | 584b9d4f5a5def7af56ba81899b23178cae0a913 (diff) | |
download | rpm-e0ddd282033b23fdcef47f8cbdfcae5c87892797.tar.gz |
Clean up rpmgiGlobArgv() a bit
- Check for NULL early once to avoid having to deal with it later
- Check for rpmGlob() return code and only append on success
- Count args centrally on exit
-rw-r--r-- | lib/rpmgi.c | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/lib/rpmgi.c b/lib/rpmgi.c index 19f8f9fdf..afc1c4916 100644 --- a/lib/rpmgi.c +++ b/lib/rpmgi.c @@ -150,33 +150,26 @@ static Header rpmgiLoadReadHeader(rpmgi gi) */ static void rpmgiGlobArgv(rpmgi gi, ARGV_const_t argv) { - const char * arg; - int ac = 0; - int xx; + if (argv == NULL) return; /* XXX Expand globs only if requested */ if ((gi->flags & RPMGI_NOGLOB)) { - if (argv != NULL) { - while (argv[ac] != NULL) - ac++; - xx = argvAppend(&gi->argv, argv); + argvAppend(&gi->argv, argv); + } else { + const char * arg; + while ((arg = *argv++) != NULL) { + char * t = rpmEscapeSpaces(arg); + char ** av = NULL; + + if (rpmGlob(t, NULL, &av) == 0) { + argvAppend(&gi->argv, av); + argvFree(av); + } + free(t); } - gi->argc = ac; - return; } + gi->argc = argvCount(gi->argv); - if (argv != NULL) - while ((arg = *argv++) != NULL) { - char * t = rpmEscapeSpaces(arg); - char ** av = NULL; - - xx = rpmGlob(t, &ac, &av); - xx = argvAppend(&gi->argv, av); - gi->argc += ac; - av = argvFree(av); - t = _free(t); - ac = 0; - } return; } |