Debian Codegraph @

lib/mbs_to_wcs.c

raw symbols SCIP
1 /*
2 * fstrcmp - fuzzy string compare library
3 * Copyright (C) 2009 Peter Miller
4 * Written by Peter Miller <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <lib/ac/stdlib.h>
21 #include <lib/ac/string.h>
22
23 #include <lib/mbs_to_wcs.h>
24
25
26 wchar_t *
27 fstrcmp_mbs_to_wcs(const char *mbs)
28 {
29 size_t mbs_len;
30 size_t wcs_len;
31 wchar_t *wcs;
32
33 mbs_len = strlen(mbs) + 1;
34 wcs_len = mbstowcs(NULL, mbs, mbs_len);
35 if (wcs_len == (size_t)-1)
36 return NULL;
37 wcs = malloc(sizeof(wchar_t) * (wcs_len + 1));
38 if (!wcs)
39 return NULL;
40 wcs_len = mbstowcs(wcs, mbs, wcs_len + 1);
41 if (wcs_len == (size_t)-1)
42 {
43 free(wcs);
44 return NULL;
45 }
46 return wcs;
47 }