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 * Copyright (c) 2011 The FreeBSD Foundation
10 * Portions of this software were developed by David Chisnall
11 * under sponsorship from the FreeBSD Foundation.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #if defined(LIBC_SCCS) && !defined(lint)
41 static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
42 #endif /* LIBC_SCCS and not lint */
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
46 #include <sys/param.h>
47 #define _WANT_FREEBSD11_STAT
51 #define _WANT_FREEBSD11_DIRENT
65 #include "gen-compat.h"
66 #include "glob-compat11.h"
69 * glob(3) expansion limits. Stop the expansion if any of these limits
70 * is reached. This caps the runtime in the face of DoS attacks. See
73 #define GLOB_LIMIT_BRACE 128 /* number of brace calls */
74 #define GLOB_LIMIT_PATH 65536 /* number of path elements */
75 #define GLOB_LIMIT_READDIR 16384 /* number of readdirs */
76 #define GLOB_LIMIT_STAT 1024 /* number of stat system calls */
77 #define GLOB_LIMIT_STRING ARG_MAX /* maximum total size for paths */
102 #define M_QUOTE 0x8000000000ULL
103 #define M_PROTECT 0x4000000000ULL
104 #define M_MASK 0xffffffffffULL
105 #define M_CHAR 0x00ffffffffULL
107 typedef uint_fast64_t Char;
109 #define CHAR(c) ((Char)((c)&M_CHAR))
110 #define META(c) ((Char)((c)|M_QUOTE))
111 #define UNPROT(c) ((c) & ~M_PROTECT)
112 #define M_ALL META(L'*')
113 #define M_END META(L']')
114 #define M_NOT META(L'!')
115 #define M_ONE META(L'?')
116 #define M_RNG META(L'-')
117 #define M_SET META(L'[')
118 #define ismeta(c) (((c)&M_QUOTE) != 0)
120 #define isprot(c) (((c)&M_PROTECT) != 0)
123 static int compare(const void *, const void *);
124 static int g_Ctoc(const Char *, char *, size_t);
125 static int g_lstat(Char *, struct freebsd11_stat *, glob11_t *);
126 static DIR *g_opendir(Char *, glob11_t *);
127 static const Char *g_strchr(const Char *, wchar_t);
129 static Char *g_strcat(Char *, const Char *);
131 static int g_stat(Char *, struct freebsd11_stat *, glob11_t *);
132 static int glob0(const Char *, glob11_t *, struct glob_limit *,
134 static int glob1(Char *, glob11_t *, struct glob_limit *);
135 static int glob2(Char *, Char *, Char *, Char *, glob11_t *,
136 struct glob_limit *);
137 static int glob3(Char *, Char *, Char *, Char *, Char *, glob11_t *,
138 struct glob_limit *);
139 static int globextend(const Char *, glob11_t *, struct glob_limit *,
142 globtilde(const Char *, Char *, size_t, glob11_t *);
143 static int globexp0(const Char *, glob11_t *, struct glob_limit *,
145 static int globexp1(const Char *, glob11_t *, struct glob_limit *);
146 static int globexp2(const Char *, const Char *, glob11_t *,
147 struct glob_limit *);
148 static int globfinal(glob11_t *, struct glob_limit *, size_t,
150 static int match(Char *, Char *, Char *);
151 static int err_nomatch(glob11_t *, struct glob_limit *, const char *);
152 static int err_aborted(glob11_t *, int, char *);
154 static void qprintf(const char *, Char *);
158 freebsd11_glob(const char * __restrict pattern, int flags,
159 int (*errfunc)(const char *, int), glob11_t * __restrict pglob)
161 struct glob_limit limit = { 0, 0, 0, 0, 0 };
163 Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;
170 if (!(flags & GLOB_APPEND)) {
172 pglob->gl_pathv = NULL;
173 if (!(flags & GLOB_DOOFFS))
176 if (flags & GLOB_LIMIT) {
177 limit.l_path_lim = pglob->gl_matchc;
178 if (limit.l_path_lim == 0)
179 limit.l_path_lim = GLOB_LIMIT_PATH;
181 pglob->gl_flags = flags & ~GLOB_MAGCHAR;
182 pglob->gl_errfunc = errfunc;
183 pglob->gl_matchc = 0;
186 bufend = bufnext + MAXPATHLEN - 1;
188 if (flags & GLOB_NOESCAPE) {
189 memset(&mbs, 0, sizeof(mbs));
190 while (bufnext <= bufend) {
191 clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
192 if (clen == (size_t)-1 || clen == (size_t)-2)
193 return (err_nomatch(pglob, &limit, pattern));
194 else if (clen == 0) {
202 /* Protect the quoted characters. */
203 memset(&mbs, 0, sizeof(mbs));
204 while (bufnext <= bufend) {
205 if (*patnext == '\\') {
206 if (*++patnext == '\0') {
213 clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
214 if (clen == (size_t)-1 || clen == (size_t)-2)
215 return (err_nomatch(pglob, &limit, pattern));
216 else if (clen == 0) {
220 *bufnext++ = wc | prot;
225 return (err_nomatch(pglob, &limit, pattern));
228 if (flags & GLOB_BRACE)
229 return (globexp0(patbuf, pglob, &limit, pattern));
231 return (glob0(patbuf, pglob, &limit, pattern));
235 globexp0(const Char *pattern, glob11_t *pglob, struct glob_limit *limit,
236 const char *origpat) {
240 /* Protect a single {}, for find(1), like csh */
241 if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) {
242 if ((pglob->gl_flags & GLOB_LIMIT) &&
243 limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) {
245 return (GLOB_NOSPACE);
247 return (glob0(pattern, pglob, limit, origpat));
250 oldpathc = pglob->gl_pathc;
252 if ((rv = globexp1(pattern, pglob, limit)) != 0)
255 return (globfinal(pglob, limit, oldpathc, origpat));
259 * Expand recursively a glob {} pattern. When there is no more expansion
260 * invoke the standard globbing routine to glob the rest of the magic
264 globexp1(const Char *pattern, glob11_t *pglob, struct glob_limit *limit)
268 if ((ptr = g_strchr(pattern, LBRACE)) != NULL) {
269 if ((pglob->gl_flags & GLOB_LIMIT) &&
270 limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) {
272 return (GLOB_NOSPACE);
274 return (globexp2(ptr, pattern, pglob, limit));
277 return (glob0(pattern, pglob, limit, NULL));
282 * Recursive brace globbing helper. Tries to expand a single brace.
283 * If it succeeds then it invokes globexp1 with the new pattern.
284 * If it fails then it tries to glob the rest of the pattern and returns.
287 globexp2(const Char *ptr, const Char *pattern, glob11_t *pglob,
288 struct glob_limit *limit)
292 const Char *pe, *pm, *pm1, *pl;
293 Char patbuf[MAXPATHLEN];
295 /* copy part up to the brace */
296 for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
301 /* Find the balanced brace */
302 for (i = 0, pe = ++ptr; *pe != EOS; pe++)
303 if (*pe == LBRACKET) {
304 /* Ignore everything between [] */
305 for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
309 * We could not find a matching RBRACKET.
310 * Ignore and just look for RBRACE
315 else if (*pe == LBRACE)
317 else if (*pe == RBRACE) {
323 /* Non matching braces; just glob the pattern */
324 if (i != 0 || *pe == EOS)
325 return (glob0(pattern, pglob, limit, NULL));
327 for (i = 0, pl = pm = ptr; pm <= pe; pm++)
330 /* Ignore everything between [] */
331 for (pm1 = pm++; *pm != RBRACKET && *pm != EOS; pm++)
335 * We could not find a matching RBRACKET.
336 * Ignore and just look for RBRACE
353 if (i && *pm == COMMA)
356 /* Append the current string */
357 for (lm = ls; (pl < pm); *lm++ = *pl++)
360 * Append the rest of the pattern after the
363 for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
366 /* Expand the current pattern */
368 qprintf("globexp2:", patbuf);
370 rv = globexp1(patbuf, pglob, limit);
374 /* move after the comma, to the next string */
388 * expand tilde from the passwd file.
391 globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob11_t *pglob)
398 wchar_t wbuf[MAXPATHLEN];
399 wchar_t *wbufend, *dc;
404 if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
408 * Copy up to the end of the string or /
410 eb = &patbuf[patbuf_len - 1];
411 for (p = pattern + 1, b = patbuf;
412 b < eb && *p != EOS && UNPROT(*p) != SEP; *b++ = *p++)
415 if (*p != EOS && UNPROT(*p) != SEP)
421 if (patbuf[0] == EOS) {
423 * handle a plain ~ or ~/ by expanding $HOME first (iff
424 * we're not running setuid or setgid) and then trying
427 if (issetugid() != 0 ||
428 (h = getenv("HOME")) == NULL) {
429 if (((h = getlogin()) != NULL &&
430 (pwd = getpwnam(h)) != NULL) ||
431 (pwd = getpwuid(getuid())) != NULL)
441 if (g_Ctoc(patbuf, (char *)wbuf, sizeof(wbuf)))
443 if ((pwd = getpwnam((char *)wbuf)) == NULL)
449 /* Copy the home directory */
452 wbufend = wbuf + MAXPATHLEN - 1;
454 memset(&mbs, 0, sizeof(mbs));
455 while (dc <= wbufend) {
456 clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
457 if (clen == (size_t)-1 || clen == (size_t)-2) {
458 /* XXX See initial comment #2. */
459 wc = (unsigned char)*sc;
461 memset(&mbs, 0, sizeof(mbs));
463 if ((*dc++ = wc) == EOS) {
473 for (b = patbuf; b < eb && *dc != EOS; *b++ = *dc++ | M_PROTECT)
478 /* Append the rest of the pattern */
482 if ((*b++ = *p++) == EOS) {
497 * The main glob() routine: compiles the pattern (optionally processing
498 * quotes), calls glob1() to do the real pattern matching, and finally
499 * sorts the list (unless unsorted operation is requested). Returns 0
500 * if things went well, nonzero if errors occurred.
503 glob0(const Char *pattern, glob11_t *pglob, struct glob_limit *limit,
504 const char *origpat) {
505 const Char *qpatnext;
508 Char *bufnext, c, patbuf[MAXPATHLEN];
510 qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
511 if (qpatnext == NULL) {
513 return (GLOB_NOSPACE);
515 oldpathc = pglob->gl_pathc;
518 /* We don't need to check for buffer overflow any more. */
519 while ((c = *qpatnext++) != EOS) {
525 if (*qpatnext == EOS ||
526 g_strchr(qpatnext+1, RBRACKET) == NULL) {
527 *bufnext++ = LBRACKET;
537 *bufnext++ = CHAR(c);
538 if (*qpatnext == RANGE &&
539 (c = qpatnext[1]) != RBRACKET) {
541 *bufnext++ = CHAR(c);
544 } while ((c = *qpatnext++) != RBRACKET);
545 pglob->gl_flags |= GLOB_MAGCHAR;
549 pglob->gl_flags |= GLOB_MAGCHAR;
553 pglob->gl_flags |= GLOB_MAGCHAR;
554 /* collapse adjacent stars to one,
555 * to avoid exponential behavior
557 if (bufnext == patbuf || bufnext[-1] != M_ALL)
561 *bufnext++ = CHAR(c);
567 qprintf("glob0:", patbuf);
570 if ((err = glob1(patbuf, pglob, limit)) != 0)
574 return (globfinal(pglob, limit, oldpathc, origpat));
580 globfinal(glob11_t *pglob, struct glob_limit *limit, size_t oldpathc,
581 const char *origpat) {
582 if (pglob->gl_pathc == oldpathc)
583 return (err_nomatch(pglob, limit, origpat));
585 if (!(pglob->gl_flags & GLOB_NOSORT))
586 qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
587 pglob->gl_pathc - oldpathc, sizeof(char *), compare);
593 compare(const void *p, const void *q)
595 return (strcoll(*(char **)p, *(char **)q));
599 glob1(Char *pattern, glob11_t *pglob, struct glob_limit *limit)
601 Char pathbuf[MAXPATHLEN];
603 /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
606 return (glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
607 pattern, pglob, limit));
611 * The functions glob2 and glob3 are mutually recursive; there is one level
612 * of recursion for each segment in the pattern that contains one or more
616 glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern,
617 glob11_t *pglob, struct glob_limit *limit)
619 struct freebsd11_stat sb;
624 * Loop over pattern segments until end of pattern or until
625 * segment with meta character found.
627 for (anymeta = 0;;) {
628 if (*pattern == EOS) { /* End of pattern? */
630 if (g_lstat(pathbuf, &sb, pglob))
633 if ((pglob->gl_flags & GLOB_LIMIT) &&
634 limit->l_stat_cnt++ >= GLOB_LIMIT_STAT) {
636 return (GLOB_NOSPACE);
638 if ((pglob->gl_flags & GLOB_MARK) &&
639 UNPROT(pathend[-1]) != SEP &&
640 (S_ISDIR(sb.st_mode) ||
641 (S_ISLNK(sb.st_mode) &&
642 g_stat(pathbuf, &sb, pglob) == 0 &&
643 S_ISDIR(sb.st_mode)))) {
644 if (pathend + 1 > pathend_last) {
646 return (GLOB_NOSPACE);
652 return (globextend(pathbuf, pglob, limit, NULL));
655 /* Find end of next segment, copy tentatively to pathend. */
658 while (*p != EOS && UNPROT(*p) != SEP) {
661 if (q + 1 > pathend_last) {
663 return (GLOB_NOSPACE);
668 if (!anymeta) { /* No expansion, do next segment. */
671 while (UNPROT(*pattern) == SEP) {
672 if (pathend + 1 > pathend_last) {
674 return (GLOB_NOSPACE);
676 *pathend++ = *pattern++;
678 } else /* Need expansion, recurse. */
679 return (glob3(pathbuf, pathend, pathend_last, pattern,
686 glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
687 Char *pattern, Char *restpattern,
688 glob11_t *pglob, struct glob_limit *limit)
690 struct freebsd11_dirent *dp;
692 int err, too_long, saverrno, saverrno2;
693 char buf[MAXPATHLEN + MB_LEN_MAX - 1];
695 struct freebsd11_dirent *(*readdirfunc)(DIR *);
697 if (pathend > pathend_last) {
699 return (GLOB_NOSPACE);
702 if (pglob->gl_errfunc != NULL &&
703 g_Ctoc(pathbuf, buf, sizeof(buf))) {
705 return (GLOB_NOSPACE);
710 if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
711 if (errno == ENOENT || errno == ENOTDIR)
713 err = err_aborted(pglob, errno, buf);
721 /* pglob->gl_readdir takes a void *, fix this manually */
722 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
724 (struct freebsd11_dirent *(*)(DIR *))pglob->gl_readdir;
726 readdirfunc = freebsd11_readdir;
729 /* Search directory for matching names. */
730 while ((dp = (*readdirfunc)(dirp)) != NULL) {
737 if ((pglob->gl_flags & GLOB_LIMIT) &&
738 limit->l_readdir_cnt++ >= GLOB_LIMIT_READDIR) {
744 /* Initial DOT must be matched literally. */
745 if (dp->d_name[0] == '.' && UNPROT(*pattern) != DOT) {
749 memset(&mbs, 0, sizeof(mbs));
753 while (dc <= pathend_last) {
754 clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
755 if (clen == (size_t)-1 || clen == (size_t)-2) {
756 /* XXX See initial comment #2. */
757 wc = (unsigned char)*sc;
759 memset(&mbs, 0, sizeof(mbs));
761 if ((*dc++ = wc) == EOS) {
767 if (too_long && (err = err_aborted(pglob, ENAMETOOLONG,
769 errno = ENAMETOOLONG;
772 if (too_long || !match(pathend, pattern, restpattern)) {
779 err = glob2(pathbuf, --dc, pathend_last, restpattern,
787 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
788 (*pglob->gl_closedir)(dirp);
796 if (dp == NULL && errno != 0 &&
797 (err = err_aborted(pglob, errno, buf)))
807 * Extend the gl_pathv member of a glob11_t structure to accommodate a new item,
808 * add the new item, and update gl_pathc.
810 * This assumes the BSD realloc, which only copies the block when its size
811 * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
814 * Return 0 if new item added, error code if memory couldn't be allocated.
816 * Invariant of the glob11_t structure:
817 * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
818 * gl_pathv points to (gl_offs + gl_pathc + 1) items.
821 globextend(const Char *path, glob11_t *pglob, struct glob_limit *limit,
829 if ((pglob->gl_flags & GLOB_LIMIT) &&
830 pglob->gl_matchc > limit->l_path_lim) {
832 return (GLOB_NOSPACE);
835 newn = 2 + pglob->gl_pathc + pglob->gl_offs;
836 /* reallocarray(NULL, newn, size) is equivalent to malloc(newn*size). */
837 pathv = reallocarray(pglob->gl_pathv, newn, sizeof(*pathv));
839 return (GLOB_NOSPACE);
841 if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
842 /* first time around -- clear initial gl_offs items */
843 pathv += pglob->gl_offs;
844 for (i = pglob->gl_offs + 1; --i > 0; )
847 pglob->gl_pathv = pathv;
850 copy = strdup(origpat);
852 for (p = path; *p++ != EOS;)
854 len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */
855 if ((copy = malloc(len)) != NULL) {
856 if (g_Ctoc(path, copy, len)) {
859 return (GLOB_NOSPACE);
864 limit->l_string_cnt += strlen(copy) + 1;
865 if ((pglob->gl_flags & GLOB_LIMIT) &&
866 limit->l_string_cnt >= GLOB_LIMIT_STRING) {
869 return (GLOB_NOSPACE);
871 pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
873 pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
874 return (copy == NULL ? GLOB_NOSPACE : 0);
878 * pattern matching function for filenames.
881 match(Char *name, Char *pat, Char *patend)
883 int ok, negate_range;
884 Char c, k, *nextp, *nextn;
885 struct xlocale_collate *table =
886 (struct xlocale_collate*)__get_locale()->components[XLC_COLLATE];
892 while (pat < patend) {
894 switch (c & M_MASK) {
909 if ((k = *name++) == EOS)
911 negate_range = ((*pat & M_MASK) == M_NOT);
912 if (negate_range != 0)
914 while (((c = *pat++) & M_MASK) != M_END)
915 if ((*pat & M_MASK) == M_RNG) {
916 if (table->__collate_load_error ?
917 CHAR(c) <= CHAR(k) &&
918 CHAR(k) <= CHAR(pat[1]) :
919 __wcollate_range_cmp(CHAR(c),
921 __wcollate_range_cmp(CHAR(k),
927 if (ok == negate_range)
948 /* Free allocated data belonging to a glob11_t structure. */
950 freebsd11_globfree(glob11_t *pglob)
955 if (pglob->gl_pathv != NULL) {
956 pp = pglob->gl_pathv + pglob->gl_offs;
957 for (i = pglob->gl_pathc; i--; ++pp)
960 free(pglob->gl_pathv);
961 pglob->gl_pathv = NULL;
966 g_opendir(Char *str, glob11_t *pglob)
968 char buf[MAXPATHLEN + MB_LEN_MAX - 1];
973 if (g_Ctoc(str, buf, sizeof(buf))) {
974 errno = ENAMETOOLONG;
979 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
980 return ((*pglob->gl_opendir)(buf));
982 return (opendir(buf));
986 g_lstat(Char *fn, struct freebsd11_stat *sb, glob11_t *pglob)
988 char buf[MAXPATHLEN + MB_LEN_MAX - 1];
990 if (g_Ctoc(fn, buf, sizeof(buf))) {
991 errno = ENAMETOOLONG;
994 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
995 return((*pglob->gl_lstat)(buf, sb));
996 return (freebsd11_lstat(buf, sb));
1000 g_stat(Char *fn, struct freebsd11_stat *sb, glob11_t *pglob)
1002 char buf[MAXPATHLEN + MB_LEN_MAX - 1];
1004 if (g_Ctoc(fn, buf, sizeof(buf))) {
1005 errno = ENAMETOOLONG;
1008 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1009 return ((*pglob->gl_stat)(buf, sb));
1010 return (freebsd11_stat(buf, sb));
1014 g_strchr(const Char *str, wchar_t ch)
1025 g_Ctoc(const Char *str, char *buf, size_t len)
1030 memset(&mbs, 0, sizeof(mbs));
1031 while (len >= MB_CUR_MAX) {
1032 clen = wcrtomb(buf, CHAR(*str), &mbs);
1033 if (clen == (size_t)-1) {
1034 /* XXX See initial comment #2. */
1035 *buf = (char)CHAR(*str);
1037 memset(&mbs, 0, sizeof(mbs));
1039 if (CHAR(*str) == EOS)
1049 err_nomatch(glob11_t *pglob, struct glob_limit *limit, const char *origpat) {
1051 * If there was no match we are going to append the origpat
1052 * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
1053 * and the origpat did not contain any magic characters
1054 * GLOB_NOMAGIC is there just for compatibility with csh.
1056 if ((pglob->gl_flags & GLOB_NOCHECK) ||
1057 ((pglob->gl_flags & GLOB_NOMAGIC) &&
1058 !(pglob->gl_flags & GLOB_MAGCHAR)))
1059 return (globextend(NULL, pglob, limit, origpat));
1060 return (GLOB_NOMATCH);
1064 err_aborted(glob11_t *pglob, int err, char *buf) {
1065 if ((pglob->gl_errfunc != NULL && pglob->gl_errfunc(buf, err)) ||
1066 (pglob->gl_flags & GLOB_ERR))
1067 return (GLOB_ABORTED);
1073 qprintf(const char *str, Char *s)
1077 (void)printf("%s\n", str);
1079 for (p = s; *p != EOS; p++)
1080 (void)printf("%c", (char)CHAR(*p));
1082 for (p = s; *p != EOS; p++)
1083 (void)printf("%c", (isprot(*p) ? '\\' : ' '));
1085 for (p = s; *p != EOS; p++)
1086 (void)printf("%c", (ismeta(*p) ? '_' : ' '));
1092 __sym_compat(glob, freebsd11_glob, FBSD_1.0);
1093 __sym_compat(globfree, freebsd11_globfree, FBSD_1.0);