1 |
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004 |
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005 |
2 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
319 |
wide characters. */ |
wide characters. */ |
320 |
memset (&ps, '\0', sizeof (ps)); |
memset (&ps, '\0', sizeof (ps)); |
321 |
patsize = mbsrtowcs (NULL, &pattern, 0, &ps) + 1; |
patsize = mbsrtowcs (NULL, &pattern, 0, &ps) + 1; |
322 |
if (__builtin_expect (patsize == 0, 0)) |
if (__builtin_expect (patsize != 0, 1)) |
|
/* Something wrong. |
|
|
XXX Do we have to set `errno' to something which mbsrtows hasn't |
|
|
already done? */ |
|
|
return -1; |
|
|
assert (mbsinit (&ps)); |
|
|
strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1; |
|
|
if (__builtin_expect (strsize == 0, 0)) |
|
|
/* Something wrong. |
|
|
XXX Do we have to set `errno' to something which mbsrtows hasn't |
|
|
already done? */ |
|
|
return -1; |
|
|
assert (mbsinit (&ps)); |
|
|
totsize = patsize + strsize; |
|
|
if (__builtin_expect (! (patsize <= totsize |
|
|
&& totsize <= SIZE_MAX / sizeof (wchar_t)), |
|
|
0)) |
|
323 |
{ |
{ |
324 |
errno = ENOMEM; |
assert (mbsinit (&ps)); |
325 |
return -1; |
strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1; |
326 |
} |
if (__builtin_expect (strsize != 0, 1)) |
|
|
|
|
/* Allocate room for the wide characters. */ |
|
|
if (__builtin_expect (totsize < ALLOCA_LIMIT, 1)) |
|
|
wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t)); |
|
|
else |
|
|
{ |
|
|
wpattern = malloc (totsize * sizeof (wchar_t)); |
|
|
if (__builtin_expect (! wpattern, 0)) |
|
327 |
{ |
{ |
328 |
errno = ENOMEM; |
assert (mbsinit (&ps)); |
329 |
return -1; |
totsize = patsize + strsize; |
330 |
|
if (__builtin_expect (! (patsize <= totsize |
331 |
|
&& totsize <= SIZE_MAX / sizeof (wchar_t)), |
332 |
|
0)) |
333 |
|
{ |
334 |
|
errno = ENOMEM; |
335 |
|
return -1; |
336 |
|
} |
337 |
|
|
338 |
|
/* Allocate room for the wide characters. */ |
339 |
|
if (__builtin_expect (totsize < ALLOCA_LIMIT, 1)) |
340 |
|
wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t)); |
341 |
|
else |
342 |
|
{ |
343 |
|
wpattern = malloc (totsize * sizeof (wchar_t)); |
344 |
|
if (__builtin_expect (! wpattern, 0)) |
345 |
|
{ |
346 |
|
errno = ENOMEM; |
347 |
|
return -1; |
348 |
|
} |
349 |
|
} |
350 |
|
wstring = wpattern + patsize; |
351 |
|
|
352 |
|
/* Convert the strings into wide characters. */ |
353 |
|
mbsrtowcs (wpattern, &pattern, patsize, &ps); |
354 |
|
assert (mbsinit (&ps)); |
355 |
|
mbsrtowcs (wstring, &string, strsize, &ps); |
356 |
|
|
357 |
|
res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1, |
358 |
|
flags & FNM_PERIOD, flags); |
359 |
|
|
360 |
|
if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0)) |
361 |
|
free (wpattern); |
362 |
|
return res; |
363 |
} |
} |
364 |
} |
} |
|
wstring = wpattern + patsize; |
|
|
|
|
|
/* Convert the strings into wide characters. */ |
|
|
mbsrtowcs (wpattern, &pattern, patsize, &ps); |
|
|
assert (mbsinit (&ps)); |
|
|
mbsrtowcs (wstring, &string, strsize, &ps); |
|
|
|
|
|
res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1, |
|
|
flags & FNM_PERIOD, flags); |
|
|
|
|
|
if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0)) |
|
|
free (wpattern); |
|
|
return res; |
|
365 |
} |
} |
366 |
|
|
367 |
# endif /* HANDLE_MULTIBYTE */ |
# endif /* HANDLE_MULTIBYTE */ |
368 |
|
|
369 |
return internal_fnmatch (pattern, string, string + strlen (string), |
return internal_fnmatch (pattern, string, string + strlen (string), |