Loading...
--- Libc/Libc-763.13/gen/FreeBSD/glob.c.patch
+++ Libc/Libc-391/gen/FreeBSD/glob.c.patch
@@ -1,132 +1,72 @@
---- glob.c.orig 2011-01-25 17:41:37.000000000 -0800
-+++ glob.c 2011-01-26 11:50:09.000000000 -0800
-@@ -36,6 +36,8 @@ static char sccsid[] = "@(#)glob.c 8.3 (
+--- glob.c.orig 2004-11-25 11:38:01.000000000 -0800
++++ glob.c 2005-02-24 16:02:34.000000000 -0800
+@@ -40,6 +40,8 @@
#include <sys/cdefs.h>
- __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.28 2010/05/12 17:44:00 gordon Exp $");
+ __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.22 2004/07/29 03:48:52 tjr Exp $");
+#include "xlocale_private.h"
+
/*
* glob(3) -- a superset of the one defined in POSIX 1003.2.
*
-@@ -89,6 +91,19 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/glo
-
- #include "collate.h"
-
-+#define GLOB_LIMIT_STRING 65536 /* number of readdirs */
-+#define GLOB_LIMIT_STAT 128 /* number of stat system calls */
-+#define GLOB_LIMIT_READDIR 16384 /* total buffer size of path strings */
-+#define GLOB_LIMIT_PATH 1024 /* number of path elements */
-+#define GLOB_LIMIT_BRACE 128 /* Number of brace calls */
-+
-+struct glob_limit {
-+ size_t l_string;
-+ size_t l_stat;
-+ size_t l_readdir;
-+ size_t l_brace;
-+};
-+
- #define DOLLAR '$'
- #define DOT '.'
- #define EOS '\0'
-@@ -139,62 +154,64 @@ typedef char Char;
- #define ismeta(c) (((c)&M_QUOTE) != 0)
-
-
--static int compare(const void *, const void *);
--static int g_Ctoc(const Char *, char *, size_t);
+@@ -144,24 +146,24 @@
+
+
+ static int compare(const void *, const void *);
+-static int g_Ctoc(const Char *, char *, u_int);
-static int g_lstat(Char *, struct stat *, glob_t *);
-static DIR *g_opendir(Char *, glob_t *);
--static const Char *g_strchr(const Char *, wchar_t);
-+#define compare __gl_compare
-+#define g_Ctoc __gl_g_Ctoc
-+#define g_strchr __gl_g_strchr
-+#define globextend __gl_globextend
-+#define globtilde __gl_globtilde
-+#define match __gl_match
-+__private_extern__ int compare(const void *, const void *);
-+__private_extern__ int g_Ctoc(const Char *, char *, size_t, locale_t);
-+__private_extern__ const Char *g_strchr(const Char *, wchar_t);
-+__private_extern__ int globextend(const Char *, glob_t *, struct glob_limit *, locale_t);
-+__private_extern__ const Char *
-+ globtilde(const Char *, Char *, size_t, glob_t *);
-+__private_extern__ int match(Char *, Char *, Char *, locale_t);
-+
-+
++static int g_Ctoc(const Char *, char *, u_int, locale_t);
+static int g_lstat(Char *, struct stat *, glob_t *, locale_t);
+static DIR *g_opendir(Char *, glob_t *, locale_t);
+ static Char *g_strchr(Char *, wchar_t);
#ifdef notdef
static Char *g_strcat(Char *, const Char *);
#endif
-static int g_stat(Char *, struct stat *, glob_t *);
--static int glob0(const Char *, glob_t *, size_t *);
--static int glob1(Char *, glob_t *, size_t *);
--static int glob2(Char *, Char *, Char *, Char *, glob_t *, size_t *);
--static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, size_t *);
--static int globextend(const Char *, glob_t *, size_t *);
--static const Char *
-- globtilde(const Char *, Char *, size_t, glob_t *);
--static int globexp1(const Char *, glob_t *, size_t *);
--static int globexp2(const Char *, const Char *, glob_t *, int *, size_t *);
+-static int glob0(const Char *, glob_t *, int *);
+-static int glob1(Char *, glob_t *, int *);
+-static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *);
+-static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *);
+-static int globextend(const Char *, glob_t *, int *);
++static int g_stat(Char *, struct stat *, glob_t *, locale_t);
++static int glob0(const Char *, glob_t *, int *, locale_t);
++static int glob1(Char *, glob_t *, int *, locale_t);
++static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
++static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
++static int globextend(const Char *, glob_t *, int *, locale_t);
+ static const Char *
+ globtilde(const Char *, Char *, size_t, glob_t *);
+-static int globexp1(const Char *, glob_t *, int *);
+-static int globexp2(const Char *, const Char *, glob_t *, int *, int *);
-static int match(Char *, Char *, Char *);
-+static int g_stat(Char *, struct stat *, glob_t *, locale_t);
-+static int glob0(const Char *, glob_t *, struct glob_limit *, locale_t);
-+static int glob1(Char *, glob_t *, struct glob_limit *, locale_t);
-+static int glob2(Char *, Char *, Char *, Char *, glob_t *, struct glob_limit *, locale_t);
-+static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, struct glob_limit *, locale_t);
-+static int globexp1(const Char *, glob_t *, struct glob_limit *, locale_t);
-+static int globexp2(const Char *, const Char *, glob_t *, int *, struct glob_limit *, locale_t);
++static int globexp1(const Char *, glob_t *, int *, locale_t);
++static int globexp2(const Char *, const Char *, glob_t *, int *, int *, locale_t);
++static int match(Char *, Char *, Char *, locale_t);
#ifdef DEBUG
static void qprintf(const char *, Char *);
#endif
-
--int
--glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob)
-+static int
-+__glob(const char *pattern, glob_t *pglob)
- {
- const char *patnext;
-- size_t limit;
-+ struct glob_limit limit = { 0, 0, 0, 0 };
- Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;
+@@ -178,6 +180,8 @@
mbstate_t mbs;
wchar_t wc;
size_t clen;
+ locale_t loc = __current_locale();
+ int mb_cur_max = MB_CUR_MAX_L(loc);
- patnext = pattern;
-- if (!(flags & GLOB_APPEND)) {
-+ if (!(pglob->gl_flags & GLOB_APPEND)) {
- pglob->gl_pathc = 0;
- pglob->gl_pathv = NULL;
-- if (!(flags & GLOB_DOOFFS))
-+ if (!(pglob->gl_flags & GLOB_DOOFFS))
- pglob->gl_offs = 0;
- }
-- if (flags & GLOB_LIMIT) {
-- limit = pglob->gl_matchc;
-- if (limit == 0)
-- limit = ARG_MAX;
-- } else
-- limit = 0;
-- pglob->gl_flags = flags & ~GLOB_MAGCHAR;
-- pglob->gl_errfunc = errfunc;
- pglob->gl_matchc = 0;
-
- bufnext = patbuf;
+ patnext = (u_char *) pattern;
+ if (!(flags & GLOB_APPEND)) {
+@@ -200,8 +204,8 @@
bufend = bufnext + MAXPATHLEN - 1;
-- if (flags & GLOB_NOESCAPE) {
-+ if (pglob->gl_flags & GLOB_NOESCAPE) {
+ if (flags & GLOB_NOESCAPE) {
memset(&mbs, 0, sizeof(mbs));
- while (bufend - bufnext >= MB_CUR_MAX) {
- clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
+ while (bufend - bufnext >= mb_cur_max) {
-+ clen = mbrtowc_l(&wc, patnext, MB_LEN_MAX, &mbs, loc);
++ clen = mbrtowc_l(&wc, (const char *)patnext, MB_LEN_MAX, &mbs, loc);
if (clen == (size_t)-1 || clen == (size_t)-2)
return (GLOB_NOMATCH);
else if (clen == 0)
-@@ -205,7 +222,7 @@ glob(const char *pattern, int flags, int
+@@ -212,7 +216,7 @@
} else {
/* Protect the quoted characters. */
memset(&mbs, 0, sizeof(mbs));
@@ -135,75 +75,47 @@
if (*patnext == QUOTE) {
if (*++patnext == EOS) {
*bufnext++ = QUOTE | M_PROTECT;
-@@ -214,7 +231,7 @@ glob(const char *pattern, int flags, int
+@@ -221,7 +225,7 @@
prot = M_PROTECT;
} else
prot = 0;
- clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
-+ clen = mbrtowc_l(&wc, patnext, MB_LEN_MAX, &mbs, loc);
++ clen = mbrtowc_l(&wc, (const char *)patnext, MB_LEN_MAX, &mbs, loc);
if (clen == (size_t)-1 || clen == (size_t)-2)
return (GLOB_NOMATCH);
else if (clen == 0)
-@@ -225,11 +242,34 @@ glob(const char *pattern, int flags, int
- }
+@@ -233,9 +237,9 @@
*bufnext = EOS;
-- if (flags & GLOB_BRACE)
+ if (flags & GLOB_BRACE)
- return globexp1(patbuf, pglob, &limit);
-+ if (pglob->gl_flags & GLOB_BRACE)
+ return globexp1(patbuf, pglob, &limit, loc);
else
- return glob0(patbuf, pglob, &limit);
+ return glob0(patbuf, pglob, &limit, loc);
-+}
-+
-+int
-+glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob)
-+{
-+#ifdef __BLOCKS__
-+ pglob->gl_flags = flags & ~(GLOB_MAGCHAR | _GLOB_ERR_BLOCK);
-+#else /* !__BLOCKS__ */
-+ pglob->gl_flags = flags & ~GLOB_MAGCHAR;
-+#endif /* __BLOCKS__ */
-+ pglob->gl_errfunc = errfunc;
-+ return __glob(pattern, pglob);
-+}
-+
-+#ifdef __BLOCKS__
-+int
-+glob_b(const char *pattern, int flags, int (^errblk)(const char *, int), glob_t *pglob)
-+{
-+ pglob->gl_flags = flags & ~GLOB_MAGCHAR;
-+ pglob->gl_flags |= _GLOB_ERR_BLOCK;
-+ pglob->gl_errblk = errblk;
-+ return __glob(pattern, pglob);
- }
-+#endif /* __BLOCKS__ */
+ }
/*
- * Expand recursively a glob {} pattern. When there is no more expansion
-@@ -237,20 +277,26 @@ glob(const char *pattern, int flags, int
+@@ -244,23 +248,24 @@
* characters
*/
static int
--globexp1(const Char *pattern, glob_t *pglob, size_t *limit)
-+globexp1(const Char *pattern, glob_t *pglob, struct glob_limit *limit, locale_t loc)
+-globexp1(pattern, pglob, limit)
++globexp1(pattern, pglob, limit, loc)
+ const Char *pattern;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
{
const Char* ptr = pattern;
int rv;
-+ if ((pglob->gl_flags & GLOB_LIMIT) &&
-+ limit->l_brace++ >= GLOB_LIMIT_BRACE) {
-+ errno = 0;
-+ return GLOB_NOSPACE;
-+ }
-+
/* Protect a single {}, for find(1), like csh */
if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
- return glob0(pattern, pglob, limit);
+ return glob0(pattern, pglob, limit, loc);
- while ((ptr = g_strchr(ptr, LBRACE)) != NULL)
+ while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL)
- if (!globexp2(ptr, pattern, pglob, &rv, limit))
+ if (!globexp2(ptr, pattern, pglob, &rv, limit, loc))
return rv;
@@ -213,16 +125,20 @@
}
-@@ -260,7 +306,7 @@ globexp1(const Char *pattern, glob_t *pg
+@@ -270,10 +275,11 @@
* If it fails then it tries to glob the rest of the pattern and returns.
*/
static int
--globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, size_t *limit)
-+globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, struct glob_limit *limit, locale_t loc)
+-globexp2(ptr, pattern, pglob, rv, limit)
++globexp2(ptr, pattern, pglob, rv, limit, loc)
+ const Char *ptr, *pattern;
+ glob_t *pglob;
+ int *rv, *limit;
++ locale_t loc;
{
int i;
Char *lm, *ls;
-@@ -297,7 +343,7 @@ globexp2(const Char *ptr, const Char *pa
+@@ -310,7 +316,7 @@
/* Non matching braces; just glob the pattern */
if (i != 0 || *pe == EOS) {
@@ -231,7 +147,7 @@
return 0;
}
-@@ -344,7 +390,7 @@ globexp2(const Char *ptr, const Char *pa
+@@ -357,7 +363,7 @@
#ifdef DEBUG
qprintf("globexp2:", patbuf);
#endif
@@ -240,48 +156,20 @@
/* move after the comma, to the next string */
pl = pm + 1;
-@@ -360,10 +406,11 @@ globexp2(const Char *ptr, const Char *pa
-
-
-
-+#ifndef BUILDING_VARIANT
- /*
- * expand tilde from the passwd file.
- */
--static const Char *
-+__private_extern__ const Char *
- globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
- {
- struct passwd *pwd;
-@@ -421,6 +468,7 @@ globtilde(const Char *pattern, Char *pat
-
- return patbuf;
- }
-+#endif /* BUILDING_VARIANT */
-
-
- /*
-@@ -430,7 +478,7 @@ globtilde(const Char *pattern, Char *pat
+@@ -447,10 +453,11 @@
* if things went well, nonzero if errors occurred.
*/
static int
--glob0(const Char *pattern, glob_t *pglob, size_t *limit)
-+glob0(const Char *pattern, glob_t *pglob, struct glob_limit *limit, locale_t loc)
+-glob0(pattern, pglob, limit)
++glob0(pattern, pglob, limit, loc)
+ const Char *pattern;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
{
const Char *qpatnext;
- int err;
-@@ -443,6 +491,10 @@ glob0(const Char *pattern, glob_t *pglob
-
- /* We don't need to check for buffer overflow any more. */
- while ((c = *qpatnext++) != EOS) {
-+ if (c & M_PROTECT) {
-+ *bufnext++ = CHAR(c);
-+ continue;
-+ } /* else */
- switch (c) {
- case LBRACKET:
- c = *qpatnext;
-@@ -493,7 +545,7 @@ glob0(const Char *pattern, glob_t *pglob
+ int c, err, oldpathc;
+@@ -512,7 +519,7 @@
qprintf("glob0:", patbuf);
#endif
@@ -290,7 +178,7 @@
return(err);
/*
-@@ -506,7 +558,7 @@ glob0(const Char *pattern, glob_t *pglob
+@@ -525,7 +532,7 @@
if (((pglob->gl_flags & GLOB_NOCHECK) ||
((pglob->gl_flags & GLOB_NOMAGIC) &&
!(pglob->gl_flags & GLOB_MAGCHAR))))
@@ -299,27 +187,20 @@
else
return(GLOB_NOMATCH);
}
-@@ -516,14 +568,16 @@ glob0(const Char *pattern, glob_t *pglob
- return(0);
- }
-
--static int
-+#ifndef BUILDING_VARIANT
-+__private_extern__ int
- compare(const void *p, const void *q)
- {
-- return(strcmp(*(char **)p, *(char **)q));
-+ return(strcoll(*(char **)p, *(char **)q));
- }
-+#endif /* BUILDING_VARIANT */
-
- static int
--glob1(Char *pattern, glob_t *pglob, size_t *limit)
-+glob1(Char *pattern, glob_t *pglob, struct glob_limit *limit, locale_t loc)
+@@ -543,10 +550,11 @@
+ }
+
+ static int
+-glob1(pattern, pglob, limit)
++glob1(pattern, pglob, limit, loc)
+ Char *pattern;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
{
Char pathbuf[MAXPATHLEN];
-@@ -531,7 +585,7 @@ glob1(Char *pattern, glob_t *pglob, size
+@@ -554,7 +562,7 @@
if (*pattern == EOS)
return(0);
return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
@@ -328,16 +209,20 @@
}
/*
-@@ -541,7 +595,7 @@ glob1(Char *pattern, glob_t *pglob, size
- */
- static int
- glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern,
-- glob_t *pglob, size_t *limit)
-+ glob_t *pglob, struct glob_limit *limit, locale_t loc)
+@@ -563,10 +571,11 @@
+ * meta characters.
+ */
+ static int
+-glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit)
++glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc)
+ Char *pathbuf, *pathend, *pathend_last, *pattern;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
{
struct stat sb;
Char *p, *q;
-@@ -554,13 +608,20 @@ glob2(Char *pathbuf, Char *pathend, Char
+@@ -579,13 +588,13 @@
for (anymeta = 0;;) {
if (*pattern == EOS) { /* End of pattern? */
*pathend = EOS;
@@ -345,13 +230,6 @@
+ if (g_lstat(pathbuf, &sb, pglob, loc))
return(0);
-+ if ((pglob->gl_flags & GLOB_LIMIT) &&
-+ limit->l_stat++ >= GLOB_LIMIT_STAT) {
-+ errno = 0;
-+ *pathend++ = SEP;
-+ *pathend = EOS;
-+ return GLOB_NOSPACE;
-+ }
if (((pglob->gl_flags & GLOB_MARK) &&
pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
|| (S_ISLNK(sb.st_mode) &&
@@ -360,7 +238,7 @@
S_ISDIR(sb.st_mode)))) {
if (pathend + 1 > pathend_last)
return (GLOB_ABORTED);
-@@ -568,7 +629,7 @@ glob2(Char *pathbuf, Char *pathend, Char
+@@ -593,7 +602,7 @@
*pathend = EOS;
}
++pglob->gl_matchc;
@@ -369,7 +247,7 @@
}
/* Find end of next segment, copy tentatively to pathend. */
-@@ -592,7 +653,7 @@ glob2(Char *pathbuf, Char *pathend, Char
+@@ -617,16 +626,17 @@
}
} else /* Need expansion, recurse. */
return(glob3(pathbuf, pathend, pathend_last, pattern, p,
@@ -378,16 +256,18 @@
}
/* NOTREACHED */
}
-@@ -600,7 +661,7 @@ glob2(Char *pathbuf, Char *pathend, Char
- static int
- glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
- Char *pattern, Char *restpattern,
-- glob_t *pglob, size_t *limit)
-+ glob_t *pglob, struct glob_limit *limit, locale_t loc)
+
+ static int
+-glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit)
++glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit, loc)
+ Char *pathbuf, *pathend, *pathend_last, *pattern, *restpattern;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
{
struct dirent *dp;
DIR *dirp;
-@@ -620,15 +681,22 @@ glob3(Char *pathbuf, Char *pathend, Char
+@@ -646,10 +656,10 @@
*pathend = EOS;
errno = 0;
@@ -398,47 +278,18 @@
- if (g_Ctoc(pathbuf, buf, sizeof(buf)))
+ if (g_Ctoc(pathbuf, buf, sizeof(buf), loc))
return (GLOB_ABORTED);
-- if (pglob->gl_errfunc(buf, errno) ||
-- pglob->gl_flags & GLOB_ERR)
-+#ifdef __BLOCKS__
-+ if (pglob->gl_flags & _GLOB_ERR_BLOCK) {
-+ if (pglob->gl_errblk(buf, errno))
-+ return (GLOB_ABORTED);
-+ } else
-+#endif /* __BLOCKS__ */
-+ if (pglob->gl_errfunc(buf, errno))
- return (GLOB_ABORTED);
- }
-+ if (pglob->gl_flags & GLOB_ERR)
-+ return (GLOB_ABORTED);
- return(0);
- }
-
-@@ -646,6 +714,14 @@ glob3(Char *pathbuf, Char *pathend, Char
- size_t clen;
- mbstate_t mbs;
-
-+ if ((pglob->gl_flags & GLOB_LIMIT) &&
-+ limit->l_readdir++ >= GLOB_LIMIT_READDIR) {
-+ errno = 0;
-+ *pathend++ = SEP;
-+ *pathend = EOS;
-+ return GLOB_NOSPACE;
-+ }
-+
- /* Initial DOT must be matched literally. */
- if (dp->d_name[0] == DOT && *pattern != DOT)
- continue;
-@@ -653,7 +729,7 @@ glob3(Char *pathbuf, Char *pathend, Char
+ if (pglob->gl_errfunc(buf, errno) ||
+ pglob->gl_flags & GLOB_ERR)
+@@ -679,7 +689,7 @@
dc = pathend;
- sc = dp->d_name;
+ sc = (u_char *) dp->d_name;
while (dc < pathend_last) {
- clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
-+ clen = mbrtowc_l(&wc, sc, MB_LEN_MAX, &mbs, loc);
++ clen = mbrtowc_l(&wc, (const char *)sc, MB_LEN_MAX, &mbs, loc);
if (clen == (size_t)-1 || clen == (size_t)-2) {
wc = *sc;
clen = 1;
-@@ -663,12 +739,12 @@ glob3(Char *pathbuf, Char *pathend, Char
+@@ -689,12 +699,12 @@
break;
sc += clen;
}
@@ -453,79 +304,43 @@
if (err)
break;
}
-@@ -681,6 +757,7 @@ glob3(Char *pathbuf, Char *pathend, Char
- }
-
-
-+#ifndef BUILDING_VARIANT
- /*
- * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
- * add the new item, and update gl_pathc.
-@@ -695,20 +772,18 @@ glob3(Char *pathbuf, Char *pathend, Char
- * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
+@@ -722,10 +732,11 @@
* gl_pathv points to (gl_offs + gl_pathc + 1) items.
*/
--static int
--globextend(const Char *path, glob_t *pglob, size_t *limit)
-+__private_extern__ int
-+globextend(const Char *path, glob_t *pglob, struct glob_limit *limit, locale_t loc)
+ static int
+-globextend(path, pglob, limit)
++globextend(path, pglob, limit, loc)
+ const Char *path;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
{
char **pathv;
- size_t i, newsize, len;
- char *copy;
- const Char *p;
-
-- if (*limit && pglob->gl_pathc > *limit) {
-- errno = 0;
-- return (GLOB_NOSPACE);
-- }
--
- newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
-+ if ((pglob->gl_flags & GLOB_LIMIT) &&
-+ newsize > GLOB_LIMIT_PATH * sizeof(*pathv))
-+ goto nospace;
- pathv = pglob->gl_pathv ?
- realloc((char *)pglob->gl_pathv, newsize) :
- malloc(newsize);
-@@ -730,24 +805,33 @@ globextend(const Char *path, glob_t *pgl
+ int i;
+@@ -760,9 +771,9 @@
for (p = path; *p++;)
continue;
- len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */
+ len = MB_CUR_MAX_L(loc) * (size_t)(p - path); /* XXX overallocation */
-+ limit->l_string += len;
if ((copy = malloc(len)) != NULL) {
- if (g_Ctoc(path, copy, len)) {
+ if (g_Ctoc(path, copy, len, loc)) {
free(copy);
return (GLOB_NOSPACE);
}
- pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
- }
- pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
-+
-+ if ((pglob->gl_flags & GLOB_LIMIT) &&
-+ (newsize + limit->l_string) >= GLOB_LIMIT_STRING)
-+ goto nospace;
-+
- return(copy == NULL ? GLOB_NOSPACE : 0);
-+nospace:
-+ errno = 0;
-+ return GLOB_NOSPACE;
- }
-
- /*
- * pattern matching function for filenames. Each occurrence of the *
+@@ -777,8 +788,9 @@
* pattern causes a recursion level.
*/
--static int
--match(Char *name, Char *pat, Char *patend)
-+__private_extern__ int
-+match(Char *name, Char *pat, Char *patend, locale_t loc)
+ static int
+-match(name, pat, patend)
++match(name, pat, patend, loc)
+ Char *name, *pat, *patend;
++ locale_t loc;
{
int ok, negate_range;
Char c, k;
-@@ -759,7 +843,7 @@ match(Char *name, Char *pat, Char *paten
+@@ -790,7 +802,7 @@
if (pat == patend)
return(1);
do
@@ -534,7 +349,7 @@
return(1);
while (*name++ != EOS);
return(0);
-@@ -775,10 +859,10 @@ match(Char *name, Char *pat, Char *paten
+@@ -806,10 +818,10 @@
++pat;
while (((c = *pat++) & M_MASK) != M_END)
if ((*pat & M_MASK) == M_RNG) {
@@ -548,15 +363,15 @@
)
ok = 1;
pat += 2;
-@@ -812,16 +896,17 @@ globfree(glob_t *pglob)
- pglob->gl_pathv = NULL;
- }
- }
-+#endif /* !BUILDING_VARIANT */
+@@ -846,16 +858,17 @@
+ }
static DIR *
--g_opendir(Char *str, glob_t *pglob)
-+g_opendir(Char *str, glob_t *pglob, locale_t loc)
+-g_opendir(str, pglob)
++g_opendir(str, pglob, loc)
+ Char *str;
+ glob_t *pglob;
++ locale_t loc;
{
char buf[MAXPATHLEN];
@@ -568,12 +383,16 @@
return (NULL);
}
-@@ -832,11 +917,11 @@ g_opendir(Char *str, glob_t *pglob)
- }
-
- static int
--g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
-+g_lstat(Char *fn, struct stat *sb, glob_t *pglob, locale_t loc)
+@@ -866,14 +879,15 @@
+ }
+
+ static int
+-g_lstat(fn, sb, pglob)
++g_lstat(fn, sb, pglob, loc)
+ Char *fn;
+ struct stat *sb;
+ glob_t *pglob;
++ locale_t loc;
{
char buf[MAXPATHLEN];
@@ -582,12 +401,16 @@
errno = ENAMETOOLONG;
return (-1);
}
-@@ -846,11 +931,11 @@ g_lstat(Char *fn, struct stat *sb, glob_
- }
-
- static int
--g_stat(Char *fn, struct stat *sb, glob_t *pglob)
-+g_stat(Char *fn, struct stat *sb, glob_t *pglob, locale_t loc)
+@@ -883,14 +897,15 @@
+ }
+
+ static int
+-g_stat(fn, sb, pglob)
++g_stat(fn, sb, pglob, loc)
+ Char *fn;
+ struct stat *sb;
+ glob_t *pglob;
++ locale_t loc;
{
char buf[MAXPATHLEN];
@@ -596,24 +419,16 @@
errno = ENAMETOOLONG;
return (-1);
}
-@@ -859,7 +944,8 @@ g_stat(Char *fn, struct stat *sb, glob_t
- return(stat(buf, sb));
- }
-
--static const Char *
-+#ifndef BUILDING_VARIANT
-+__private_extern__ const Char *
- g_strchr(const Char *str, wchar_t ch)
- {
-
-@@ -870,15 +956,16 @@ g_strchr(const Char *str, wchar_t ch)
- return (NULL);
- }
-
--static int
--g_Ctoc(const Char *str, char *buf, size_t len)
-+__private_extern__ int
-+g_Ctoc(const Char *str, char *buf, size_t len, locale_t loc)
+@@ -912,17 +927,19 @@
+ }
+
+ static int
+-g_Ctoc(str, buf, len)
++g_Ctoc(str, buf, len, loc)
+ const Char *str;
+ char *buf;
+ u_int len;
++ locale_t loc;
{
mbstate_t mbs;
size_t clen;
@@ -627,8 +442,3 @@
if (clen == (size_t)-1)
return (1);
if (*str == L'\0')
-@@ -908,3 +995,4 @@ qprintf(const char *str, Char *s)
- (void)printf("\n");
- }
- #endif
-+#endif /* !BUILDING_VARIANT */