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