14
14
15
15
typedef unsigned char uchar ;
16
16
17
+ /* Internal return values */
18
+ #define WM_ABORT_ALL -1
19
+ #define WM_ABORT_TO_STARSTAR -2
20
+
17
21
/* What character marks an inverted character class? */
18
22
#define NEGATE_CLASS '!'
19
23
#define NEGATE_CLASS2 '^'
@@ -83,12 +87,12 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
83
87
continue ;
84
88
case '*' :
85
89
if (* ++ p == '*' ) {
86
- const uchar * prev_p = p - 2 ;
90
+ const uchar * prev_p = p ;
87
91
while (* ++ p == '*' ) {}
88
92
if (!(flags & WM_PATHNAME ))
89
93
/* without WM_PATHNAME, '*' == '**' */
90
94
match_slash = 1 ;
91
- else if ((prev_p < pattern || * prev_p == '/' ) &&
95
+ else if ((prev_p - pattern < 2 || * ( prev_p - 2 ) == '/' ) &&
92
96
(* p == '\0' || * p == '/' ||
93
97
(p [0 ] == '\\' && p [1 ] == '/' ))) {
94
98
/*
@@ -114,7 +118,7 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
114
118
* only if there are no more slash characters. */
115
119
if (!match_slash ) {
116
120
if (strchr ((char * )text , '/' ))
117
- return WM_NOMATCH ;
121
+ return WM_ABORT_TO_STARSTAR ;
118
122
}
119
123
return WM_MATCH ;
120
124
} else if (!match_slash && * p == '/' ) {
@@ -125,7 +129,7 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
125
129
*/
126
130
const char * slash = strchr ((char * )text , '/' );
127
131
if (!slash )
128
- return WM_NOMATCH ;
132
+ return WM_ABORT_ALL ;
129
133
text = (const uchar * )slash ;
130
134
/* the slash is consumed by the top-level for loop */
131
135
break ;
@@ -153,8 +157,12 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
153
157
break ;
154
158
text ++ ;
155
159
}
156
- if (t_ch != p_ch )
157
- return WM_NOMATCH ;
160
+ if (t_ch != p_ch ) {
161
+ if (match_slash )
162
+ return WM_ABORT_ALL ;
163
+ else
164
+ return WM_ABORT_TO_STARSTAR ;
165
+ }
158
166
}
159
167
if ((matched = dowild (p , text , flags )) != WM_NOMATCH ) {
160
168
if (!match_slash || matched != WM_ABORT_TO_STARSTAR )
@@ -274,5 +282,6 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
274
282
/* Match the "pattern" against the "text" string. */
275
283
int wildmatch (const char * pattern , const char * text , unsigned int flags )
276
284
{
277
- return dowild ((const uchar * )pattern , (const uchar * )text , flags );
285
+ int res = dowild ((const uchar * )pattern , (const uchar * )text , flags );
286
+ return res == WM_MATCH ? WM_MATCH : WM_NOMATCH ;
278
287
}
0 commit comments