Skip to content

Commit

Permalink
Refactor rpmGlob()
Browse files Browse the repository at this point in the history
No functional change, just shuffle some lines around for better
readability.
  • Loading branch information
dmnks authored and pmatilai committed Aug 18, 2022
1 parent 493dd91 commit f183ad4
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions rpmio/rpmglob.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,29 @@ int rpmGlob(const char * pattern, int * argcPtr, ARGV_t * argvPtr)
int dir_only = (plen > 0 && path[plen-1] == '/');
glob_t gl;
int flags = 0;
int i;
int rc = 0;

#ifdef ENABLE_NLS
char * old_collate = NULL;
char * old_ctype = NULL;
const char * t;
#endif
int i;
int rc = 0;

if (argvPtr == NULL)
/* We still want to count matches so use a scratch list */
argvPtr = &argv;

flags |= GLOB_BRACE;
if (!local || !ismagic(pattern)) {
argvAdd(argvPtr, pattern);
goto exit;
}

flags |= GLOB_BRACE;
if (home != NULL && strlen(home) > 0)
flags |= GLOB_TILDE;
if (dir_only)
flags |= GLOB_ONLYDIR;

#ifdef ENABLE_NLS
t = setlocale(LC_COLLATE, NULL);
Expand All @@ -89,14 +96,6 @@ int rpmGlob(const char * pattern, int * argcPtr, ARGV_t * argvPtr)
(void) setlocale(LC_COLLATE, "C");
(void) setlocale(LC_CTYPE, "C");
#endif

if (!local || !ismagic(pattern)) {
argvAdd(argvPtr, pattern);
goto exit;
}

if (dir_only)
flags |= GLOB_ONLYDIR;

gl.gl_pathc = 0;
gl.gl_pathv = NULL;
Expand All @@ -117,12 +116,12 @@ int rpmGlob(const char * pattern, int * argcPtr, ARGV_t * argvPtr)

exit:
argc = argvCount(*argvPtr);
argvFree(argv);
if (argcPtr)
*argcPtr = argc;
if (argc == 0 && rc == 0)
rc = GLOB_NOMATCH;


#ifdef ENABLE_NLS
if (old_collate) {
(void) setlocale(LC_COLLATE, old_collate);
Expand All @@ -133,6 +132,6 @@ int rpmGlob(const char * pattern, int * argcPtr, ARGV_t * argvPtr)
free(old_ctype);
}
#endif
argvFree(argv);

return rc;
}

0 comments on commit f183ad4

Please sign in to comment.