1 /* Compare two wide strings using the current locale.
2 Copyright (C) 2011-2017 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2011.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 wcscoll (const wchar_t *s1
, const wchar_t *s2
)
27 int saved_errno
= errno
;
29 /* Convert s1 to a multibyte string, trying to avoid malloc(). */
33 ret
= wcstombs (mbbuf1
, s1
, sizeof (mbbuf1
));
34 if (ret
== (size_t)-1)
36 if (ret
< sizeof (mbbuf1
))
40 size_t need
= wcstombs (NULL
, s1
, 0);
41 if (need
== (size_t)-1)
43 mbs1
= (char *) malloc (need
+ 1);
46 ret
= wcstombs (mbs1
, s1
, need
+ 1);
52 /* Convert s2 to a multibyte string, trying to avoid malloc(). */
56 ret
= wcstombs (mbbuf2
, s2
, sizeof (mbbuf2
));
57 if (ret
== (size_t)-1)
59 if (ret
< sizeof (mbbuf2
))
63 size_t need
= wcstombs (NULL
, s2
, 0);
64 if (need
== (size_t)-1)
66 mbs2
= (char *) malloc (need
+ 1);
69 ret
= wcstombs (mbs2
, s2
, need
+ 1);
75 /* No error so far. */
79 /* Compare the two multibyte strings. */
81 int result
= strcoll (mbs1
, mbs2
);
85 int saved_errno
= errno
;
91 int saved_errno
= errno
;