summaryrefslogtreecommitdiffstats
path: root/gl/mbsinit.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/mbsinit.c')
-rw-r--r--gl/mbsinit.c52
1 files changed, 30 insertions, 22 deletions
diff --git a/gl/mbsinit.c b/gl/mbsinit.c
index 26fbb7f..6e60079 100644
--- a/gl/mbsinit.c
+++ b/gl/mbsinit.c
@@ -1,38 +1,27 @@
1/* Test for initial conversion state. 1/* Test for initial conversion state.
2 Copyright (C) 2008-2013 Free Software Foundation, Inc. 2 Copyright (C) 2008-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU Lesser General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
20/* Specification. */ 20/* Specification. */
21#include <wchar.h> 21#include <wchar.h>
22 22
23#include "verify.h"
24 23
25#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ 24#if GNULIB_defined_mbstate_t
26
27/* On native Windows, 'mbstate_t' is defined as 'int'. */
28
29int
30mbsinit (const mbstate_t *ps)
31{
32 return ps == NULL || *ps == 0;
33}
34
35#else
36 25
37/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs() 26/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs()
38 and wcrtomb(), wcsrtombs(). 27 and wcrtomb(), wcsrtombs().
@@ -45,10 +34,11 @@ mbsinit (const mbstate_t *ps)
45 We define the meaning of mbstate_t as follows: 34 We define the meaning of mbstate_t as follows:
46 - In mb -> wc direction, mbstate_t's first byte contains the number of 35 - In mb -> wc direction, mbstate_t's first byte contains the number of
47 buffered bytes (in the range 0..3), followed by up to 3 buffered bytes. 36 buffered bytes (in the range 0..3), followed by up to 3 buffered bytes.
37 See mbrtowc.c.
48 - In wc -> mb direction, mbstate_t contains no information. In other 38 - In wc -> mb direction, mbstate_t contains no information. In other
49 words, it is always in the initial state. */ 39 words, it is always in the initial state. */
50 40
51verify (sizeof (mbstate_t) >= 4); 41static_assert (sizeof (mbstate_t) >= 4);
52 42
53int 43int
54mbsinit (const mbstate_t *ps) 44mbsinit (const mbstate_t *ps)
@@ -58,4 +48,22 @@ mbsinit (const mbstate_t *ps)
58 return pstate == NULL || pstate[0] == 0; 48 return pstate == NULL || pstate[0] == 0;
59} 49}
60 50
51#else
52
53int
54mbsinit (const mbstate_t *ps)
55{
56# if defined _WIN32 && !defined __CYGWIN__
57 /* Native Windows. */
58 /* MSVC defines 'mbstate_t' as an 8-byte struct; the first 4 bytes matter.
59 On mingw, 'mbstate_t' is sometimes defined as 'int', sometimes defined as
60 an 8-byte struct, of which the first 4 bytes matter. */
61 return ps == NULL || *(const unsigned int *)ps == 0;
62# else
63 /* Minix, HP-UX 11.00, Solaris 2.6, Interix, ... */
64 /* Maybe this definition works, maybe not... */
65 return ps == NULL || *(const char *)ps == 0;
66# endif
67}
68
61#endif 69#endif