1 /* Copyright (C) 1991-1993,1996-2001,2003-2005,2007,2010,2011
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 int no_leading_period
;
27 /* Match STRING against the filename pattern PATTERN, returning zero if
28 it matches, nonzero if not. */
29 static int FCT (const CHAR
*pattern
, const CHAR
*string
,
30 const CHAR
*string_end
, int no_leading_period
, int flags
,
31 struct STRUCT
*ends
, size_t alloca_used
)
33 static int EXT (INT opt
, const CHAR
*pattern
, const CHAR
*string
,
34 const CHAR
*string_end
, int no_leading_period
, int flags
,
37 static const CHAR
*END (const CHAR
*patternp
) internal_function
;
41 FCT (pattern
, string
, string_end
, no_leading_period
, flags
, ends
, alloca_used
)
44 const CHAR
*string_end
;
45 int no_leading_period
;
50 register const CHAR
*p
= pattern
, *n
= string
;
53 # if WIDE_CHAR_VERSION
54 const char *collseq
= (const char *)
55 _NL_CURRENT(LC_COLLATE
, _NL_COLLATE_COLLSEQWC
);
57 const UCHAR
*collseq
= (const UCHAR
*)
58 _NL_CURRENT(LC_COLLATE
, _NL_COLLATE_COLLSEQMB
);
62 while ((c
= *p
++) != L('\0'))
64 int new_no_leading_period
= 0;
70 if (__builtin_expect (flags
& FNM_EXTMATCH
, 0) && *p
== '(')
72 int res
= EXT (c
, p
, n
, string_end
, no_leading_period
,
80 else if (*n
== L('/') && (flags
& FNM_FILE_NAME
))
82 else if (*n
== L('.') && no_leading_period
)
87 if (!(flags
& FNM_NOESCAPE
))
91 /* Trailing \ loses. */
95 if (n
== string_end
|| FOLD ((UCHAR
) *n
) != c
)
100 if (__builtin_expect (flags
& FNM_EXTMATCH
, 0) && *p
== '(')
102 int res
= EXT (c
, p
, n
, string_end
, no_leading_period
,
107 else if (ends
!= NULL
)
109 ends
->pattern
= p
- 1;
111 ends
->no_leading_period
= no_leading_period
;
115 if (n
!= string_end
&& *n
== L('.') && no_leading_period
)
118 for (c
= *p
++; c
== L('?') || c
== L('*'); c
= *p
++)
120 if (*p
== L('(') && (flags
& FNM_EXTMATCH
) != 0)
122 const CHAR
*endp
= END (p
);
125 /* This is a pattern. Skip over it. */
133 /* A ? needs to match one character. */
135 /* There isn't another character; no match. */
137 else if (*n
== L('/')
138 && __builtin_expect (flags
& FNM_FILE_NAME
, 0))
139 /* A slash does not match a wildcard under
143 /* One character of the string is consumed in matching
144 this ? wildcard, so *??? won't match if there are
145 less than three characters. */
151 /* The wildcard(s) is/are the last element of the pattern.
152 If the name is a file name and contains another slash
153 this means it cannot match, unless the FNM_LEADING_DIR
156 int result
= (flags
& FNM_FILE_NAME
) == 0 ? 0 : FNM_NOMATCH
;
158 if (flags
& FNM_FILE_NAME
)
160 if (flags
& FNM_LEADING_DIR
)
164 if (MEMCHR (n
, L('/'), string_end
- n
) == NULL
)
177 endp
= MEMCHR (n
, (flags
& FNM_FILE_NAME
) ? L('/') : L('\0'),
183 || (__builtin_expect (flags
& FNM_EXTMATCH
, 0) != 0
184 && (c
== L('@') || c
== L('+') || c
== L('!'))
187 int flags2
= ((flags
& FNM_FILE_NAME
)
188 ? flags
: (flags
& ~FNM_PERIOD
));
190 for (--p
; n
< endp
; ++n
, no_leading_period
= 0)
191 if (FCT (p
, n
, string_end
, no_leading_period
, flags2
,
192 &end
, alloca_used
) == 0)
195 else if (c
== L('/') && (flags
& FNM_FILE_NAME
))
197 while (n
< string_end
&& *n
!= L('/'))
199 if (n
< string_end
&& *n
== L('/')
200 && (FCT (p
, n
+ 1, string_end
, flags
& FNM_PERIOD
, flags
,
201 NULL
, alloca_used
) == 0))
206 int flags2
= ((flags
& FNM_FILE_NAME
)
207 ? flags
: (flags
& ~FNM_PERIOD
));
209 if (c
== L('\\') && !(flags
& FNM_NOESCAPE
))
212 for (--p
; n
< endp
; ++n
, no_leading_period
= 0)
213 if (FOLD ((UCHAR
) *n
) == c
214 && (FCT (p
, n
, string_end
, no_leading_period
, flags2
,
215 &end
, alloca_used
) == 0))
218 if (end
.pattern
== NULL
)
222 if (end
.pattern
!= NULL
)
226 no_leading_period
= end
.no_leading_period
;
232 /* If we come here no match is possible with the wildcard. */
237 /* Nonzero if the sense of the character class is inverted. */
238 const CHAR
*p_init
= p
;
239 const CHAR
*n_init
= n
;
244 if (posixly_correct
== 0)
245 posixly_correct
= getenv ("POSIXLY_CORRECT") != NULL
? 1 : -1;
250 if (*n
== L('.') && no_leading_period
)
253 if (*n
== L('/') && (flags
& FNM_FILE_NAME
))
254 /* `/' cannot be matched. */
257 not = (*p
== L('!') || (posixly_correct
< 0 && *p
== L('^')));
261 fn
= FOLD ((UCHAR
) *n
);
266 if (!(flags
& FNM_NOESCAPE
) && c
== L('\\'))
270 c
= FOLD ((UCHAR
) *p
);
275 else if (c
== L('[') && *p
== L(':'))
277 /* Leave room for the null. */
278 CHAR str
[CHAR_CLASS_MAX_LENGTH
+ 1];
280 #if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H)
283 const CHAR
*startp
= p
;
287 if (c1
== CHAR_CLASS_MAX_LENGTH
)
288 /* The name is too long and therefore the pattern
293 if (c
== L(':') && p
[1] == L(']'))
298 if (c
< L('a') || c
>= L('z'))
300 /* This cannot possibly be a character class name.
301 Match it as a normal range. */
310 #if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H)
311 wt
= IS_CHAR_CLASS (str
);
313 /* Invalid character class name. */
316 # if defined _LIBC && ! WIDE_CHAR_VERSION
317 /* The following code is glibc specific but does
318 there a good job in speeding up the code since
319 we can avoid the btowc() call. */
320 if (_ISCTYPE ((UCHAR
) *n
, wt
))
323 if (ISWCTYPE (BTOWC ((UCHAR
) *n
), wt
))
327 if ((STREQ (str
, L("alnum")) && ISALNUM ((UCHAR
) *n
))
328 || (STREQ (str
, L("alpha")) && ISALPHA ((UCHAR
) *n
))
329 || (STREQ (str
, L("blank")) && ISBLANK ((UCHAR
) *n
))
330 || (STREQ (str
, L("cntrl")) && ISCNTRL ((UCHAR
) *n
))
331 || (STREQ (str
, L("digit")) && ISDIGIT ((UCHAR
) *n
))
332 || (STREQ (str
, L("graph")) && ISGRAPH ((UCHAR
) *n
))
333 || (STREQ (str
, L("lower")) && ISLOWER ((UCHAR
) *n
))
334 || (STREQ (str
, L("print")) && ISPRINT ((UCHAR
) *n
))
335 || (STREQ (str
, L("punct")) && ISPUNCT ((UCHAR
) *n
))
336 || (STREQ (str
, L("space")) && ISSPACE ((UCHAR
) *n
))
337 || (STREQ (str
, L("upper")) && ISUPPER ((UCHAR
) *n
))
338 || (STREQ (str
, L("xdigit")) && ISXDIGIT ((UCHAR
) *n
)))
344 else if (c
== L('[') && *p
== L('='))
348 _NL_CURRENT_WORD (LC_COLLATE
, _NL_COLLATE_NRULES
);
349 const CHAR
*startp
= p
;
361 if (c
!= L('=') || p
[1] != L(']'))
371 if ((UCHAR
) *n
== str
[0])
376 const int32_t *table
;
377 # if WIDE_CHAR_VERSION
378 const int32_t *weights
;
379 const int32_t *extra
;
381 const unsigned char *weights
;
382 const unsigned char *extra
;
384 const int32_t *indirect
;
386 const UCHAR
*cp
= (const UCHAR
*) str
;
388 /* This #include defines a local function! */
389 # if WIDE_CHAR_VERSION
390 # include <locale/weightwc.h>
392 # include <locale/weight.h>
395 # if WIDE_CHAR_VERSION
396 table
= (const int32_t *)
397 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_TABLEWC
);
398 weights
= (const int32_t *)
399 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_WEIGHTWC
);
400 extra
= (const int32_t *)
401 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_EXTRAWC
);
402 indirect
= (const int32_t *)
403 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_INDIRECTWC
);
405 table
= (const int32_t *)
406 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_TABLEMB
);
407 weights
= (const unsigned char *)
408 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_WEIGHTMB
);
409 extra
= (const unsigned char *)
410 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_EXTRAMB
);
411 indirect
= (const int32_t *)
412 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_INDIRECTMB
);
415 idx
= findidx (&cp
, 1);
418 /* We found a table entry. Now see whether the
419 character we are currently at has the same
420 equivalance class value. */
421 int len
= weights
[idx
& 0xffffff];
423 const UCHAR
*np
= (const UCHAR
*) n
;
425 idx2
= findidx (&np
, string_end
- n
);
427 && (idx
>> 24) == (idx2
>> 24)
428 && len
== weights
[idx2
& 0xffffff])
436 && (weights
[idx
+ 1 + cnt
]
437 == weights
[idx2
+ 1 + cnt
]))
449 else if (c
== L('\0'))
451 /* [ unterminated, treat as normal character. */
464 if (c
== L('[') && *p
== L('.'))
467 _NL_CURRENT_WORD (LC_COLLATE
, _NL_COLLATE_NRULES
);
468 const CHAR
*startp
= p
;
474 if (c
== L('.') && p
[1] == L(']'))
484 /* We have to handling the symbols differently in
485 ranges since then the collation sequence is
487 is_range
= *p
== L('-') && p
[1] != L('\0');
491 /* There are no names defined in the collation
492 data. Therefore we only accept the trivial
493 names consisting of the character itself. */
497 if (!is_range
&& *n
== startp
[1])
506 const int32_t *symb_table
;
507 # ifdef WIDE_CHAR_VERSION
511 # define str (startp + 1)
513 const unsigned char *extra
;
519 # ifdef WIDE_CHAR_VERSION
520 /* We have to convert the name to a single-byte
521 string. This is possible since the names
522 consist of ASCII characters and the internal
523 representation is UCS4. */
524 for (strcnt
= 0; strcnt
< c1
; ++strcnt
)
525 str
[strcnt
] = startp
[1 + strcnt
];
529 _NL_CURRENT_WORD (LC_COLLATE
,
530 _NL_COLLATE_SYMB_HASH_SIZEMB
);
531 symb_table
= (const int32_t *)
532 _NL_CURRENT (LC_COLLATE
,
533 _NL_COLLATE_SYMB_TABLEMB
);
534 extra
= (const unsigned char *)
535 _NL_CURRENT (LC_COLLATE
,
536 _NL_COLLATE_SYMB_EXTRAMB
);
538 /* Locate the character in the hashing table. */
539 hash
= elem_hash (str
, c1
);
542 elem
= hash
% table_size
;
543 if (symb_table
[2 * elem
] != 0)
545 second
= hash
% (table_size
- 2) + 1;
549 /* First compare the hashing value. */
550 if (symb_table
[2 * elem
] == hash
552 == extra
[symb_table
[2 * elem
+ 1]])
554 &extra
[symb_table
[2 * elem
558 /* Yep, this is the entry. */
559 idx
= symb_table
[2 * elem
+ 1];
560 idx
+= 1 + extra
[idx
];
567 while (symb_table
[2 * elem
] != 0);
570 if (symb_table
[2 * elem
] != 0)
572 /* Compare the byte sequence but only if
573 this is not part of a range. */
574 # ifdef WIDE_CHAR_VERSION
577 idx
+= 1 + extra
[idx
];
578 /* Adjust for the alignment. */
579 idx
= (idx
+ 3) & ~3;
581 wextra
= (int32_t *) &extra
[idx
+ 4];
586 # ifdef WIDE_CHAR_VERSION
588 (int32_t) c1
< wextra
[idx
];
590 if (n
[c1
] != wextra
[1 + c1
])
593 if ((int32_t) c1
== wextra
[idx
])
596 for (c1
= 0; c1
< extra
[idx
]; ++c1
)
597 if (n
[c1
] != extra
[1 + c1
])
600 if (c1
== extra
[idx
])
605 /* Get the collation sequence value. */
607 # ifdef WIDE_CHAR_VERSION
608 cold
= wextra
[1 + wextra
[idx
]];
610 /* Adjust for the alignment. */
611 idx
+= 1 + extra
[idx
];
612 idx
= (idx
+ 3) & ~4;
613 cold
= *((int32_t *) &extra
[idx
]);
620 /* No valid character. Match it as a
622 if (!is_range
&& *n
== str
[0])
639 /* We have to handling the symbols differently in
640 ranges since then the collation sequence is
642 is_range
= (*p
== L('-') && p
[1] != L('\0')
645 if (!is_range
&& c
== fn
)
648 /* This is needed if we goto normal_bracket; from
649 outside of is_seqval's scope. */
655 if (c
== L('-') && *p
!= L(']'))
658 /* We have to find the collation sequence
659 value for C. Collation sequence is nothing
660 we can regularly access. The sequence
661 value is defined by the order in which the
662 definitions of the collation values for the
663 various characters appear in the source
664 file. A strange concept, nowhere
670 # ifdef WIDE_CHAR_VERSION
671 /* Search in the `names' array for the characters. */
672 fcollseq
= __collseq_table_lookup (collseq
, fn
);
673 if (fcollseq
== ~((uint32_t) 0))
674 /* XXX We don't know anything about the character
675 we are supposed to match. This means we are
677 goto range_not_matched
;
682 lcollseq
= __collseq_table_lookup (collseq
, cold
);
684 fcollseq
= collseq
[fn
];
685 lcollseq
= is_seqval
? cold
: collseq
[(UCHAR
) cold
];
689 if (cend
== L('[') && *p
== L('.'))
692 _NL_CURRENT_WORD (LC_COLLATE
,
694 const CHAR
*startp
= p
;
700 if (c
== L('.') && p
[1] == L(']'))
712 /* There are no names defined in the
713 collation data. Therefore we only
714 accept the trivial names consisting
715 of the character itself. */
724 const int32_t *symb_table
;
725 # ifdef WIDE_CHAR_VERSION
729 # define str (startp + 1)
731 const unsigned char *extra
;
737 # ifdef WIDE_CHAR_VERSION
738 /* We have to convert the name to a single-byte
739 string. This is possible since the names
740 consist of ASCII characters and the internal
741 representation is UCS4. */
742 for (strcnt
= 0; strcnt
< c1
; ++strcnt
)
743 str
[strcnt
] = startp
[1 + strcnt
];
747 _NL_CURRENT_WORD (LC_COLLATE
,
748 _NL_COLLATE_SYMB_HASH_SIZEMB
);
749 symb_table
= (const int32_t *)
750 _NL_CURRENT (LC_COLLATE
,
751 _NL_COLLATE_SYMB_TABLEMB
);
752 extra
= (const unsigned char *)
753 _NL_CURRENT (LC_COLLATE
,
754 _NL_COLLATE_SYMB_EXTRAMB
);
756 /* Locate the character in the hashing
758 hash
= elem_hash (str
, c1
);
761 elem
= hash
% table_size
;
762 if (symb_table
[2 * elem
] != 0)
764 second
= hash
% (table_size
- 2) + 1;
768 /* First compare the hashing value. */
769 if (symb_table
[2 * elem
] == hash
771 == extra
[symb_table
[2 * elem
+ 1]])
773 &extra
[symb_table
[2 * elem
+ 1]
776 /* Yep, this is the entry. */
777 idx
= symb_table
[2 * elem
+ 1];
778 idx
+= 1 + extra
[idx
];
785 while (symb_table
[2 * elem
] != 0);
788 if (symb_table
[2 * elem
] != 0)
790 /* Compare the byte sequence but only if
791 this is not part of a range. */
792 # ifdef WIDE_CHAR_VERSION
795 idx
+= 1 + extra
[idx
];
796 /* Adjust for the alignment. */
797 idx
= (idx
+ 3) & ~4;
799 wextra
= (int32_t *) &extra
[idx
+ 4];
801 /* Get the collation sequence value. */
803 # ifdef WIDE_CHAR_VERSION
804 cend
= wextra
[1 + wextra
[idx
]];
806 /* Adjust for the alignment. */
807 idx
+= 1 + extra
[idx
];
808 idx
= (idx
+ 3) & ~4;
809 cend
= *((int32_t *) &extra
[idx
]);
812 else if (symb_table
[2 * elem
] != 0 && c1
== 1)
824 if (!(flags
& FNM_NOESCAPE
) && cend
== L('\\'))
831 /* XXX It is not entirely clear to me how to handle
832 characters which are not mentioned in the
833 collation specification. */
835 # ifdef WIDE_CHAR_VERSION
836 lcollseq
== 0xffffffff ||
838 lcollseq
<= fcollseq
)
840 /* We have to look at the upper bound. */
847 # ifdef WIDE_CHAR_VERSION
849 __collseq_table_lookup (collseq
, cend
);
850 if (hcollseq
== ~((uint32_t) 0))
852 /* Hum, no information about the upper
853 bound. The matching succeeds if the
854 lower bound is matched exactly. */
855 if (lcollseq
!= fcollseq
)
856 goto range_not_matched
;
861 hcollseq
= collseq
[cend
];
865 if (lcollseq
<= hcollseq
&& fcollseq
<= hcollseq
)
868 # ifdef WIDE_CHAR_VERSION
872 /* We use a boring value comparison of the character
873 values. This is better than comparing using
874 `strcoll' since the latter would have surprising
875 and sometimes fatal consequences. */
878 if (!(flags
& FNM_NOESCAPE
) && cend
== L('\\'))
884 if (cold
<= fn
&& fn
<= cend
)
901 /* Skip the rest of the [...] that already matched. */
908 /* [... (unterminated) loses. */
911 if (!(flags
& FNM_NOESCAPE
) && c
== L('\\'))
915 /* XXX 1003.2d11 is unclear if this is right. */
918 else if (c
== L('[') && *p
== L(':'))
921 const CHAR
*startp
= p
;
926 if (++c1
== CHAR_CLASS_MAX_LENGTH
)
929 if (*p
== L(':') && p
[1] == L(']'))
932 if (c
< L('a') || c
>= L('z'))
941 else if (c
== L('[') && *p
== L('='))
947 if (c
!= L('=') || p
[1] != L(']'))
952 else if (c
== L('[') && *p
== L('.'))
961 if (*p
== L('.') && p
[1] == L(']'))
977 if (__builtin_expect (flags
& FNM_EXTMATCH
, 0) && *p
== '(')
979 int res
= EXT (c
, p
, n
, string_end
, no_leading_period
, flags
,
987 if (NO_LEADING_PERIOD (flags
))
989 if (n
== string_end
|| c
!= (UCHAR
) *n
)
992 new_no_leading_period
= 1;
998 if (n
== string_end
|| c
!= FOLD ((UCHAR
) *n
))
1002 no_leading_period
= new_no_leading_period
;
1006 if (n
== string_end
)
1009 if ((flags
& FNM_LEADING_DIR
) && n
!= string_end
&& *n
== L('/'))
1010 /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
1019 END (const CHAR
*pattern
)
1021 const CHAR
*p
= pattern
;
1024 if (*++p
== L('\0'))
1025 /* This is an invalid pattern. */
1027 else if (*p
== L('['))
1029 /* Handle brackets special. */
1030 if (posixly_correct
== 0)
1031 posixly_correct
= getenv ("POSIXLY_CORRECT") != NULL
? 1 : -1;
1033 /* Skip the not sign. We have to recognize it because of a possibly
1035 if (*++p
== L('!') || (posixly_correct
< 0 && *p
== L('^')))
1037 /* A leading ']' is recognized as such. */
1040 /* Skip over all characters of the list. */
1041 while (*p
!= L(']'))
1042 if (*p
++ == L('\0'))
1043 /* This is no valid pattern. */
1046 else if ((*p
== L('?') || *p
== L('*') || *p
== L('+') || *p
== L('@')
1047 || *p
== L('!')) && p
[1] == L('('))
1049 else if (*p
== L(')'))
1058 EXT (INT opt
, const CHAR
*pattern
, const CHAR
*string
, const CHAR
*string_end
,
1059 int no_leading_period
, int flags
, size_t alloca_used
)
1065 struct patternlist
*next
;
1069 struct patternlist
**lastp
= &list
;
1070 size_t pattern_len
= STRLEN (pattern
);
1071 int any_malloced
= 0;
1076 /* Parse the pattern. Store the individual parts in the list. */
1078 for (startp
= p
= pattern
+ 1; level
>= 0; ++p
)
1081 /* This is an invalid pattern. */
1085 else if (*p
== L('['))
1087 /* Handle brackets special. */
1088 if (posixly_correct
== 0)
1089 posixly_correct
= getenv ("POSIXLY_CORRECT") != NULL
? 1 : -1;
1091 /* Skip the not sign. We have to recognize it because of a possibly
1093 if (*++p
== L('!') || (posixly_correct
< 0 && *p
== L('^')))
1095 /* A leading ']' is recognized as such. */
1098 /* Skip over all characters of the list. */
1099 while (*p
!= L(']'))
1100 if (*p
++ == L('\0'))
1102 /* This is no valid pattern. */
1107 else if ((*p
== L('?') || *p
== L('*') || *p
== L('+') || *p
== L('@')
1108 || *p
== L('!')) && p
[1] == L('('))
1109 /* Remember the nesting level. */
1111 else if (*p
== L(')'))
1115 /* This means we found the end of the pattern. */
1116 #define NEW_PATTERN \
1117 struct patternlist *newp; \
1118 size_t slen = (opt == L('?') || opt == L('@') \
1119 ? pattern_len : (p - startp + 1)); \
1120 slen = sizeof (struct patternlist) + (slen * sizeof (CHAR)); \
1121 int malloced = ! __libc_use_alloca (alloca_used + slen); \
1122 if (__builtin_expect (malloced, 0)) \
1124 newp = malloc (slen); \
1133 newp = alloca_account (slen, alloca_used); \
1134 newp->next = NULL; \
1135 newp->malloced = malloced; \
1136 *((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L('\0'); \
1142 else if (*p
== L('|'))
1150 assert (list
!= NULL
);
1151 assert (p
[-1] == L(')'));
1157 if (FCT (p
, string
, string_end
, no_leading_period
, flags
, NULL
,
1165 for (rs
= string
; rs
<= string_end
; ++rs
)
1166 /* First match the prefix with the current pattern with the
1168 if (FCT (list
->str
, string
, rs
, no_leading_period
,
1169 flags
& FNM_FILE_NAME
? flags
: flags
& ~FNM_PERIOD
,
1170 NULL
, alloca_used
) == 0
1171 /* This was successful. Now match the rest with the rest
1173 && (FCT (p
, rs
, string_end
,
1176 : rs
[-1] == '/' && NO_LEADING_PERIOD (flags
) ? 1 : 0,
1177 flags
& FNM_FILE_NAME
1178 ? flags
: flags
& ~FNM_PERIOD
, NULL
, alloca_used
) == 0
1179 /* This didn't work. Try the whole pattern. */
1181 && FCT (pattern
- 1, rs
, string_end
,
1184 : (rs
[-1] == '/' && NO_LEADING_PERIOD (flags
)
1186 flags
& FNM_FILE_NAME
1187 ? flags
: flags
& ~FNM_PERIOD
, NULL
,
1188 alloca_used
) == 0)))
1189 /* It worked. Signal success. */
1192 while ((list
= list
->next
) != NULL
);
1194 /* None of the patterns lead to a match. */
1195 retval
= FNM_NOMATCH
;
1199 if (FCT (p
, string
, string_end
, no_leading_period
, flags
, NULL
,
1206 /* I cannot believe it but `strcat' is actually acceptable
1207 here. Match the entire string with the prefix from the
1208 pattern list and the rest of the pattern following the
1210 if (FCT (STRCAT (list
->str
, p
), string
, string_end
,
1212 flags
& FNM_FILE_NAME
? flags
: flags
& ~FNM_PERIOD
,
1213 NULL
, alloca_used
) == 0)
1214 /* It worked. Signal success. */
1216 while ((list
= list
->next
) != NULL
);
1218 /* None of the patterns lead to a match. */
1219 retval
= FNM_NOMATCH
;
1223 for (rs
= string
; rs
<= string_end
; ++rs
)
1225 struct patternlist
*runp
;
1227 for (runp
= list
; runp
!= NULL
; runp
= runp
->next
)
1228 if (FCT (runp
->str
, string
, rs
, no_leading_period
,
1229 flags
& FNM_FILE_NAME
? flags
: flags
& ~FNM_PERIOD
,
1230 NULL
, alloca_used
) == 0)
1233 /* If none of the patterns matched see whether the rest does. */
1235 && (FCT (p
, rs
, string_end
,
1238 : rs
[-1] == '/' && NO_LEADING_PERIOD (flags
) ? 1 : 0,
1239 flags
& FNM_FILE_NAME
? flags
: flags
& ~FNM_PERIOD
,
1240 NULL
, alloca_used
) == 0))
1241 /* This is successful. */
1245 /* None of the patterns together with the rest of the pattern
1247 retval
= FNM_NOMATCH
;
1251 assert (! "Invalid extended matching operator");
1259 while (list
!= NULL
)
1261 struct patternlist
*old
= list
;