2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #if defined(LIBC_SCCS) && !defined(lint)
34 static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
35 /* most changes between the version above and the one below have been ported:
36 static char sscsid[]= "$OpenBSD: glob.c,v 1.8.10.1 2001/04/10 jason Exp $";
38 #endif /* LIBC_SCCS and not lint */
41 * glob(3) -- a superset of the one defined in POSIX 1003.2.
43 * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
45 * Optional extra services, controlled by flags not defined by POSIX:
48 * Escaping convention: \ inhibits any special meaning the following
49 * character might have (except \ at end of string is retained).
51 * Set in gl_flags if pattern contained a globbing character.
53 * Same as GLOB_NOCHECK, but it will only append pattern if it did
54 * not contain any magic characters. [Used in csh style globbing]
56 * Use alternately specified directory access functions.
58 * expand ~user/foo to the /home/dir/of/user/foo
60 * expand {1,2}{a,b} to 1a 1b 2a 2b
62 * Number of matches in the current invocation of glob.
64 * sort alphabetically like csh (case doesn't matter) instead of in ASCII
76 #if defined(HAS_PASSWD) && !defined(VMS)
77 struct passwd *getpwnam(char *);
78 struct passwd *getpwuid(Uid_t);
84 # define MAXPATHLEN PATH_MAX
86 # define MAXPATHLEN 1024
94 # define ARG_MAX (sysconf(_SC_ARG_MAX))
96 # ifdef _POSIX_ARG_MAX
97 # define ARG_MAX _POSIX_ARG_MAX
100 # define ARG_MAX 14500 /* from VC's limits.h */
102 # define ARG_MAX 4096 /* from POSIX, be conservative */
108 #define BG_DOLLAR '$'
111 #define BG_LBRACKET '['
113 #define BG_QUESTION '?'
114 #define BG_QUOTE '\\'
116 #define BG_RBRACKET ']'
123 #define BG_UNDERSCORE '_'
124 #define BG_LBRACE '{'
125 #define BG_RBRACE '}'
131 #define M_QUOTE 0x8000
132 #define M_PROTECT 0x4000
133 #define M_MASK 0xffff
134 #define M_ASCII 0x00ff
141 #define M_PROTECT 0x40
147 #endif /* !GLOB_DEBUG */
150 #define CHAR(c) ((Char)((c)&M_ASCII))
151 #define META(c) ((Char)((c)|M_QUOTE))
152 #define M_ALL META('*')
153 #define M_END META(']')
154 #define M_NOT META('!')
155 #define M_ONE META('?')
156 #define M_RNG META('-')
157 #define M_SET META('[')
158 #define ismeta(c) (((c)&M_QUOTE) != 0)
161 static int compare(const void *, const void *);
162 static int ci_compare(const void *, const void *);
163 static int g_Ctoc(const Char *, char *, STRLEN);
164 static int g_lstat(Char *, Stat_t *, glob_t *);
165 static DIR *g_opendir(Char *, glob_t *);
166 static Char *g_strchr(Char *, int);
167 static int g_stat(Char *, Stat_t *, glob_t *);
168 static int glob0(const Char *, glob_t *);
169 static int glob1(Char *, Char *, glob_t *, size_t *);
170 static int glob2(Char *, Char *, Char *, Char *, Char *, Char *,
172 static int glob3(Char *, Char *, Char *, Char *, Char *,
173 Char *, Char *, glob_t *, size_t *);
174 static int globextend(const Char *, glob_t *, size_t *);
176 globtilde(const Char *, Char *, size_t, glob_t *);
177 static int globexp1(const Char *, glob_t *);
178 static int globexp2(const Char *, const Char *, glob_t *, int *);
179 static int match(Char *, Char *, Char *, int);
181 static void qprintf(const char *, Char *);
182 #endif /* GLOB_DEBUG */
185 static Direntry_t * my_readdir(DIR*);
190 return PerlDir_read(d);
194 /* ReliantUNIX (OS formerly known as SINIX) defines readdir
195 * in LFS-mode to be a 64-bit version of readdir. */
198 static Direntry_t * my_readdir(DIR*);
207 # define my_readdir readdir
214 bsd_glob(const char *pattern, int flags,
215 int (*errfunc)(const char *, int), glob_t *pglob)
219 Char *bufnext, *bufend, patbuf[MAXPATHLEN];
220 patnext = (U8 *) pattern;
221 /* TODO: GLOB_APPEND / GLOB_DOOFFS aren't supported yet */
223 if (!(flags & GLOB_APPEND)) {
225 pglob->gl_pathv = NULL;
226 if (!(flags & GLOB_DOOFFS))
231 pglob->gl_pathv = NULL;
234 pglob->gl_flags = flags & ~GLOB_MAGCHAR;
235 pglob->gl_errfunc = errfunc;
236 pglob->gl_matchc = 0;
239 bufend = bufnext + MAXPATHLEN - 1;
241 /* Nasty hack to treat patterns like "C:*" correctly. In this
242 * case, the * should match any file in the current directory
243 * on the C: drive. However, the glob code does not treat the
244 * colon specially, so it looks for files beginning "C:" in
245 * the current directory. To fix this, change the pattern to
246 * add an explicit "./" at the start (just after the drive
247 * letter and colon - ie change to "C:./").
249 if (isalpha(pattern[0]) && pattern[1] == ':' &&
250 pattern[2] != BG_SEP && pattern[2] != BG_SEP2 &&
251 bufend - bufnext > 4) {
252 *bufnext++ = pattern[0];
260 if (flags & GLOB_QUOTE) {
261 /* Protect the quoted characters. */
262 while (bufnext < bufend && (c = *patnext++) != BG_EOS)
265 /* To avoid backslashitis on Win32,
266 * we only treat \ as a quoting character
267 * if it precedes one of the
268 * metacharacters []-{}~\
270 if ((c = *patnext++) != '[' && c != ']' &&
271 c != '-' && c != '{' && c != '}' &&
272 c != '~' && c != '\\') {
274 if ((c = *patnext++) == BG_EOS) {
279 *bufnext++ = c | M_PROTECT;
283 while (bufnext < bufend && (c = *patnext++) != BG_EOS)
287 if (flags & GLOB_BRACE)
288 return globexp1(patbuf, pglob);
290 return glob0(patbuf, pglob);
294 * Expand recursively a glob {} pattern. When there is no more expansion
295 * invoke the standard globbing routine to glob the rest of the magic
299 globexp1(const Char *pattern, glob_t *pglob)
301 const Char* ptr = pattern;
304 /* Protect a single {}, for find(1), like csh */
305 if (pattern[0] == BG_LBRACE && pattern[1] == BG_RBRACE && pattern[2] == BG_EOS)
306 return glob0(pattern, pglob);
308 while ((ptr = (const Char *) g_strchr((Char *) ptr, BG_LBRACE)) != NULL)
309 if (!globexp2(ptr, pattern, pglob, &rv))
312 return glob0(pattern, pglob);
317 * Recursive brace globbing helper. Tries to expand a single brace.
318 * If it succeeds then it invokes globexp1 with the new pattern.
319 * If it fails then it tries to glob the rest of the pattern and returns.
322 globexp2(const Char *ptr, const Char *pattern,
323 glob_t *pglob, int *rv)
327 const Char *pe, *pm, *pm1, *pl;
328 Char patbuf[MAXPATHLEN];
330 /* copy part up to the brace */
331 for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
336 /* Find the balanced brace */
337 for (i = 0, pe = ++ptr; *pe; pe++)
338 if (*pe == BG_LBRACKET) {
339 /* Ignore everything between [] */
340 for (pm = pe++; *pe != BG_RBRACKET && *pe != BG_EOS; pe++)
344 * We could not find a matching BG_RBRACKET.
345 * Ignore and just look for BG_RBRACE
349 } else if (*pe == BG_LBRACE)
351 else if (*pe == BG_RBRACE) {
357 /* Non matching braces; just glob the pattern */
358 if (i != 0 || *pe == BG_EOS) {
359 *rv = glob0(patbuf, pglob);
363 for (i = 0, pl = pm = ptr; pm <= pe; pm++) {
366 /* Ignore everything between [] */
367 for (pm1 = pm++; *pm != BG_RBRACKET && *pm != BG_EOS; pm++)
371 * We could not find a matching BG_RBRACKET.
372 * Ignore and just look for BG_RBRACE
389 if (i && *pm == BG_COMMA)
392 /* Append the current string */
393 for (lm = ls; (pl < pm); *lm++ = *pl++)
397 * Append the rest of the pattern after the
400 for (pl = pe + 1; (*lm++ = *pl++) != BG_EOS; )
403 /* Expand the current pattern */
405 qprintf("globexp2:", patbuf);
406 #endif /* GLOB_DEBUG */
407 *rv = globexp1(patbuf, pglob);
409 /* move after the comma, to the next string */
425 * expand tilde from the passwd file.
428 globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
434 if (*pattern != BG_TILDE || !(pglob->gl_flags & GLOB_TILDE))
437 /* Copy up to the end of the string or / */
438 eb = &patbuf[patbuf_len - 1];
439 for (p = pattern + 1, h = (char *) patbuf;
440 h < (char*)eb && *p && *p != BG_SLASH; *h++ = (char)*p++)
450 if (((char *) patbuf)[0] == BG_EOS) {
452 * handle a plain ~ or ~/ by expanding $HOME
453 * first and then trying the password file
454 * or $USERPROFILE on DOSISH systems
456 if ((h = PerlEnv_getenv("HOME")) == NULL) {
459 if ((pwd = getpwuid(getuid())) == NULL)
465 * When no passwd file, fallback to the USERPROFILE
466 * environment variable on DOSish systems.
468 if ((h = PerlEnv_getenv("USERPROFILE")) == NULL) {
481 if ((pwd = getpwnam((char*) patbuf)) == NULL)
490 /* Copy the home directory */
491 for (b = patbuf; b < eb && *h; *b++ = *h++)
494 /* Append the rest of the pattern */
495 while (b < eb && (*b++ = *p++) != BG_EOS)
504 * The main glob() routine: compiles the pattern (optionally processing
505 * quotes), calls glob1() to do the real pattern matching, and finally
506 * sorts the list (unless unsorted operation is requested). Returns 0
507 * if things went well, nonzero if errors occurred. It is not an error
508 * to find no matches.
511 glob0(const Char *pattern, glob_t *pglob)
513 const Char *qpat, *qpatnext;
514 int c, err, oldflags, oldpathc;
515 Char *bufnext, patbuf[MAXPATHLEN];
518 qpat = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
520 oldflags = pglob->gl_flags;
521 oldpathc = pglob->gl_pathc;
524 /* We don't need to check for buffer overflow any more. */
525 while ((c = *qpatnext++) != BG_EOS) {
531 if (*qpatnext == BG_EOS ||
532 g_strchr((Char *) qpatnext+1, BG_RBRACKET) == NULL) {
533 *bufnext++ = BG_LBRACKET;
543 *bufnext++ = CHAR(c);
544 if (*qpatnext == BG_RANGE &&
545 (c = qpatnext[1]) != BG_RBRACKET) {
547 *bufnext++ = CHAR(c);
550 } while ((c = *qpatnext++) != BG_RBRACKET);
551 pglob->gl_flags |= GLOB_MAGCHAR;
555 pglob->gl_flags |= GLOB_MAGCHAR;
559 pglob->gl_flags |= GLOB_MAGCHAR;
560 /* Collapse adjacent stars to one.
561 * This is required to ensure that a pattern like
562 * "a**" matches a name like "a", as without this
563 * check when the first star matched everything it would
564 * cause the second star to return a match fail.
565 * As long ** is folded here this does not happen.
567 if (bufnext == patbuf || bufnext[-1] != M_ALL)
571 *bufnext++ = CHAR(c);
577 qprintf("glob0:", patbuf);
578 #endif /* GLOB_DEBUG */
580 if ((err = glob1(patbuf, patbuf+MAXPATHLEN-1, pglob, &limit)) != 0) {
581 pglob->gl_flags = oldflags;
586 * If there was no match we are going to append the pattern
587 * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
588 * and the pattern did not contain any magic characters
589 * GLOB_NOMAGIC is there just for compatibility with csh.
591 if (pglob->gl_pathc == oldpathc &&
592 ((pglob->gl_flags & GLOB_NOCHECK) ||
593 ((pglob->gl_flags & GLOB_NOMAGIC) &&
594 !(pglob->gl_flags & GLOB_MAGCHAR))))
597 printf("calling globextend from glob0\n");
598 #endif /* GLOB_DEBUG */
599 pglob->gl_flags = oldflags;
600 return(globextend(qpat, pglob, &limit));
602 else if (!(pglob->gl_flags & GLOB_NOSORT))
604 qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
605 pglob->gl_pathc - oldpathc, sizeof(char *),
606 (pglob->gl_flags & (GLOB_ALPHASORT|GLOB_NOCASE))
607 ? ci_compare : compare);
608 pglob->gl_flags = oldflags;
613 ci_compare(const void *p, const void *q)
615 const char *pp = *(const char **)p;
616 const char *qq = *(const char **)q;
619 if (toFOLD(*pp) != toFOLD(*qq))
624 ci = toFOLD(*pp) - toFOLD(*qq);
626 return compare(p, q);
631 compare(const void *p, const void *q)
633 return(strcmp(*(char **)p, *(char **)q));
637 glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
639 Char pathbuf[MAXPATHLEN];
641 assert(pattern < pattern_last);
643 /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
644 if (*pattern == BG_EOS)
646 return(glob2(pathbuf, pathbuf+MAXPATHLEN-1,
647 pathbuf, pathbuf+MAXPATHLEN-1,
648 pattern, pattern_last, pglob, limitp));
652 * The functions glob2 and glob3 are mutually recursive; there is one level
653 * of recursion for each segment in the pattern that contains one or more
657 glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
658 Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
664 assert(pattern < pattern_last);
667 * Loop over pattern segments until end of pattern or until
668 * segment with meta character found.
670 for (anymeta = 0;;) {
671 if (*pattern == BG_EOS) { /* End of pattern? */
673 if (g_lstat(pathbuf, &sb, pglob))
676 if (((pglob->gl_flags & GLOB_MARK) &&
677 pathend[-1] != BG_SEP
679 && pathend[-1] != BG_SEP2
681 ) && (S_ISDIR(sb.st_mode) ||
682 (S_ISLNK(sb.st_mode) &&
683 (g_stat(pathbuf, &sb, pglob) == 0) &&
684 S_ISDIR(sb.st_mode)))) {
685 if (pathend+1 > pathend_last)
692 printf("calling globextend from glob2\n");
693 #endif /* GLOB_DEBUG */
694 return(globextend(pathbuf, pglob, limitp));
697 /* Find end of next segment, copy tentatively to pathend. */
700 while (*p != BG_EOS && *p != BG_SEP
705 assert(p < pattern_last);
708 if (q+1 > pathend_last)
713 if (!anymeta) { /* No expansion, do next segment. */
716 while (*pattern == BG_SEP
718 || *pattern == BG_SEP2
721 assert(p < pattern_last);
722 if (pathend+1 > pathend_last)
724 *pathend++ = *pattern++;
727 /* Need expansion, recurse. */
728 return(glob3(pathbuf, pathbuf_last, pathend,
729 pathend_last, pattern,
730 p, pattern_last, pglob, limitp));
736 glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
738 Char *restpattern, Char *restpattern_last, glob_t *pglob, size_t *limitp)
744 char buf[MAXPATHLEN];
747 * The readdirfunc declaration can't be prototyped, because it is
748 * assigned, below, to two functions which are prototyped in glob.h
749 * and dirent.h as taking pointers to differently typed opaque
752 Direntry_t *(*readdirfunc)(DIR*);
754 assert(pattern < restpattern_last);
755 assert(restpattern < restpattern_last);
757 if (pathend > pathend_last)
765 if (q - pathbuf > 5) {
768 tolower(q[1]) == 'd' && tolower(q[2]) == 'i' &&
769 tolower(q[3]) == 'r' && q[4] == '/')
779 if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
780 /* TODO: don't call for ENOENT or ENOTDIR? */
781 if (pglob->gl_errfunc) {
782 if (g_Ctoc(pathbuf, buf, sizeof(buf)))
784 if (pglob->gl_errfunc(buf, errno) ||
785 (pglob->gl_flags & GLOB_ERR))
792 nocase = ((pglob->gl_flags & GLOB_NOCASE) != 0);
794 /* Search directory for matching names. */
795 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
796 readdirfunc = (Direntry_t *(*)(DIR *))pglob->gl_readdir;
798 readdirfunc = (Direntry_t *(*)(DIR *))my_readdir;
799 while ((dp = (*readdirfunc)(dirp))) {
803 /* Initial BG_DOT must be matched literally. */
804 if (dp->d_name[0] == BG_DOT && *pattern != BG_DOT)
807 sc = (U8 *) dp->d_name;
808 while (dc < pathend_last && (*dc++ = *sc++) != BG_EOS)
810 if (dc >= pathend_last) {
816 if (!match(pathend, pattern, restpattern, nocase)) {
820 err = glob2(pathbuf, pathbuf_last, --dc, pathend_last,
821 restpattern, restpattern_last, pglob, limitp);
826 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
827 (*pglob->gl_closedir)(dirp);
835 * Extend the gl_pathv member of a glob_t structure to accommodate a new item,
836 * add the new item, and update gl_pathc.
838 * This assumes the BSD realloc, which only copies the block when its size
839 * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
842 * Return 0 if new item added, error code if memory couldn't be allocated.
844 * Invariant of the glob_t structure:
845 * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
846 * gl_pathv points to (gl_offs + gl_pathc + 1) items.
849 globextend(const Char *path, glob_t *pglob, size_t *limitp)
859 for (p = path; *p; p++)
860 (void)printf("%c", CHAR(*p));
862 #endif /* GLOB_DEBUG */
864 newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
866 pathv = Renew(pglob->gl_pathv,newsize,char*);
868 Newx(pathv,newsize,char*);
870 if (pglob->gl_pathv) {
871 Safefree(pglob->gl_pathv);
872 pglob->gl_pathv = NULL;
874 return(GLOB_NOSPACE);
877 if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
878 /* first time around -- clear initial gl_offs items */
879 pathv += pglob->gl_offs;
880 for (i = pglob->gl_offs; --i >= 0; )
883 pglob->gl_pathv = pathv;
885 for (p = path; *p++;)
887 len = (STRLEN)(p - path);
889 Newx(copy, p-path, char);
891 if (g_Ctoc(path, copy, len)) {
893 return(GLOB_NOSPACE);
895 pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
897 pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
899 if ((pglob->gl_flags & GLOB_LIMIT) &&
900 newsize + *limitp >= (unsigned long)ARG_MAX) {
902 return(GLOB_NOSPACE);
905 return(copy == NULL ? GLOB_NOSPACE : 0);
910 * pattern matching function for filenames using state machine to avoid
911 * recursion. We maintain a "nextp" and "nextn" to allow us to backtrack
912 * without additional callframes, and to do cleanly prune the backtracking
913 * state when multiple '*' (start) matches are included in the pattern.
915 * Thanks to Russ Cox for the improved state machine logic to avoid quadratic
916 * matching on failure.
918 * https://research.swtch.com/glob
920 * An example would be a pattern
922 * against a file name like
927 match(Char *name, Char *pat, Char *patend, int nocase)
929 int ok, negate_range;
935 while (pat < patend) {
937 switch (c & M_MASK) {
947 /* since * matches leftmost-shortest first *
948 * if we encounter the EOS then backtracking *
949 * will not help, so we can exit early here. */
950 if (*name++ == BG_EOS)
955 /* since * matches leftmost-shortest first *
956 * if we encounter the EOS then backtracking *
957 * will not help, so we can exit early here. */
958 if ((k = *name++) == BG_EOS)
960 if ((negate_range = ((*pat & M_MASK) == M_NOT)) != BG_EOS)
962 while (((c = *pat++) & M_MASK) != M_END)
963 if ((*pat & M_MASK) == M_RNG) {
965 if (tolower(c) <= tolower(k) && tolower(k) <= tolower(pat[1]))
968 if (c <= k && k <= pat[1])
972 } else if (nocase ? (tolower(c) == tolower(k)) : (c == k))
974 if (ok == negate_range)
979 if (nocase ? (tolower(k) != tolower(c)) : (k != c))
996 /* Free allocated data belonging to a glob_t structure. */
998 bsd_globfree(glob_t *pglob)
1003 if (pglob->gl_pathv != NULL) {
1004 pp = pglob->gl_pathv + pglob->gl_offs;
1005 for (i = pglob->gl_pathc; i--; ++pp)
1008 Safefree(pglob->gl_pathv);
1009 pglob->gl_pathv = NULL;
1014 g_opendir(Char *str, glob_t *pglob)
1016 char buf[MAXPATHLEN];
1019 my_strlcpy(buf, ".", sizeof(buf));
1021 if (g_Ctoc(str, buf, sizeof(buf)))
1025 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1026 return((DIR*)(*pglob->gl_opendir)(buf));
1028 return(PerlDir_open(buf));
1032 g_lstat(Char *fn, Stat_t *sb, glob_t *pglob)
1034 char buf[MAXPATHLEN];
1036 if (g_Ctoc(fn, buf, sizeof(buf)))
1038 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1039 return((*pglob->gl_lstat)(buf, sb));
1041 return(PerlLIO_lstat(buf, sb));
1043 return(PerlLIO_stat(buf, sb));
1044 #endif /* HAS_LSTAT */
1048 g_stat(Char *fn, Stat_t *sb, glob_t *pglob)
1050 char buf[MAXPATHLEN];
1052 if (g_Ctoc(fn, buf, sizeof(buf)))
1054 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1055 return((*pglob->gl_stat)(buf, sb));
1056 return(PerlLIO_stat(buf, sb));
1060 g_strchr(Char *str, int ch)
1070 g_Ctoc(const Char *str, char *buf, STRLEN len)
1073 if ((*buf++ = (char)*str++) == BG_EOS)
1081 qprintf(const char *str, Char *s)
1085 (void)printf("%s:\n", str);
1086 for (p = s; *p; p++)
1087 (void)printf("%c", CHAR(*p));
1089 for (p = s; *p; p++)
1090 (void)printf("%c", *p & M_PROTECT ? '"' : ' ');
1092 for (p = s; *p; p++)
1093 (void)printf("%c", ismeta(*p) ? '_' : ' ');
1096 #endif /* GLOB_DEBUG */