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
37 * From: @(#)glob.c 8.3 (Berkeley) 10/13/93
38 * From: FreeBSD: head/lib/libc/gen/glob.c 317913 2017-05-07 19:52:56Z jilles
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
44 #include <sys/param.h>
45 #define _WANT_FREEBSD11_STAT
49 #define _WANT_FREEBSD11_DIRENT
63 #include "gen-compat.h"
64 #include "glob-compat11.h"
67 * glob(3) expansion limits. Stop the expansion if any of these limits
68 * is reached. This caps the runtime in the face of DoS attacks. See
71 #define GLOB_LIMIT_BRACE 128 /* number of brace calls */
72 #define GLOB_LIMIT_PATH 65536 /* number of path elements */
73 #define GLOB_LIMIT_READDIR 16384 /* number of readdirs */
74 #define GLOB_LIMIT_STAT 1024 /* number of stat system calls */
75 #define GLOB_LIMIT_STRING ARG_MAX /* maximum total size for paths */
100 #define M_QUOTE 0x8000000000ULL
101 #define M_PROTECT 0x4000000000ULL
102 #define M_MASK 0xffffffffffULL
103 #define M_CHAR 0x00ffffffffULL
105 typedef uint_fast64_t Char;
107 #define CHAR(c) ((Char)((c)&M_CHAR))
108 #define META(c) ((Char)((c)|M_QUOTE))
109 #define UNPROT(c) ((c) & ~M_PROTECT)
110 #define M_ALL META(L'*')
111 #define M_END META(L']')
112 #define M_NOT META(L'!')
113 #define M_ONE META(L'?')
114 #define M_RNG META(L'-')
115 #define M_SET META(L'[')
116 #define ismeta(c) (((c)&M_QUOTE) != 0)
118 #define isprot(c) (((c)&M_PROTECT) != 0)
121 static int compare(const void *, const void *);
122 static int g_Ctoc(const Char *, char *, size_t);
123 static int g_lstat(Char *, struct freebsd11_stat *, glob11_t *);
124 static DIR *g_opendir(Char *, glob11_t *);
125 static const Char *g_strchr(const Char *, wchar_t);
127 static Char *g_strcat(Char *, const Char *);
129 static int g_stat(Char *, struct freebsd11_stat *, glob11_t *);
130 static int glob0(const Char *, glob11_t *, struct glob_limit *,
132 static int glob1(Char *, glob11_t *, struct glob_limit *);
133 static int glob2(Char *, Char *, Char *, Char *, glob11_t *,
134 struct glob_limit *);
135 static int glob3(Char *, Char *, Char *, Char *, Char *, glob11_t *,
136 struct glob_limit *);
137 static int globextend(const Char *, glob11_t *, struct glob_limit *,
140 globtilde(const Char *, Char *, size_t, glob11_t *);
141 static int globexp0(const Char *, glob11_t *, struct glob_limit *,
143 static int globexp1(const Char *, glob11_t *, struct glob_limit *);
144 static int globexp2(const Char *, const Char *, glob11_t *,
145 struct glob_limit *);
146 static int globfinal(glob11_t *, struct glob_limit *, size_t,
148 static int match(Char *, Char *, Char *);
149 static int err_nomatch(glob11_t *, struct glob_limit *, const char *);
150 static int err_aborted(glob11_t *, int, char *);
152 static void qprintf(const char *, Char *);
156 freebsd11_glob(const char * __restrict pattern, int flags,
157 int (*errfunc)(const char *, int), glob11_t * __restrict pglob)
159 struct glob_limit limit = { 0, 0, 0, 0, 0 };
161 Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;
168 if (!(flags & GLOB_APPEND)) {
170 pglob->gl_pathv = NULL;
171 if (!(flags & GLOB_DOOFFS))
174 if (flags & GLOB_LIMIT) {
175 limit.l_path_lim = pglob->gl_matchc;
176 if (limit.l_path_lim == 0)
177 limit.l_path_lim = GLOB_LIMIT_PATH;
179 pglob->gl_flags = flags & ~GLOB_MAGCHAR;
180 pglob->gl_errfunc = errfunc;
181 pglob->gl_matchc = 0;
184 bufend = bufnext + MAXPATHLEN - 1;
186 if (flags & GLOB_NOESCAPE) {
187 memset(&mbs, 0, sizeof(mbs));
188 while (bufnext <= bufend) {
189 clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
190 if (clen == (size_t)-1 || clen == (size_t)-2)
191 return (err_nomatch(pglob, &limit, pattern));
192 else if (clen == 0) {
200 /* Protect the quoted characters. */
201 memset(&mbs, 0, sizeof(mbs));
202 while (bufnext <= bufend) {
203 if (*patnext == '\\') {
204 if (*++patnext == '\0') {
211 clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
212 if (clen == (size_t)-1 || clen == (size_t)-2)
213 return (err_nomatch(pglob, &limit, pattern));
214 else if (clen == 0) {
218 *bufnext++ = wc | prot;
223 return (err_nomatch(pglob, &limit, pattern));
226 if (flags & GLOB_BRACE)
227 return (globexp0(patbuf, pglob, &limit, pattern));
229 return (glob0(patbuf, pglob, &limit, pattern));
233 globexp0(const Char *pattern, glob11_t *pglob, struct glob_limit *limit,
234 const char *origpat) {
238 /* Protect a single {}, for find(1), like csh */
239 if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) {
240 if ((pglob->gl_flags & GLOB_LIMIT) &&
241 limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) {
243 return (GLOB_NOSPACE);
245 return (glob0(pattern, pglob, limit, origpat));
248 oldpathc = pglob->gl_pathc;
250 if ((rv = globexp1(pattern, pglob, limit)) != 0)
253 return (globfinal(pglob, limit, oldpathc, origpat));
257 * Expand recursively a glob {} pattern. When there is no more expansion
258 * invoke the standard globbing routine to glob the rest of the magic
262 globexp1(const Char *pattern, glob11_t *pglob, struct glob_limit *limit)
266 if ((ptr = g_strchr(pattern, LBRACE)) != NULL) {
267 if ((pglob->gl_flags & GLOB_LIMIT) &&
268 limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) {
270 return (GLOB_NOSPACE);
272 return (globexp2(ptr, pattern, pglob, limit));
275 return (glob0(pattern, pglob, limit, NULL));
280 * Recursive brace globbing helper. Tries to expand a single brace.
281 * If it succeeds then it invokes globexp1 with the new pattern.
282 * If it fails then it tries to glob the rest of the pattern and returns.
285 globexp2(const Char *ptr, const Char *pattern, glob11_t *pglob,
286 struct glob_limit *limit)
290 const Char *pe, *pm, *pm1, *pl;
291 Char patbuf[MAXPATHLEN];
293 /* copy part up to the brace */
294 for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
299 /* Find the balanced brace */
300 for (i = 0, pe = ++ptr; *pe != EOS; pe++)
301 if (*pe == LBRACKET) {
302 /* Ignore everything between [] */
303 for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
307 * We could not find a matching RBRACKET.
308 * Ignore and just look for RBRACE
313 else if (*pe == LBRACE)
315 else if (*pe == RBRACE) {
321 /* Non matching braces; just glob the pattern */
322 if (i != 0 || *pe == EOS)
323 return (glob0(pattern, pglob, limit, NULL));
325 for (i = 0, pl = pm = ptr; pm <= pe; pm++)
328 /* Ignore everything between [] */
329 for (pm1 = pm++; *pm != RBRACKET && *pm != EOS; pm++)
333 * We could not find a matching RBRACKET.
334 * Ignore and just look for RBRACE
351 if (i && *pm == COMMA)
354 /* Append the current string */
355 for (lm = ls; (pl < pm); *lm++ = *pl++)
358 * Append the rest of the pattern after the
361 for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
364 /* Expand the current pattern */
366 qprintf("globexp2:", patbuf);
368 rv = globexp1(patbuf, pglob, limit);
372 /* move after the comma, to the next string */
386 * expand tilde from the passwd file.
389 globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob11_t *pglob)
396 wchar_t wbuf[MAXPATHLEN];
397 wchar_t *wbufend, *dc;
402 if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
406 * Copy up to the end of the string or /
408 eb = &patbuf[patbuf_len - 1];
409 for (p = pattern + 1, b = patbuf;
410 b < eb && *p != EOS && UNPROT(*p) != SEP; *b++ = *p++)
413 if (*p != EOS && UNPROT(*p) != SEP)
419 if (patbuf[0] == EOS) {
421 * handle a plain ~ or ~/ by expanding $HOME first (iff
422 * we're not running setuid or setgid) and then trying
425 if (issetugid() != 0 ||
426 (h = getenv("HOME")) == NULL) {
427 if (((h = getlogin()) != NULL &&
428 (pwd = getpwnam(h)) != NULL) ||
429 (pwd = getpwuid(getuid())) != NULL)
439 if (g_Ctoc(patbuf, (char *)wbuf, sizeof(wbuf)))
441 if ((pwd = getpwnam((char *)wbuf)) == NULL)
447 /* Copy the home directory */
450 wbufend = wbuf + MAXPATHLEN - 1;
452 memset(&mbs, 0, sizeof(mbs));
453 while (dc <= wbufend) {
454 clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
455 if (clen == (size_t)-1 || clen == (size_t)-2) {
456 /* XXX See initial comment #2. */
457 wc = (unsigned char)*sc;
459 memset(&mbs, 0, sizeof(mbs));
461 if ((*dc++ = wc) == EOS) {
471 for (b = patbuf; b < eb && *dc != EOS; *b++ = *dc++ | M_PROTECT)
476 /* Append the rest of the pattern */
480 if ((*b++ = *p++) == EOS) {
495 * The main glob() routine: compiles the pattern (optionally processing
496 * quotes), calls glob1() to do the real pattern matching, and finally
497 * sorts the list (unless unsorted operation is requested). Returns 0
498 * if things went well, nonzero if errors occurred.
501 glob0(const Char *pattern, glob11_t *pglob, struct glob_limit *limit,
502 const char *origpat) {
503 const Char *qpatnext;
506 Char *bufnext, c, patbuf[MAXPATHLEN];
508 qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
509 if (qpatnext == NULL) {
511 return (GLOB_NOSPACE);
513 oldpathc = pglob->gl_pathc;
516 /* We don't need to check for buffer overflow any more. */
517 while ((c = *qpatnext++) != EOS) {
523 if (*qpatnext == EOS ||
524 g_strchr(qpatnext+1, RBRACKET) == NULL) {
525 *bufnext++ = LBRACKET;
535 *bufnext++ = CHAR(c);
536 if (*qpatnext == RANGE &&
537 (c = qpatnext[1]) != RBRACKET) {
539 *bufnext++ = CHAR(c);
542 } while ((c = *qpatnext++) != RBRACKET);
543 pglob->gl_flags |= GLOB_MAGCHAR;
547 pglob->gl_flags |= GLOB_MAGCHAR;
551 pglob->gl_flags |= GLOB_MAGCHAR;
552 /* collapse adjacent stars to one,
553 * to avoid exponential behavior
555 if (bufnext == patbuf || bufnext[-1] != M_ALL)
559 *bufnext++ = CHAR(c);
565 qprintf("glob0:", patbuf);
568 if ((err = glob1(patbuf, pglob, limit)) != 0)
572 return (globfinal(pglob, limit, oldpathc, origpat));
578 globfinal(glob11_t *pglob, struct glob_limit *limit, size_t oldpathc,
579 const char *origpat) {
580 if (pglob->gl_pathc == oldpathc)
581 return (err_nomatch(pglob, limit, origpat));
583 if (!(pglob->gl_flags & GLOB_NOSORT))
584 qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
585 pglob->gl_pathc - oldpathc, sizeof(char *), compare);
591 compare(const void *p, const void *q)
593 return (strcoll(*(char **)p, *(char **)q));
597 glob1(Char *pattern, glob11_t *pglob, struct glob_limit *limit)
599 Char pathbuf[MAXPATHLEN];
601 /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
604 return (glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
605 pattern, pglob, limit));
609 * The functions glob2 and glob3 are mutually recursive; there is one level
610 * of recursion for each segment in the pattern that contains one or more
614 glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern,
615 glob11_t *pglob, struct glob_limit *limit)
617 struct freebsd11_stat sb;
622 * Loop over pattern segments until end of pattern or until
623 * segment with meta character found.
625 for (anymeta = 0;;) {
626 if (*pattern == EOS) { /* End of pattern? */
628 if (g_lstat(pathbuf, &sb, pglob))
631 if ((pglob->gl_flags & GLOB_LIMIT) &&
632 limit->l_stat_cnt++ >= GLOB_LIMIT_STAT) {
634 return (GLOB_NOSPACE);
636 if ((pglob->gl_flags & GLOB_MARK) &&
637 UNPROT(pathend[-1]) != SEP &&
638 (S_ISDIR(sb.st_mode) ||
639 (S_ISLNK(sb.st_mode) &&
640 g_stat(pathbuf, &sb, pglob) == 0 &&
641 S_ISDIR(sb.st_mode)))) {
642 if (pathend + 1 > pathend_last) {
644 return (GLOB_NOSPACE);
650 return (globextend(pathbuf, pglob, limit, NULL));
653 /* Find end of next segment, copy tentatively to pathend. */
656 while (*p != EOS && UNPROT(*p) != SEP) {
659 if (q + 1 > pathend_last) {
661 return (GLOB_NOSPACE);
666 if (!anymeta) { /* No expansion, do next segment. */
669 while (UNPROT(*pattern) == SEP) {
670 if (pathend + 1 > pathend_last) {
672 return (GLOB_NOSPACE);
674 *pathend++ = *pattern++;
676 } else /* Need expansion, recurse. */
677 return (glob3(pathbuf, pathend, pathend_last, pattern,
684 glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
685 Char *pattern, Char *restpattern,
686 glob11_t *pglob, struct glob_limit *limit)
688 struct freebsd11_dirent *dp;
690 int err, too_long, saverrno, saverrno2;
691 char buf[MAXPATHLEN + MB_LEN_MAX - 1];
693 struct freebsd11_dirent *(*readdirfunc)(DIR *);
695 if (pathend > pathend_last) {
697 return (GLOB_NOSPACE);
700 if (pglob->gl_errfunc != NULL &&
701 g_Ctoc(pathbuf, buf, sizeof(buf))) {
703 return (GLOB_NOSPACE);
708 if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
709 if (errno == ENOENT || errno == ENOTDIR)
711 err = err_aborted(pglob, errno, buf);
719 /* pglob->gl_readdir takes a void *, fix this manually */
720 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
722 (struct freebsd11_dirent *(*)(DIR *))pglob->gl_readdir;
724 readdirfunc = freebsd11_readdir;
727 /* Search directory for matching names. */
728 while ((dp = (*readdirfunc)(dirp)) != NULL) {
735 if ((pglob->gl_flags & GLOB_LIMIT) &&
736 limit->l_readdir_cnt++ >= GLOB_LIMIT_READDIR) {
742 /* Initial DOT must be matched literally. */
743 if (dp->d_name[0] == '.' && UNPROT(*pattern) != DOT) {
747 memset(&mbs, 0, sizeof(mbs));
751 while (dc <= pathend_last) {
752 clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
753 if (clen == (size_t)-1 || clen == (size_t)-2) {
754 /* XXX See initial comment #2. */
755 wc = (unsigned char)*sc;
757 memset(&mbs, 0, sizeof(mbs));
759 if ((*dc++ = wc) == EOS) {
765 if (too_long && (err = err_aborted(pglob, ENAMETOOLONG,
767 errno = ENAMETOOLONG;
770 if (too_long || !match(pathend, pattern, restpattern)) {
777 err = glob2(pathbuf, --dc, pathend_last, restpattern,
785 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
786 (*pglob->gl_closedir)(dirp);
794 if (dp == NULL && errno != 0 &&
795 (err = err_aborted(pglob, errno, buf)))
805 * Extend the gl_pathv member of a glob11_t structure to accommodate a new item,
806 * add the new item, and update gl_pathc.
808 * This assumes the BSD realloc, which only copies the block when its size
809 * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
812 * Return 0 if new item added, error code if memory couldn't be allocated.
814 * Invariant of the glob11_t structure:
815 * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
816 * gl_pathv points to (gl_offs + gl_pathc + 1) items.
819 globextend(const Char *path, glob11_t *pglob, struct glob_limit *limit,
827 if ((pglob->gl_flags & GLOB_LIMIT) &&
828 pglob->gl_matchc > limit->l_path_lim) {
830 return (GLOB_NOSPACE);
833 newn = 2 + pglob->gl_pathc + pglob->gl_offs;
834 /* reallocarray(NULL, newn, size) is equivalent to malloc(newn*size). */
835 pathv = reallocarray(pglob->gl_pathv, newn, sizeof(*pathv));
837 return (GLOB_NOSPACE);
839 if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
840 /* first time around -- clear initial gl_offs items */
841 pathv += pglob->gl_offs;
842 for (i = pglob->gl_offs + 1; --i > 0; )
845 pglob->gl_pathv = pathv;
848 copy = strdup(origpat);
850 for (p = path; *p++ != EOS;)
852 len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */
853 if ((copy = malloc(len)) != NULL) {
854 if (g_Ctoc(path, copy, len)) {
857 return (GLOB_NOSPACE);
862 limit->l_string_cnt += strlen(copy) + 1;
863 if ((pglob->gl_flags & GLOB_LIMIT) &&
864 limit->l_string_cnt >= GLOB_LIMIT_STRING) {
867 return (GLOB_NOSPACE);
869 pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
871 pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
872 return (copy == NULL ? GLOB_NOSPACE : 0);
876 * pattern matching function for filenames.
879 match(Char *name, Char *pat, Char *patend)
881 int ok, negate_range;
882 Char c, k, *nextp, *nextn;
883 struct xlocale_collate *table =
884 (struct xlocale_collate*)__get_locale()->components[XLC_COLLATE];
890 while (pat < patend) {
892 switch (c & M_MASK) {
907 if ((k = *name++) == EOS)
909 negate_range = ((*pat & M_MASK) == M_NOT);
910 if (negate_range != 0)
912 while (((c = *pat++) & M_MASK) != M_END)
913 if ((*pat & M_MASK) == M_RNG) {
914 if (table->__collate_load_error ?
915 CHAR(c) <= CHAR(k) &&
916 CHAR(k) <= CHAR(pat[1]) :
917 __wcollate_range_cmp(CHAR(c),
919 __wcollate_range_cmp(CHAR(k),
925 if (ok == negate_range)
946 /* Free allocated data belonging to a glob11_t structure. */
948 freebsd11_globfree(glob11_t *pglob)
953 if (pglob->gl_pathv != NULL) {
954 pp = pglob->gl_pathv + pglob->gl_offs;
955 for (i = pglob->gl_pathc; i--; ++pp)
958 free(pglob->gl_pathv);
959 pglob->gl_pathv = NULL;
964 g_opendir(Char *str, glob11_t *pglob)
966 char buf[MAXPATHLEN + MB_LEN_MAX - 1];
971 if (g_Ctoc(str, buf, sizeof(buf))) {
972 errno = ENAMETOOLONG;
977 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
978 return ((*pglob->gl_opendir)(buf));
980 return (opendir(buf));
984 g_lstat(Char *fn, struct freebsd11_stat *sb, glob11_t *pglob)
986 char buf[MAXPATHLEN + MB_LEN_MAX - 1];
988 if (g_Ctoc(fn, buf, sizeof(buf))) {
989 errno = ENAMETOOLONG;
992 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
993 return((*pglob->gl_lstat)(buf, sb));
994 return (freebsd11_lstat(buf, sb));
998 g_stat(Char *fn, struct freebsd11_stat *sb, glob11_t *pglob)
1000 char buf[MAXPATHLEN + MB_LEN_MAX - 1];
1002 if (g_Ctoc(fn, buf, sizeof(buf))) {
1003 errno = ENAMETOOLONG;
1006 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1007 return ((*pglob->gl_stat)(buf, sb));
1008 return (freebsd11_stat(buf, sb));
1012 g_strchr(const Char *str, wchar_t ch)
1023 g_Ctoc(const Char *str, char *buf, size_t len)
1028 memset(&mbs, 0, sizeof(mbs));
1029 while (len >= MB_CUR_MAX) {
1030 clen = wcrtomb(buf, CHAR(*str), &mbs);
1031 if (clen == (size_t)-1) {
1032 /* XXX See initial comment #2. */
1033 *buf = (char)CHAR(*str);
1035 memset(&mbs, 0, sizeof(mbs));
1037 if (CHAR(*str) == EOS)
1047 err_nomatch(glob11_t *pglob, struct glob_limit *limit, const char *origpat) {
1049 * If there was no match we are going to append the origpat
1050 * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
1051 * and the origpat did not contain any magic characters
1052 * GLOB_NOMAGIC is there just for compatibility with csh.
1054 if ((pglob->gl_flags & GLOB_NOCHECK) ||
1055 ((pglob->gl_flags & GLOB_NOMAGIC) &&
1056 !(pglob->gl_flags & GLOB_MAGCHAR)))
1057 return (globextend(NULL, pglob, limit, origpat));
1058 return (GLOB_NOMATCH);
1062 err_aborted(glob11_t *pglob, int err, char *buf) {
1063 if ((pglob->gl_errfunc != NULL && pglob->gl_errfunc(buf, err)) ||
1064 (pglob->gl_flags & GLOB_ERR))
1065 return (GLOB_ABORTED);
1071 qprintf(const char *str, Char *s)
1075 (void)printf("%s\n", str);
1077 for (p = s; *p != EOS; p++)
1078 (void)printf("%c", (char)CHAR(*p));
1080 for (p = s; *p != EOS; p++)
1081 (void)printf("%c", (isprot(*p) ? '\\' : ' '));
1083 for (p = s; *p != EOS; p++)
1084 (void)printf("%c", (ismeta(*p) ? '_' : ' '));
1090 __sym_compat(glob, freebsd11_glob, FBSD_1.0);
1091 __sym_compat(globfree, freebsd11_globfree, FBSD_1.0);