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, see
17 <http://www.gnu.org/licenses/>. */
23 int no_leading_period
;
26 /* Match STRING against the filename pattern PATTERN, returning zero if
27 it matches, nonzero if not. */
28 static int FCT (const CHAR
*pattern
, const CHAR
*string
,
29 const CHAR
*string_end
, int no_leading_period
, int flags
,
30 struct STRUCT
*ends
, size_t alloca_used
)
32 static int EXT (INT opt
, const CHAR
*pattern
, const CHAR
*string
,
33 const CHAR
*string_end
, int no_leading_period
, int flags
,
36 static const CHAR
*END (const CHAR
*patternp
) internal_function
;
40 FCT (pattern
, string
, string_end
, no_leading_period
, flags
, ends
, alloca_used
)
43 const CHAR
*string_end
;
44 int no_leading_period
;
49 register const CHAR
*p
= pattern
, *n
= string
;
52 # if WIDE_CHAR_VERSION
53 const char *collseq
= (const char *)
54 _NL_CURRENT(LC_COLLATE
, _NL_COLLATE_COLLSEQWC
);
56 const UCHAR
*collseq
= (const UCHAR
*)
57 _NL_CURRENT(LC_COLLATE
, _NL_COLLATE_COLLSEQMB
);
61 while ((c
= *p
++) != L('\0'))
63 int new_no_leading_period
= 0;
69 if (__builtin_expect (flags
& FNM_EXTMATCH
, 0) && *p
== '(')
71 int res
= EXT (c
, p
, n
, string_end
, no_leading_period
,
79 else if (*n
== L('/') && (flags
& FNM_FILE_NAME
))
81 else if (*n
== L('.') && no_leading_period
)
86 if (!(flags
& FNM_NOESCAPE
))
90 /* Trailing \ loses. */
94 if (n
== string_end
|| FOLD ((UCHAR
) *n
) != c
)
99 if (__builtin_expect (flags
& FNM_EXTMATCH
, 0) && *p
== '(')
101 int res
= EXT (c
, p
, n
, string_end
, no_leading_period
,
106 else if (ends
!= NULL
)
108 ends
->pattern
= p
- 1;
110 ends
->no_leading_period
= no_leading_period
;
114 if (n
!= string_end
&& *n
== L('.') && no_leading_period
)
117 for (c
= *p
++; c
== L('?') || c
== L('*'); c
= *p
++)
119 if (*p
== L('(') && (flags
& FNM_EXTMATCH
) != 0)
121 const CHAR
*endp
= END (p
);
124 /* This is a pattern. Skip over it. */
132 /* A ? needs to match one character. */
134 /* There isn't another character; no match. */
136 else if (*n
== L('/')
137 && __builtin_expect (flags
& FNM_FILE_NAME
, 0))
138 /* A slash does not match a wildcard under
142 /* One character of the string is consumed in matching
143 this ? wildcard, so *??? won't match if there are
144 less than three characters. */
150 /* The wildcard(s) is/are the last element of the pattern.
151 If the name is a file name and contains another slash
152 this means it cannot match, unless the FNM_LEADING_DIR
155 int result
= (flags
& FNM_FILE_NAME
) == 0 ? 0 : FNM_NOMATCH
;
157 if (flags
& FNM_FILE_NAME
)
159 if (flags
& FNM_LEADING_DIR
)
163 if (MEMCHR (n
, L('/'), string_end
- n
) == NULL
)
176 endp
= MEMCHR (n
, (flags
& FNM_FILE_NAME
) ? L('/') : L('\0'),
182 || (__builtin_expect (flags
& FNM_EXTMATCH
, 0) != 0
183 && (c
== L('@') || c
== L('+') || c
== L('!'))
186 int flags2
= ((flags
& FNM_FILE_NAME
)
187 ? flags
: (flags
& ~FNM_PERIOD
));
189 for (--p
; n
< endp
; ++n
, no_leading_period
= 0)
190 if (FCT (p
, n
, string_end
, no_leading_period
, flags2
,
191 &end
, alloca_used
) == 0)
194 else if (c
== L('/') && (flags
& FNM_FILE_NAME
))
196 while (n
< string_end
&& *n
!= L('/'))
198 if (n
< string_end
&& *n
== L('/')
199 && (FCT (p
, n
+ 1, string_end
, flags
& FNM_PERIOD
, flags
,
200 NULL
, alloca_used
) == 0))
205 int flags2
= ((flags
& FNM_FILE_NAME
)
206 ? flags
: (flags
& ~FNM_PERIOD
));
208 if (c
== L('\\') && !(flags
& FNM_NOESCAPE
))
211 for (--p
; n
< endp
; ++n
, no_leading_period
= 0)
212 if (FOLD ((UCHAR
) *n
) == c
213 && (FCT (p
, n
, string_end
, no_leading_period
, flags2
,
214 &end
, alloca_used
) == 0))
217 if (end
.pattern
== NULL
)
221 if (end
.pattern
!= NULL
)
225 no_leading_period
= end
.no_leading_period
;
231 /* If we come here no match is possible with the wildcard. */
236 /* Nonzero if the sense of the character class is inverted. */
237 const CHAR
*p_init
= p
;
238 const CHAR
*n_init
= n
;
243 if (posixly_correct
== 0)
244 posixly_correct
= getenv ("POSIXLY_CORRECT") != NULL
? 1 : -1;
249 if (*n
== L('.') && no_leading_period
)
252 if (*n
== L('/') && (flags
& FNM_FILE_NAME
))
253 /* `/' cannot be matched. */
256 not = (*p
== L('!') || (posixly_correct
< 0 && *p
== L('^')));
260 fn
= FOLD ((UCHAR
) *n
);
265 if (!(flags
& FNM_NOESCAPE
) && c
== L('\\'))
269 c
= FOLD ((UCHAR
) *p
);
274 else if (c
== L('[') && *p
== L(':'))
276 /* Leave room for the null. */
277 CHAR str
[CHAR_CLASS_MAX_LENGTH
+ 1];
279 #if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H)
282 const CHAR
*startp
= p
;
286 if (c1
== CHAR_CLASS_MAX_LENGTH
)
287 /* The name is too long and therefore the pattern
292 if (c
== L(':') && p
[1] == L(']'))
297 if (c
< L('a') || c
>= L('z'))
299 /* This cannot possibly be a character class name.
300 Match it as a normal range. */
309 #if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H)
310 wt
= IS_CHAR_CLASS (str
);
312 /* Invalid character class name. */
315 # if defined _LIBC && ! WIDE_CHAR_VERSION
316 /* The following code is glibc specific but does
317 there a good job in speeding up the code since
318 we can avoid the btowc() call. */
319 if (_ISCTYPE ((UCHAR
) *n
, wt
))
322 if (ISWCTYPE (BTOWC ((UCHAR
) *n
), wt
))
326 if ((STREQ (str
, L("alnum")) && ISALNUM ((UCHAR
) *n
))
327 || (STREQ (str
, L("alpha")) && ISALPHA ((UCHAR
) *n
))
328 || (STREQ (str
, L("blank")) && ISBLANK ((UCHAR
) *n
))
329 || (STREQ (str
, L("cntrl")) && ISCNTRL ((UCHAR
) *n
))
330 || (STREQ (str
, L("digit")) && ISDIGIT ((UCHAR
) *n
))
331 || (STREQ (str
, L("graph")) && ISGRAPH ((UCHAR
) *n
))
332 || (STREQ (str
, L("lower")) && ISLOWER ((UCHAR
) *n
))
333 || (STREQ (str
, L("print")) && ISPRINT ((UCHAR
) *n
))
334 || (STREQ (str
, L("punct")) && ISPUNCT ((UCHAR
) *n
))
335 || (STREQ (str
, L("space")) && ISSPACE ((UCHAR
) *n
))
336 || (STREQ (str
, L("upper")) && ISUPPER ((UCHAR
) *n
))
337 || (STREQ (str
, L("xdigit")) && ISXDIGIT ((UCHAR
) *n
)))
343 else if (c
== L('[') && *p
== L('='))
347 _NL_CURRENT_WORD (LC_COLLATE
, _NL_COLLATE_NRULES
);
348 const CHAR
*startp
= p
;
360 if (c
!= L('=') || p
[1] != L(']'))
370 if ((UCHAR
) *n
== str
[0])
375 const int32_t *table
;
376 # if WIDE_CHAR_VERSION
377 const int32_t *weights
;
378 const int32_t *extra
;
380 const unsigned char *weights
;
381 const unsigned char *extra
;
383 const int32_t *indirect
;
385 const UCHAR
*cp
= (const UCHAR
*) str
;
387 /* This #include defines a local function! */
388 # if WIDE_CHAR_VERSION
389 # include <locale/weightwc.h>
391 # include <locale/weight.h>
394 # if WIDE_CHAR_VERSION
395 table
= (const int32_t *)
396 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_TABLEWC
);
397 weights
= (const int32_t *)
398 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_WEIGHTWC
);
399 extra
= (const int32_t *)
400 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_EXTRAWC
);
401 indirect
= (const int32_t *)
402 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_INDIRECTWC
);
404 table
= (const int32_t *)
405 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_TABLEMB
);
406 weights
= (const unsigned char *)
407 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_WEIGHTMB
);
408 extra
= (const unsigned char *)
409 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_EXTRAMB
);
410 indirect
= (const int32_t *)
411 _NL_CURRENT (LC_COLLATE
, _NL_COLLATE_INDIRECTMB
);
414 idx
= findidx (&cp
, 1);
417 /* We found a table entry. Now see whether the
418 character we are currently at has the same
419 equivalance class value. */
420 int len
= weights
[idx
& 0xffffff];
422 const UCHAR
*np
= (const UCHAR
*) n
;
424 idx2
= findidx (&np
, string_end
- n
);
426 && (idx
>> 24) == (idx2
>> 24)
427 && len
== weights
[idx2
& 0xffffff])
435 && (weights
[idx
+ 1 + cnt
]
436 == weights
[idx2
+ 1 + cnt
]))
448 else if (c
== L('\0'))
450 /* [ unterminated, treat as normal character. */
463 if (c
== L('[') && *p
== L('.'))
466 _NL_CURRENT_WORD (LC_COLLATE
, _NL_COLLATE_NRULES
);
467 const CHAR
*startp
= p
;
473 if (c
== L('.') && p
[1] == L(']'))
483 /* We have to handling the symbols differently in
484 ranges since then the collation sequence is
486 is_range
= *p
== L('-') && p
[1] != L('\0');
490 /* There are no names defined in the collation
491 data. Therefore we only accept the trivial
492 names consisting of the character itself. */
496 if (!is_range
&& *n
== startp
[1])
505 const int32_t *symb_table
;
506 # ifdef WIDE_CHAR_VERSION
510 # define str (startp + 1)
512 const unsigned char *extra
;
518 # ifdef WIDE_CHAR_VERSION
519 /* We have to convert the name to a single-byte
520 string. This is possible since the names
521 consist of ASCII characters and the internal
522 representation is UCS4. */
523 for (strcnt
= 0; strcnt
< c1
; ++strcnt
)
524 str
[strcnt
] = startp
[1 + strcnt
];
528 _NL_CURRENT_WORD (LC_COLLATE
,
529 _NL_COLLATE_SYMB_HASH_SIZEMB
);
530 symb_table
= (const int32_t *)
531 _NL_CURRENT (LC_COLLATE
,
532 _NL_COLLATE_SYMB_TABLEMB
);
533 extra
= (const unsigned char *)
534 _NL_CURRENT (LC_COLLATE
,
535 _NL_COLLATE_SYMB_EXTRAMB
);
537 /* Locate the character in the hashing table. */
538 hash
= elem_hash (str
, c1
);
541 elem
= hash
% table_size
;
542 if (symb_table
[2 * elem
] != 0)
544 second
= hash
% (table_size
- 2) + 1;
548 /* First compare the hashing value. */
549 if (symb_table
[2 * elem
] == hash
551 == extra
[symb_table
[2 * elem
+ 1]])
553 &extra
[symb_table
[2 * elem
557 /* Yep, this is the entry. */
558 idx
= symb_table
[2 * elem
+ 1];
559 idx
+= 1 + extra
[idx
];
566 while (symb_table
[2 * elem
] != 0);
569 if (symb_table
[2 * elem
] != 0)
571 /* Compare the byte sequence but only if
572 this is not part of a range. */
573 # ifdef WIDE_CHAR_VERSION
576 idx
+= 1 + extra
[idx
];
577 /* Adjust for the alignment. */
578 idx
= (idx
+ 3) & ~3;
580 wextra
= (int32_t *) &extra
[idx
+ 4];
585 # ifdef WIDE_CHAR_VERSION
587 (int32_t) c1
< wextra
[idx
];
589 if (n
[c1
] != wextra
[1 + c1
])
592 if ((int32_t) c1
== wextra
[idx
])
595 for (c1
= 0; c1
< extra
[idx
]; ++c1
)
596 if (n
[c1
] != extra
[1 + c1
])
599 if (c1
== extra
[idx
])
604 /* Get the collation sequence value. */
606 # ifdef WIDE_CHAR_VERSION
607 cold
= wextra
[1 + wextra
[idx
]];
609 /* Adjust for the alignment. */
610 idx
+= 1 + extra
[idx
];
611 idx
= (idx
+ 3) & ~4;
612 cold
= *((int32_t *) &extra
[idx
]);
619 /* No valid character. Match it as a
621 if (!is_range
&& *n
== str
[0])
638 /* We have to handling the symbols differently in
639 ranges since then the collation sequence is
641 is_range
= (*p
== L('-') && p
[1] != L('\0')
644 if (!is_range
&& c
== fn
)
647 /* This is needed if we goto normal_bracket; from
648 outside of is_seqval's scope. */
654 if (c
== L('-') && *p
!= L(']'))
657 /* We have to find the collation sequence
658 value for C. Collation sequence is nothing
659 we can regularly access. The sequence
660 value is defined by the order in which the
661 definitions of the collation values for the
662 various characters appear in the source
663 file. A strange concept, nowhere
669 # ifdef WIDE_CHAR_VERSION
670 /* Search in the `names' array for the characters. */
671 fcollseq
= __collseq_table_lookup (collseq
, fn
);
672 if (fcollseq
== ~((uint32_t) 0))
673 /* XXX We don't know anything about the character
674 we are supposed to match. This means we are
676 goto range_not_matched
;
681 lcollseq
= __collseq_table_lookup (collseq
, cold
);
683 fcollseq
= collseq
[fn
];
684 lcollseq
= is_seqval
? cold
: collseq
[(UCHAR
) cold
];
688 if (cend
== L('[') && *p
== L('.'))
691 _NL_CURRENT_WORD (LC_COLLATE
,
693 const CHAR
*startp
= p
;
699 if (c
== L('.') && p
[1] == L(']'))
711 /* There are no names defined in the
712 collation data. Therefore we only
713 accept the trivial names consisting
714 of the character itself. */
723 const int32_t *symb_table
;
724 # ifdef WIDE_CHAR_VERSION
728 # define str (startp + 1)
730 const unsigned char *extra
;
736 # ifdef WIDE_CHAR_VERSION
737 /* We have to convert the name to a single-byte
738 string. This is possible since the names
739 consist of ASCII characters and the internal
740 representation is UCS4. */
741 for (strcnt
= 0; strcnt
< c1
; ++strcnt
)
742 str
[strcnt
] = startp
[1 + strcnt
];
746 _NL_CURRENT_WORD (LC_COLLATE
,
747 _NL_COLLATE_SYMB_HASH_SIZEMB
);
748 symb_table
= (const int32_t *)
749 _NL_CURRENT (LC_COLLATE
,
750 _NL_COLLATE_SYMB_TABLEMB
);
751 extra
= (const unsigned char *)
752 _NL_CURRENT (LC_COLLATE
,
753 _NL_COLLATE_SYMB_EXTRAMB
);
755 /* Locate the character in the hashing
757 hash
= elem_hash (str
, c1
);
760 elem
= hash
% table_size
;
761 if (symb_table
[2 * elem
] != 0)
763 second
= hash
% (table_size
- 2) + 1;
767 /* First compare the hashing value. */
768 if (symb_table
[2 * elem
] == hash
770 == extra
[symb_table
[2 * elem
+ 1]])
772 &extra
[symb_table
[2 * elem
+ 1]
775 /* Yep, this is the entry. */
776 idx
= symb_table
[2 * elem
+ 1];
777 idx
+= 1 + extra
[idx
];
784 while (symb_table
[2 * elem
] != 0);
787 if (symb_table
[2 * elem
] != 0)
789 /* Compare the byte sequence but only if
790 this is not part of a range. */
791 # ifdef WIDE_CHAR_VERSION
794 idx
+= 1 + extra
[idx
];
795 /* Adjust for the alignment. */
796 idx
= (idx
+ 3) & ~4;
798 wextra
= (int32_t *) &extra
[idx
+ 4];
800 /* Get the collation sequence value. */
802 # ifdef WIDE_CHAR_VERSION
803 cend
= wextra
[1 + wextra
[idx
]];
805 /* Adjust for the alignment. */
806 idx
+= 1 + extra
[idx
];
807 idx
= (idx
+ 3) & ~4;
808 cend
= *((int32_t *) &extra
[idx
]);
811 else if (symb_table
[2 * elem
] != 0 && c1
== 1)
823 if (!(flags
& FNM_NOESCAPE
) && cend
== L('\\'))
830 /* XXX It is not entirely clear to me how to handle
831 characters which are not mentioned in the
832 collation specification. */
834 # ifdef WIDE_CHAR_VERSION
835 lcollseq
== 0xffffffff ||
837 lcollseq
<= fcollseq
)
839 /* We have to look at the upper bound. */
846 # ifdef WIDE_CHAR_VERSION
848 __collseq_table_lookup (collseq
, cend
);
849 if (hcollseq
== ~((uint32_t) 0))
851 /* Hum, no information about the upper
852 bound. The matching succeeds if the
853 lower bound is matched exactly. */
854 if (lcollseq
!= fcollseq
)
855 goto range_not_matched
;
860 hcollseq
= collseq
[cend
];
864 if (lcollseq
<= hcollseq
&& fcollseq
<= hcollseq
)
867 # ifdef WIDE_CHAR_VERSION
871 /* We use a boring value comparison of the character
872 values. This is better than comparing using
873 `strcoll' since the latter would have surprising
874 and sometimes fatal consequences. */
877 if (!(flags
& FNM_NOESCAPE
) && cend
== L('\\'))
883 if (cold
<= fn
&& fn
<= cend
)
900 /* Skip the rest of the [...] that already matched. */
907 /* [... (unterminated) loses. */
910 if (!(flags
& FNM_NOESCAPE
) && c
== L('\\'))
914 /* XXX 1003.2d11 is unclear if this is right. */
917 else if (c
== L('[') && *p
== L(':'))
920 const CHAR
*startp
= p
;
925 if (++c1
== CHAR_CLASS_MAX_LENGTH
)
928 if (*p
== L(':') && p
[1] == L(']'))
931 if (c
< L('a') || c
>= L('z'))
940 else if (c
== L('[') && *p
== L('='))
946 if (c
!= L('=') || p
[1] != L(']'))
951 else if (c
== L('[') && *p
== L('.'))
960 if (*p
== L('.') && p
[1] == L(']'))
976 if (__builtin_expect (flags
& FNM_EXTMATCH
, 0) && *p
== '(')
978 int res
= EXT (c
, p
, n
, string_end
, no_leading_period
, flags
,
986 if (NO_LEADING_PERIOD (flags
))
988 if (n
== string_end
|| c
!= (UCHAR
) *n
)
991 new_no_leading_period
= 1;
997 if (n
== string_end
|| c
!= FOLD ((UCHAR
) *n
))
1001 no_leading_period
= new_no_leading_period
;
1005 if (n
== string_end
)
1008 if ((flags
& FNM_LEADING_DIR
) && n
!= string_end
&& *n
== L('/'))
1009 /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
1018 END (const CHAR
*pattern
)
1020 const CHAR
*p
= pattern
;
1023 if (*++p
== L('\0'))
1024 /* This is an invalid pattern. */
1026 else if (*p
== L('['))
1028 /* Handle brackets special. */
1029 if (posixly_correct
== 0)
1030 posixly_correct
= getenv ("POSIXLY_CORRECT") != NULL
? 1 : -1;
1032 /* Skip the not sign. We have to recognize it because of a possibly
1034 if (*++p
== L('!') || (posixly_correct
< 0 && *p
== L('^')))
1036 /* A leading ']' is recognized as such. */
1039 /* Skip over all characters of the list. */
1040 while (*p
!= L(']'))
1041 if (*p
++ == L('\0'))
1042 /* This is no valid pattern. */
1045 else if ((*p
== L('?') || *p
== L('*') || *p
== L('+') || *p
== L('@')
1046 || *p
== L('!')) && p
[1] == L('('))
1048 else if (*p
== L(')'))
1057 EXT (INT opt
, const CHAR
*pattern
, const CHAR
*string
, const CHAR
*string_end
,
1058 int no_leading_period
, int flags
, size_t alloca_used
)
1064 struct patternlist
*next
;
1068 struct patternlist
**lastp
= &list
;
1069 size_t pattern_len
= STRLEN (pattern
);
1070 int any_malloced
= 0;
1075 /* Parse the pattern. Store the individual parts in the list. */
1077 for (startp
= p
= pattern
+ 1; level
>= 0; ++p
)
1080 /* This is an invalid pattern. */
1084 else if (*p
== L('['))
1086 /* Handle brackets special. */
1087 if (posixly_correct
== 0)
1088 posixly_correct
= getenv ("POSIXLY_CORRECT") != NULL
? 1 : -1;
1090 /* Skip the not sign. We have to recognize it because of a possibly
1092 if (*++p
== L('!') || (posixly_correct
< 0 && *p
== L('^')))
1094 /* A leading ']' is recognized as such. */
1097 /* Skip over all characters of the list. */
1098 while (*p
!= L(']'))
1099 if (*p
++ == L('\0'))
1101 /* This is no valid pattern. */
1106 else if ((*p
== L('?') || *p
== L('*') || *p
== L('+') || *p
== L('@')
1107 || *p
== L('!')) && p
[1] == L('('))
1108 /* Remember the nesting level. */
1110 else if (*p
== L(')'))
1114 /* This means we found the end of the pattern. */
1115 #define NEW_PATTERN \
1116 struct patternlist *newp; \
1117 size_t slen = (opt == L('?') || opt == L('@') \
1118 ? pattern_len : (p - startp + 1)); \
1119 slen = sizeof (struct patternlist) + (slen * sizeof (CHAR)); \
1120 int malloced = ! __libc_use_alloca (alloca_used + slen); \
1121 if (__builtin_expect (malloced, 0)) \
1123 newp = malloc (slen); \
1132 newp = alloca_account (slen, alloca_used); \
1133 newp->next = NULL; \
1134 newp->malloced = malloced; \
1135 *((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L('\0'); \
1141 else if (*p
== L('|'))
1149 assert (list
!= NULL
);
1150 assert (p
[-1] == L(')'));
1156 if (FCT (p
, string
, string_end
, no_leading_period
, flags
, NULL
,
1164 for (rs
= string
; rs
<= string_end
; ++rs
)
1165 /* First match the prefix with the current pattern with the
1167 if (FCT (list
->str
, string
, rs
, no_leading_period
,
1168 flags
& FNM_FILE_NAME
? flags
: flags
& ~FNM_PERIOD
,
1169 NULL
, alloca_used
) == 0
1170 /* This was successful. Now match the rest with the rest
1172 && (FCT (p
, rs
, string_end
,
1175 : rs
[-1] == '/' && NO_LEADING_PERIOD (flags
) ? 1 : 0,
1176 flags
& FNM_FILE_NAME
1177 ? flags
: flags
& ~FNM_PERIOD
, NULL
, alloca_used
) == 0
1178 /* This didn't work. Try the whole pattern. */
1180 && FCT (pattern
- 1, rs
, string_end
,
1183 : (rs
[-1] == '/' && NO_LEADING_PERIOD (flags
)
1185 flags
& FNM_FILE_NAME
1186 ? flags
: flags
& ~FNM_PERIOD
, NULL
,
1187 alloca_used
) == 0)))
1188 /* It worked. Signal success. */
1191 while ((list
= list
->next
) != NULL
);
1193 /* None of the patterns lead to a match. */
1194 retval
= FNM_NOMATCH
;
1198 if (FCT (p
, string
, string_end
, no_leading_period
, flags
, NULL
,
1205 /* I cannot believe it but `strcat' is actually acceptable
1206 here. Match the entire string with the prefix from the
1207 pattern list and the rest of the pattern following the
1209 if (FCT (STRCAT (list
->str
, p
), string
, string_end
,
1211 flags
& FNM_FILE_NAME
? flags
: flags
& ~FNM_PERIOD
,
1212 NULL
, alloca_used
) == 0)
1213 /* It worked. Signal success. */
1215 while ((list
= list
->next
) != NULL
);
1217 /* None of the patterns lead to a match. */
1218 retval
= FNM_NOMATCH
;
1222 for (rs
= string
; rs
<= string_end
; ++rs
)
1224 struct patternlist
*runp
;
1226 for (runp
= list
; runp
!= NULL
; runp
= runp
->next
)
1227 if (FCT (runp
->str
, string
, rs
, no_leading_period
,
1228 flags
& FNM_FILE_NAME
? flags
: flags
& ~FNM_PERIOD
,
1229 NULL
, alloca_used
) == 0)
1232 /* If none of the patterns matched see whether the rest does. */
1234 && (FCT (p
, rs
, string_end
,
1237 : rs
[-1] == '/' && NO_LEADING_PERIOD (flags
) ? 1 : 0,
1238 flags
& FNM_FILE_NAME
? flags
: flags
& ~FNM_PERIOD
,
1239 NULL
, alloca_used
) == 0))
1240 /* This is successful. */
1244 /* None of the patterns together with the rest of the pattern
1246 retval
= FNM_NOMATCH
;
1250 assert (! "Invalid extended matching operator");
1258 while (list
!= NULL
)
1260 struct patternlist
*old
= list
;