Home | History | Annotate | Line # | Download | only in include
      1 /*	$NetBSD: uchar.h,v 1.6 2024/10/13 22:00:38 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/cdefs.h>
     40 #include <sys/featuretest.h>
     41 
     42 /*
     43  * C23	`2. The macro
     44  *
     45  *		__STDC_VERSION_UCHAR_H__
     46  *
     47  *	    is an integer constant expression with a value equivalent
     48  *	    to 202311L.'
     49  */
     50 #if defined(_NETBSD_SOURCE) || defined(_ISOC23_SOURCE) || \
     51     __STDC_VERSION__ - 0 >= 202311L
     52 #define	__STDC_VERSION_UCHAR_H__	202311L
     53 #endif
     54 
     55 /*
     56  * C11	`2. The types declared are mbstate_t (described in 7.30.1) and
     57  *	    size_t (described in 7.19);
     58  *
     59  *	    	char16_t
     60  *
     61  *	    which is an unsigned integer type used for 16-bit
     62  *	    characters and is the same type as uint_least16_t
     63  *	    (described in 7.20.1.2); and
     64  *
     65  *		char32_t
     66  *
     67  *	    which is an unsigned integer type used for 32-bit
     68  *	    characters and is the same type as uint_least32_t (also
     69  *	    described in 7.20.1.2).'
     70  */
     71 
     72 #ifdef _BSD_MBSTATE_T_
     73 typedef _BSD_MBSTATE_T_	mbstate_t;
     74 #undef _BSD_MBSTATE_T_
     75 #endif
     76 
     77 #ifdef _BSD_SIZE_T_
     78 typedef _BSD_SIZE_T_	size_t;
     79 #undef _BSD_SIZE_T_
     80 #endif
     81 
     82 /*
     83  * C23	`char8_t...is an unsigned integer type used for 8-bit
     84  *	 characters and is the same type as unsigned char'
     85  */
     86 #if defined(_NETBSD_SOURCE) || defined(_ISOC23_SOURCE) || \
     87     __STDC_VERSION__ - 0 >= 202311L
     88 #if __cpp_char8_t - 0 < 201811L
     89 typedef unsigned char		char8_t;
     90 #endif
     91 #endif
     92 
     93 #if __cplusplus - 0 < 201103L
     94 typedef __UINT_LEAST16_TYPE__	char16_t;
     95 typedef __UINT_LEAST32_TYPE__	char32_t;
     96 #endif
     97 
     98 __BEGIN_DECLS
     99 
    100 #if defined(_NETBSD_SOURCE) || defined(_ISOC23_SOURCE) || \
    101     __STDC_VERSION__ - 0 >= 202311L
    102 size_t	mbrtoc8(char8_t *__restrict, const char *__restrict, size_t,
    103 	    mbstate_t *__restrict);
    104 size_t	c8rtomb(char *__restrict, char8_t, mbstate_t *__restrict);
    105 #endif
    106 size_t	mbrtoc16(char16_t *__restrict, const char *__restrict, size_t,
    107 	    mbstate_t *__restrict);
    108 size_t	c16rtomb(char *__restrict, char16_t, mbstate_t *__restrict);
    109 size_t	mbrtoc32(char32_t *__restrict, const char *__restrict, size_t,
    110 	    mbstate_t *__restrict);
    111 size_t	c32rtomb(char *__restrict, char32_t, mbstate_t *__restrict);
    112 
    113 #ifdef _NETBSD_SOURCE
    114 struct _locale;
    115 size_t	mbrtoc8_l(char8_t *__restrict, const char *__restrict, size_t,
    116 	    mbstate_t *__restrict, struct _locale *__restrict);
    117 size_t	c8rtomb_l(char *__restrict, char8_t, mbstate_t *__restrict,
    118 	    struct _locale *__restrict);
    119 size_t	mbrtoc16_l(char16_t *__restrict, const char *__restrict, size_t,
    120 	    mbstate_t *__restrict, struct _locale *__restrict);
    121 size_t	c16rtomb_l(char *__restrict, char16_t, mbstate_t *__restrict,
    122 	    struct _locale *__restrict);
    123 size_t	mbrtoc32_l(char32_t *__restrict, const char *__restrict, size_t,
    124 	    mbstate_t *__restrict, struct _locale *__restrict);
    125 size_t	c32rtomb_l(char *__restrict, char32_t, mbstate_t *__restrict,
    126 	    struct _locale *__restrict);
    127 #endif
    128 
    129 __END_DECLS
    130 
    131 #endif	/* _UCHAR_H */
    132