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
96 # define ARG_MAX (sysconf(_SC_ARG_MAX))
98 # ifdef _POSIX_ARG_MAX
99 # define ARG_MAX _POSIX_ARG_MAX
102 # define ARG_MAX 14500 /* from VC's limits.h */
104 # define ARG_MAX 4096 /* from POSIX, be conservative */
110 #define BG_DOLLAR '$'
113 #define BG_LBRACKET '['
115 #define BG_QUESTION '?'
116 #define BG_QUOTE '\\'
118 #define BG_RBRACKET ']'
125 #define BG_UNDERSCORE '_'
126 #define BG_LBRACE '{'
127 #define BG_RBRACE '}'
133 #define M_QUOTE 0x8000
134 #define M_PROTECT 0x4000
135 #define M_MASK 0xffff
136 #define M_ASCII 0x00ff
143 #define M_PROTECT 0x40
149 #endif /* !GLOB_DEBUG */
152 #define CHAR(c) ((Char)((c)&M_ASCII))
153 #define META(c) ((Char)((c)|M_QUOTE))
154 #define M_ALL META('*')
155 #define M_END META(']')
156 #define M_NOT META('!')
157 #define M_ONE META('?')
158 #define M_RNG META('-')
159 #define M_SET META('[')
160 #define ismeta(c) (((c)&M_QUOTE) != 0)
163 static int compare(const void *, const void *);
164 static int ci_compare(const void *, const void *);
165 static int g_Ctoc(const Char *, char *, STRLEN);
166 static int g_lstat(Char *, Stat_t *, glob_t *);
167 static DIR *g_opendir(Char *, glob_t *);
168 static Char *g_strchr(Char *, int);
169 static int g_stat(Char *, Stat_t *, glob_t *);
170 static int glob0(const Char *, glob_t *);
171 static int glob1(Char *, Char *, glob_t *, size_t *);
172 static int glob2(Char *, Char *, Char *, Char *, Char *, Char *,
174 static int glob3(Char *, Char *, Char *, Char *, Char *,
175 Char *, Char *, glob_t *, size_t *);
176 static int globextend(const Char *, glob_t *, size_t *);
178 globtilde(const Char *, Char *, size_t, glob_t *);
179 static int globexp1(const Char *, glob_t *);
180 static int globexp2(const Char *, const Char *, glob_t *, int *);
181 static int match(Char *, Char *, Char *, int);
183 static void qprintf(const char *, Char *);
184 #endif /* GLOB_DEBUG */
186 #ifdef PERL_IMPLICIT_CONTEXT
187 static Direntry_t * my_readdir(DIR*);
193 return PerlDir_read(d);
195 return (DIR *)PerlDir_read(d);
200 /* ReliantUNIX (OS formerly known as SINIX) defines readdir
201 * in LFS-mode to be a 64-bit version of readdir. */
204 static Direntry_t * my_readdir(DIR*);
213 # define my_readdir readdir
220 bsd_glob(const char *pattern, int flags,
221 int (*errfunc)(const char *, int), glob_t *pglob)
225 Char *bufnext, *bufend, patbuf[MAXPATHLEN];
226 patnext = (U8 *) pattern;
227 /* TODO: GLOB_APPEND / GLOB_DOOFFS aren't supported yet */
229 if (!(flags & GLOB_APPEND)) {
231 pglob->gl_pathv = NULL;
232 if (!(flags & GLOB_DOOFFS))
237 pglob->gl_pathv = NULL;
240 pglob->gl_flags = flags & ~GLOB_MAGCHAR;
241 pglob->gl_errfunc = errfunc;
242 pglob->gl_matchc = 0;
245 bufend = bufnext + MAXPATHLEN - 1;
247 /* Nasty hack to treat patterns like "C:*" correctly. In this
248 * case, the * should match any file in the current directory
249 * on the C: drive. However, the glob code does not treat the
250 * colon specially, so it looks for files beginning "C:" in
251 * the current directory. To fix this, change the pattern to
252 * add an explicit "./" at the start (just after the drive
253 * letter and colon - ie change to "C:./").
255 if (isalpha(pattern[0]) && pattern[1] == ':' &&
256 pattern[2] != BG_SEP && pattern[2] != BG_SEP2 &&
257 bufend - bufnext > 4) {
258 *bufnext++ = pattern[0];
266 if (flags & GLOB_QUOTE) {
267 /* Protect the quoted characters. */
268 while (bufnext < bufend && (c = *patnext++) != BG_EOS)
271 /* To avoid backslashitis on Win32,
272 * we only treat \ as a quoting character
273 * if it precedes one of the
274 * metacharacters []-{}~\
276 if ((c = *patnext++) != '[' && c != ']' &&
277 c != '-' && c != '{' && c != '}' &&
278 c != '~' && c != '\\') {
280 if ((c = *patnext++) == BG_EOS) {
285 *bufnext++ = c | M_PROTECT;
289 while (bufnext < bufend && (c = *patnext++) != BG_EOS)
293 if (flags & GLOB_BRACE)
294 return globexp1(patbuf, pglob);
296 return glob0(patbuf, pglob);
300 * Expand recursively a glob {} pattern. When there is no more expansion
301 * invoke the standard globbing routine to glob the rest of the magic
305 globexp1(const Char *pattern, glob_t *pglob)
307 const Char* ptr = pattern;
310 /* Protect a single {}, for find(1), like csh */
311 if (pattern[0] == BG_LBRACE && pattern[1] == BG_RBRACE && pattern[2] == BG_EOS)
312 return glob0(pattern, pglob);
314 while ((ptr = (const Char *) g_strchr((Char *) ptr, BG_LBRACE)) != NULL)
315 if (!globexp2(ptr, pattern, pglob, &rv))
318 return glob0(pattern, pglob);
323 * Recursive brace globbing helper. Tries to expand a single brace.
324 * If it succeeds then it invokes globexp1 with the new pattern.
325 * If it fails then it tries to glob the rest of the pattern and returns.
328 globexp2(const Char *ptr, const Char *pattern,
329 glob_t *pglob, int *rv)
333 const Char *pe, *pm, *pm1, *pl;
334 Char patbuf[MAXPATHLEN];
336 /* copy part up to the brace */
337 for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
342 /* Find the balanced brace */
343 for (i = 0, pe = ++ptr; *pe; pe++)
344 if (*pe == BG_LBRACKET) {
345 /* Ignore everything between [] */
346 for (pm = pe++; *pe != BG_RBRACKET && *pe != BG_EOS; pe++)
350 * We could not find a matching BG_RBRACKET.
351 * Ignore and just look for BG_RBRACE
355 } else if (*pe == BG_LBRACE)
357 else if (*pe == BG_RBRACE) {
363 /* Non matching braces; just glob the pattern */
364 if (i != 0 || *pe == BG_EOS) {
365 *rv = glob0(patbuf, pglob);
369 for (i = 0, pl = pm = ptr; pm <= pe; pm++) {
372 /* Ignore everything between [] */
373 for (pm1 = pm++; *pm != BG_RBRACKET && *pm != BG_EOS; pm++)
377 * We could not find a matching BG_RBRACKET.
378 * Ignore and just look for BG_RBRACE
395 if (i && *pm == BG_COMMA)
398 /* Append the current string */
399 for (lm = ls; (pl < pm); *lm++ = *pl++)
403 * Append the rest of the pattern after the
406 for (pl = pe + 1; (*lm++ = *pl++) != BG_EOS; )
409 /* Expand the current pattern */
411 qprintf("globexp2:", patbuf);
412 #endif /* GLOB_DEBUG */
413 *rv = globexp1(patbuf, pglob);
415 /* move after the comma, to the next string */
431 * expand tilde from the passwd file.
434 globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
440 if (*pattern != BG_TILDE || !(pglob->gl_flags & GLOB_TILDE))
443 /* Copy up to the end of the string or / */
444 eb = &patbuf[patbuf_len - 1];
445 for (p = pattern + 1, h = (char *) patbuf;
446 h < (char*)eb && *p && *p != BG_SLASH; *h++ = (char)*p++)
456 if (((char *) patbuf)[0] == BG_EOS) {
458 * handle a plain ~ or ~/ by expanding $HOME
459 * first and then trying the password file
460 * or $USERPROFILE on DOSISH systems
462 if ((h = getenv("HOME")) == NULL) {
465 if ((pwd = getpwuid(getuid())) == NULL)
471 * When no passwd file, fallback to the USERPROFILE
472 * environment variable on DOSish systems.
474 if ((h = getenv("USERPROFILE")) == NULL) {
487 if ((pwd = getpwnam((char*) patbuf)) == NULL)
496 /* Copy the home directory */
497 for (b = patbuf; b < eb && *h; *b++ = *h++)
500 /* Append the rest of the pattern */
501 while (b < eb && (*b++ = *p++) != BG_EOS)
510 * The main glob() routine: compiles the pattern (optionally processing
511 * quotes), calls glob1() to do the real pattern matching, and finally
512 * sorts the list (unless unsorted operation is requested). Returns 0
513 * if things went well, nonzero if errors occurred. It is not an error
514 * to find no matches.
517 glob0(const Char *pattern, glob_t *pglob)
519 const Char *qpat, *qpatnext;
520 int c, err, oldflags, oldpathc;
521 Char *bufnext, patbuf[MAXPATHLEN];
524 qpat = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
526 oldflags = pglob->gl_flags;
527 oldpathc = pglob->gl_pathc;
530 /* We don't need to check for buffer overflow any more. */
531 while ((c = *qpatnext++) != BG_EOS) {
537 if (*qpatnext == BG_EOS ||
538 g_strchr((Char *) qpatnext+1, BG_RBRACKET) == NULL) {
539 *bufnext++ = BG_LBRACKET;
549 *bufnext++ = CHAR(c);
550 if (*qpatnext == BG_RANGE &&
551 (c = qpatnext[1]) != BG_RBRACKET) {
553 *bufnext++ = CHAR(c);
556 } while ((c = *qpatnext++) != BG_RBRACKET);
557 pglob->gl_flags |= GLOB_MAGCHAR;
561 pglob->gl_flags |= GLOB_MAGCHAR;
565 pglob->gl_flags |= GLOB_MAGCHAR;
566 /* collapse adjacent stars to one,
567 * to avoid exponential behavior
569 if (bufnext == patbuf || bufnext[-1] != M_ALL)
573 *bufnext++ = CHAR(c);
579 qprintf("glob0:", patbuf);
580 #endif /* GLOB_DEBUG */
582 if ((err = glob1(patbuf, patbuf+MAXPATHLEN-1, pglob, &limit)) != 0) {
583 pglob->gl_flags = oldflags;
588 * If there was no match we are going to append the pattern
589 * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
590 * and the pattern did not contain any magic characters
591 * GLOB_NOMAGIC is there just for compatibility with csh.
593 if (pglob->gl_pathc == oldpathc &&
594 ((pglob->gl_flags & GLOB_NOCHECK) ||
595 ((pglob->gl_flags & GLOB_NOMAGIC) &&
596 !(pglob->gl_flags & GLOB_MAGCHAR))))
599 printf("calling globextend from glob0\n");
600 #endif /* GLOB_DEBUG */
601 pglob->gl_flags = oldflags;
602 return(globextend(qpat, pglob, &limit));
604 else if (!(pglob->gl_flags & GLOB_NOSORT))
606 qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
607 pglob->gl_pathc - oldpathc, sizeof(char *),
608 (pglob->gl_flags & (GLOB_ALPHASORT|GLOB_NOCASE))
609 ? ci_compare : compare);
610 pglob->gl_flags = oldflags;
615 ci_compare(const void *p, const void *q)
617 const char *pp = *(const char **)p;
618 const char *qq = *(const char **)q;
621 if (toFOLD(*pp) != toFOLD(*qq))
626 ci = toFOLD(*pp) - toFOLD(*qq);
628 return compare(p, q);
633 compare(const void *p, const void *q)
635 return(strcmp(*(char **)p, *(char **)q));
639 glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
641 Char pathbuf[MAXPATHLEN];
643 assert(pattern < pattern_last);
645 /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
646 if (*pattern == BG_EOS)
648 return(glob2(pathbuf, pathbuf+MAXPATHLEN-1,
649 pathbuf, pathbuf+MAXPATHLEN-1,
650 pattern, pattern_last, pglob, limitp));
654 * The functions glob2 and glob3 are mutually recursive; there is one level
655 * of recursion for each segment in the pattern that contains one or more
659 glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
660 Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
666 assert(pattern < pattern_last);
669 * Loop over pattern segments until end of pattern or until
670 * segment with meta character found.
672 for (anymeta = 0;;) {
673 if (*pattern == BG_EOS) { /* End of pattern? */
675 if (g_lstat(pathbuf, &sb, pglob))
678 if (((pglob->gl_flags & GLOB_MARK) &&
679 pathend[-1] != BG_SEP
681 && pathend[-1] != BG_SEP2
683 ) && (S_ISDIR(sb.st_mode) ||
684 (S_ISLNK(sb.st_mode) &&
685 (g_stat(pathbuf, &sb, pglob) == 0) &&
686 S_ISDIR(sb.st_mode)))) {
687 if (pathend+1 > pathend_last)
694 printf("calling globextend from glob2\n");
695 #endif /* GLOB_DEBUG */
696 return(globextend(pathbuf, pglob, limitp));
699 /* Find end of next segment, copy tentatively to pathend. */
702 while (*p != BG_EOS && *p != BG_SEP
707 assert(p < pattern_last);
710 if (q+1 > pathend_last)
715 if (!anymeta) { /* No expansion, do next segment. */
718 while (*pattern == BG_SEP
720 || *pattern == BG_SEP2
723 assert(p < pattern_last);
724 if (pathend+1 > pathend_last)
726 *pathend++ = *pattern++;
729 /* Need expansion, recurse. */
730 return(glob3(pathbuf, pathbuf_last, pathend,
731 pathend_last, pattern,
732 p, pattern_last, pglob, limitp));
738 glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
740 Char *restpattern, Char *restpattern_last, glob_t *pglob, size_t *limitp)
746 char buf[MAXPATHLEN];
749 * The readdirfunc declaration can't be prototyped, because it is
750 * assigned, below, to two functions which are prototyped in glob.h
751 * and dirent.h as taking pointers to differently typed opaque
754 Direntry_t *(*readdirfunc)(DIR*);
756 assert(pattern < restpattern_last);
757 assert(restpattern < restpattern_last);
759 if (pathend > pathend_last)
767 if (q - pathbuf > 5) {
770 tolower(q[1]) == 'd' && tolower(q[2]) == 'i' &&
771 tolower(q[3]) == 'r' && q[4] == '/')
781 if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
782 /* TODO: don't call for ENOENT or ENOTDIR? */
783 if (pglob->gl_errfunc) {
784 if (g_Ctoc(pathbuf, buf, sizeof(buf)))
786 if (pglob->gl_errfunc(buf, errno) ||
787 (pglob->gl_flags & GLOB_ERR))
794 nocase = ((pglob->gl_flags & GLOB_NOCASE) != 0);
796 /* Search directory for matching names. */
797 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
798 readdirfunc = (Direntry_t *(*)(DIR *))pglob->gl_readdir;
800 readdirfunc = (Direntry_t *(*)(DIR *))my_readdir;
801 while ((dp = (*readdirfunc)(dirp))) {
805 /* Initial BG_DOT must be matched literally. */
806 if (dp->d_name[0] == BG_DOT && *pattern != BG_DOT)
809 sc = (U8 *) dp->d_name;
810 while (dc < pathend_last && (*dc++ = *sc++) != BG_EOS)
812 if (dc >= pathend_last) {
818 if (!match(pathend, pattern, restpattern, nocase)) {
822 err = glob2(pathbuf, pathbuf_last, --dc, pathend_last,
823 restpattern, restpattern_last, pglob, limitp);
828 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
829 (*pglob->gl_closedir)(dirp);
837 * Extend the gl_pathv member of a glob_t structure to accommodate a new item,
838 * add the new item, and update gl_pathc.
840 * This assumes the BSD realloc, which only copies the block when its size
841 * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
844 * Return 0 if new item added, error code if memory couldn't be allocated.
846 * Invariant of the glob_t structure:
847 * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
848 * gl_pathv points to (gl_offs + gl_pathc + 1) items.
851 globextend(const Char *path, glob_t *pglob, size_t *limitp)
861 for (p = path; *p; p++)
862 (void)printf("%c", CHAR(*p));
864 #endif /* GLOB_DEBUG */
866 newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
868 pathv = Renew(pglob->gl_pathv,newsize,char*);
870 Newx(pathv,newsize,char*);
872 if (pglob->gl_pathv) {
873 Safefree(pglob->gl_pathv);
874 pglob->gl_pathv = NULL;
876 return(GLOB_NOSPACE);
879 if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
880 /* first time around -- clear initial gl_offs items */
881 pathv += pglob->gl_offs;
882 for (i = pglob->gl_offs; --i >= 0; )
885 pglob->gl_pathv = pathv;
887 for (p = path; *p++;)
889 len = (STRLEN)(p - path);
891 Newx(copy, p-path, char);
893 if (g_Ctoc(path, copy, len)) {
895 return(GLOB_NOSPACE);
897 pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
899 pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
901 if ((pglob->gl_flags & GLOB_LIMIT) &&
902 newsize + *limitp >= (unsigned long)ARG_MAX) {
904 return(GLOB_NOSPACE);
907 return(copy == NULL ? GLOB_NOSPACE : 0);
912 * pattern matching function for filenames. Each occurrence of the *
913 * pattern causes a recursion level.
916 match(Char *name, Char *pat, Char *patend, int nocase)
918 int ok, negate_range;
921 while (pat < patend) {
923 switch (c & M_MASK) {
928 if (match(name, pat, patend, nocase))
930 while (*name++ != BG_EOS)
934 if (*name++ == BG_EOS)
939 if ((k = *name++) == BG_EOS)
941 if ((negate_range = ((*pat & M_MASK) == M_NOT)) != BG_EOS)
943 while (((c = *pat++) & M_MASK) != M_END)
944 if ((*pat & M_MASK) == M_RNG) {
946 if (tolower(c) <= tolower(k) && tolower(k) <= tolower(pat[1]))
949 if (c <= k && k <= pat[1])
953 } else if (nocase ? (tolower(c) == tolower(k)) : (c == k))
955 if (ok == negate_range)
960 if (nocase ? (tolower(k) != tolower(c)) : (k != c))
965 return(*name == BG_EOS);
968 /* Free allocated data belonging to a glob_t structure. */
970 bsd_globfree(glob_t *pglob)
975 if (pglob->gl_pathv != NULL) {
976 pp = pglob->gl_pathv + pglob->gl_offs;
977 for (i = pglob->gl_pathc; i--; ++pp)
980 Safefree(pglob->gl_pathv);
981 pglob->gl_pathv = NULL;
986 g_opendir(Char *str, glob_t *pglob)
988 char buf[MAXPATHLEN];
991 my_strlcpy(buf, ".", sizeof(buf));
993 if (g_Ctoc(str, buf, sizeof(buf)))
997 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
998 return((DIR*)(*pglob->gl_opendir)(buf));
1000 return(PerlDir_open(buf));
1004 g_lstat(Char *fn, Stat_t *sb, glob_t *pglob)
1006 char buf[MAXPATHLEN];
1008 if (g_Ctoc(fn, buf, sizeof(buf)))
1010 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1011 return((*pglob->gl_lstat)(buf, sb));
1013 return(PerlLIO_lstat(buf, sb));
1015 return(PerlLIO_stat(buf, sb));
1016 #endif /* HAS_LSTAT */
1020 g_stat(Char *fn, Stat_t *sb, glob_t *pglob)
1022 char buf[MAXPATHLEN];
1024 if (g_Ctoc(fn, buf, sizeof(buf)))
1026 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1027 return((*pglob->gl_stat)(buf, sb));
1028 return(PerlLIO_stat(buf, sb));
1032 g_strchr(Char *str, int ch)
1042 g_Ctoc(const Char *str, char *buf, STRLEN len)
1045 if ((*buf++ = (char)*str++) == BG_EOS)
1053 qprintf(const char *str, Char *s)
1057 (void)printf("%s:\n", str);
1058 for (p = s; *p; p++)
1059 (void)printf("%c", CHAR(*p));
1061 for (p = s; *p; p++)
1062 (void)printf("%c", *p & M_PROTECT ? '"' : ' ');
1064 for (p = s; *p; p++)
1065 (void)printf("%c", ismeta(*p) ? '_' : ' ');
1068 #endif /* GLOB_DEBUG */