|
Packit Service |
a2ae7a |
/* Test for initial conversion state.
|
|
Packit Service |
a2ae7a |
Copyright (C) 2008-2019 Free Software Foundation, Inc.
|
|
Packit Service |
a2ae7a |
Written by Bruno Haible <bruno@clisp.org>, 2008.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
a2ae7a |
it under the terms of the GNU Lesser General Public License as published by
|
|
Packit Service |
a2ae7a |
the Free Software Foundation; either version 2.1 of the License, or
|
|
Packit Service |
a2ae7a |
(at your option) any later version.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
a2ae7a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2ae7a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
a2ae7a |
GNU Lesser General Public License for more details.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
a2ae7a |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <config.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Specification. */
|
|
Packit Service |
a2ae7a |
#include <wchar.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "verify.h"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#if GNULIB_defined_mbstate_t
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs()
|
|
Packit Service |
a2ae7a |
and wcrtomb(), wcsrtombs().
|
|
Packit Service |
a2ae7a |
We assume that
|
|
Packit Service |
a2ae7a |
- sizeof (mbstate_t) >= 4,
|
|
Packit Service |
a2ae7a |
- only stateless encodings are supported (such as UTF-8 and EUC-JP, but
|
|
Packit Service |
a2ae7a |
not ISO-2022 variants),
|
|
Packit Service |
a2ae7a |
- for each encoding, the number of bytes for a wide character is <= 4.
|
|
Packit Service |
a2ae7a |
(This maximum is attained for UTF-8, GB18030, EUC-TW.)
|
|
Packit Service |
a2ae7a |
We define the meaning of mbstate_t as follows:
|
|
Packit Service |
a2ae7a |
- In mb -> wc direction, mbstate_t's first byte contains the number of
|
|
Packit Service |
a2ae7a |
buffered bytes (in the range 0..3), followed by up to 3 buffered bytes.
|
|
Packit Service |
a2ae7a |
See mbrtowc.c.
|
|
Packit Service |
a2ae7a |
- In wc -> mb direction, mbstate_t contains no information. In other
|
|
Packit Service |
a2ae7a |
words, it is always in the initial state. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
verify (sizeof (mbstate_t) >= 4);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
int
|
|
Packit Service |
a2ae7a |
mbsinit (const mbstate_t *ps)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
const char *pstate = (const char *)ps;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
return pstate == NULL || pstate[0] == 0;
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#else
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
int
|
|
Packit Service |
a2ae7a |
mbsinit (const mbstate_t *ps)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
# if defined _WIN32 && !defined __CYGWIN__
|
|
Packit Service |
a2ae7a |
/* Native Windows. */
|
|
Packit Service |
a2ae7a |
# ifdef __MINGW32__
|
|
Packit Service |
a2ae7a |
/* On mingw, 'mbstate_t' is defined as 'int'. */
|
|
Packit Service |
a2ae7a |
return ps == NULL || *ps == 0;
|
|
Packit Service |
a2ae7a |
# else
|
|
Packit Service |
a2ae7a |
/* MSVC defines 'mbstate_t' as an 8-byte struct; the first 4-bytes matter. */
|
|
Packit Service |
a2ae7a |
return ps == NULL || *(const unsigned int *)ps == 0;
|
|
Packit Service |
a2ae7a |
# endif
|
|
Packit Service |
a2ae7a |
# else
|
|
Packit Service |
a2ae7a |
/* Minix, HP-UX 11.00, Solaris 2.6, Interix, ... */
|
|
Packit Service |
a2ae7a |
/* Maybe this definition works, maybe not... */
|
|
Packit Service |
a2ae7a |
return ps == NULL || *(const char *)ps == 0;
|
|
Packit Service |
a2ae7a |
# endif
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#endif
|