xref: /illumos-gate/usr/src/head/uchar.h (revision e8d3efa1c56e5f2b5368600a2baeb7b1d54a07f8)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2026 Oxide Computer Company
14  */
15 
16 #ifndef _UCHAR_H
17 #define	_UCHAR_H
18 
19 /*
20  * C11+ Unicode utilities support.
21  */
22 
23 #include <sys/isa_defs.h>
24 #include <sys/feature_tests.h>
25 #include <wchar_impl.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /*
32  * Declare our version.
33  */
34 #define	__STDC_VERSION_UCHAR_H__	202311L
35 
36 #if !defined(_SIZE_T) || __cplusplus >= 199711L
37 #define	_SIZE_T
38 #if defined(_LP64)
39 typedef	unsigned long size_t;	/* size of something in bytes */
40 #else
41 typedef	unsigned int size_t;	/* (historical version) */
42 #endif
43 #endif	/* _SIZE_T */
44 
45 #if !defined(_MBSTATE_T) || __cplusplus >= 199711L
46 #define	_MBSTATE_T
47 typedef __mbstate_t	mbstate_t;
48 #endif	/* _MBSTATE_T */
49 
50 /*
51  * These types must match the uint_least16_t and uint_least32_t. They are
52  * defined in terms of the same type so as to minimize the needed includes.
53  * C++11 also defines these types and they are considered built in, so we should
54  * not define them in that context.
55  */
56 #if __cplusplus < 201103L
57 typedef unsigned short	char16_t;
58 typedef unsigned int	char32_t;
59 #endif
60 
61 extern size_t mbrtoc16(char16_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
62     size_t, mbstate_t *_RESTRICT_KYWD);
63 extern size_t mbrtoc32(char32_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
64     size_t, mbstate_t *_RESTRICT_KYWD);
65 extern size_t c16rtomb(char *_RESTRICT_KYWD, char16_t,
66     mbstate_t *_RESTRICT_KYWD);
67 extern size_t c32rtomb(char *_RESTRICT_KYWD, char32_t,
68     mbstate_t *_RESTRICT_KYWD);
69 
70 /*
71  * C23 added variants and types that operate on UTF-8 based encodings. C++20
72  * added the char8_t type hence the guards below. Because these weren't reserved
73  * symbols, C11 strictly speaking isn't supposed to see these, hence why we have
74  * _STRICT_SYMBOLS checks. Unlike the types above which are in terms of the
75  * uint_leastXX_t, this is strictly defined in terms of an unsigned char.
76  */
77 #if !defined(_STRICT_SYMBOLS) || defined(_STDC_C23)
78 #if __cplusplus < 202002L
79 typedef unsigned char	char8_t;
80 #endif
81 
82 extern size_t mbrtoc8(char8_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
83     size_t, mbstate_t *_RESTRICT_KYWD);
84 extern size_t c8rtomb(char *_RESTRICT_KYWD, char8_t, mbstate_t *_RESTRICT_KYWD);
85 #endif	/* !_STRICT_SYMBOLS || _STDC_C23 */
86 
87 /*
88  * We provide locale aware versions of all of the functions in a non-strict
89  * compilation environment.
90  */
91 #if !defined(_STRICT_SYMBOLS)
92 
93 #ifndef _LOCALE_T
94 #define	_LOCALE_T
95 typedef struct _locale *locale_t;
96 #endif
97 
98 extern size_t mbrtoc8_l(char8_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
99     size_t, mbstate_t *_RESTRICT_KYWD, locale_t _RESTRICT_KWYD);
100 extern size_t mbrtoc16_l(char16_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
101     size_t, mbstate_t *_RESTRICT_KYWD, locale_t _RESTRICT_KWYD);
102 extern size_t mbrtoc32_l(char32_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
103     size_t, mbstate_t *_RESTRICT_KYWD, locale_t _RESTRICT_KWYD);
104 
105 extern size_t c8rtomb_l(char *_RESTRICT_KYWD, char8_t,
106     mbstate_t *_RESTRICT_KYWD, locale_t _RESTRICT_KYWD);
107 extern size_t c16rtomb_l(char *_RESTRICT_KYWD, char16_t,
108     mbstate_t *_RESTRICT_KYWD, locale_t _RESTRICT_KYWD);
109 extern size_t c32rtomb_l(char *_RESTRICT_KYWD, char32_t,
110     mbstate_t *_RESTRICT_KYWD, locale_t _RESTRICT_KYWD);
111 #endif	/* !_STRICT_SYMBOLS */
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif /* _UCHAR_H */
118