--- glob.c-w8 Mon Feb 4 14:13:50 2013 +++ glob.c-w9 Mon Feb 18 14:57:50 2013 @@ -59,6 +59,13 @@ * Number of matches in the current invocation of glob. */ +#pragma weak _glob = glob +#pragma weak __glob_ext = _glob_ext +#pragma weak _globfree = globfree +#pragma weak __globfree_ext = _globfree_ext + +#include "lint.h" + #include #include @@ -65,7 +72,9 @@ #include #include #include +#define _GLOB_LIBC #include +#undef _GLOB_LIBC #include #include #include @@ -136,6 +145,8 @@ static DIR *g_opendir(wcat_t *, glob_t *); static wcat_t *g_strchr(const wcat_t *, wchar_t); static int g_stat(wcat_t *, struct stat *, glob_t *); +static int glob_com(const char *, int, int (*)(const char *, int), + glob_t *); static int glob0(const wcat_t *, glob_t *, struct glob_lim *, int (*)(const char *, int)); static int glob1(wcat_t *, wcat_t *, glob_t *, struct glob_lim *, @@ -155,14 +166,35 @@ static int globexp2(const wcat_t *, const wcat_t *, glob_t *, struct glob_lim *, int (*)(const char *, int)); static int match(wcat_t *, wcat_t *, wcat_t *, int); +static void globfree_com(glob_t *); #ifdef DEBUG static void qprintf(const char *, wcat_t *); #endif +/* glob() function with legacy glob structure */ int glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) { + /* Only POSIX flags allowed */ + if ((flags & ~GLOB_POSIX) != 0) + return (GLOB_NOMATCH); + + return (glob_com(pattern, flags, errfunc, pglob)); +} + +/* Extended glob() function, selected by #pragma redefine_extname in glob.h */ +int +_glob_ext(const char *pattern, int flags, int (*errfunc)(const char *, int), + glob_t *pglob) +{ + return (glob_com(pattern, flags, errfunc, pglob)); +} + +static int +glob_com(const char *pattern, int flags, int (*errfunc)(const char *, int), + glob_t *pglob) +{ const char *patnext; int n; size_t patlen; @@ -1118,10 +1150,30 @@ return (name->w_wc == EOS); } -/* Free allocated data belonging to a glob_t structure. */ +/* globfree() function with legacy glob structure */ void globfree(glob_t *pglob) { + /* Only POSIX flags allowed */ + pglob->gl_flags &= GLOB_POSIX; + + globfree_com(pglob); +} + +/* + * Extended globfree() function, selected by #pragma redefine_extname + * in glob.h + */ +void +_globfree_ext(glob_t *pglob) +{ + globfree_com(pglob); +} + +/* Free allocated data belonging to a glob_t structure. */ +void +globfree_com(glob_t *pglob) +{ int i; char **pp;