Module Name:    src
Committed By:   riastradh
Date:           Thu Aug 15 13:14:44 UTC 2024

Modified Files:
        src/distrib/sets/lists/comp: mi
        src/distrib/sets/lists/debug: mi
        src/distrib/sets/lists/tests: mi
        src/include: Makefile
        src/tests/lib/libc/locale: Makefile
Added Files:
        src/include: uchar.h
        src/tests/lib/libc/locale: t_uchar.c

Log Message:
uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later.  Updates for C23 to come later.

PR lib/52374: <uchar.h> missing


To generate a diff of this commit:
cvs rdiff -u -r1.2467 -r1.2468 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.441 -r1.442 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.1329 -r1.1330 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.146 -r1.147 src/include/Makefile
cvs rdiff -u -r0 -r1.1 src/include/uchar.h
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/locale/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/locale/t_uchar.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2467 src/distrib/sets/lists/comp/mi:1.2468
--- src/distrib/sets/lists/comp/mi:1.2467	Mon Aug  5 13:06:38 2024
+++ src/distrib/sets/lists/comp/mi	Thu Aug 15 13:14:43 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2467 2024/08/05 13:06:38 christos Exp $
+#	$NetBSD: mi,v 1.2468 2024/08/15 13:14:43 riastradh Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp				comp-sys-root
@@ -3679,6 +3679,7 @@
 ./usr/include/tss/tss_typedef.h			comp-c-include		tpm
 ./usr/include/ttyent.h				comp-c-include
 ./usr/include/tzfile.h				comp-c-include
+./usr/include/uchar.h				comp-c-include
 ./usr/include/ucontext.h			comp-c-include
 ./usr/include/ufs/ext2fs/ext2fs.h		comp-c-include
 ./usr/include/ufs/ext2fs/ext2fs_dinode.h	comp-c-include

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.441 src/distrib/sets/lists/debug/mi:1.442
--- src/distrib/sets/lists/debug/mi:1.441	Fri Aug  9 23:24:15 2024
+++ src/distrib/sets/lists/debug/mi	Thu Aug 15 13:14:44 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.441 2024/08/09 23:24:15 bad Exp $
+# $NetBSD: mi,v 1.442 2024/08/15 13:14:44 riastradh Exp $
 #
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib					comp-sys-usr		compatdir
@@ -2070,6 +2070,7 @@
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_sprintf.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_strfmon.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_toupper.debug		tests-lib-debug		debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/locale/t_uchar.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_wcscoll.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_wcscspn.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_wcspbrk.debug		tests-lib-debug		debug,atf,compattestfile

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1329 src/distrib/sets/lists/tests/mi:1.1330
--- src/distrib/sets/lists/tests/mi:1.1329	Fri Aug  9 23:24:15 2024
+++ src/distrib/sets/lists/tests/mi	Thu Aug 15 13:14:44 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1329 2024/08/09 23:24:15 bad Exp $
+# $NetBSD: mi,v 1.1330 2024/08/15 13:14:44 riastradh Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3085,6 +3085,7 @@
 ./usr/tests/lib/libc/locale/t_sprintf			tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/locale/t_strfmon			tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/locale/t_toupper			tests-lib-tests		compattestfile,atf
+./usr/tests/lib/libc/locale/t_uchar			tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/locale/t_wcscoll			tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/locale/t_wcscspn			tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/locale/t_wcspbrk			tests-lib-tests		compattestfile,atf

Index: src/include/Makefile
diff -u src/include/Makefile:1.146 src/include/Makefile:1.147
--- src/include/Makefile:1.146	Tue Jun  4 15:07:55 2019
+++ src/include/Makefile	Thu Aug 15 13:14:44 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.146 2019/06/04 15:07:55 hannken Exp $
+#	$NetBSD: Makefile,v 1.147 2024/08/15 13:14:44 riastradh Exp $
 #	@(#)Makefile	8.2 (Berkeley) 1/4/94
 
 # Doing a make includes builds /usr/include
@@ -21,6 +21,7 @@ INCS=	a.out.h aio.h ar.h assert.h atomic
 	string.h sgtty.h signal.h spawn.h stab.h stdalign.h stddef.h stdio.h \
 	stdlib.h stdnoreturn.h strings.h stringlist.h struct.h sysexits.h \
 	tar.h time.h ttyent.h tzfile.h \
+	uchar.h \
 	ucontext.h ulimit.h unistd.h util.h utime.h utmp.h utmpx.h uuid.h \
 	vis.h wchar.h wctype.h wordexp.h
 INCS+=	arpa/ftp.h arpa/inet.h arpa/nameser.h arpa/nameser_compat.h \

Index: src/tests/lib/libc/locale/Makefile
diff -u src/tests/lib/libc/locale/Makefile:1.15 src/tests/lib/libc/locale/Makefile:1.16
--- src/tests/lib/libc/locale/Makefile:1.15	Wed Aug 14 23:32:31 2024
+++ src/tests/lib/libc/locale/Makefile	Thu Aug 15 13:14:44 2024
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.15 2024/08/14 23:32:31 riastradh Exp $
+# $NetBSD: Makefile,v 1.16 2024/08/15 13:14:44 riastradh Exp $
 
 .include <bsd.own.mk>
 
