Mercurial > gnulib
annotate lib/fnmatch.c @ 17363:5a51fb7777a9
sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin
Problem reported by Marco Atzeri in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>.
* lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]:
Simply delegate to the system <sys/select.h> in this case too.
Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only
if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to
be needed on Solaris either.
* lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]:
Simply delgate to the system <sys/time.h> in this case.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 19 Mar 2013 09:08:47 -0700 |
parents | e542fd46ad6f |
children | 344018b6e5d7 |
rev | line source |
---|---|
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16366
diff
changeset
|
1 /* Copyright (C) 1991-1993, 1996-2007, 2009-2013 Free Software Foundation, Inc. |
5 | 2 |
1249 | 3 This program is free software; you can redistribute it and/or modify |
4 it under the terms of the GNU General Public License as published by | |
5 the Free Software Foundation; either version 2, or (at your option) | |
6 any later version. | |
335 | 7 |
763 | 8 This program is distributed in the hope that it will be useful, |
9 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 GNU General Public License for more details. | |
5 | 12 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
16366
bb182ee4a09d
maint: replace FSF snail-mail addresses with URLs
Paul Eggert <eggert@cs.ucla.edu>
parents:
16358
diff
changeset
|
14 along with this program; if not, see <http://www.gnu.org/licenses/>. */ |
5 | 15 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6932
diff
changeset
|
16 #ifndef _LIBC |
763 | 17 # include <config.h> |
77 | 18 #endif |
19 | |
1249 | 20 /* Enable GNU extensions in fnmatch.h. */ |
21 #ifndef _GNU_SOURCE | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
22 # define _GNU_SOURCE 1 |
1249 | 23 #endif |
24 | |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
25 #if ! defined __builtin_expect && __GNUC__ < 3 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
26 # define __builtin_expect(expr, expected) (expr) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
27 #endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
28 |
42 | 29 #include <fnmatch.h> |
5 | 30 |
5063
1aecdc8063ba
alloca cleanup: always include <alloca.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4906
diff
changeset
|
31 #include <alloca.h> |
4643 | 32 #include <assert.h> |
33 #include <ctype.h> | |
34 #include <errno.h> | |
35 #include <stddef.h> | |
5159 | 36 #include <stdbool.h> |
4643 | 37 #include <stdlib.h> |
38 #include <string.h> | |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
39 |
5181
050058152c7c
(WIDE_CHAR_SUPPORT): Don't set to 1 if missing
Paul Eggert <eggert@cs.ucla.edu>
parents:
5159
diff
changeset
|
40 #define WIDE_CHAR_SUPPORT \ |
7888
b6376840b47b
* modules/fnmatch (Depends-on): Depend on wchar.
Eric Blake <ebb9@byu.net>
parents:
7757
diff
changeset
|
41 (HAVE_WCTYPE_H && HAVE_BTOWC && HAVE_ISWCTYPE \ |
5181
050058152c7c
(WIDE_CHAR_SUPPORT): Don't set to 1 if missing
Paul Eggert <eggert@cs.ucla.edu>
parents:
5159
diff
changeset
|
42 && HAVE_WMEMCHR && (HAVE_WMEMCPY || HAVE_WMEMPCPY)) |
3920
678b6b899b7c
(WIDE_CHAR_SUPPORT): New macro. Use it uniformly instead of
Jim Meyering <jim@meyering.net>
parents:
3912
diff
changeset
|
43 |
16358 | 44 /* For platform which support the ISO C amendment 1 functionality we |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
45 support user defined character classes. */ |
3920
678b6b899b7c
(WIDE_CHAR_SUPPORT): New macro. Use it uniformly instead of
Jim Meyering <jim@meyering.net>
parents:
3912
diff
changeset
|
46 #if defined _LIBC || WIDE_CHAR_SUPPORT |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
47 # include <wctype.h> |
7757
e94e9d19184b
* lib/fnmatch.c: Reinstate inclusion of <wchar.h>, since this
Eric Blake <ebb9@byu.net>
parents:
7733
diff
changeset
|
48 # include <wchar.h> |
2954 | 49 #endif |
1249 | 50 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
51 /* We need some of the locale data (the collation sequence information) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
52 but there is no interface to get this information in general. Therefore |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
53 we support a correct implementation only in glibc. */ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
54 #ifdef _LIBC |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
55 # include "../locale/localeinfo.h" |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
56 # include "../locale/elem-hash.h" |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
57 # include "../locale/coll-lookup.h" |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
58 # include <shlib-compat.h> |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
59 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
60 # define CONCAT(a,b) __CONCAT(a,b) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
61 # define mbsrtowcs __mbsrtowcs |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
62 # define fnmatch __fnmatch |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
63 extern int fnmatch (const char *pattern, const char *string, int flags); |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
64 #endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
65 |
4791
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
66 #ifndef SIZE_MAX |
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
67 # define SIZE_MAX ((size_t) -1) |
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
68 #endif |
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
69 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
70 /* We often have to test for FNM_FILE_NAME and FNM_PERIOD being both set. */ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
71 #define NO_LEADING_PERIOD(flags) \ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
72 ((flags & (FNM_FILE_NAME | FNM_PERIOD)) == (FNM_FILE_NAME | FNM_PERIOD)) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
73 |
4906
374463b88e34
Merge fnmatch patches from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4791
diff
changeset
|
74 /* Comment out all this code if we are using the GNU C Library, and are not |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
75 actually compiling the library itself, and have not detected a bug |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
76 in the library. This code is part of the GNU C |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
77 Library, but also included in many other GNU distributions. Compiling |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
78 and linking in this code is a waste when using the GNU C library |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
79 (especially if it is a shared library). Rather than having every GNU |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
80 program understand 'configure --with-gnu-libc' and omit the object files, |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
81 it is simpler to just do this in the source for each such file. */ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
82 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
83 #if defined _LIBC || !defined __GNU_LIBRARY__ || !HAVE_FNMATCH_GNU |
1249 | 84 |
763 | 85 |
8921
28ffab893f7a
Work around problem reported by Steven M. Schweda in
Paul Eggert <eggert@cs.ucla.edu>
parents:
7888
diff
changeset
|
86 # if ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK)) |
6932
6aeb4d6c28d9
* lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6927
diff
changeset
|
87 # define isblank(c) ((c) == ' ' || (c) == '\t') |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
88 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
89 |
11709
61fffcc71917
remove superfluous parentheses in STREQ definition
Jim Meyering <meyering@redhat.com>
parents:
8921
diff
changeset
|
90 # define STREQ(s1, s2) (strcmp (s1, s2) == 0) |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
91 |
3920
678b6b899b7c
(WIDE_CHAR_SUPPORT): New macro. Use it uniformly instead of
Jim Meyering <jim@meyering.net>
parents:
3912
diff
changeset
|
92 # if defined _LIBC || WIDE_CHAR_SUPPORT |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
93 /* The GNU C library provides support for user-defined character classes |
16358 | 94 and the functions from ISO C amendment 1. */ |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
95 # ifdef CHARCLASS_NAME_MAX |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
96 # define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
97 # else |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
98 /* This shouldn't happen but some implementation might still have this |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
99 problem. Use a reasonable default value. */ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
100 # define CHAR_CLASS_MAX_LENGTH 256 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
101 # endif |
5 | 102 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
103 # ifdef _LIBC |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
104 # define IS_CHAR_CLASS(string) __wctype (string) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
105 # else |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
106 # define IS_CHAR_CLASS(string) wctype (string) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
107 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
108 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
109 # ifdef _LIBC |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
110 # define ISWCTYPE(WC, WT) __iswctype (WC, WT) |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
111 # else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
112 # define ISWCTYPE(WC, WT) iswctype (WC, WT) |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
113 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
114 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
115 # if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
116 /* In this case we are implementing the multibyte character handling. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
117 # define HANDLE_MULTIBYTE 1 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
118 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
119 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
120 # else |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
121 # define CHAR_CLASS_MAX_LENGTH 6 /* Namely, 'xdigit'. */ |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
122 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
123 # define IS_CHAR_CLASS(string) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
124 (STREQ (string, "alpha") || STREQ (string, "upper") \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
125 || STREQ (string, "lower") || STREQ (string, "digit") \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
126 || STREQ (string, "alnum") || STREQ (string, "xdigit") \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
127 || STREQ (string, "space") || STREQ (string, "print") \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
128 || STREQ (string, "punct") || STREQ (string, "graph") \ |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
129 || STREQ (string, "cntrl") || STREQ (string, "blank")) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
130 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
131 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
132 /* Avoid depending on library functions or files |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
133 whose names are inconsistent. */ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
134 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
135 /* Global variable. */ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
136 static int posixly_correct; |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
137 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
138 # ifndef internal_function |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
139 /* Inside GNU libc we mark some function in a special way. In other |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
140 environments simply ignore the marking. */ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
141 # define internal_function |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
142 # endif |
5 | 143 |
884 | 144 /* Note that this evaluates C many times. */ |
6932
6aeb4d6c28d9
* lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6927
diff
changeset
|
145 # define FOLD(c) ((flags & FNM_CASEFOLD) ? tolower (c) : (c)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
146 # define CHAR char |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
147 # define UCHAR unsigned char |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
148 # define INT int |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
149 # define FCT internal_fnmatch |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
150 # define EXT ext_match |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
151 # define END end_pattern |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
152 # define L_(CS) CS |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
153 # ifdef _LIBC |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
154 # define BTOWC(C) __btowc (C) |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
155 # else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
156 # define BTOWC(C) btowc (C) |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
157 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
158 # define STRLEN(S) strlen (S) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
159 # define STRCAT(D, S) strcat (D, S) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
160 # ifdef _LIBC |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
161 # define MEMPCPY(D, S, N) __mempcpy (D, S, N) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
162 # else |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
163 # if HAVE_MEMPCPY |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
164 # define MEMPCPY(D, S, N) mempcpy (D, S, N) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
165 # else |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
166 # define MEMPCPY(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N))) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
167 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
168 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
169 # define MEMCHR(S, C, N) memchr (S, C, N) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
170 # include "fnmatch_loop.c" |
42 | 171 |
5 | 172 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
173 # if HANDLE_MULTIBYTE |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
174 # define FOLD(c) ((flags & FNM_CASEFOLD) ? towlower (c) : (c)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
175 # define CHAR wchar_t |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
176 # define UCHAR wint_t |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
177 # define INT wint_t |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
178 # define FCT internal_fnwmatch |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
179 # define EXT ext_wmatch |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
180 # define END end_wpattern |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
181 # define L_(CS) L##CS |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
182 # define BTOWC(C) (C) |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
183 # ifdef _LIBC |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
184 # define STRLEN(S) __wcslen (S) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
185 # define STRCAT(D, S) __wcscat (D, S) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
186 # define MEMPCPY(D, S, N) __wmempcpy (D, S, N) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
187 # else |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
188 # define STRLEN(S) wcslen (S) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
189 # define STRCAT(D, S) wcscat (D, S) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
190 # if HAVE_WMEMPCPY |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
191 # define MEMPCPY(D, S, N) wmempcpy (D, S, N) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
192 # else |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
193 # define MEMPCPY(D, S, N) (wmemcpy (D, S, N) + (N)) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
194 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
195 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
196 # define MEMCHR(S, C, N) wmemchr (S, C, N) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
197 # define WIDE_CHAR_VERSION 1 |
5 | 198 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
199 # undef IS_CHAR_CLASS |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
200 /* We have to convert the wide character string in a multibyte string. But |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
201 we know that the character class names consist of alphanumeric characters |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
202 from the portable character set, and since the wide character encoding |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
203 for a member of the portable character set is the same code point as |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
204 its single-byte encoding, we can use a simplified method to convert the |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
205 string to a multibyte character string. */ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
206 static wctype_t |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
207 is_char_class (const wchar_t *wcs) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
208 { |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
209 char s[CHAR_CLASS_MAX_LENGTH + 1]; |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
210 char *cp = s; |
5 | 211 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
212 do |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
213 { |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
214 /* Test for a printable character from the portable character set. */ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
215 # ifdef _LIBC |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
216 if (*wcs < 0x20 || *wcs > 0x7e |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
217 || *wcs == 0x24 || *wcs == 0x40 || *wcs == 0x60) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
218 return (wctype_t) 0; |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
219 # else |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
220 switch (*wcs) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
221 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
222 case L' ': case L'!': case L'"': case L'#': case L'%': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
223 case L'&': case L'\'': case L'(': case L')': case L'*': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
224 case L'+': case L',': case L'-': case L'.': case L'/': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
225 case L'0': case L'1': case L'2': case L'3': case L'4': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
226 case L'5': case L'6': case L'7': case L'8': case L'9': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
227 case L':': case L';': case L'<': case L'=': case L'>': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
228 case L'?': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
229 case L'A': case L'B': case L'C': case L'D': case L'E': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
230 case L'F': case L'G': case L'H': case L'I': case L'J': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
231 case L'K': case L'L': case L'M': case L'N': case L'O': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
232 case L'P': case L'Q': case L'R': case L'S': case L'T': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
233 case L'U': case L'V': case L'W': case L'X': case L'Y': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
234 case L'Z': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
235 case L'[': case L'\\': case L']': case L'^': case L'_': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
236 case L'a': case L'b': case L'c': case L'd': case L'e': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
237 case L'f': case L'g': case L'h': case L'i': case L'j': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
238 case L'k': case L'l': case L'm': case L'n': case L'o': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
239 case L'p': case L'q': case L'r': case L's': case L't': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
240 case L'u': case L'v': case L'w': case L'x': case L'y': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
241 case L'z': case L'{': case L'|': case L'}': case L'~': |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
242 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
243 default: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
244 return (wctype_t) 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
245 } |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
246 # endif |
5 | 247 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
248 /* Avoid overrunning the buffer. */ |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
249 if (cp == s + CHAR_CLASS_MAX_LENGTH) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
250 return (wctype_t) 0; |
5 | 251 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
252 *cp++ = (char) *wcs++; |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
253 } |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
254 while (*wcs != L'\0'); |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
255 |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
256 *cp = '\0'; |
5 | 257 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
258 # ifdef _LIBC |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
259 return __wctype (s); |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
260 # else |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
261 return wctype (s); |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
262 # endif |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
263 } |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
264 # define IS_CHAR_CLASS(string) is_char_class (string) |
42 | 265 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
266 # include "fnmatch_loop.c" |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
267 # endif |
5 | 268 |
269 | |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
270 int |
4643 | 271 fnmatch (const char *pattern, const char *string, int flags) |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
272 { |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
273 # if HANDLE_MULTIBYTE |
4791
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
274 # define ALLOCA_LIMIT 2000 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
275 if (__builtin_expect (MB_CUR_MAX, 1) != 1) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
276 { |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
277 mbstate_t ps; |
4791
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
278 size_t patsize; |
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
279 size_t strsize; |
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
280 size_t totsize; |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
281 wchar_t *wpattern; |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
282 wchar_t *wstring; |
4791
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
283 int res; |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
284 |
4791
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
285 /* Calculate the size needed to convert the strings to |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
286 wide characters. */ |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
287 memset (&ps, '\0', sizeof (ps)); |
4791
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
288 patsize = mbsrtowcs (NULL, &pattern, 0, &ps) + 1; |
5919
1c2b6487c46b
* fnmatch.c (fnmatch): If there is an encoding error in a
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
289 if (__builtin_expect (patsize != 0, 1)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
290 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
291 assert (mbsinit (&ps)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
292 strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
293 if (__builtin_expect (strsize != 0, 1)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
294 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
295 assert (mbsinit (&ps)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
296 totsize = patsize + strsize; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
297 if (__builtin_expect (! (patsize <= totsize |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
298 && totsize <= SIZE_MAX / sizeof (wchar_t)), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
299 0)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
300 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
301 errno = ENOMEM; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
302 return -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
303 } |
4791
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
304 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
305 /* Allocate room for the wide characters. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
306 if (__builtin_expect (totsize < ALLOCA_LIMIT, 1)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
307 wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
308 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
309 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
310 wpattern = malloc (totsize * sizeof (wchar_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
311 if (__builtin_expect (! wpattern, 0)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
312 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
313 errno = ENOMEM; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
314 return -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
315 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
316 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
317 wstring = wpattern + patsize; |
5919
1c2b6487c46b
* fnmatch.c (fnmatch): If there is an encoding error in a
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
318 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
319 /* Convert the strings into wide characters. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
320 mbsrtowcs (wpattern, &pattern, patsize, &ps); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
321 assert (mbsinit (&ps)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
322 mbsrtowcs (wstring, &string, strsize, &ps); |
5919
1c2b6487c46b
* fnmatch.c (fnmatch): If there is an encoding error in a
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
323 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
324 res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
325 flags & FNM_PERIOD, flags); |
5919
1c2b6487c46b
* fnmatch.c (fnmatch): If there is an encoding error in a
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
326 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
327 if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
328 free (wpattern); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
329 return res; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
330 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
331 } |
5919
1c2b6487c46b
* fnmatch.c (fnmatch): If there is an encoding error in a
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
332 } |
4791
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
333 |
c47569f6dfaa
Check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4643
diff
changeset
|
334 # endif /* HANDLE_MULTIBYTE */ |
5 | 335 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
336 return internal_fnmatch (pattern, string, string + strlen (string), |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
337 flags & FNM_PERIOD, flags); |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
338 } |
5 | 339 |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
340 # ifdef _LIBC |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
341 # undef fnmatch |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
342 versioned_symbol (libc, __fnmatch, fnmatch, GLIBC_2_2_3); |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
343 # if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_2_3) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
344 strong_alias (__fnmatch, __fnmatch_old) |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
345 compat_symbol (libc, __fnmatch_old, fnmatch, GLIBC_2_0); |
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
346 # endif |
4906
374463b88e34
Merge fnmatch patches from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4791
diff
changeset
|
347 libc_hidden_ver (__fnmatch, fnmatch) |
3908
a6f24c3fd333
Update from diffutils-2.8.2.
Jim Meyering <jim@meyering.net>
parents:
2954
diff
changeset
|
348 # endif |
42 | 349 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11709
diff
changeset
|
350 #endif /* _LIBC or not __GNU_LIBRARY__. */ |