]> git.saurik.com Git - apple/libc.git/blame - gen/FreeBSD/glob.c.patch
Libc-594.9.4.tar.gz
[apple/libc.git] / gen / FreeBSD / glob.c.patch
CommitLineData
34e8f829
A
1--- glob.c.orig 2009-05-12 11:21:55.000000000 -0700
2+++ glob.c 2009-05-20 16:26:02.000000000 -0700
b5d655f7 3@@ -40,6 +40,8 @@ static char sccsid[] = "@(#)glob.c 8.3 (
3d9156a7
A
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.22 2004/07/29 03:48:52 tjr Exp $");
6
7+#include "xlocale_private.h"
8+
9 /*
10 * glob(3) -- a superset of the one defined in POSIX 1003.2.
11 *
34e8f829 12@@ -143,33 +145,40 @@ typedef char Char;
224c7076 13 #define ismeta(c) (((c)&M_QUOTE) != 0)
3d9156a7 14
b5d655f7
A
15
16-static int compare(const void *, const void *);
17-static int g_Ctoc(const Char *, char *, u_int);
18-static int g_lstat(Char *, struct stat *, glob_t *);
19-static DIR *g_opendir(Char *, glob_t *);
20-static Char *g_strchr(Char *, wchar_t);
21+#define compare __gl_compare
224c7076 22+#define g_Ctoc __gl_g_Ctoc
b5d655f7 23+#define g_strchr __gl_g_strchr
224c7076 24+#define globextend __gl_globextend
b5d655f7
A
25+#define globtilde __gl_globtilde
26+#define match __gl_match
27+__private_extern__ int compare(const void *, const void *);
224c7076 28+__private_extern__ int g_Ctoc(const Char *, char *, u_int, locale_t);
b5d655f7 29+__private_extern__ Char *g_strchr(Char *, wchar_t);
224c7076 30+__private_extern__ int globextend(const Char *, glob_t *, int *, locale_t);
b5d655f7
A
31+__private_extern__ const Char *
32+ globtilde(const Char *, Char *, size_t, glob_t *);
33+__private_extern__ int match(Char *, Char *, Char *, locale_t);
224c7076 34+
b5d655f7
A
35+
36+static int g_lstat(Char *, struct stat *, glob_t *, locale_t);
3d9156a7 37+static DIR *g_opendir(Char *, glob_t *, locale_t);
3d9156a7
A
38 #ifdef notdef
39 static Char *g_strcat(Char *, const Char *);
40 #endif
41-static int g_stat(Char *, struct stat *, glob_t *);
42-static int glob0(const Char *, glob_t *, int *);
43-static int glob1(Char *, glob_t *, int *);
44-static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *);
45-static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *);
46-static int globextend(const Char *, glob_t *, int *);
b5d655f7
A
47-static const Char *
48- globtilde(const Char *, Char *, size_t, glob_t *);
3d9156a7
A
49-static int globexp1(const Char *, glob_t *, int *);
50-static int globexp2(const Char *, const Char *, glob_t *, int *, int *);
51-static int match(Char *, Char *, Char *);
b5d655f7
A
52+static int g_stat(Char *, struct stat *, glob_t *, locale_t);
53+static int glob0(const Char *, glob_t *, int *, locale_t);
54+static int glob1(Char *, glob_t *, int *, locale_t);
55+static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
56+static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
57+static int globexp1(const Char *, glob_t *, int *, locale_t);
3d9156a7 58+static int globexp2(const Char *, const Char *, glob_t *, int *, int *, locale_t);
3d9156a7
A
59 #ifdef DEBUG
60 static void qprintf(const char *, Char *);
61 #endif
34e8f829
A
62
63-int
64-glob(pattern, flags, errfunc, pglob)
65+static int
66+__glob(pattern, pglob)
67 const char *pattern;
68- int flags, (*errfunc)(const char *, int);
69 glob_t *pglob;
70 {
71 const u_char *patnext;
72@@ -178,30 +187,30 @@ glob(pattern, flags, errfunc, pglob)
3d9156a7
A
73 mbstate_t mbs;
74 wchar_t wc;
75 size_t clen;
76+ locale_t loc = __current_locale();
77+ int mb_cur_max = MB_CUR_MAX_L(loc);
78
79 patnext = (u_char *) pattern;
34e8f829
A
80- if (!(flags & GLOB_APPEND)) {
81+ if (!(pglob->gl_flags & GLOB_APPEND)) {
82 pglob->gl_pathc = 0;
83 pglob->gl_pathv = NULL;
84- if (!(flags & GLOB_DOOFFS))
85+ if (!(pglob->gl_flags & GLOB_DOOFFS))
86 pglob->gl_offs = 0;
87 }
88- if (flags & GLOB_LIMIT) {
89+ if (pglob->gl_flags & GLOB_LIMIT) {
90 limit = pglob->gl_matchc;
91 if (limit == 0)
92 limit = ARG_MAX;
93 } else
94 limit = 0;
95- pglob->gl_flags = flags & ~GLOB_MAGCHAR;
96- pglob->gl_errfunc = errfunc;
97 pglob->gl_matchc = 0;
98
99 bufnext = patbuf;
3d9156a7 100 bufend = bufnext + MAXPATHLEN - 1;
34e8f829
A
101- if (flags & GLOB_NOESCAPE) {
102+ if (pglob->gl_flags & GLOB_NOESCAPE) {
3d9156a7
A
103 memset(&mbs, 0, sizeof(mbs));
104- while (bufend - bufnext >= MB_CUR_MAX) {
105- clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
106+ while (bufend - bufnext >= mb_cur_max) {
107+ clen = mbrtowc_l(&wc, (const char *)patnext, MB_LEN_MAX, &mbs, loc);
108 if (clen == (size_t)-1 || clen == (size_t)-2)
109 return (GLOB_NOMATCH);
110 else if (clen == 0)
34e8f829 111@@ -212,7 +221,7 @@ glob(pattern, flags, errfunc, pglob)
3d9156a7
A
112 } else {
113 /* Protect the quoted characters. */
114 memset(&mbs, 0, sizeof(mbs));
115- while (bufend - bufnext >= MB_CUR_MAX) {
116+ while (bufend - bufnext >= mb_cur_max) {
117 if (*patnext == QUOTE) {
118 if (*++patnext == EOS) {
119 *bufnext++ = QUOTE | M_PROTECT;
34e8f829 120@@ -221,7 +230,7 @@ glob(pattern, flags, errfunc, pglob)
3d9156a7
A
121 prot = M_PROTECT;
122 } else
123 prot = 0;
124- clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
125+ clen = mbrtowc_l(&wc, (const char *)patnext, MB_LEN_MAX, &mbs, loc);
126 if (clen == (size_t)-1 || clen == (size_t)-2)
127 return (GLOB_NOMATCH);
128 else if (clen == 0)
34e8f829
A
129@@ -232,11 +241,40 @@ glob(pattern, flags, errfunc, pglob)
130 }
3d9156a7
A
131 *bufnext = EOS;
132
34e8f829 133- if (flags & GLOB_BRACE)
3d9156a7 134- return globexp1(patbuf, pglob, &limit);
34e8f829 135+ if (pglob->gl_flags & GLOB_BRACE)
3d9156a7
A
136+ return globexp1(patbuf, pglob, &limit, loc);
137 else
138- return glob0(patbuf, pglob, &limit);
139+ return glob0(patbuf, pglob, &limit, loc);
34e8f829
A
140+}
141+
142+int
143+glob(pattern, flags, errfunc, pglob)
144+ const char *pattern;
145+ int flags, (*errfunc)(const char *, int);
146+ glob_t *pglob;
147+{
148+#ifdef __BLOCKS__
149+ pglob->gl_flags = flags & ~(GLOB_MAGCHAR | _GLOB_ERR_BLOCK);
150+#else /* !__BLOCKS__ */
151+ pglob->gl_flags = flags & ~GLOB_MAGCHAR;
152+#endif /* __BLOCKS__ */
153+ pglob->gl_errfunc = errfunc;
154+ return __glob(pattern, pglob);
155+}
156+
157+#ifdef __BLOCKS__
158+int
159+glob_b(pattern, flags, errblk, pglob)
160+ const char *pattern;
161+ int flags, (^errblk)(const char *, int);
162+ glob_t *pglob;
163+{
164+ pglob->gl_flags = flags & ~GLOB_MAGCHAR;
165+ pglob->gl_flags |= _GLOB_ERR_BLOCK;
166+ pglob->gl_errblk = errblk;
167+ return __glob(pattern, pglob);
3d9156a7 168 }
34e8f829 169+#endif /* __BLOCKS__ */
3d9156a7
A
170
171 /*
34e8f829
A
172 * Expand recursively a glob {} pattern. When there is no more expansion
173@@ -244,23 +282,24 @@ glob(pattern, flags, errfunc, pglob)
3d9156a7
A
174 * characters
175 */
b5d655f7 176 static int
3d9156a7
A
177-globexp1(pattern, pglob, limit)
178+globexp1(pattern, pglob, limit, loc)
179 const Char *pattern;
180 glob_t *pglob;
181 int *limit;
182+ locale_t loc;
183 {
184 const Char* ptr = pattern;
185 int rv;
186
187 /* Protect a single {}, for find(1), like csh */
188 if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
189- return glob0(pattern, pglob, limit);
190+ return glob0(pattern, pglob, limit, loc);
191
192 while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL)
193- if (!globexp2(ptr, pattern, pglob, &rv, limit))
194+ if (!globexp2(ptr, pattern, pglob, &rv, limit, loc))
195 return rv;
196
197- return glob0(pattern, pglob, limit);
198+ return glob0(pattern, pglob, limit, loc);
199 }
200
201
34e8f829 202@@ -270,10 +309,11 @@ globexp1(pattern, pglob, limit)
3d9156a7
A
203 * If it fails then it tries to glob the rest of the pattern and returns.
204 */
205 static int
206-globexp2(ptr, pattern, pglob, rv, limit)
207+globexp2(ptr, pattern, pglob, rv, limit, loc)
208 const Char *ptr, *pattern;
209 glob_t *pglob;
210 int *rv, *limit;
211+ locale_t loc;
212 {
213 int i;
214 Char *lm, *ls;
34e8f829 215@@ -310,7 +350,7 @@ globexp2(ptr, pattern, pglob, rv, limit)
3d9156a7
A
216
217 /* Non matching braces; just glob the pattern */
218 if (i != 0 || *pe == EOS) {
219- *rv = glob0(patbuf, pglob, limit);
220+ *rv = glob0(patbuf, pglob, limit, loc);
221 return 0;
222 }
223
34e8f829 224@@ -357,7 +397,7 @@ globexp2(ptr, pattern, pglob, rv, limit)
3d9156a7
A
225 #ifdef DEBUG
226 qprintf("globexp2:", patbuf);
227 #endif
228- *rv = globexp1(patbuf, pglob, limit);
229+ *rv = globexp1(patbuf, pglob, limit, loc);
230
231 /* move after the comma, to the next string */
232 pl = pm + 1;
34e8f829 233@@ -373,10 +413,11 @@ globexp2(ptr, pattern, pglob, rv, limit)
b5d655f7
A
234
235
236
237+#ifndef BUILDING_VARIANT
238 /*
239 * expand tilde from the passwd file.
240 */
241-static const Char *
242+__private_extern__ const Char *
243 globtilde(pattern, patbuf, patbuf_len, pglob)
244 const Char *pattern;
245 Char *patbuf;
34e8f829 246@@ -438,6 +479,7 @@ globtilde(pattern, patbuf, patbuf_len, p
b5d655f7
A
247
248 return patbuf;
249 }
250+#endif /* BUILDING_VARIANT */
251
252
253 /*
34e8f829 254@@ -447,13 +489,15 @@ globtilde(pattern, patbuf, patbuf_len, p
3d9156a7
A
255 * if things went well, nonzero if errors occurred.
256 */
b5d655f7 257 static int
3d9156a7
A
258-glob0(pattern, pglob, limit)
259+glob0(pattern, pglob, limit, loc)
260 const Char *pattern;
261 glob_t *pglob;
262 int *limit;
263+ locale_t loc;
264 {
265 const Char *qpatnext;
224c7076
A
266- int c, err, oldpathc;
267+ Char c;
268+ int err, oldpathc;
269 Char *bufnext, patbuf[MAXPATHLEN];
270
271 qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
34e8f829 272@@ -462,6 +506,10 @@ glob0(pattern, pglob, limit)
224c7076
A
273
274 /* We don't need to check for buffer overflow any more. */
275 while ((c = *qpatnext++) != EOS) {
276+ if (c & M_PROTECT) {
277+ *bufnext++ = CHAR(c);
278+ continue;
279+ } /* else */
280 switch (c) {
281 case LBRACKET:
282 c = *qpatnext;
34e8f829 283@@ -512,7 +560,7 @@ glob0(pattern, pglob, limit)
3d9156a7
A
284 qprintf("glob0:", patbuf);
285 #endif
286
287- if ((err = glob1(patbuf, pglob, limit)) != 0)
288+ if ((err = glob1(patbuf, pglob, limit, loc)) != 0)
289 return(err);
290
291 /*
34e8f829 292@@ -525,7 +573,7 @@ glob0(pattern, pglob, limit)
3d9156a7
A
293 if (((pglob->gl_flags & GLOB_NOCHECK) ||
294 ((pglob->gl_flags & GLOB_NOMAGIC) &&
295 !(pglob->gl_flags & GLOB_MAGCHAR))))
296- return(globextend(pattern, pglob, limit));
297+ return(globextend(pattern, pglob, limit, loc));
298 else
299 return(GLOB_NOMATCH);
300 }
34e8f829 301@@ -535,18 +583,21 @@ glob0(pattern, pglob, limit)
b5d655f7
A
302 return(0);
303 }
304
305-static int
306+#ifndef BUILDING_VARIANT
307+__private_extern__ int
224c7076
A
308 compare(p, q)
309 const void *p, *q;
310 {
311- return(strcmp(*(char **)p, *(char **)q));
312+ return(strcoll(*(char **)p, *(char **)q));
3d9156a7 313 }
b5d655f7 314+#endif /* BUILDING_VARIANT */
3d9156a7
A
315
316 static int
317-glob1(pattern, pglob, limit)
318+glob1(pattern, pglob, limit, loc)
319 Char *pattern;
320 glob_t *pglob;
321 int *limit;
322+ locale_t loc;
323 {
324 Char pathbuf[MAXPATHLEN];
325
34e8f829 326@@ -554,7 +605,7 @@ glob1(pattern, pglob, limit)
3d9156a7
A
327 if (*pattern == EOS)
328 return(0);
329 return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
330- pattern, pglob, limit));
331+ pattern, pglob, limit, loc));
332 }
333
334 /*
34e8f829 335@@ -563,10 +614,11 @@ glob1(pattern, pglob, limit)
3d9156a7
A
336 * meta characters.
337 */
b5d655f7 338 static int
3d9156a7 339-glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit)
b5d655f7 340+glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc)
3d9156a7
A
341 Char *pathbuf, *pathend, *pathend_last, *pattern;
342 glob_t *pglob;
343 int *limit;
344+ locale_t loc;
345 {
346 struct stat sb;
347 Char *p, *q;
34e8f829 348@@ -579,13 +631,13 @@ glob2(pathbuf, pathend, pathend_last, pa
3d9156a7
A
349 for (anymeta = 0;;) {
350 if (*pattern == EOS) { /* End of pattern? */
351 *pathend = EOS;
352- if (g_lstat(pathbuf, &sb, pglob))
353+ if (g_lstat(pathbuf, &sb, pglob, loc))
354 return(0);
355
356 if (((pglob->gl_flags & GLOB_MARK) &&
357 pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
358 || (S_ISLNK(sb.st_mode) &&
359- (g_stat(pathbuf, &sb, pglob) == 0) &&
360+ (g_stat(pathbuf, &sb, pglob, loc) == 0) &&
361 S_ISDIR(sb.st_mode)))) {
362 if (pathend + 1 > pathend_last)
363 return (GLOB_ABORTED);
34e8f829 364@@ -593,7 +645,7 @@ glob2(pathbuf, pathend, pathend_last, pa
3d9156a7
A
365 *pathend = EOS;
366 }
367 ++pglob->gl_matchc;
368- return(globextend(pathbuf, pglob, limit));
369+ return(globextend(pathbuf, pglob, limit, loc));
370 }
371
372 /* Find end of next segment, copy tentatively to pathend. */
34e8f829 373@@ -617,16 +669,17 @@ glob2(pathbuf, pathend, pathend_last, pa
3d9156a7
A
374 }
375 } else /* Need expansion, recurse. */
376 return(glob3(pathbuf, pathend, pathend_last, pattern, p,
377- pglob, limit));
378+ pglob, limit, loc));
379 }
380 /* NOTREACHED */
381 }
382
b5d655f7 383 static int
3d9156a7
A
384-glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit)
385+glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit, loc)
386 Char *pathbuf, *pathend, *pathend_last, *pattern, *restpattern;
387 glob_t *pglob;
388 int *limit;
389+ locale_t loc;
390 {
391 struct dirent *dp;
392 DIR *dirp;
34e8f829 393@@ -646,15 +699,22 @@ glob3(pathbuf, pathend, pathend_last, pa
3d9156a7
A
394 *pathend = EOS;
395 errno = 0;
396
397- if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
398+ if ((dirp = g_opendir(pathbuf, pglob, loc)) == NULL) {
399 /* TODO: don't call for ENOENT or ENOTDIR? */
400 if (pglob->gl_errfunc) {
401- if (g_Ctoc(pathbuf, buf, sizeof(buf)))
402+ if (g_Ctoc(pathbuf, buf, sizeof(buf), loc))
403 return (GLOB_ABORTED);
224c7076
A
404- if (pglob->gl_errfunc(buf, errno) ||
405- pglob->gl_flags & GLOB_ERR)
34e8f829
A
406+#ifdef __BLOCKS__
407+ if (pglob->gl_flags & _GLOB_ERR_BLOCK) {
408+ if (pglob->gl_errblk(buf, errno))
409+ return (GLOB_ABORTED);
410+ } else
411+#endif /* __BLOCKS__ */
224c7076
A
412+ if (pglob->gl_errfunc(buf, errno))
413 return (GLOB_ABORTED);
414 }
415+ if (pglob->gl_flags & GLOB_ERR)
416+ return (GLOB_ABORTED);
417 return(0);
418 }
419
34e8f829 420@@ -679,7 +739,7 @@ glob3(pathbuf, pathend, pathend_last, pa
3d9156a7
A
421 dc = pathend;
422 sc = (u_char *) dp->d_name;
423 while (dc < pathend_last) {
424- clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
425+ clen = mbrtowc_l(&wc, (const char *)sc, MB_LEN_MAX, &mbs, loc);
426 if (clen == (size_t)-1 || clen == (size_t)-2) {
427 wc = *sc;
428 clen = 1;
34e8f829 429@@ -689,12 +749,12 @@ glob3(pathbuf, pathend, pathend_last, pa
3d9156a7
A
430 break;
431 sc += clen;
432 }
433- if (!match(pathend, pattern, restpattern)) {
434+ if (!match(pathend, pattern, restpattern, loc)) {
435 *pathend = EOS;
436 continue;
437 }
438 err = glob2(pathbuf, --dc, pathend_last, restpattern,
439- pglob, limit);
440+ pglob, limit, loc);
441 if (err)
442 break;
443 }
34e8f829 444@@ -707,6 +767,7 @@ glob3(pathbuf, pathend, pathend_last, pa
b5d655f7
A
445 }
446
447
448+#ifndef BUILDING_VARIANT
449 /*
450 * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
451 * add the new item, and update gl_pathc.
34e8f829 452@@ -721,11 +782,12 @@ glob3(pathbuf, pathend, pathend_last, pa
224c7076 453 * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
3d9156a7
A
454 * gl_pathv points to (gl_offs + gl_pathc + 1) items.
455 */
224c7076 456-static int
3d9156a7 457-globextend(path, pglob, limit)
224c7076 458+__private_extern__ int
3d9156a7
A
459+globextend(path, pglob, limit, loc)
460 const Char *path;
461 glob_t *pglob;
462 int *limit;
463+ locale_t loc;
464 {
465 char **pathv;
466 int i;
34e8f829 467@@ -760,9 +822,9 @@ globextend(path, pglob, limit)
3d9156a7
A
468
469 for (p = path; *p++;)
470 continue;
471- len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */
472+ len = MB_CUR_MAX_L(loc) * (size_t)(p - path); /* XXX overallocation */
473 if ((copy = malloc(len)) != NULL) {
474- if (g_Ctoc(path, copy, len)) {
475+ if (g_Ctoc(path, copy, len, loc)) {
476 free(copy);
477 return (GLOB_NOSPACE);
478 }
34e8f829 479@@ -776,9 +838,10 @@ globextend(path, pglob, limit)
b5d655f7 480 * pattern matching function for filenames. Each occurrence of the *
3d9156a7
A
481 * pattern causes a recursion level.
482 */
b5d655f7 483-static int
3d9156a7 484-match(name, pat, patend)
b5d655f7 485+__private_extern__ int
3d9156a7
A
486+match(name, pat, patend, loc)
487 Char *name, *pat, *patend;
488+ locale_t loc;
489 {
490 int ok, negate_range;
491 Char c, k;
34e8f829 492@@ -790,7 +853,7 @@ match(name, pat, patend)
3d9156a7
A
493 if (pat == patend)
494 return(1);
495 do
496- if (match(name, pat, patend))
497+ if (match(name, pat, patend, loc))
498 return(1);
499 while (*name++ != EOS);
500 return(0);
34e8f829 501@@ -806,10 +869,10 @@ match(name, pat, patend)
3d9156a7
A
502 ++pat;
503 while (((c = *pat++) & M_MASK) != M_END)
504 if ((*pat & M_MASK) == M_RNG) {
505- if (__collate_load_error ?
506+ if (loc->__collate_load_error ?
507 CHAR(c) <= CHAR(k) && CHAR(k) <= CHAR(pat[1]) :
508- __collate_range_cmp(CHAR(c), CHAR(k)) <= 0
509- && __collate_range_cmp(CHAR(k), CHAR(pat[1])) <= 0
510+ __collate_range_cmp(CHAR(c), CHAR(k), loc) <= 0
511+ && __collate_range_cmp(CHAR(k), CHAR(pat[1]), loc) <= 0
512 )
513 ok = 1;
514 pat += 2;
34e8f829 515@@ -844,18 +907,20 @@ globfree(pglob)
b5d655f7
A
516 pglob->gl_pathv = NULL;
517 }
3d9156a7 518 }
b5d655f7 519+#endif /* !BUILDING_VARIANT */
3d9156a7
A
520
521 static DIR *
522-g_opendir(str, pglob)
523+g_opendir(str, pglob, loc)
524 Char *str;
525 glob_t *pglob;
526+ locale_t loc;
527 {
528 char buf[MAXPATHLEN];
529
530 if (!*str)
531 strcpy(buf, ".");
532 else {
533- if (g_Ctoc(str, buf, sizeof(buf)))
534+ if (g_Ctoc(str, buf, sizeof(buf), loc))
535 return (NULL);
536 }
537
34e8f829 538@@ -866,14 +931,15 @@ g_opendir(str, pglob)
3d9156a7
A
539 }
540
541 static int
542-g_lstat(fn, sb, pglob)
543+g_lstat(fn, sb, pglob, loc)
544 Char *fn;
545 struct stat *sb;
546 glob_t *pglob;
547+ locale_t loc;
548 {
549 char buf[MAXPATHLEN];
550
551- if (g_Ctoc(fn, buf, sizeof(buf))) {
552+ if (g_Ctoc(fn, buf, sizeof(buf), loc)) {
553 errno = ENAMETOOLONG;
554 return (-1);
555 }
34e8f829 556@@ -883,14 +949,15 @@ g_lstat(fn, sb, pglob)
3d9156a7
A
557 }
558
559 static int
560-g_stat(fn, sb, pglob)
561+g_stat(fn, sb, pglob, loc)
562 Char *fn;
563 struct stat *sb;
564 glob_t *pglob;
565+ locale_t loc;
566 {
567 char buf[MAXPATHLEN];
568
569- if (g_Ctoc(fn, buf, sizeof(buf))) {
570+ if (g_Ctoc(fn, buf, sizeof(buf), loc)) {
571 errno = ENAMETOOLONG;
572 return (-1);
573 }
34e8f829 574@@ -899,7 +966,8 @@ g_stat(fn, sb, pglob)
224c7076 575 return(stat(buf, sb));
3d9156a7
A
576 }
577
b5d655f7 578-static Char *
224c7076 579+#ifndef BUILDING_VARIANT
b5d655f7 580+__private_extern__ Char *
224c7076
A
581 g_strchr(str, ch)
582 Char *str;
b5d655f7 583 wchar_t ch;
34e8f829 584@@ -911,18 +979,20 @@ g_strchr(str, ch)
224c7076
A
585 return (NULL);
586 }
587
588-static int
3d9156a7 589-g_Ctoc(str, buf, len)
224c7076 590+__private_extern__ int
3d9156a7
A
591+g_Ctoc(str, buf, len, loc)
592 const Char *str;
593 char *buf;
594 u_int len;
595+ locale_t loc;
596 {
597 mbstate_t mbs;
598 size_t clen;
599+ int mb_cur_max = MB_CUR_MAX_L(loc);
600
601 memset(&mbs, 0, sizeof(mbs));
602- while (len >= MB_CUR_MAX) {
603- clen = wcrtomb(buf, *str, &mbs);
604+ while (len >= mb_cur_max) {
605+ clen = wcrtomb_l(buf, *str, &mbs, loc);
606 if (clen == (size_t)-1)
607 return (1);
608 if (*str == L'\0')
34e8f829 609@@ -954,3 +1024,4 @@ qprintf(str, s)
224c7076
A
610 (void)printf("\n");
611 }
612 #endif
613+#endif /* !BUILDING_VARIANT */