xref: /netbsd-src/include/uchar.h (revision 0e2070ac98d1e81b871328485d0fc5739ae12ea9)
1*0e2070acSriastradh /*	$NetBSD: uchar.h,v 1.6 2024/10/13 22:00:38 riastradh Exp $	*/
2cc1e5796Sriastradh 
3cc1e5796Sriastradh /*-
4cc1e5796Sriastradh  * Copyright (c) 2024 The NetBSD Foundation, Inc.
5cc1e5796Sriastradh  * All rights reserved.
6cc1e5796Sriastradh  *
7cc1e5796Sriastradh  * Redistribution and use in source and binary forms, with or without
8cc1e5796Sriastradh  * modification, are permitted provided that the following conditions
9cc1e5796Sriastradh  * are met:
10cc1e5796Sriastradh  * 1. Redistributions of source code must retain the above copyright
11cc1e5796Sriastradh  *    notice, this list of conditions and the following disclaimer.
12cc1e5796Sriastradh  * 2. Redistributions in binary form must reproduce the above copyright
13cc1e5796Sriastradh  *    notice, this list of conditions and the following disclaimer in the
14cc1e5796Sriastradh  *    documentation and/or other materials provided with the distribution.
15cc1e5796Sriastradh  *
16cc1e5796Sriastradh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17cc1e5796Sriastradh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18cc1e5796Sriastradh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19cc1e5796Sriastradh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20cc1e5796Sriastradh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21cc1e5796Sriastradh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22cc1e5796Sriastradh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23cc1e5796Sriastradh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24cc1e5796Sriastradh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25cc1e5796Sriastradh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26cc1e5796Sriastradh  * POSSIBILITY OF SUCH DAMAGE.
27cc1e5796Sriastradh  */
28cc1e5796Sriastradh 
29cc1e5796Sriastradh /*
30cc1e5796Sriastradh  * C11, 7.28: Unicode utilities <uchar.h>
31c4e44ee2Sriastradh  * C17, 7.28: Unicode utilities <uchar.h> (unchanged from C11)
32c4e44ee2Sriastradh  * C23, 7.30: Unicode utilities <uchar.h>
33cc1e5796Sriastradh  */
34cc1e5796Sriastradh 
35cc1e5796Sriastradh #ifndef	_UCHAR_H
36cc1e5796Sriastradh #define	_UCHAR_H
37cc1e5796Sriastradh 
38cc1e5796Sriastradh #include <sys/ansi.h>
39ecf4058cSriastradh #include <sys/cdefs.h>
402b82e545Sriastradh #include <sys/featuretest.h>
41cc1e5796Sriastradh 
42cc1e5796Sriastradh /*
43c4e44ee2Sriastradh  * C23	`2. The macro
44c4e44ee2Sriastradh  *
45c4e44ee2Sriastradh  *		__STDC_VERSION_UCHAR_H__
46c4e44ee2Sriastradh  *
47c4e44ee2Sriastradh  *	    is an integer constant expression with a value equivalent
48c4e44ee2Sriastradh  *	    to 202311L.'
49c4e44ee2Sriastradh  */
50c4e44ee2Sriastradh #if defined(_NETBSD_SOURCE) || defined(_ISOC23_SOURCE) || \
51c4e44ee2Sriastradh     __STDC_VERSION__ - 0 >= 202311L
52c4e44ee2Sriastradh #define	__STDC_VERSION_UCHAR_H__	202311L
53c4e44ee2Sriastradh #endif
54c4e44ee2Sriastradh 
55c4e44ee2Sriastradh /*
56c4e44ee2Sriastradh  * C11	`2. The types declared are mbstate_t (described in 7.30.1) and
57cc1e5796Sriastradh  *	    size_t (described in 7.19);
58cc1e5796Sriastradh  *
59cc1e5796Sriastradh  *	    	char16_t
60cc1e5796Sriastradh  *
61cc1e5796Sriastradh  *	    which is an unsigned integer type used for 16-bit
62cc1e5796Sriastradh  *	    characters and is the same type as uint_least16_t
63cc1e5796Sriastradh  *	    (described in 7.20.1.2); and
64cc1e5796Sriastradh  *
65cc1e5796Sriastradh  *		char32_t
66cc1e5796Sriastradh  *
67cc1e5796Sriastradh  *	    which is an unsigned integer type used for 32-bit
68cc1e5796Sriastradh  *	    characters and is the same type as uint_least32_t (also
69cc1e5796Sriastradh  *	    described in 7.20.1.2).'
70cc1e5796Sriastradh  */
71cc1e5796Sriastradh 
72cc1e5796Sriastradh #ifdef _BSD_MBSTATE_T_
73cc1e5796Sriastradh typedef _BSD_MBSTATE_T_	mbstate_t;
74cc1e5796Sriastradh #undef _BSD_MBSTATE_T_
75cc1e5796Sriastradh #endif
76cc1e5796Sriastradh 
77cc1e5796Sriastradh #ifdef _BSD_SIZE_T_
78cc1e5796Sriastradh typedef _BSD_SIZE_T_	size_t;
79cc1e5796Sriastradh #undef _BSD_SIZE_T_
80cc1e5796Sriastradh #endif
81cc1e5796Sriastradh 
82c4e44ee2Sriastradh /*
83c4e44ee2Sriastradh  * C23	`char8_t...is an unsigned integer type used for 8-bit
84c4e44ee2Sriastradh  *	 characters and is the same type as unsigned char'
85c4e44ee2Sriastradh  */
86c4e44ee2Sriastradh #if defined(_NETBSD_SOURCE) || defined(_ISOC23_SOURCE) || \
87c4e44ee2Sriastradh     __STDC_VERSION__ - 0 >= 202311L
88*0e2070acSriastradh #if __cpp_char8_t - 0 < 201811L
89c4e44ee2Sriastradh typedef unsigned char		char8_t;
90c4e44ee2Sriastradh #endif
91c4e44ee2Sriastradh #endif
92c4e44ee2Sriastradh 
93*0e2070acSriastradh #if __cplusplus - 0 < 201103L
94cc1e5796Sriastradh typedef __UINT_LEAST16_TYPE__	char16_t;
95cc1e5796Sriastradh typedef __UINT_LEAST32_TYPE__	char32_t;
96cc1e5796Sriastradh #endif
97cc1e5796Sriastradh 
98cc1e5796Sriastradh __BEGIN_DECLS
99cc1e5796Sriastradh 
100c4e44ee2Sriastradh #if defined(_NETBSD_SOURCE) || defined(_ISOC23_SOURCE) || \
101c4e44ee2Sriastradh     __STDC_VERSION__ - 0 >= 202311L
102c4e44ee2Sriastradh size_t	mbrtoc8(char8_t *__restrict, const char *__restrict, size_t,
103c4e44ee2Sriastradh 	    mbstate_t *__restrict);
104c4e44ee2Sriastradh size_t	c8rtomb(char *__restrict, char8_t, mbstate_t *__restrict);
105c4e44ee2Sriastradh #endif
106cc1e5796Sriastradh size_t	mbrtoc16(char16_t *__restrict, const char *__restrict, size_t,
107cc1e5796Sriastradh 	    mbstate_t *__restrict);
108cc1e5796Sriastradh size_t	c16rtomb(char *__restrict, char16_t, mbstate_t *__restrict);
109cc1e5796Sriastradh size_t	mbrtoc32(char32_t *__restrict, const char *__restrict, size_t,
110cc1e5796Sriastradh 	    mbstate_t *__restrict);
111cc1e5796Sriastradh size_t	c32rtomb(char *__restrict, char32_t, mbstate_t *__restrict);
112cc1e5796Sriastradh 
1134651a634Sriastradh #ifdef _NETBSD_SOURCE
1144651a634Sriastradh struct _locale;
1154651a634Sriastradh size_t	mbrtoc8_l(char8_t *__restrict, const char *__restrict, size_t,
1164651a634Sriastradh 	    mbstate_t *__restrict, struct _locale *__restrict);
1174651a634Sriastradh size_t	c8rtomb_l(char *__restrict, char8_t, mbstate_t *__restrict,
1184651a634Sriastradh 	    struct _locale *__restrict);
1194651a634Sriastradh size_t	mbrtoc16_l(char16_t *__restrict, const char *__restrict, size_t,
1204651a634Sriastradh 	    mbstate_t *__restrict, struct _locale *__restrict);
1214651a634Sriastradh size_t	c16rtomb_l(char *__restrict, char16_t, mbstate_t *__restrict,
1224651a634Sriastradh 	    struct _locale *__restrict);
1234651a634Sriastradh size_t	mbrtoc32_l(char32_t *__restrict, const char *__restrict, size_t,
1244651a634Sriastradh 	    mbstate_t *__restrict, struct _locale *__restrict);
1254651a634Sriastradh size_t	c32rtomb_l(char *__restrict, char32_t, mbstate_t *__restrict,
1264651a634Sriastradh 	    struct _locale *__restrict);
1274651a634Sriastradh #endif
1284651a634Sriastradh 
129cc1e5796Sriastradh __END_DECLS
130cc1e5796Sriastradh 
131cc1e5796Sriastradh #endif	/* _UCHAR_H */
132