@@ -15,6 +15,7 @@ TESTS_C+=	t_mbtowc
 TESTS_C+=	t_sprintf
 TESTS_C+=	t_strfmon
 TESTS_C+=	t_toupper
+TESTS_C+=	t_uchar
 TESTS_C+=	t_wcscoll
 TESTS_C+=	t_wcscspn
 TESTS_C+=	t_wcspbrk

Added files:

Index: src/include/uchar.h
diff -u /dev/null src/include/uchar.h:1.1
--- /dev/null	Thu Aug 15 13:14:45 2024
+++ src/include/uchar.h	Thu Aug 15 13:14:44 2024
@@ -0,0 +1,84 @@
+/*	$NetBSD: uchar.h,v 1.1 2024/08/15 13:14:44 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2024 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * C11, 7.28: Unicode utilities <uchar.h>
+ *
+ *	`1. The header <uchar.h> declares types and functions for
+ *	    manipulating Unicode characters.'
+ */
+
+#ifndef	_UCHAR_H
+#define	_UCHAR_H
+
+#include <sys/ansi.h>
+
+/*
+ *	`2. The types declared are mbstate_t (described in 7.30.1) and
+ *	    size_t (described in 7.19);
+ *
+ *	    	char16_t
+ *
+ *	    which is an unsigned integer type used for 16-bit
+ *	    characters and is the same type as uint_least16_t
+ *	    (described in 7.20.1.2); and
+ *
+ *		char32_t
+ *
+ *	    which is an unsigned integer type used for 32-bit
+ *	    characters and is the same type as uint_least32_t (also
+ *	    described in 7.20.1.2).'
+ */
+
+#ifdef _BSD_MBSTATE_T_
+typedef _BSD_MBSTATE_T_	mbstate_t;
+#undef _BSD_MBSTATE_T_
+#endif
+
+#ifdef _BSD_SIZE_T_
+typedef _BSD_SIZE_T_	size_t;
+#undef _BSD_SIZE_T_
+#endif
+
+#if !defined(__cplusplus) || __cplusplus < 201103L
+typedef __UINT_LEAST16_TYPE__	char16_t;
+typedef __UINT_LEAST32_TYPE__	char32_t;
+#endif
+
+__BEGIN_DECLS
+
+size_t	mbrtoc16(char16_t *__restrict, const char *__restrict, size_t,
+	    mbstate_t *__restrict);
+size_t	c16rtomb(char *__restrict, char16_t, mbstate_t *__restrict);
+size_t	mbrtoc32(char32_t *__restrict, const char *__restrict, size_t,
+	    mbstate_t *__restrict);
+size_t	c32rtomb(char *__restrict, char32_t, mbstate_t *__restrict);
+
+__END_DECLS
+
+#endif	/* _UCHAR_H */

Index: src/tests/lib/libc/locale/t_uchar.c
diff -u /dev/null src/tests/lib/libc/locale/t_uchar.c:1.1
--- /dev/null	Thu Aug 15 13:14:45 2024
+++ src/tests/lib/libc/locale/t_uchar.c	Thu Aug 15 13:14:44 2024
@@ -0,0 +1,73 @@
+/*	$NetBSD: t_uchar.c,v 1.1 2024/08/15 13:14:44 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2024 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Include <uchar.h> first to verify it declares everything we need.
+ */
+#include <uchar.h>
+typedef mbstate_t nbtest_mbstate_t;
+typedef size_t nbtest_size_t;
+typedef char16_t nbtest_char16_t;
+typedef char32_t nbtest_char32_t;
+static size_t (*nbtest_mbrtoc16)(char16_t *restrict, const char *restrict,
+    size_t, mbstate_t *restrict) __unused = &mbrtoc16;
+static size_t (*nbtest_c16rtomb)(char *restrict, char16_t,
+    mbstate_t *restrict) __unused = &c16rtomb;
+static size_t (*nbtest_mbrtoc32)(char32_t *restrict, const char *restrict,
+    size_t, mbstate_t *restrict) __unused = mbrtoc32;
+static size_t (*nbtest_c32rtomb)(char *restrict, char32_t,
+    mbstate_t *restrict) __unused = &c32rtomb;
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_uchar.c,v 1.1 2024/08/15 13:14:44 riastradh Exp $");
+
+#include <atf-c.h>
+#include <stdint.h>
+
+ATF_TC(uchartypes);
+ATF_TC_HEAD(uchartypes, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test <uchar.h> types are reasonable");
+}
+ATF_TC_BODY(uchartypes, tc)
+{
+
+	ATF_CHECK_EQ_MSG(sizeof(char16_t), sizeof(uint_least16_t),
+	    "char16_t %zu, uint_least16_t %zu",
+	    sizeof(char16_t), sizeof(uint_least16_t));
+	ATF_CHECK_EQ_MSG(sizeof(char32_t), sizeof(uint_least32_t),
+	    "char32_t %zu, uint_least32_t %zu",
+	    sizeof(char32_t), sizeof(uint_least32_t));
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, uchartypes);
+	return atf_no_error();
+}

Reply via email to