Skip to content

Commit 9b4edc0

Browse files
pcloudsgitster
authored andcommitted
wildmatch: remove static variable force_lower_case
One place less to worry about thread safety. Also combine wildmatch and iwildmatch into one. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3ae5396 commit 9b4edc0

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

test-wildmatch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
int main(int argc, char **argv)
55
{
66
if (!strcmp(argv[1], "wildmatch"))
7-
return !!wildmatch(argv[3], argv[2]);
7+
return !!wildmatch(argv[3], argv[2], 0);
88
else if (!strcmp(argv[1], "iwildmatch"))
9-
return !!iwildmatch(argv[3], argv[2]);
9+
return !!wildmatch(argv[3], argv[2], FNM_CASEFOLD);
1010
else if (!strcmp(argv[1], "fnmatch"))
1111
return !!fnmatch(argv[3], argv[2], FNM_PATHNAME);
1212
else

wildmatch.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ typedef unsigned char uchar;
5959
#define ISUPPER(c) (ISASCII(c) && isupper(c))
6060
#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
6161

62-
static int force_lower_case = 0;
63-
6462
/* Match pattern "p" against "text" */
65-
static int dowild(const uchar *p, const uchar *text)
63+
static int dowild(const uchar *p, const uchar *text, int force_lower_case)
6664
{
6765
uchar p_ch;
6866

@@ -106,7 +104,7 @@ static int dowild(const uchar *p, const uchar *text)
106104
while (1) {
107105
if (t_ch == '\0')
108106
break;
109-
if ((matched = dowild(p, text)) != NOMATCH) {
107+
if ((matched = dowild(p, text, force_lower_case)) != NOMATCH) {
110108
if (!special || matched != ABORT_TO_STARSTAR)
111109
return matched;
112110
} else if (!special && t_ch == '/')
@@ -214,17 +212,8 @@ static int dowild(const uchar *p, const uchar *text)
214212
}
215213

216214
/* Match the "pattern" against the "text" string. */
217-
int wildmatch(const char *pattern, const char *text)
218-
{
219-
return dowild((const uchar*)pattern, (const uchar*)text);
220-
}
221-
222-
/* Match the "pattern" against the forced-to-lower-case "text" string. */
223-
int iwildmatch(const char *pattern, const char *text)
215+
int wildmatch(const char *pattern, const char *text, int flags)
224216
{
225-
int ret;
226-
force_lower_case = 1;
227-
ret = dowild((const uchar*)pattern, (const uchar*)text);
228-
force_lower_case = 0;
229-
return ret;
217+
return dowild((const uchar*)pattern, (const uchar*)text,
218+
flags & FNM_CASEFOLD ? 1 :0);
230219
}

wildmatch.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
/* wildmatch.h */
22

3-
int wildmatch(const char *pattern, const char *text);
4-
int iwildmatch(const char *pattern, const char *text);
3+
int wildmatch(const char *pattern, const char *text, int flags);

0 commit comments

Comments
 (0)