* sysdeps/m68k/fpu/s_nextafterl.c: New file.
[glibc/pb-stable.git] / posix / fnmatch_loop.c
blob80f6796b1ecc343a9bfdc9b67b12271c1fbee6ad
1 /* Copyright (C) 1991-1993, 1996-2000, 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 /* Match STRING against the filename pattern PATTERN, returning zero if
20 it matches, nonzero if not. */
21 static int FCT (const CHAR *pattern, const CHAR *string,
22 int no_leading_period, int flags) internal_function;
24 static int
25 internal_function
26 FCT (pattern, string, no_leading_period, flags)
27 const CHAR *pattern;
28 const CHAR *string;
29 int no_leading_period;
30 int flags;
32 register const CHAR *p = pattern, *n = string;
33 register UCHAR c;
34 #ifdef _LIBC
35 # if WIDE_CHAR_VERSION
36 const char *collseq = (const char *)
37 _NL_CURRENT(LC_COLLATE, _NL_COLLATE_COLLSEQWC);
38 # else
39 const UCHAR *collseq = (const UCHAR *)
40 _NL_CURRENT(LC_COLLATE, _NL_COLLATE_COLLSEQMB);
41 # endif
42 #endif
44 while ((c = *p++) != L('\0'))
46 c = FOLD (c);
48 switch (c)
50 case L('?'):
51 if (*n == L('\0'))
52 return FNM_NOMATCH;
53 else if (*n == L('/') && (flags & FNM_FILE_NAME))
54 return FNM_NOMATCH;
55 else if (*n == L('.') && no_leading_period
56 && (n == string
57 || (n[-1] == L('/') && (flags & FNM_FILE_NAME))))
58 return FNM_NOMATCH;
59 break;
61 case L('\\'):
62 if (!(flags & FNM_NOESCAPE))
64 c = *p++;
65 if (c == L('\0'))
66 /* Trailing \ loses. */
67 return FNM_NOMATCH;
68 c = FOLD (c);
70 if (FOLD ((UCHAR) *n) != c)
71 return FNM_NOMATCH;
72 break;
74 case L('*'):
75 if (*n == L('.') && no_leading_period
76 && (n == string
77 || (n[-1] == L('/') && (flags & FNM_FILE_NAME))))
78 return FNM_NOMATCH;
80 for (c = *p++; c == L('?') || c == L('*'); c = *p++)
82 if (*n == L('/') && (flags & FNM_FILE_NAME))
83 /* A slash does not match a wildcard under FNM_FILE_NAME. */
84 return FNM_NOMATCH;
85 else if (c == L('?'))
87 /* A ? needs to match one character. */
88 if (*n == L('\0'))
89 /* There isn't another character; no match. */
90 return FNM_NOMATCH;
91 else
92 /* One character of the string is consumed in matching
93 this ? wildcard, so *??? won't match if there are
94 less than three characters. */
95 ++n;
99 if (c == L('\0'))
100 /* The wildcard(s) is/are the last element of the pattern.
101 If the name is a file name and contains another slash
102 this means it cannot match, unless the FNM_LEADING_DIR
103 flag is set. */
105 int result = (flags & FNM_FILE_NAME) == 0 ? 0 : FNM_NOMATCH;
107 if (flags & FNM_FILE_NAME)
109 if (flags & FNM_LEADING_DIR)
110 result = 0;
111 else
113 if (STRCHR (n, L('/')) == NULL)
114 result = 0;
118 return result;
120 else
122 const CHAR *endp;
124 endp = STRCHRNUL (n, (flags & FNM_FILE_NAME) ? L('/') : L('\0'));
126 if (c == L('['))
128 int flags2 = ((flags & FNM_FILE_NAME)
129 ? flags : (flags & ~FNM_PERIOD));
131 for (--p; n < endp; ++n)
132 if (FCT (p, n, (no_leading_period
133 && (n == string
134 || (n[-1] == L('/')
135 && (flags & FNM_FILE_NAME)))),
136 flags2) == 0)
137 return 0;
139 else if (c == L('/') && (flags & FNM_FILE_NAME))
141 while (*n != L('\0') && *n != L('/'))
142 ++n;
143 if (*n == L('/')
144 && (FCT (p, n + 1, flags & FNM_PERIOD, flags) == 0))
145 return 0;
147 else
149 int flags2 = ((flags & FNM_FILE_NAME)
150 ? flags : (flags & ~FNM_PERIOD));
152 if (c == L('\\') && !(flags & FNM_NOESCAPE))
153 c = *p;
154 c = FOLD (c);
155 for (--p; n < endp; ++n)
156 if (FOLD ((UCHAR) *n) == c
157 && (FCT (p, n, (no_leading_period
158 && (n == string
159 || (n[-1] == L('/')
160 && (flags & FNM_FILE_NAME)))),
161 flags2) == 0))
162 return 0;
166 /* If we come here no match is possible with the wildcard. */
167 return FNM_NOMATCH;
169 case L('['):
171 static int posixly_correct;
172 /* Nonzero if the sense of the character class is inverted. */
173 register int not;
174 CHAR cold;
176 if (posixly_correct == 0)
177 posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1;
179 if (*n == L('\0'))
180 return FNM_NOMATCH;
182 if (*n == L('.') && no_leading_period
183 && (n == string
184 || (n[-1] == L('/') && (flags & FNM_FILE_NAME))))
185 return FNM_NOMATCH;
187 if (*n == L('/') && (flags & FNM_FILE_NAME))
188 /* `/' cannot be matched. */
189 return FNM_NOMATCH;
191 not = (*p == L('!') || (posixly_correct < 0 && *p == L('^')));
192 if (not)
193 ++p;
195 c = *p++;
196 for (;;)
198 UCHAR fn = FOLD ((UCHAR) *n);
200 if (!(flags & FNM_NOESCAPE) && c == L('\\'))
202 if (*p == L('\0'))
203 return FNM_NOMATCH;
204 c = FOLD ((UCHAR) *p);
205 ++p;
207 if (c == fn)
208 goto matched;
210 else if (c == L('[') && *p == L(':'))
212 /* Leave room for the null. */
213 CHAR str[CHAR_CLASS_MAX_LENGTH + 1];
214 size_t c1 = 0;
215 #if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H)
216 wctype_t wt;
217 #endif
218 const CHAR *startp = p;
220 for (;;)
222 if (c1 == CHAR_CLASS_MAX_LENGTH)
223 /* The name is too long and therefore the pattern
224 is ill-formed. */
225 return FNM_NOMATCH;
227 c = *++p;
228 if (c == L(':') && p[1] == L(']'))
230 p += 2;
231 break;
233 if (c < L('a') || c >= L('z'))
235 /* This cannot possibly be a character class name.
236 Match it as a normal range. */
237 p = startp;
238 c = L('[');
239 goto normal_bracket;
241 str[c1++] = c;
243 str[c1] = L('\0');
245 #if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H)
246 wt = IS_CHAR_CLASS (str);
247 if (wt == 0)
248 /* Invalid character class name. */
249 return FNM_NOMATCH;
251 # if defined _LIBC && ! WIDE_CHAR_VERSION
252 /* The following code is glibc specific but does
253 there a good job in speeding up the code since
254 we can avoid the btowc() call. */
255 if (_ISCTYPE ((UCHAR) *n, wt))
256 goto matched;
257 # else
258 if (ISWCTYPE (BTOWC ((UCHAR) *n), wt))
259 goto matched;
260 # endif
261 #else
262 if ((STREQ (str, L("alnum")) && ISALNUM ((UCHAR) *n))
263 || (STREQ (str, L("alpha")) && ISALPHA ((UCHAR) *n))
264 || (STREQ (str, L("blank")) && ISBLANK ((UCHAR) *n))
265 || (STREQ (str, L("cntrl")) && ISCNTRL ((UCHAR) *n))
266 || (STREQ (str, L("digit")) && ISDIGIT ((UCHAR) *n))
267 || (STREQ (str, L("graph")) && ISGRAPH ((UCHAR) *n))
268 || (STREQ (str, L("lower")) && ISLOWER ((UCHAR) *n))
269 || (STREQ (str, L("print")) && ISPRINT ((UCHAR) *n))
270 || (STREQ (str, L("punct")) && ISPUNCT ((UCHAR) *n))
271 || (STREQ (str, L("space")) && ISSPACE ((UCHAR) *n))
272 || (STREQ (str, L("upper")) && ISUPPER ((UCHAR) *n))
273 || (STREQ (str, L("xdigit")) && ISXDIGIT ((UCHAR) *n)))
274 goto matched;
275 #endif
276 c = *p++;
278 #ifdef _LIBC
279 else if (c == L('[') && *p == L('='))
281 UCHAR str[1];
282 uint32_t nrules =
283 _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
284 const CHAR *startp = p;
286 c = *++p;
287 if (c == L('\0'))
289 p = startp;
290 c = L('[');
291 goto normal_bracket;
293 str[0] = c;
295 c = *++p;
296 if (c != L('=') || p[1] != L(']'))
298 p = startp;
299 c = L('[');
300 goto normal_bracket;
302 p += 2;
304 if (nrules == 0)
306 if ((UCHAR) *n == str[0])
307 goto matched;
309 else
311 const int32_t *table;
312 # if WIDE_CHAR_VERSION
313 const int32_t *weights;
314 const int32_t *extra;
315 # else
316 const unsigned char *weights;
317 const unsigned char *extra;
318 # endif
319 const int32_t *indirect;
320 int32_t idx;
321 const UCHAR *cp = (const UCHAR *) str;
323 /* This #include defines a local function! */
324 # if WIDE_CHAR_VERSION
325 # include <locale/weightwc.h>
326 # else
327 # include <locale/weight.h>
328 # endif
330 # if WIDE_CHAR_VERSION
331 table = (const int32_t *)
332 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEWC);
333 weights = (const int32_t *)
334 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTWC);
335 extra = (const int32_t *)
336 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAWC);
337 indirect = (const int32_t *)
338 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTWC);
339 # else
340 table = (const int32_t *)
341 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
342 weights = (const unsigned char *)
343 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTMB);
344 extra = (const unsigned char *)
345 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
346 indirect = (const int32_t *)
347 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
348 # endif
350 idx = findidx (&cp);
351 if (idx != 0)
353 /* We found a table entry. Now see whether the
354 character we are currently at has the same
355 equivalance class value. */
356 int len = weights[idx];
357 int32_t idx2;
358 const UCHAR *np = (const UCHAR *) n;
360 idx2 = findidx (&np);
361 if (idx2 != 0 && len == weights[idx2])
363 int cnt = 0;
365 while (cnt < len
366 && (weights[idx + 1 + cnt]
367 == weights[idx2 + 1 + cnt]))
368 ++cnt;
370 if (cnt == len)
371 goto matched;
376 c = *p++;
378 #endif
379 else if (c == L('\0'))
380 /* [ (unterminated) loses. */
381 return FNM_NOMATCH;
382 else
384 int is_range = 0;
386 #ifdef _LIBC
387 int is_seqval = 0;
389 if (c == L('[') && *p == L('.'))
391 uint32_t nrules =
392 _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
393 const CHAR *startp = p;
394 size_t c1 = 0;
396 while (1)
398 c = *++p;
399 if (c == L('.') && p[1] == L(']'))
401 p += 2;
402 break;
404 if (c == '\0')
405 return FNM_NOMATCH;
406 ++c1;
409 /* We have to handling the symbols differently in
410 ranges since then the collation sequence is
411 important. */
412 is_range = *p == L('-') && p[1] != L('\0');
414 if (nrules == 0)
416 /* There are no names defined in the collation
417 data. Therefore we only accept the trivial
418 names consisting of the character itself. */
419 if (c1 != 1)
420 return FNM_NOMATCH;
422 if (!is_range && *n == startp[1])
423 goto matched;
425 cold = startp[1];
426 c = *p++;
428 else
430 int32_t table_size;
431 const int32_t *symb_table;
432 # ifdef WIDE_CHAR_VERSION
433 char str[c1];
434 unsigned int strcnt;
435 # else
436 # define str (startp + 1)
437 # endif
438 const unsigned char *extra;
439 int32_t idx;
440 int32_t elem;
441 int32_t second;
442 int32_t hash;
444 # ifdef WIDE_CHAR_VERSION
445 /* We have to convert the name to a single-byte
446 string. This is possible since the names
447 consist of ASCII characters and the internal
448 representation is UCS4. */
449 for (strcnt = 0; strcnt < c1; ++strcnt)
450 str[strcnt] = startp[1 + strcnt];
451 #endif
453 table_size =
454 _NL_CURRENT_WORD (LC_COLLATE,
455 _NL_COLLATE_SYMB_HASH_SIZEMB);
456 symb_table = (const int32_t *)
457 _NL_CURRENT (LC_COLLATE,
458 _NL_COLLATE_SYMB_TABLEMB);
459 extra = (const unsigned char *)
460 _NL_CURRENT (LC_COLLATE,
461 _NL_COLLATE_SYMB_EXTRAMB);
463 /* Locate the character in the hashing table. */
464 hash = elem_hash (str, c1);
466 idx = 0;
467 elem = hash % table_size;
468 second = hash % (table_size - 2);
469 while (symb_table[2 * elem] != 0)
471 /* First compare the hashing value. */
472 if (symb_table[2 * elem] == hash
473 && c1 == extra[symb_table[2 * elem + 1]]
474 && memcmp (str,
475 &extra[symb_table[2 * elem + 1]
476 + 1], c1) == 0)
478 /* Yep, this is the entry. */
479 idx = symb_table[2 * elem + 1];
480 idx += 1 + extra[idx];
481 break;
484 /* Next entry. */
485 elem += second;
488 if (symb_table[2 * elem] != 0)
490 /* Compare the byte sequence but only if
491 this is not part of a range. */
492 # ifdef WIDE_CHAR_VERSION
493 int32_t *wextra;
495 idx += 1 + extra[idx];
496 /* Adjust for the alignment. */
497 idx = (idx + 3) & ~4;
499 wextra = (int32_t *) &extra[idx + 4];
500 # endif
502 if (! is_range)
504 # ifdef WIDE_CHAR_VERSION
505 for (c1 = 0; c1 < wextra[idx]; ++c1)
506 if (n[c1] != wextra[1 + c1])
507 break;
509 if (c1 == wextra[idx])
510 goto matched;
511 # else
512 for (c1 = 0; c1 < extra[idx]; ++c1)
513 if (n[c1] != extra[1 + c1])
514 break;
516 if (c1 == extra[idx])
517 goto matched;
518 # endif
521 /* Get the collation sequence value. */
522 is_seqval = 1;
523 # ifdef WIDE_CHAR_VERSION
524 cold = wextra[1 + wextra[idx]];
525 # else
526 /* Adjust for the alignment. */
527 idx += 1 + extra[idx];
528 idx = (idx + 3) & ~4;
529 cold = *((int32_t *) &extra[idx]);
530 # endif
532 c = *p++;
534 else if (c1 == 1)
536 /* No valid character. Match it as a
537 single byte. */
538 if (!is_range && *n == str[0])
539 goto matched;
541 cold = str[0];
542 c = *p++;
544 else
545 return FNM_NOMATCH;
548 else
549 # undef str
550 #endif
552 c = FOLD (c);
553 normal_bracket:
555 /* We have to handling the symbols differently in
556 ranges since then the collation sequence is
557 important. */
558 is_range = *p == L('-') && p[1] != L('\0');
560 if (!is_range && c == fn)
561 goto matched;
563 cold = c;
564 c = *p++;
567 if (c == L('-') && *p != L(']'))
569 #if _LIBC
570 /* We have to find the collation sequence
571 value for C. Collation sequence is nothing
572 we can regularly access. The sequence
573 value is defined by the order in which the
574 definitions of the collation values for the
575 various characters appear in the source
576 file. A strange concept, nowhere
577 documented. */
578 uint32_t fcollseq;
579 uint32_t lcollseq;
580 UCHAR cend = *p++;
582 # ifdef WIDE_CHAR_VERSION
583 /* Search in the `names' array for the characters. */
584 fcollseq = collseq_table_lookup (collseq, fn);
585 if (fcollseq == ~((uint32_t) 0))
586 /* XXX We don't know anything about the character
587 we are supposed to match. This means we are
588 failing. */
589 goto range_not_matched;
591 if (is_seqval)
592 lcollseq = cold;
593 else
594 lcollseq = collseq_table_lookup (collseq, cold);
595 # else
596 fcollseq = collseq[fn];
597 lcollseq = is_seqval ? cold : collseq[(UCHAR) cold];
598 # endif
600 is_seqval = 0;
601 if (cend == L('[') && *p == L('.'))
603 uint32_t nrules =
604 _NL_CURRENT_WORD (LC_COLLATE,
605 _NL_COLLATE_NRULES);
606 const CHAR *startp = p;
607 size_t c1 = 0;
609 while (1)
611 c = *++p;
612 if (c == L('.') && p[1] == L(']'))
614 p += 2;
615 break;
617 if (c == '\0')
618 return FNM_NOMATCH;
619 ++c1;
622 if (nrules == 0)
624 /* There are no names defined in the
625 collation data. Therefore we only
626 accept the trivial names consisting
627 of the character itself. */
628 if (c1 != 1)
629 return FNM_NOMATCH;
631 cend = startp[1];
633 else
635 int32_t table_size;
636 const int32_t *symb_table;
637 # ifdef WIDE_CHAR_VERSION
638 char str[c1];
639 unsigned int strcnt;
640 # else
641 # define str (startp + 1)
642 # endif
643 const unsigned char *extra;
644 int32_t idx;
645 int32_t elem;
646 int32_t second;
647 int32_t hash;
649 # ifdef WIDE_CHAR_VERSION
650 /* We have to convert the name to a single-byte
651 string. This is possible since the names
652 consist of ASCII characters and the internal
653 representation is UCS4. */
654 for (strcnt = 0; strcnt < c1; ++strcnt)
655 str[strcnt] = startp[1 + strcnt];
656 # endif
658 table_size =
659 _NL_CURRENT_WORD (LC_COLLATE,
660 _NL_COLLATE_SYMB_HASH_SIZEMB);
661 symb_table = (const int32_t *)
662 _NL_CURRENT (LC_COLLATE,
663 _NL_COLLATE_SYMB_TABLEMB);
664 extra = (const unsigned char *)
665 _NL_CURRENT (LC_COLLATE,
666 _NL_COLLATE_SYMB_EXTRAMB);
668 /* Locate the character in the hashing
669 table. */
670 hash = elem_hash (str, c1);
672 idx = 0;
673 elem = hash % table_size;
674 second = hash % (table_size - 2);
675 while (symb_table[2 * elem] != 0)
677 /* First compare the hashing value. */
678 if (symb_table[2 * elem] == hash
679 && (c1
680 == extra[symb_table[2 * elem + 1]])
681 && memcmp (str,
682 &extra[symb_table[2 * elem + 1]
683 + 1], c1) == 0)
685 /* Yep, this is the entry. */
686 idx = symb_table[2 * elem + 1];
687 idx += 1 + extra[idx];
688 break;
691 /* Next entry. */
692 elem += second;
695 if (symb_table[2 * elem] != 0)
697 /* Compare the byte sequence but only if
698 this is not part of a range. */
699 # ifdef WIDE_CHAR_VERSION
700 int32_t *wextra;
702 idx += 1 + extra[idx];
703 /* Adjust for the alignment. */
704 idx = (idx + 3) & ~4;
706 wextra = (int32_t *) &extra[idx + 4];
707 # endif
708 /* Get the collation sequence value. */
709 is_seqval = 1;
710 # ifdef WIDE_CHAR_VERSION
711 cend = wextra[1 + wextra[idx]];
712 # else
713 /* Adjust for the alignment. */
714 idx += 1 + extra[idx];
715 idx = (idx + 3) & ~4;
716 cend = *((int32_t *) &extra[idx]);
717 # endif
719 else if (symb_table[2 * elem] != 0 && c1 == 1)
721 cend = str[0];
722 c = *p++;
724 else
725 return FNM_NOMATCH;
727 # undef str
729 else
731 if (!(flags & FNM_NOESCAPE) && cend == L('\\'))
732 cend = *p++;
733 if (cend == L('\0'))
734 return FNM_NOMATCH;
735 cend = FOLD (cend);
738 /* XXX It is not entirely clear to me how to handle
739 characters which are not mentioned in the
740 collation specification. */
741 if (
742 # ifdef WIDE_CHAR_VERSION
743 lcollseq == 0xffffffff ||
744 # endif
745 lcollseq <= fcollseq)
747 /* We have to look at the upper bound. */
748 uint32_t hcollseq;
750 if (is_seqval)
751 hcollseq = cend;
752 else
754 # ifdef WIDE_CHAR_VERSION
755 hcollseq =
756 collseq_table_lookup (collseq, cend);
757 if (hcollseq == ~((uint32_t) 0))
759 /* Hum, no information about the upper
760 bound. The matching succeeds if the
761 lower bound is matched exactly. */
762 if (lcollseq != fcollseq)
763 goto range_not_matched;
765 goto matched;
767 # else
768 hcollseq = collseq[cend];
769 # endif
772 if (lcollseq <= hcollseq && fcollseq <= hcollseq)
773 goto matched;
775 # ifdef WIDE_CHAR_VERSION
776 range_not_matched:
777 # endif
778 #else
779 /* We use a boring value comparison of the character
780 values. This is better than comparing using
781 `strcoll' since the latter would have surprising
782 and sometimes fatal consequences. */
783 UCHAR cend = *p++;
785 if (!(flags & FNM_NOESCAPE) && cend == L('\\'))
786 cend = *p++;
787 if (cend == L('\0'))
788 return FNM_NOMATCH;
790 /* It is a range. */
791 if (cold <= fn && fn <= c)
792 goto matched;
793 #endif
795 c = *p++;
799 if (c == L(']'))
800 break;
803 if (!not)
804 return FNM_NOMATCH;
805 break;
807 matched:
808 /* Skip the rest of the [...] that already matched. */
811 ignore_next:
812 c = *p++;
814 if (c == L('\0'))
815 /* [... (unterminated) loses. */
816 return FNM_NOMATCH;
818 if (!(flags & FNM_NOESCAPE) && c == L('\\'))
820 if (*p == L('\0'))
821 return FNM_NOMATCH;
822 /* XXX 1003.2d11 is unclear if this is right. */
823 ++p;
825 else if (c == L('[') && *p == L(':'))
827 int c1 = 0;
828 const CHAR *startp = p;
830 while (1)
832 c = *++p;
833 if (++c1 == CHAR_CLASS_MAX_LENGTH)
834 return FNM_NOMATCH;
836 if (*p == L(':') && p[1] == L(']'))
837 break;
839 if (c < L('a') || c >= L('z'))
841 p = startp;
842 goto ignore_next;
845 p += 2;
846 c = *p++;
848 else if (c == L('[') && *p == L('='))
850 c = *++p;
851 if (c == L('\0'))
852 return FNM_NOMATCH;
853 c = *++p;
854 if (c != L('=') || p[1] != L(']'))
855 return FNM_NOMATCH;
856 p += 2;
857 c = *p++;
859 else if (c == L('[') && *p == L('.'))
861 ++p;
862 while (1)
864 c = *++p;
865 if (c == '\0')
866 return FNM_NOMATCH;
868 if (*p == L('.') && p[1] == L(']'))
869 break;
871 p += 2;
872 c = *p++;
875 while (c != L(']'));
876 if (not)
877 return FNM_NOMATCH;
879 break;
881 default:
882 if (c != FOLD ((UCHAR) *n))
883 return FNM_NOMATCH;
886 ++n;
889 if (*n == '\0')
890 return 0;
892 if ((flags & FNM_LEADING_DIR) && *n == L('/'))
893 /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
894 return 0;
896 return FNM_NOMATCH;
899 #undef FOLD
900 #undef CHAR
901 #undef UCHAR
902 #undef FCT
903 #undef STRCHR
904 #undef STRCHRNUL
905 #undef STRCOLL
906 #undef L
907 #undef BTOWC