Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/fnmatch.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1299 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 /*
2 * fnmatch.c
3 *
4 * Original implementation by Kay Sievers, modified by H. Peter Anvin.
5 */
6
7 #include <fnmatch.h>
8
9 int fnmatch(const char *p, const char *s, int flags)
10 {
11 if (flags & FNM_PATHNAME && *s == '/')
12 return (*p != '/') || fnmatch(p+1, s+1, flags);
13 if (flags & FNM_PERIOD && *s == '.')
14 return (*p != '.') || fnmatch(p+1, s+1, flags);
15
16 flags &= ~FNM_PERIOD; /* Only applies at beginning */
17
18 if (!(flags & FNM_NOESCAPE) && *p == '\\') {
19 p++;
20 return (*p != *s) || fnmatch(p+1, s+1, flags);
21 }
22
23 if (*s == '\0') {
24 while (*p == '*')
25 p++;
26 return (*p != '\0');
27 }
28
29 switch (*p) {
30 case '[':
31 {
32 int not = 0;
33 p++;
34 if (*p == '!') {
35 not = 1;
36 p++;
37 }
38 while ((*p != '\0') && (*p != ']')) {
39 int match = 0;
40 if (p[1] == '-') {
41 if ((*s >= *p) && (*s <= p[2]))
42 match = 1;
43 p += 3;
44 } else {
45 match = (*p == *s);
46 p++;
47 }
48 if (match ^ not) {
49 while ((*p != '\0') && (*p != ']'))
50 p++;
51 if (*p == ']')
52 return fnmatch(p+1, s+1, flags);
53 }
54 }
55 }
56 break;
57 case '*':
58 if (fnmatch(p, s+1, flags))
59 return fnmatch(p+1, s, flags);
60 return 0;
61 case '\0':
62 if (*s == '\0') {
63 return 0;
64 }
65 break;
66 default:
67 if ((*p == *s) || (*p == '?'))
68 return fnmatch(p+1, s+1, flags);
69 break;
70 }
71 return 1;
72 }