2007-12-12 20:12:24 +08:00
|
|
|
/* wchar.h: Extra wchar defs
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#ifndef _CYGWIN_WCHAR_H
|
|
|
|
#define _CYGWIN_WCHAR_H
|
|
|
|
|
|
|
|
#include_next <wchar.h>
|
|
|
|
|
2016-07-21 04:05:59 +08:00
|
|
|
/* Internal headers from newlib */
|
|
|
|
#include "../locale/setlocale.h"
|
|
|
|
|
2009-04-07 20:13:37 +08:00
|
|
|
#define ENCODING_LEN 31
|
|
|
|
|
2007-12-12 20:12:24 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-03-24 20:18:34 +08:00
|
|
|
typedef int mbtowc_f (struct _reent *, wchar_t *, const char *, size_t,
|
2016-07-21 04:05:59 +08:00
|
|
|
mbstate_t *);
|
2009-03-24 20:18:34 +08:00
|
|
|
typedef mbtowc_f *mbtowc_p;
|
2007-12-12 20:12:24 +08:00
|
|
|
|
2009-03-24 21:21:23 +08:00
|
|
|
extern mbtowc_f __ascii_mbtowc;
|
|
|
|
extern mbtowc_f __utf8_mbtowc;
|
2016-07-21 04:05:59 +08:00
|
|
|
extern mbtowc_p __iso_mbtowc (int);
|
|
|
|
extern mbtowc_p __cp_mbtowc (int);
|
|
|
|
|
|
|
|
#define __MBTOWC (__get_current_locale ()->mbtowc)
|
|
|
|
|
|
|
|
typedef int wctomb_f (struct _reent *, char *, wchar_t, mbstate_t *);
|
2009-04-07 20:13:37 +08:00
|
|
|
typedef wctomb_f *wctomb_p;
|
|
|
|
|
2009-05-15 03:49:37 +08:00
|
|
|
extern wctomb_f __ascii_wctomb;
|
2009-04-07 20:13:37 +08:00
|
|
|
extern wctomb_f __utf8_wctomb;
|
|
|
|
|
2016-07-21 04:05:59 +08:00
|
|
|
#define __WCTOMB (__get_current_locale ()->wctomb)
|
2009-03-24 20:18:34 +08:00
|
|
|
|
2023-02-21 05:29:37 +08:00
|
|
|
/* convert wint_t string to wchar_t string. Make sure dest
|
|
|
|
has room for at least twice as much characters to account
|
|
|
|
for surrogate pairs, plus a wchar_t NUL. */
|
|
|
|
void wcintowcs (wchar_t *, wint_t *, size_t);
|
|
|
|
|
2023-02-22 17:03:03 +08:00
|
|
|
/* replacement function for wcrtomb, converting a UTF-32 char to a
|
|
|
|
multibyte string. */
|
|
|
|
size_t wirtomb (char *, wint_t, mbstate_t *);
|
|
|
|
|
2023-02-14 19:20:20 +08:00
|
|
|
/* replacement function for mbrtowc, returning a wint_t representing
|
|
|
|
a UTF-32 value. Defined in strfuncs.cc */
|
2023-02-15 03:18:42 +08:00
|
|
|
extern size_t mbrtowi (wint_t *, const char *, size_t, mbstate_t *);
|
2023-02-14 19:20:20 +08:00
|
|
|
|
2023-02-21 05:29:37 +08:00
|
|
|
/* like wcslen, just for wint_t */
|
|
|
|
static inline size_t
|
|
|
|
wcilen (const wint_t *wcs)
|
|
|
|
{
|
|
|
|
size_t ret = 0;
|
|
|
|
|
|
|
|
if (wcs)
|
|
|
|
while (*wcs++)
|
|
|
|
++ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* like wcscmp, just for wint_t */
|
|
|
|
static inline int
|
|
|
|
wcicmp (const wint_t *s1, const wint_t *s2)
|
|
|
|
{
|
|
|
|
while (*s1 == *s2++)
|
|
|
|
if (*s1++ == 0)
|
|
|
|
return (0);
|
|
|
|
return (*s1 - *--s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* like wcsncmp, just for wint_t */
|
|
|
|
static inline int
|
|
|
|
wcincmp (const wint_t *s1, const wint_t *s2, size_t n)
|
|
|
|
{
|
|
|
|
if (n == 0)
|
|
|
|
return (0);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (*s1 != *s2++)
|
|
|
|
{
|
|
|
|
return (*s1 - *--s2);
|
|
|
|
}
|
|
|
|
if (*s1++ == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (--n != 0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-12-12 20:12:24 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2009-04-07 20:13:37 +08:00
|
|
|
|
2009-04-08 00:22:55 +08:00
|
|
|
#ifdef __INSIDE_CYGWIN__
|
2010-02-04 20:35:49 +08:00
|
|
|
#ifdef __cplusplus
|
2020-07-10 16:29:33 +08:00
|
|
|
extern size_t _sys_wcstombs (char *dst, size_t len, const wchar_t *src,
|
|
|
|
size_t nwc, bool is_path);
|
|
|
|
extern size_t _sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src,
|
|
|
|
size_t nwc, bool is_path);
|
|
|
|
|
|
|
|
static inline size_t
|
|
|
|
sys_wcstombs (char *dst, size_t len, const wchar_t * src,
|
|
|
|
size_t nwc = (size_t) -1)
|
|
|
|
{
|
|
|
|
return _sys_wcstombs (dst, len, src, nwc, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t
|
|
|
|
sys_wcstombs_no_path (char *dst, size_t len, const wchar_t * src,
|
|
|
|
size_t nwc = (size_t) -1)
|
|
|
|
{
|
|
|
|
return _sys_wcstombs (dst, len, src, nwc, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t
|
|
|
|
sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src,
|
|
|
|
size_t nwc = (size_t) -1)
|
|
|
|
{
|
|
|
|
return _sys_wcstombs_alloc (dst_p, type, src, nwc, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t
|
|
|
|
sys_wcstombs_alloc_no_path (char **dst_p, int type, const wchar_t *src,
|
|
|
|
size_t nwc = (size_t) -1)
|
|
|
|
{
|
|
|
|
return _sys_wcstombs_alloc (dst_p, type, src, nwc, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t _sys_mbstowcs (mbtowc_p, wchar_t *, size_t, const char *,
|
|
|
|
size_t = (size_t) -1);
|
|
|
|
|
|
|
|
static inline size_t
|
|
|
|
sys_mbstowcs (wchar_t * dst, size_t dlen, const char *src,
|
|
|
|
size_t nms = (size_t) -1)
|
|
|
|
{
|
|
|
|
mbtowc_p f_mbtowc = (__MBTOWC == __ascii_mbtowc) ? __utf8_mbtowc : __MBTOWC;
|
|
|
|
return _sys_mbstowcs (f_mbtowc, dst, dlen, src, nms);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t sys_mbstowcs_alloc (wchar_t **, int, const char *, size_t = (size_t) -1);
|
|
|
|
|
2022-08-05 17:45:49 +08:00
|
|
|
static inline size_t
|
|
|
|
sys_mbstouni (PUNICODE_STRING dst, int type, const char *src,
|
|
|
|
size_t nms = (size_t) -1)
|
|
|
|
{
|
|
|
|
/* sys_mbstowcs returns length *excluding* trailing \0 */
|
|
|
|
size_t len = sys_mbstowcs (dst->Buffer, type, src, nms);
|
|
|
|
dst->Length = len * sizeof (WCHAR);
|
|
|
|
dst->MaximumLength = dst->Length + sizeof (WCHAR);
|
|
|
|
return dst->Length;
|
|
|
|
}
|
|
|
|
|
2022-08-05 05:48:19 +08:00
|
|
|
static inline size_t
|
|
|
|
sys_mbstouni_alloc (PUNICODE_STRING dst, int type, const char *src,
|
|
|
|
size_t nms = (size_t) -1)
|
|
|
|
{
|
2022-08-21 02:27:37 +08:00
|
|
|
/* sys_mbstowcs_alloc returns length *including* trailing \0 */
|
2022-08-05 05:48:19 +08:00
|
|
|
size_t len = sys_mbstowcs_alloc (&dst->Buffer, type, src, nms);
|
|
|
|
dst->MaximumLength = len * sizeof (WCHAR);
|
|
|
|
dst->Length = dst->MaximumLength - sizeof (WCHAR);
|
|
|
|
return dst->MaximumLength;
|
|
|
|
}
|
|
|
|
|
2010-02-04 20:35:49 +08:00
|
|
|
#endif /* __cplusplus */
|
2009-04-08 00:22:55 +08:00
|
|
|
#endif /* __INSIDE_CYGWIN__ */
|
2009-04-07 20:13:37 +08:00
|
|
|
|
2007-12-12 20:12:24 +08:00
|
|
|
#endif /* _CYGWIN_WCHAR_H */
|