summaryrefslogtreecommitdiff
path: root/lib/glob/smatch.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/glob/smatch.c')
-rw-r--r--lib/glob/smatch.c27
1 files changed, 4 insertions, 23 deletions
diff --git a/lib/glob/smatch.c b/lib/glob/smatch.c
index 8c54702b..d0b7403d 100644
--- a/lib/glob/smatch.c
+++ b/lib/glob/smatch.c
@@ -362,44 +362,25 @@ xstrmatch (pattern, string, flags)
{
#if HANDLE_MULTIBYTE
int ret;
- mbstate_t ps;
size_t n;
- char *pattern_bak;
wchar_t *wpattern, *wstring;
if (MB_CUR_MAX == 1)
return (internal_strmatch (pattern, string, flags));
- pattern_bak = (char *)xmalloc (strlen (pattern) + 1);
- strcpy (pattern_bak, pattern);
-
- memset (&ps, '\0', sizeof (mbstate_t));
- n = xmbsrtowcs (NULL, (const char **)&pattern, 0, &ps);
+ n = xdupmbstowcs (&wpattern, NULL, pattern);
if (n == (size_t)-1 || n == (size_t)-2)
- {
- free (pattern_bak);
- return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
- }
+ return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
- wpattern = (wchar_t *)xmalloc ((n + 1) * sizeof (wchar_t));
- (void) xmbsrtowcs (wpattern, (const char **)&pattern, n + 1, &ps);
-
- memset (&ps, '\0', sizeof (mbstate_t));
- n = xmbsrtowcs (NULL, (const char **)&string, 0, &ps);
+ n = xdupmbstowcs (&wstring, NULL, string);
if (n == (size_t)-1 || n == (size_t)-2)
{
free (wpattern);
- ret = internal_strmatch (pattern_bak, string, flags);
- free (pattern_bak);
- return ret;
+ return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
}
- wstring = (wchar_t *)xmalloc ((n + 1) * sizeof (wchar_t));
- (void) xmbsrtowcs (wstring, (const char **)&string, n + 1, &ps);
-
ret = internal_wstrmatch (wpattern, wstring, flags);
- free (pattern_bak);
free (wpattern);
free (wstring);