xref: /illumos-gate/usr/src/head/uchar.h (revision 99ea293e719ac006d413e4fde6ac0d5cd4dd6c59)
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 2020 Robert Mustacchi
14  */
15 
16 #ifndef _UCHAR_H
17 #define	_UCHAR_H
18 
19 /*
20  * C11 Unicode utilities support.
21  *
22  * Note, we do not define either __STDC_UTF_16__ or __STDC_UTF_32__. While the
23  * functions that are implemented work in that fashion, the ability to represent
24  * any UTF-16 or UTF-32 code point depends on the current locale. Though in
25  * practice they function that way.
26  */
27 
28 #include <sys/isa_defs.h>
29 #include <sys/feature_tests.h>
30 #include <wchar_impl.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #if !defined(_SIZE_T) || __cplusplus >= 199711L
37 #define	_SIZE_T
38 #if defined(_LP64) || defined(_I32LPx)
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 < 2011103L
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 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif /* _UCHAR_H */
75