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