CVS commit: src/lib/libc/regex

2024-09-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Sep 22 00:22:09 UTC 2024

Modified Files:
src/lib/libc/regex: regex.3

Log Message:
Fix section header (Anonymous)


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/lib/libc/regex/regex.3

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

Modified files:

Index: src/lib/libc/regex/regex.3
diff -u src/lib/libc/regex/regex.3:1.33 src/lib/libc/regex/regex.3:1.34
--- src/lib/libc/regex/regex.3:1.33	Sat Dec  3 20:29:32 2022
+++ src/lib/libc/regex/regex.3	Sat Sep 21 20:22:08 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: regex.3,v 1.33 2022/12/04 01:29:32 uwe Exp $
+.\" $NetBSD: regex.3,v 1.34 2024/09/22 00:22:08 christos Exp $
 .\"
 .\" Copyright (c) 1992, 1993, 1994 Henry Spencer.
 .\" Copyright (c) 1992, 1993, 1994
@@ -34,7 +34,7 @@
 .\"	@(#)regex.3	8.4 (Berkeley) 3/20/94
 .\" $FreeBSD: head/lib/libc/regex/regex.3 363817 2020-08-04 02:06:49Z kevans $
 .\"
-.Dd March 11, 2021
+.Dd September 21, 2024
 .Dt REGEX 3
 .Os
 .Sh NAME
@@ -260,7 +260,7 @@ If
 .Fn regcomp
 fails, it returns a non-zero error code;
 see
-.Sx DIAGNOSTICS .
+.Sx RETURN VALUES .
 .Pp
 The
 .Fn regexec
@@ -375,7 +375,7 @@ returns 0 for success and the non-zero c
 for failure.
 Other non-zero error codes may be returned in exceptional situations;
 see
-.Sx DIAGNOSTICS .
+.Sx RETURN VALUES .
 .Pp
 If
 .Dv REG_NOSUB



CVS commit: src/lib/libc/regex

2024-09-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Sep 22 00:22:09 UTC 2024

Modified Files:
src/lib/libc/regex: regex.3

Log Message:
Fix section header (Anonymous)


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/lib/libc/regex/regex.3

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



CVS commit: src/lib/libm/src

2024-09-20 Thread Greg Troxel
Module Name:src
Committed By:   gdt
Date:   Fri Sep 20 22:45:15 UTC 2024

Modified Files:
src/lib/libm/src: s_remquo.c

Log Message:
libm/remquo: Fix bug where remquo returned wrong sign of quo

ISO C requires that quo be congruent to the quotient mod 2^k and have
a particular sign.  The current code can return 0 when it should be
negative.

Because the code chooses k=31 (for the requirement of congruence
modulo 2^k), the only value available (in ILP32 or LP64) that is
negative and congruent to 0 is 0x8000.  In the specific case of
wanting "-0", return 0x8000.

Resolves t_remquo test failure.

\todo pullups
\todo check/fix remquof and remquol


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libm/src/s_remquo.c

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



CVS commit: src/lib/libm/src

2024-09-20 Thread Greg Troxel
Module Name:src
Committed By:   gdt
Date:   Fri Sep 20 22:45:15 UTC 2024

Modified Files:
src/lib/libm/src: s_remquo.c

Log Message:
libm/remquo: Fix bug where remquo returned wrong sign of quo

ISO C requires that quo be congruent to the quotient mod 2^k and have
a particular sign.  The current code can return 0 when it should be
negative.

Because the code chooses k=31 (for the requirement of congruence
modulo 2^k), the only value available (in ILP32 or LP64) that is
negative and congruent to 0 is 0x8000.  In the specific case of
wanting "-0", return 0x8000.

Resolves t_remquo test failure.

\todo pullups
\todo check/fix remquof and remquol


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libm/src/s_remquo.c

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

Modified files:

Index: src/lib/libm/src/s_remquo.c
diff -u src/lib/libm/src/s_remquo.c:1.3 src/lib/libm/src/s_remquo.c:1.4
--- src/lib/libm/src/s_remquo.c:1.3	Fri Sep 20 18:08:32 2024
+++ src/lib/libm/src/s_remquo.c	Fri Sep 20 22:45:15 2024
@@ -156,5 +156,12 @@ fixup:
 	SET_HIGH_WORD(x,hx^sx);
 	q &= 0x7fff;
 	*quo = (sxy ? -q : q);
+	/*
+	 * If q is 0 and we need to return negative, we have to choose
+	 * the largest negative number (in 32 bits) because it is the
+	 * only value that is negative and congruent to 0 mod 2^31.
+	 */
+	if (q == 0 && sxy)
+	  *quo = 0x8000;
 	return x;
 }



CVS commit: src/lib/libm/src

2024-09-20 Thread Greg Troxel
Module Name:src
Committed By:   gdt
Date:   Fri Sep 20 18:08:33 UTC 2024

Modified Files:
src/lib/libm/src: s_remquo.c

Log Message:
libm/remquo: Fix bug where wrong quotient was returned

Fix taken from FreeBSD:

  https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=166463
  
https://cgit.freebsd.org/src/commit/lib/msun/src/s_remquo.c?id=1cbd288942b08217e99bf889e0967895d53af00c

FreeBSD commit message:

  Fix a bug in remquo{,f,l}, in which the quotient didn't always have the
  correct sign when the remainder was 0.

  Fix a separate bug in remquo alone, in which the remainder and
  quotient were both off by a bit in certain cases involving subnormal
  remainders.

  The bugs affected all platforms except amd64 and i386, on which the
  routines are implemented in assembly.

(On NetBSD, this bug manifests on amd64.)

\todo pullups
\todo check/fix remquof and remquol


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libm/src/s_remquo.c

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

Modified files:

Index: src/lib/libm/src/s_remquo.c
diff -u src/lib/libm/src/s_remquo.c:1.2 src/lib/libm/src/s_remquo.c:1.3
--- src/lib/libm/src/s_remquo.c:1.2	Sat Feb 24 19:32:09 2024
+++ src/lib/libm/src/s_remquo.c	Fri Sep 20 18:08:32 2024
@@ -56,7 +56,7 @@ remquo(double x, double y, int *quo)
 		goto fixup;	/* |x|<|y| return x or x-y */
 	}
 	if(lx==ly) {
-		*quo = 1;
+		*quo = (sxy ? -1 : 1);
 		return Zero[(u_int32_t)sx>>31];	/* |x|=|y| return x*0*/
 	}
 	}
@@ -119,6 +119,7 @@ remquo(double x, double y, int *quo)
 
 /* convert back to floating value and restore the sign */
 	if((hx|lx)==0) {			/* return sign(x)*0 */
+	q &= 0x7fff;
 	*quo = (sxy ? -q : q);
 	return Zero[(u_int32_t)sx>>31];
 	}
@@ -134,9 +135,9 @@ remquo(double x, double y, int *quo)
 		lx = (lx>>n)|((u_int32_t)hx<<(32-n));
 		hx >>= n;
 	} else if (n<=31) {
-		lx = (hx<<(32-n))|(lx>>n); hx = sx;
+		lx = (hx<<(32-n))|(lx>>n); hx = 0;
 	} else {
-		lx = hx>>(n-32); hx = sx;
+		lx = hx>>(n-32); hx = 0;
 	}
 	}
 fixup:



CVS commit: src/lib/libm/src

2024-09-20 Thread Greg Troxel
Module Name:src
Committed By:   gdt
Date:   Fri Sep 20 18:08:33 UTC 2024

Modified Files:
src/lib/libm/src: s_remquo.c

Log Message:
libm/remquo: Fix bug where wrong quotient was returned

Fix taken from FreeBSD:

  https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=166463
  
https://cgit.freebsd.org/src/commit/lib/msun/src/s_remquo.c?id=1cbd288942b08217e99bf889e0967895d53af00c

FreeBSD commit message:

  Fix a bug in remquo{,f,l}, in which the quotient didn't always have the
  correct sign when the remainder was 0.

  Fix a separate bug in remquo alone, in which the remainder and
  quotient were both off by a bit in certain cases involving subnormal
  remainders.

  The bugs affected all platforms except amd64 and i386, on which the
  routines are implemented in assembly.

(On NetBSD, this bug manifests on amd64.)

\todo pullups
\todo check/fix remquof and remquol


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libm/src/s_remquo.c

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



Re: CVS commit: src/lib/libc

2024-09-15 Thread Taylor R Campbell
> Date: Sat, 14 Sep 2024 22:26:37 - (UTC)
> From: chris...@astron.com (Christos Zoulas)
> 
> In article ,
> Thomas Klausner   wrote:
> >On Wed, Sep 11, 2024 at 09:50:35AM -0400, Christos Zoulas wrote:
> >> POSIX.1-2024 removes asctime_r and ctime_r and does not let
> >> libraries define them, so remove them except when needed to
> >> conform to earlier POSIX.  These functions are dangerous as they
> >> can overrun user buffers.  If you still need them, add
> >> -DSUPPORT_POSIX2008 to CFLAGS.
> >
> >Hm, that sounds like we should hide asctime_r and ctime_r?
> 
> I think that it will break stuff in pkgsrc... We could, I guess.

We have to continue defining the symbols in libc.  We can put the
declarations in time.h under

#if (_POSIX_C_SOURCE - 0 < 202405L) || defined(_NETBSD_SOURCE)
...
#endif

in addition to whatever conditions are already there.

The _POSIX_C_SOURCE part is mandatory for POSIX.1-2024 compliance.

The _NETBSD_SOURCE part is up to us and we could choose to remove it
later (or invent a date system for _NETBSD_SOURCE like
_POSIX_C_SOURCE), or, rather, replace it by __LIBC12_SOURCE__ so the
libc definitions still work.


Re: CVS commit: src/lib/libc

2024-09-14 Thread Greg Troxel
chris...@astron.com (Christos Zoulas) writes:

>>> POSIX.1-2024 removes asctime_r and ctime_r and does not let
>>> libraries define them, so remove them except when needed to
>>> conform to earlier POSIX.  These functions are dangerous as they
>>> can overrun user buffers.  If you still need them, add
>>> -DSUPPORT_POSIX2008 to CFLAGS.
>>
>>Hm, that sounds like we should hide asctime_r and ctime_r?
>>
>
> I think that it will break stuff in pkgsrc... We could, I guess.

Visisbility define use is a nice theory but in practice it's a mess.

Probably, before hiding, someone(tm) should build a system with them
hidden and do a bulk build.

More seriously, NetBSD having breaking changes generally does not go
well, unless Linux has had the change for a year, so that upstreams have
had time to adapt.


Re: CVS commit: src/lib/libc

2024-09-14 Thread Christos Zoulas
In article ,
Thomas Klausner   wrote:
>On Wed, Sep 11, 2024 at 09:50:35AM -0400, Christos Zoulas wrote:
>> Module Name: src
>> Committed By:christos
>> Date:Wed Sep 11 13:50:35 UTC 2024
>> 
>> Modified Files:
>>  src/lib/libc/compat/time: compat_localtime.c
>>  src/lib/libc/time: CONTRIBUTING Makefile Makefile.inc NEWS asctime.c
>>  localtime.c private.h theory.html tz-art.html tz-link.html tzfile.5
>>  tzselect.ksh version zdump.c zic.8 zic.c
>> 
>> Log Message:
>> Merge tzcode-2024b
>> 
>> Release 2024b - 2024-09-04 12:27:47 -0700
>> 
>>   Changes to code
>> 
>> localtime.c now always uses a TZif file's time type 0 to handle
>> timestamps before the file's first transition.  Formerly,
>> localtime.c sometimes inferred a different time type, in order to
>> handle problematic data generated by zic 2018e or earlier.  As it
>> is now safe to assume more recent versions of zic, there is no
>> longer a pressing need to fail to conform RFC 8536 section 3.2,
>> which requires using time type 0 in this situation.  This change
>> does not affect behavior when reading TZif files generated by zic
>> 2018f and later.
>> 
>> POSIX.1-2024 removes asctime_r and ctime_r and does not let
>> libraries define them, so remove them except when needed to
>> conform to earlier POSIX.  These functions are dangerous as they
>> can overrun user buffers.  If you still need them, add
>> -DSUPPORT_POSIX2008 to CFLAGS.
>
>Hm, that sounds like we should hide asctime_r and ctime_r?
>

I think that it will break stuff in pkgsrc... We could, I guess.

christos





Re: CVS commit: src/lib/libc

2024-09-11 Thread Thomas Klausner
On Wed, Sep 11, 2024 at 09:50:35AM -0400, Christos Zoulas wrote:
> Module Name:  src
> Committed By: christos
> Date: Wed Sep 11 13:50:35 UTC 2024
> 
> Modified Files:
>   src/lib/libc/compat/time: compat_localtime.c
>   src/lib/libc/time: CONTRIBUTING Makefile Makefile.inc NEWS asctime.c
>   localtime.c private.h theory.html tz-art.html tz-link.html tzfile.5
>   tzselect.ksh version zdump.c zic.8 zic.c
> 
> Log Message:
> Merge tzcode-2024b
> 
> Release 2024b - 2024-09-04 12:27:47 -0700
> 
>   Changes to code
> 
> localtime.c now always uses a TZif file's time type 0 to handle
> timestamps before the file's first transition.  Formerly,
> localtime.c sometimes inferred a different time type, in order to
> handle problematic data generated by zic 2018e or earlier.  As it
> is now safe to assume more recent versions of zic, there is no
> longer a pressing need to fail to conform RFC 8536 section 3.2,
> which requires using time type 0 in this situation.  This change
> does not affect behavior when reading TZif files generated by zic
> 2018f and later.
> 
> POSIX.1-2024 removes asctime_r and ctime_r and does not let
> libraries define them, so remove them except when needed to
> conform to earlier POSIX.  These functions are dangerous as they
> can overrun user buffers.  If you still need them, add
> -DSUPPORT_POSIX2008 to CFLAGS.

Hm, that sounds like we should hide asctime_r and ctime_r?
 Thomas


CVS commit: src/lib/libc

2024-09-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Sep 11 13:50:35 UTC 2024

Modified Files:
src/lib/libc/compat/time: compat_localtime.c
src/lib/libc/time: CONTRIBUTING Makefile Makefile.inc NEWS asctime.c
localtime.c private.h theory.html tz-art.html tz-link.html tzfile.5
tzselect.ksh version zdump.c zic.8 zic.c

Log Message:
Merge tzcode-2024b

Release 2024b - 2024-09-04 12:27:47 -0700

  Changes to code

localtime.c now always uses a TZif file's time type 0 to handle
timestamps before the file's first transition.  Formerly,
localtime.c sometimes inferred a different time type, in order to
handle problematic data generated by zic 2018e or earlier.  As it
is now safe to assume more recent versions of zic, there is no
longer a pressing need to fail to conform RFC 8536 section 3.2,
which requires using time type 0 in this situation.  This change
does not affect behavior when reading TZif files generated by zic
2018f and later.

POSIX.1-2024 removes asctime_r and ctime_r and does not let
libraries define them, so remove them except when needed to
conform to earlier POSIX.  These functions are dangerous as they
can overrun user buffers.  If you still need them, add
-DSUPPORT_POSIX2008 to CFLAGS.

The SUPPORT_C89 option now defaults to 1 instead of 0, fixing a
POSIX-conformance bug introduced in 2023a.

tzselect now supports POSIX.1-2024 proleptic TZ strings.  Also, it
assumes POSIX.2-1992 or later, as practical porting targets now
all support that, and it uses some features from POSIX.1-2024 if
available.

  Changes to build procedure

'make check' no longer requires curl and Internet access.

The build procedure now assumes POSIX.2-1992 or later, to simplify
maintenance.  To build on Solaris 10, the only extant system still
defaulting to pre-POSIX, prepend /usr/xpg4/bin to PATH.

  Changes to documentation

The documentation now reflects POSIX.1-2024.

  Changes to commentary

Commentary about historical transitions in Portugal and her former
colonies has been expanded with links to many relevant legislation.
(Thanks to Tim Parenti.)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/compat/time/compat_localtime.c
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/time/CONTRIBUTING
cvs rdiff -u -r1.57 -r1.58 src/lib/libc/time/Makefile
cvs rdiff -u -r1.23 -r1.24 src/lib/libc/time/Makefile.inc \
src/lib/libc/time/tzselect.ksh
cvs rdiff -u -r1.44 -r1.45 src/lib/libc/time/NEWS
cvs rdiff -u -r1.30 -r1.31 src/lib/libc/time/asctime.c
cvs rdiff -u -r1.143 -r1.144 src/lib/libc/time/localtime.c
cvs rdiff -u -r1.69 -r1.70 src/lib/libc/time/private.h
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/time/theory.html
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/time/tz-art.html
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/time/tz-link.html
cvs rdiff -u -r1.35 -r1.36 src/lib/libc/time/tzfile.5
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/time/version
cvs rdiff -u -r1.63 -r1.64 src/lib/libc/time/zdump.c
cvs rdiff -u -r1.50 -r1.51 src/lib/libc/time/zic.8
cvs rdiff -u -r1.91 -r1.92 src/lib/libc/time/zic.c

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



CVS commit: src/lib/libc/gen

2024-09-10 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep 10 17:11:19 UTC 2024

Modified Files:
src/lib/libc/gen: readdir.c

Log Message:
readdir(3): Preserve errno on end-of-directory.

PR pkg/57145: gmake: *** INTERNAL: readdir: Operation not supported.
Stop.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libc/gen/readdir.c

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

Modified files:

Index: src/lib/libc/gen/readdir.c
diff -u src/lib/libc/gen/readdir.c:1.26 src/lib/libc/gen/readdir.c:1.27
--- src/lib/libc/gen/readdir.c:1.26	Mon Jun 25 22:32:43 2012
+++ src/lib/libc/gen/readdir.c	Tue Sep 10 17:11:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: readdir.c,v 1.26 2012/06/25 22:32:43 abs Exp $	*/
+/*	$NetBSD: readdir.c,v 1.27 2024/09/10 17:11:19 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)readdir.c	8.3 (Berkeley) 9/29/94";
 #else
-__RCSID("$NetBSD: readdir.c,v 1.26 2012/06/25 22:32:43 abs Exp $");
+__RCSID("$NetBSD: readdir.c,v 1.27 2024/09/10 17:11:19 riastradh Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -56,35 +56,50 @@ __RCSID("$NetBSD: readdir.c,v 1.26 2012/
 struct dirent *
 _readdir_unlocked(DIR *dirp, int skipdeleted)
 {
+	const int saved_errno = errno;
 	struct dirent *dp;
 
 	for (;;) {
 		if (dirp->dd_loc >= dirp->dd_size) {
 			if (dirp->dd_flags & __DTF_READALL)
-return (NULL);
+break;
 			dirp->dd_loc = 0;
 		}
 		if (dirp->dd_loc == 0 && !(dirp->dd_flags & __DTF_READALL)) {
 			dirp->dd_seek = lseek(dirp->dd_fd, (off_t)0, SEEK_CUR);
 			dirp->dd_size = getdents(dirp->dd_fd,
 			dirp->dd_buf, (size_t)dirp->dd_len);
-			if (dirp->dd_size <= 0)
-return (NULL);
+			if (dirp->dd_size == 0) /* end of directory */
+break;
+			if (dirp->dd_size == -1) /* getdents sets errno */
+return NULL;
+			if (dirp->dd_size < 0) { /* paranoia */
+errno = EIO;
+return NULL;
+			}
 		}
 		dp = (struct dirent *)
 		(void *)(dirp->dd_buf + (size_t)dirp->dd_loc);
-		if ((intptr_t)dp & _DIRENT_ALIGN(dp))/* bogus pointer check */
-			return (NULL);
+		/* bogus pointer check */
+		if ((intptr_t)dp & _DIRENT_ALIGN(dp)) {
+			errno = EIO;
+			return NULL;
+		}
 		/* d_reclen is unsigned; no need to compare it <= 0 */
-		if (dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc)
-			return (NULL);
+		if (dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc) {
+			errno = EIO;
+			return NULL;
+		}
 		dirp->dd_loc += dp->d_reclen;
 		if (dp->d_ino == 0 && skipdeleted)
 			continue;
 		if (dp->d_type == DT_WHT && (dirp->dd_flags & DTF_HIDEW))
 			continue;
-		return (dp);
+		return dp;
 	}
+
+	errno = saved_errno;
+	return NULL;
 }
 
 struct dirent *



CVS commit: src/lib/libc/gen

2024-09-10 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep 10 17:11:19 UTC 2024

Modified Files:
src/lib/libc/gen: readdir.c

Log Message:
readdir(3): Preserve errno on end-of-directory.

PR pkg/57145: gmake: *** INTERNAL: readdir: Operation not supported.
Stop.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libc/gen/readdir.c

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



CVS commit: src/lib/libc

2024-09-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Sep 10 04:43:39 UTC 2024

Modified Files:
src/lib/libc/locale: wcsftime.3 wcsrtombs.3
src/lib/libc/net: getnameinfo.3

Log Message:
libc: new function parameter, new line


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/wcsftime.3
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/locale/wcsrtombs.3
cvs rdiff -u -r1.44 -r1.45 src/lib/libc/net/getnameinfo.3

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

Modified files:

Index: src/lib/libc/locale/wcsftime.3
diff -u src/lib/libc/locale/wcsftime.3:1.3 src/lib/libc/locale/wcsftime.3:1.4
--- src/lib/libc/locale/wcsftime.3:1.3	Thu Apr 14 05:50:49 2011
+++ src/lib/libc/locale/wcsftime.3	Tue Sep 10 04:43:39 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: wcsftime.3,v 1.3 2011/04/14 05:50:49 jruoho Exp $
+.\" $NetBSD: wcsftime.3,v 1.4 2024/09/10 04:43:39 rillig Exp $
 .\"
 .\" Copyright (c) 2002 Tim J. Robbins
 .\" All rights reserved.
@@ -38,8 +38,10 @@
 .In wchar.h
 .Ft size_t
 .Fo wcsftime
-.Fa "wchar_t * restrict wcs" "size_t maxsize"
-.Fa "const wchar_t * restrict format" "const struct tm * restrict timeptr"
+.Fa "wchar_t * restrict wcs"
+.Fa "size_t maxsize"
+.Fa "const wchar_t * restrict format"
+.Fa "const struct tm * restrict timeptr"
 .Fc
 .Sh DESCRIPTION
 The

Index: src/lib/libc/locale/wcsrtombs.3
diff -u src/lib/libc/locale/wcsrtombs.3:1.16 src/lib/libc/locale/wcsrtombs.3:1.17
--- src/lib/libc/locale/wcsrtombs.3:1.16	Mon Sep  9 18:55:26 2024
+++ src/lib/libc/locale/wcsrtombs.3	Tue Sep 10 04:43:39 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: wcsrtombs.3,v 1.16 2024/09/09 18:55:26 wiz Exp $
+.\" $NetBSD: wcsrtombs.3,v 1.17 2024/09/10 04:43:39 rillig Exp $
 .\"
 .\" Copyright (c)2002 Citrus Project,
 .\" All rights reserved.
@@ -45,7 +45,8 @@
 .Fo wcsrtombs
 .Fa "char * restrict s"
 .Fa "const wchar_t ** restrict pwcs"
-.Fa "size_t n" "mbstate_t * restrict ps"
+.Fa "size_t n"
+.Fa "mbstate_t * restrict ps"
 .Fc
 .
 .Ft size_t

Index: src/lib/libc/net/getnameinfo.3
diff -u src/lib/libc/net/getnameinfo.3:1.44 src/lib/libc/net/getnameinfo.3:1.45
--- src/lib/libc/net/getnameinfo.3:1.44	Fri Feb 16 22:50:33 2024
+++ src/lib/libc/net/getnameinfo.3	Tue Sep 10 04:43:39 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getnameinfo.3,v 1.44 2024/02/16 22:50:33 uwe Exp $
+.\"	$NetBSD: getnameinfo.3,v 1.45 2024/09/10 04:43:39 rillig Exp $
 .\"	$KAME: getnameinfo.3,v 1.37 2005/01/05 03:23:05 itojun Exp $
 .\"	$OpenBSD: getnameinfo.3,v 1.36 2004/12/21 09:48:20 jmc Exp $
 .\"
@@ -34,7 +34,8 @@
 .Fa "char * restrict host"
 .Fa "socklen_t hostlen"
 .Fa "char * restrict serv"
-.Fa "socklen_t servlen" "int flags"
+.Fa "socklen_t servlen"
+.Fa "int flags"
 .Fc
 .
 .Sh DESCRIPTION



CVS commit: src/lib/libc

2024-09-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Sep 10 04:43:39 UTC 2024

Modified Files:
src/lib/libc/locale: wcsftime.3 wcsrtombs.3
src/lib/libc/net: getnameinfo.3

Log Message:
libc: new function parameter, new line


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/wcsftime.3
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/locale/wcsrtombs.3
cvs rdiff -u -r1.44 -r1.45 src/lib/libc/net/getnameinfo.3

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



CVS commit: src/lib/libc/locale

2024-09-09 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Sep  9 18:55:26 UTC 2024

Modified Files:
src/lib/libc/locale: mbsrtowcs.3 wcsrtombs.3

Log Message:
SYNOPSIS fixes, uppercase NUL and NULL


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/locale/mbsrtowcs.3
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/locale/wcsrtombs.3

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



CVS commit: src/lib/libc/locale

2024-09-09 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Sep  9 18:55:26 UTC 2024

Modified Files:
src/lib/libc/locale: mbsrtowcs.3 wcsrtombs.3

Log Message:
SYNOPSIS fixes, uppercase NUL and NULL


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/locale/mbsrtowcs.3
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/locale/wcsrtombs.3

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

Modified files:

Index: src/lib/libc/locale/mbsrtowcs.3
diff -u src/lib/libc/locale/mbsrtowcs.3:1.14 src/lib/libc/locale/mbsrtowcs.3:1.15
--- src/lib/libc/locale/mbsrtowcs.3:1.14	Mon Sep  9 14:21:37 2024
+++ src/lib/libc/locale/mbsrtowcs.3	Mon Sep  9 18:55:26 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: mbsrtowcs.3,v 1.14 2024/09/09 14:21:37 uwe Exp $
+.\" $NetBSD: mbsrtowcs.3,v 1.15 2024/09/09 18:55:26 wiz Exp $
 .\"
 .\" Copyright (c)2002 Citrus Project,
 .\" All rights reserved.
@@ -29,7 +29,7 @@
 .Os
 .\" --
 .Sh NAME
-.Nm mbsrtowcs
+.Nm mbsrtowcs ,
 .Nm mbsrntowcs
 .Nd converts a multibyte character string to a wide-character string \
 (restartable)
@@ -71,8 +71,8 @@ array pointed to by
 The conversion stops due to the following reasons:
 .Bl -bullet
 .It
-The conversion reaches a nul byte.
-In this case, the nul byte is also converted.
+The conversion reaches a NUL byte.
+In this case, the NUL byte is also converted.
 .It
 The
 .Fn mbsrtowcs
@@ -90,18 +90,18 @@ is continuously called.
 After conversion,
 if
 .Fa pwcs
-is not a null pointer,
+is not a NULL pointer,
 the pointer object pointed to by
 .Fa s
-is a null pointer
-.Pq if the conversion is stopped due to reaching a nul byte
+is a NULL pointer
+.Pq if the conversion is stopped due to reaching a NUL byte
 or the first byte of the character just after the last character
 converted.
 .Pp
 If
 .Fa pwcs
-is not a null pointer and the conversion is stopped due to reaching
-a nul byte, the
+is not a NULL pointer and the conversion is stopped due to reaching
+a NUL byte, the
 .Fn mbsrtowcs
 places the state object pointed to by
 .Fa ps
@@ -163,7 +163,7 @@ functions return:
 The value returned is the number of elements stored in the array
 pointed to by
 .Fa pwcs ,
-except for a terminating nul wide character (if any).
+except for a terminating NUL wide character (if any).
 If
 .Fa pwcs
 is not
@@ -172,11 +172,11 @@ and the value returned is equal to
 .Fa n ,
 the wide-character string pointed to by
 .Fa pwcs
-is not nul-terminated.
+is not NUL-terminated.
 If
 .Fa pwcs
-is a null pointer, the value returned is the number of elements to contain
-the whole string converted, except for a terminating nul wide character.
+is a NULL pointer, the value returned is the number of elements to contain
+the whole string converted, except for a terminating NUL wide character.
 .It Li "(size_t)-1"
 The array indirectly pointed to by
 .Fa s

Index: src/lib/libc/locale/wcsrtombs.3
diff -u src/lib/libc/locale/wcsrtombs.3:1.15 src/lib/libc/locale/wcsrtombs.3:1.16
--- src/lib/libc/locale/wcsrtombs.3:1.15	Mon Sep  9 14:21:37 2024
+++ src/lib/libc/locale/wcsrtombs.3	Mon Sep  9 18:55:26 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: wcsrtombs.3,v 1.15 2024/09/09 14:21:37 uwe Exp $
+.\" $NetBSD: wcsrtombs.3,v 1.16 2024/09/09 18:55:26 wiz Exp $
 .\"
 .\" Copyright (c)2002 Citrus Project,
 .\" All rights reserved.
@@ -29,7 +29,8 @@
 .Os
 .\" --
 .Sh NAME
-.Nm wcsrtombs, wcsnrtombs
+.Nm wcsrtombs ,
+.Nm wcsnrtombs
 .Nd converts a wide-character string to a multibyte character string \
 (restartable)
 .\" --
@@ -60,7 +61,7 @@
 .Sh DESCRIPTION
 The
 .Fn wcsrtombs
-function converts the nul-terminated wide-character string indirectly
+function converts the NUL-terminated wide-character string indirectly
 pointed to by
 .Fa pwcs
 to the corresponding multibyte character string,
@@ -69,8 +70,8 @@ and stores it in the array pointed to by
 The conversion stops due to the following reasons:
 .Bl -bullet
 .It
-The conversion reaches a nul wide character.
-In this case, the nul wide character is also converted.
+The conversion reaches a NUL wide character.
+In this case, the NUL wide character is also converted.
 .It
 The
 .Fn wcsrtombs
@@ -91,23 +92,23 @@ will not be affected.
 After conversion,
 if
 .Fa s
-is not a null pointer, the pointer object pointed to by
+is not a NULL pointer, the pointer object pointed to by
 .Fa pwcs
-is a null pointer
-.Pq if the conversion is stopped due to reaching a nul wide character
+is a NULL pointer
+.Pq if the conversion is stopped due to reaching a NUL wide character
 or points to the first byte of the character just after the last
 character converted.
 .Pp
 If
 .Fa s
-is not a null pointer and the conversion is stopped due to reaching
-a nul wide character,
+is not a NULL pointer and the conversion i

CVS commit: src/lib/libc/locale

2024-09-09 Thread Valery Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon Sep  9 14:21:37 UTC 2024

Modified Files:
src/lib/libc/locale: mbsrtowcs.3 wcsrtombs.3

Log Message:
mbsnrtowcs(3), wcsnrtombs(3): brush ip markup


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/locale/mbsrtowcs.3
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/locale/wcsrtombs.3

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

Modified files:

Index: src/lib/libc/locale/mbsrtowcs.3
diff -u src/lib/libc/locale/mbsrtowcs.3:1.13 src/lib/libc/locale/mbsrtowcs.3:1.14
--- src/lib/libc/locale/mbsrtowcs.3:1.13	Mon Sep  9 11:30:05 2024
+++ src/lib/libc/locale/mbsrtowcs.3	Mon Sep  9 14:21:37 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: mbsrtowcs.3,v 1.13 2024/09/09 11:30:05 riastradh Exp $
+.\" $NetBSD: mbsrtowcs.3,v 1.14 2024/09/09 14:21:37 uwe Exp $
 .\"
 .\" Copyright (c)2002 Citrus Project,
 .\" All rights reserved.
@@ -38,13 +38,26 @@
 .Lb libc
 .\" --
 .Sh SYNOPSIS
+.
 .In wchar.h
+.
 .Ft size_t
-.Fn mbsrtowcs "wchar_t * restrict pwcs" "const char ** restrict s" "size_t n" \
-"mbstate_t * restrict ps"
-.Fn mbsnrtowcs "wchar_t * restrict pwcs" "const char ** restrict s" \
-"size_t nmc" "size_t n" \
-"mbstate_t * restrict ps"
+.Fo mbsrtowcs
+.Fa "wchar_t * restrict pwcs"
+.Fa "const char ** restrict s"
+.Fa "size_t n"
+.Fa "mbstate_t * restrict ps"
+.Fc
+.
+.Ft size_t
+.Fo mbsnrtowcs
+.Fa "wchar_t * restrict pwcs"
+.Fa "const char ** restrict s"
+.Fa "size_t nmc"
+.Fa "size_t n"
+.Fa "mbstate_t * restrict ps"
+.Fc
+.
 .\" --
 .Sh DESCRIPTION
 The
@@ -80,9 +93,10 @@ if
 is not a null pointer,
 the pointer object pointed to by
 .Fa s
-is a null pointer (if the conversion is stopped due to reaching a
-nul byte) or the first byte of the character just after the last
-character converted.
+is a null pointer
+.Pq if the conversion is stopped due to reaching a nul byte
+or the first byte of the character just after the last character
+converted.
 .Pp
 If
 .Fa pwcs
@@ -100,10 +114,12 @@ is affected by the
 category of the current locale.
 .Pp
 These are the special cases:
-.Bl -tag -width 012345678901
-.It "s == NULL || *s == NULL"
+.Bl -tag -width Li
+.
+.It Li "s == NULL || *s == NULL"
 Undefined (may cause the program to crash).
-.It "pwcs == NULL"
+.
+.It Li "pwcs == NULL"
 The conversion has taken place, but the resulting wide-character string
 was discarded.
 In this case, the pointer object pointed to by
@@ -111,7 +127,8 @@ In this case, the pointer object pointed
 is not modified and
 .Fa n
 is ignored.
-.It "ps == NULL"
+.
+.It Li "ps == NULL"
 The
 .Fn mbsrtowcs
 uses its own internal state object to keep the conversion state,
@@ -141,8 +158,8 @@ The
 and
 .Fn mbsnrtowcs
 functions return:
-.Bl -tag -width 012345678901
-.It 0 or positive
+.Bl -tag -width Li
+.It Li 0 , No or positive
 The value returned is the number of elements stored in the array
 pointed to by
 .Fa pwcs ,
@@ -160,7 +177,7 @@ If
 .Fa pwcs
 is a null pointer, the value returned is the number of elements to contain
 the whole string converted, except for a terminating nul wide character.
-.It (size_t)-1
+.It Li "(size_t)-1"
 The array indirectly pointed to by
 .Fa s
 contains a byte sequence forming invalid character.

Index: src/lib/libc/locale/wcsrtombs.3
diff -u src/lib/libc/locale/wcsrtombs.3:1.14 src/lib/libc/locale/wcsrtombs.3:1.15
--- src/lib/libc/locale/wcsrtombs.3:1.14	Mon Sep  9 11:30:05 2024
+++ src/lib/libc/locale/wcsrtombs.3	Mon Sep  9 14:21:37 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: wcsrtombs.3,v 1.14 2024/09/09 11:30:05 riastradh Exp $
+.\" $NetBSD: wcsrtombs.3,v 1.15 2024/09/09 14:21:37 uwe Exp $
 .\"
 .\" Copyright (c)2002 Citrus Project,
 .\" All rights reserved.
@@ -37,13 +37,25 @@
 .Lb libc
 .\" --
 .Sh SYNOPSIS
+.
 .In wchar.h
+.
 .Ft size_t
-.Fn wcsrtombs "char * restrict s" "const wchar_t ** restrict pwcs" \
-"size_t n" "mbstate_t * restrict ps"
+.Fo wcsrtombs
+.Fa "char * restrict s"
+.Fa "const wchar_t ** restrict pwcs"
+.Fa "size_t n" "mbstate_t * restrict ps"
+.Fc
+.
 .Ft size_t
-.Fn wcsnrtombs "char * restrict s" "const wchar_t ** restrict pwcs" \
-"size_t nwc" "size_t n" "mbstat_t * restrict ps"
+.Fo wcsnrtombs
+.Fa "char * restrict s"
+.Fa "const wchar_t ** restrict pwcs"
+.Fa "size_t nwc"
+.Fa "size_t n"
+.Fa "mbstat_t * restrict ps"
+.Fc
+.
 .\" --
 .Sh DESCRIPTION
 The
@@ -81,9 +93,10 @@ if
 .Fa s
 is not a null pointer, the pointer object pointed to by
 .Fa pwcs
-is a null pointer (if the conversion is stopped due to reaching a
-nul wide character) or the first byte of the character just after
-the last character converted.
+is a null pointer
+.Pq if the conversion is stopped due to reaching a nul wide char

CVS commit: src/lib/libc/locale

2024-09-09 Thread Valery Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon Sep  9 14:21:37 UTC 2024

Modified Files:
src/lib/libc/locale: mbsrtowcs.3 wcsrtombs.3

Log Message:
mbsnrtowcs(3), wcsnrtombs(3): brush ip markup


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/locale/mbsrtowcs.3
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/locale/wcsrtombs.3

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



CVS commit: src/lib/libc/sys

2024-09-08 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Sep  9 01:20:20 UTC 2024

Modified Files:
src/lib/libc/sys: select.2

Log Message:
select(2): Cite standards conformance in man page.

(Should we cite the earliest standard, or the most recent standard,
if they're the same as far as anyone has noticed?)

PR standards/4: the history and standards conformance of
pselect(2) is not documented


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/lib/libc/sys/select.2

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

Modified files:

Index: src/lib/libc/sys/select.2
diff -u src/lib/libc/sys/select.2:1.45 src/lib/libc/sys/select.2:1.46
--- src/lib/libc/sys/select.2:1.45	Tue Aug  1 23:33:04 2023
+++ src/lib/libc/sys/select.2	Mon Sep  9 01:20:20 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: select.2,v 1.45 2023/08/01 23:33:04 gutteridge Exp $
+.\"	$NetBSD: select.2,v 1.46 2024/09/09 01:20:20 riastradh Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)select.2	8.2 (Berkeley) 3/25/94
 .\"
-.Dd August 1, 2023
+.Dd September 9, 2024
 .Dt SELECT 2
 .Os
 .Sh NAME
@@ -268,6 +268,21 @@ One of its components is negative or too
 .Xr send 2 ,
 .Xr write 2 ,
 .Xr getdtablesize 3
+.Sh STANDARDS
+The
+.Fn select
+function, along with
+.Fn FD_CLR ,
+.Fn FD_ISSET ,
+.Fn FD_SET , and
+.Fn FD_ZERO ,
+conforms to
+.St -xpg4.2 .
+.Pp
+The
+.Fn pselect
+function conforms to
+.St -p1003.1-2004 .
 .Sh HISTORY
 The
 .Fn select



CVS commit: src/lib/libc/sys

2024-09-08 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Sep  9 01:20:20 UTC 2024

Modified Files:
src/lib/libc/sys: select.2

Log Message:
select(2): Cite standards conformance in man page.

(Should we cite the earliest standard, or the most recent standard,
if they're the same as far as anyone has noticed?)

PR standards/4: the history and standards conformance of
pselect(2) is not documented


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/lib/libc/sys/select.2

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



CVS commit: src/lib/libc/net

2024-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  7 21:04:43 UTC 2024

Modified Files:
src/lib/libc/net: getservent.3

Log Message:
getservent.3: fix format of day of month


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/net/getservent.3

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

Modified files:

Index: src/lib/libc/net/getservent.3
diff -u src/lib/libc/net/getservent.3:1.16 src/lib/libc/net/getservent.3:1.17
--- src/lib/libc/net/getservent.3:1.16	Sun Dec  4 00:13:11 2022
+++ src/lib/libc/net/getservent.3	Sat Sep  7 21:04:43 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getservent.3,v 1.16 2022/12/04 00:13:11 uwe Exp $
+.\"	$NetBSD: getservent.3,v 1.17 2024/09/07 21:04:43 rillig Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)getservent.3  8.4 (Berkeley) 5/25/95
 .\"
-.Dd December 03, 2022
+.Dd December 3, 2022
 .Dt GETSERVENT 3
 .Os
 .Sh NAME



CVS commit: src/lib/libc/net

2024-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  7 21:04:43 UTC 2024

Modified Files:
src/lib/libc/net: getservent.3

Log Message:
getservent.3: fix format of day of month


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/net/getservent.3

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



CVS commit: src/lib/libc/gen

2024-08-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Aug 29 21:05:01 UTC 2024

Modified Files:
src/lib/libc/gen: Makefile.inc

Log Message:
arc4random: suppress another lint warning


To generate a diff of this commit:
cvs rdiff -u -r1.219 -r1.220 src/lib/libc/gen/Makefile.inc

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

Modified files:

Index: src/lib/libc/gen/Makefile.inc
diff -u src/lib/libc/gen/Makefile.inc:1.219 src/lib/libc/gen/Makefile.inc:1.220
--- src/lib/libc/gen/Makefile.inc:1.219	Thu Aug 29 13:39:42 2024
+++ src/lib/libc/gen/Makefile.inc	Thu Aug 29 21:05:01 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.219 2024/08/29 13:39:42 riastradh Exp $
+#	$NetBSD: Makefile.inc,v 1.220 2024/08/29 21:05:01 rillig Exp $
 #	from: @(#)Makefile.inc	8.6 (Berkeley) 5/4/95
 
 # gen sources
@@ -40,6 +40,7 @@ SRCS+=	alarm.c alphasort.c arc4random.c 
 	vwarn.c vwarnx.c vwarnc.c verr.c verrx.c verrc.c
 
 LINTFLAGS.arc4random.c+=-Ac11	# stdatomic.h
+LINTFLAGS.arc4random.c+=-X 129	# expression has null effect (in atomic macros)
 
 # uses alloca
 COPTS.execvp.c = -Wno-stack-protector



CVS commit: src/lib/libc/gen

2024-08-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Aug 29 21:05:01 UTC 2024

Modified Files:
src/lib/libc/gen: Makefile.inc

Log Message:
arc4random: suppress another lint warning


To generate a diff of this commit:
cvs rdiff -u -r1.219 -r1.220 src/lib/libc/gen/Makefile.inc

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



CVS commit: src/lib/libc/gen

2024-08-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Aug 29 13:39:42 UTC 2024

Modified Files:
src/lib/libc/gen: Makefile.inc arc4random.c

Log Message:
arc4random(3): Pacify some of lint's complaints.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/lib/libc/gen/Makefile.inc
cvs rdiff -u -r1.37 -r1.38 src/lib/libc/gen/arc4random.c

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

Modified files:

Index: src/lib/libc/gen/Makefile.inc
diff -u src/lib/libc/gen/Makefile.inc:1.218 src/lib/libc/gen/Makefile.inc:1.219
--- src/lib/libc/gen/Makefile.inc:1.218	Mon Jul  8 22:14:31 2024
+++ src/lib/libc/gen/Makefile.inc	Thu Aug 29 13:39:42 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.218 2024/07/08 22:14:31 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.219 2024/08/29 13:39:42 riastradh Exp $
 #	from: @(#)Makefile.inc	8.6 (Berkeley) 5/4/95
 
 # gen sources
@@ -39,6 +39,8 @@ SRCS+=	alarm.c alphasort.c arc4random.c 
 	warnx.c warnc.c wordexp.c xsyslog.c \
 	vwarn.c vwarnx.c vwarnc.c verr.c verrx.c verrc.c
 
+LINTFLAGS.arc4random.c+=-Ac11	# stdatomic.h
+
 # uses alloca
 COPTS.execvp.c = -Wno-stack-protector
 COPTS.execl.c = -Wno-stack-protector

Index: src/lib/libc/gen/arc4random.c
diff -u src/lib/libc/gen/arc4random.c:1.37 src/lib/libc/gen/arc4random.c:1.38
--- src/lib/libc/gen/arc4random.c:1.37	Tue Aug 27 13:43:02 2024
+++ src/lib/libc/gen/arc4random.c	Thu Aug 29 13:39:42 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: arc4random.c,v 1.37 2024/08/27 13:43:02 riastradh Exp $	*/
+/*	$NetBSD: arc4random.c,v 1.38 2024/08/29 13:39:42 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: arc4random.c,v 1.37 2024/08/27 13:43:02 riastradh Exp $");
+__RCSID("$NetBSD: arc4random.c,v 1.38 2024/08/29 13:39:42 riastradh Exp $");
 
 #include "namespace.h"
 #include "reentrant.h"
@@ -422,7 +422,7 @@ entropy_epoch(void)
 	static atomic_int mib0[3];
 	static atomic_bool initialized = false;
 	int mib[3];
-	unsigned epoch = -1;
+	unsigned epoch = (unsigned)-1;
 	size_t epochlen = sizeof(epoch);
 
 	/*
@@ -438,9 +438,9 @@ entropy_epoch(void)
 		size_t nmib = __arraycount(mib);
 
 		if (sysctlnametomib("kern.entropy.epoch", mib, &nmib) == -1)
-			return -1;
+			return (unsigned)-1;
 		if (nmib != __arraycount(mib))
-			return -1;
+			return (unsigned)-1;
 		atomic_store_explicit(&mib0[0], mib[0], memory_order_relaxed);
 		atomic_store_explicit(&mib0[1], mib[1], memory_order_relaxed);
 		atomic_store_explicit(&mib0[2], mib[2], memory_order_relaxed);
@@ -449,9 +449,9 @@ entropy_epoch(void)
 	}
 
 	if (sysctl(mib, __arraycount(mib), &epoch, &epochlen, NULL, 0) == -1)
-		return -1;
+		return (unsigned)-1;
 	if (epochlen != sizeof(epoch))
-		return -1;
+		return (unsigned)-1;
 
 	return epoch;
 }



CVS commit: src/lib/libc/gen

2024-08-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Aug 29 13:39:42 UTC 2024

Modified Files:
src/lib/libc/gen: Makefile.inc arc4random.c

Log Message:
arc4random(3): Pacify some of lint's complaints.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/lib/libc/gen/Makefile.inc
cvs rdiff -u -r1.37 -r1.38 src/lib/libc/gen/arc4random.c

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



CVS commit: src/lib/libc/gen

2024-08-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 28 14:08:48 UTC 2024

Modified Files:
src/lib/libc/gen: getentropy.3

Log Message:
getentropy(3): Note intent to reseed on VM clone, and caveats.

Tidy markup and pacify some mandoc -Tlint complaints while here.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/gen/getentropy.3

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

Modified files:

Index: src/lib/libc/gen/getentropy.3
diff -u src/lib/libc/gen/getentropy.3:1.7 src/lib/libc/gen/getentropy.3:1.8
--- src/lib/libc/gen/getentropy.3:1.7	Thu Aug 15 23:44:49 2024
+++ src/lib/libc/gen/getentropy.3	Wed Aug 28 14:08:48 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getentropy.3,v 1.7 2024/08/15 23:44:49 riastradh Exp $ $
+.\"	$NetBSD: getentropy.3,v 1.8 2024/08/28 14:08:48 riastradh Exp $ $
 .\"
 .\" Copyright (c) 2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd February 28, 2023
+.Dd August 28, 2024
 .Dt GETENTROPY 3
 .Os
 .Sh NAME
@@ -41,9 +41,8 @@
 .Fn getentropy "void *buf" "size_t buflen"
 .In limits.h
 .Pp
-.Li #define GETENTROPY_MAX	256
+.Li #define GETENTROPY_MAX  256
 .Sh DESCRIPTION
-.Pp
 The
 .Nm
 function fills
@@ -99,6 +98,21 @@ However, the
 interface alone can make no security guarantees without a physical
 system configuration that includes random number generation hardware or
 secret seed material from such hardware on another machine.
+.Pp
+.Nx
+attempts to reseed the system entropy pool when it has detected the
+system has been cloned as a guest in a virtual machine, so that
+subsequent calls to
+.Nm
+in the clones yield independent outputs.
+However, this relies on the virtual machine host to notify the guest,
+e.g. through the
+.Xr acpivmgenid 4
+device, and even so there is an unavoidable small window of time
+between when the virtual machine is actually cloned and when the system
+is reseeded during which
+.Nm
+may yield identical outputs in the clones.
 .Sh SEE ALSO
 .Xr arc4random 3 ,
 .Xr rnd 4 ,



CVS commit: src/lib/libc/gen

2024-08-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 28 14:08:48 UTC 2024

Modified Files:
src/lib/libc/gen: getentropy.3

Log Message:
getentropy(3): Note intent to reseed on VM clone, and caveats.

Tidy markup and pacify some mandoc -Tlint complaints while here.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/gen/getentropy.3

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



CVS commit: src/lib

2024-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 28 11:54:43 UTC 2024

Modified Files:
src/lib: Makefile

Log Message:
Fix gdb's llvm build


To generate a diff of this commit:
cvs rdiff -u -r1.300 -r1.301 src/lib/Makefile

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



CVS commit: src/lib

2024-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 28 11:54:43 UTC 2024

Modified Files:
src/lib: Makefile

Log Message:
Fix gdb's llvm build


To generate a diff of this commit:
cvs rdiff -u -r1.300 -r1.301 src/lib/Makefile

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

Modified files:

Index: src/lib/Makefile
diff -u src/lib/Makefile:1.300 src/lib/Makefile:1.301
--- src/lib/Makefile:1.300	Mon Jul  1 00:03:03 2024
+++ src/lib/Makefile	Wed Aug 28 07:54:43 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.300 2024/07/01 04:03:03 mrg Exp $
+#	$NetBSD: Makefile,v 1.301 2024/08/28 11:54:43 christos Exp $
 #	from: @(#)Makefile	5.25.1.1 (Berkeley) 5/7/91
 
 .include 
@@ -97,18 +97,13 @@ SUBDIR+=	../external/bsd/jemalloc/lib
 .if (${MKGCC} != "no")
 SUBDIR+=	../external/gpl3/${EXTERNAL_GCC_SUBDIR}/lib/libobjc
 SUBDIR+=	../external/gpl3/${EXTERNAL_GCC_SUBDIR}/lib/libgomp
-# Should probably move GMP, MPFR and MPC builds into the GCC >= 4.5
-# specific build area, but we get better parallelism this way.
-# We don't build compat versions of these.
-. if !defined(MLIBDIR) && (${MKGCCCMDS} != "no")
-SUBDIR+=	../external/lgpl3/mpfr/lib/libmpfr
-SUBDIR+=	../external/lgpl3/mpc/lib/libmpc
-. endif
 .endif
 
 # GCC and GDB >= 13 require GMP.
-.if !defined(MLIBDIR) && (${MKGCCCMDS} != "no" || \
-(${MKGDB} != "no" && ${HAVE_GDB:U0} >= 1320))
+# We don't build compat versions of these
+.if !defined(MLIBDIR) && (${MKGCCCMDS} != "no" || ${MKGDB} != "no")
+SUBDIR+=	../external/lgpl3/mpfr/lib/libmpfr
+SUBDIR+=	../external/lgpl3/mpc/lib/libmpc
 SUBDIR+=	../external/lgpl3/gmp/lib/libgmp
 .endif
 



CVS commit: src/lib/libc/gen

2024-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 27 11:55:16 UTC 2024

Modified Files:
src/lib/libc/gen: arc4random.3

Log Message:
arc4random(3): Note that arc4random respects kern.entropy.epoch.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libc/gen/arc4random.3

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

Modified files:

Index: src/lib/libc/gen/arc4random.3
diff -u src/lib/libc/gen/arc4random.3:1.21 src/lib/libc/gen/arc4random.3:1.22
--- src/lib/libc/gen/arc4random.3:1.21	Fri Jul 15 21:19:19 2016
+++ src/lib/libc/gen/arc4random.3	Tue Aug 27 11:55:16 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: arc4random.3,v 1.21 2016/07/15 21:19:19 wiz Exp $
+.\"	$NetBSD: arc4random.3,v 1.22 2024/08/27 11:55:16 riastradh Exp $
 .\"
 .\" Copyright (c) 2014 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -233,6 +233,15 @@ and
 .Fn arc4random_addrandom
 may abort the process in the highly unlikely event that the operating
 system fails to provide entropy.
+.Pp
+If
+.Nm
+detects that the sysctl variable
+.Li kern.entropy.epoch
+.Pq see Xr rnd 4
+has changed since its last output, it reseeds itself with additional
+data from the system entropy pool again before generating its next
+output.
 .Sh SEE ALSO
 .Xr rand 3 ,
 .Xr random 3 ,
@@ -252,7 +261,7 @@ for testing purposes.
 .Pp
 The name
 .Sq arc4random
-was chosen for hysterical raisins -- it was originally implemented
+was chosen for hysterical raisins \(em it was originally implemented
 using the RC4 stream cipher, which has been known since shortly after
 it was published in 1994 to have observable biases in the output, and
 is now known to be broken badly enough to admit practical attacks in



CVS commit: src/lib/libc/gen

2024-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 27 11:55:16 UTC 2024

Modified Files:
src/lib/libc/gen: arc4random.3

Log Message:
arc4random(3): Note that arc4random respects kern.entropy.epoch.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libc/gen/arc4random.3

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



CVS commit: src/lib/libc/gen

2024-08-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 26 15:50:26 UTC 2024

Modified Files:
src/lib/libc/gen: arc4random.c

Log Message:
arc4random.c: Fix test program.

This isn't wired up anywhere, but let's reduce the bitrot.  It was
helpful in reminding me that kern.entropy.epoch was, for reasons I
can't remember, restricted to privileged access.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/libc/gen/arc4random.c

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

Modified files:

Index: src/lib/libc/gen/arc4random.c
diff -u src/lib/libc/gen/arc4random.c:1.35 src/lib/libc/gen/arc4random.c:1.36
--- src/lib/libc/gen/arc4random.c:1.35	Mon Aug 26 15:19:22 2024
+++ src/lib/libc/gen/arc4random.c	Mon Aug 26 15:50:26 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: arc4random.c,v 1.35 2024/08/26 15:19:22 riastradh Exp $	*/
+/*	$NetBSD: arc4random.c,v 1.36 2024/08/26 15:50:26 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: arc4random.c,v 1.35 2024/08/26 15:19:22 riastradh Exp $");
+__RCSID("$NetBSD: arc4random.c,v 1.36 2024/08/26 15:50:26 riastradh Exp $");
 
 #include "namespace.h"
 #include "reentrant.h"
@@ -810,8 +810,18 @@ main(int argc __unused, char **argv __un
 	switch (pid) {
 	case -1:
 		err(1, "fork");
-	case 0:
-		_exit(arc4random_prng_get()->arc4_seeded);
+	case 0: {
+		/*
+		 * Verify the epoch has been set to zero by fork.
+		 */
+		struct arc4random_prng *prng = NULL;
+#ifdef _REENTRANT
+		prng = thr_getspecific(arc4random_global.thread_key);
+#endif
+		if (prng == NULL)
+			prng = &arc4random_global.prng;
+		_exit(prng->arc4_epoch != 0);
+	}
 	default:
 		rpid = waitpid(pid, &status, 0);
 		if (rpid == -1)



CVS commit: src/lib/libc/gen

2024-08-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 26 15:50:26 UTC 2024

Modified Files:
src/lib/libc/gen: arc4random.c

Log Message:
arc4random.c: Fix test program.

This isn't wired up anywhere, but let's reduce the bitrot.  It was
helpful in reminding me that kern.entropy.epoch was, for reasons I
can't remember, restricted to privileged access.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/libc/gen/arc4random.c

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



CVS commit: src/lib/libc/gen

2024-08-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 26 15:19:22 UTC 2024

Modified Files:
src/lib/libc/gen: arc4random.c

Log Message:
arc4random(3): Reseed if system entropy epoch changes.

This can happen, for example, if the system is a VM instance, and the
VM is cloned.

This incurs the cost of a system call on every arc4random call, which
is unfortunate, but

1. we don't currently have a (machine-independent) mechanism for
   exposing a read-only page to userland shared by the kernel to
   enable a cheaper access path to the entropy epoch; and

2. the algorithm here -- a simple application of ChaCha -- is likely
   also a bottleneck and could be much cheaper by

   (a) using sys/crypto/chacha for machine-dependent vectorized
   ChaCha code, and

   (b) filling a buffer (somewhere between a cipher block and a page)
   in a batch at a time, instead of running ChaCha to generate
   only 32 bytes at a time.

So although this might be a performance hit, the security benefit is
worthwhile and we have a clear path to do better than reversing the
performance hit later.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/libc/gen/arc4random.c

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

Modified files:

Index: src/lib/libc/gen/arc4random.c
diff -u src/lib/libc/gen/arc4random.c:1.34 src/lib/libc/gen/arc4random.c:1.35
--- src/lib/libc/gen/arc4random.c:1.34	Sat Jan 20 14:52:47 2024
+++ src/lib/libc/gen/arc4random.c	Mon Aug 26 15:19:22 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: arc4random.c,v 1.34 2024/01/20 14:52:47 christos Exp $	*/
+/*	$NetBSD: arc4random.c,v 1.35 2024/08/26 15:19:22 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: arc4random.c,v 1.34 2024/01/20 14:52:47 christos Exp $");
+__RCSID("$NetBSD: arc4random.c,v 1.35 2024/08/26 15:19:22 riastradh Exp $");
 
 #include "namespace.h"
 #include "reentrant.h"
@@ -65,6 +65,7 @@ __RCSID("$NetBSD: arc4random.c,v 1.34 20
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -398,11 +399,67 @@ crypto_onetimestream(const void *seed, v
 		(void)explicit_memset(block, 0, sizeof block);
 }
 
+/*
+ * entropy_epoch()
+ *
+ *	Return the current entropy epoch, from the sysctl node
+ *	kern.entropy.epoch.
+ *
+ *	The entropy epoch is never zero.  Initially, or on error, it is
+ *	(unsigned)-1.  It may wrap around but it skips (unsigned)-1 and
+ *	0 when it does.  Changes happen less than once per second, so
+ *	wraparound will only affect systems after 136 years of uptime.
+ *
+ *	XXX This should get it from a page shared read-only by kernel
+ *	with userland, but until we implement such a mechanism, this
+ *	sysctl -- incurring the cost of a syscall -- will have to
+ *	serve.
+ */
+static unsigned
+entropy_epoch(void)
+{
+	static atomic_int mib0[3];
+	static atomic_bool initialized = false;
+	int mib[3];
+	unsigned epoch = -1;
+	size_t epochlen = sizeof(epoch);
+
+	/*
+	 * Resolve kern.entropy.epoch if we haven't already.  Cache it
+	 * for the next caller.  Initialization is idempotent, so it's
+	 * OK if two threads do it at once.
+	 */
+	if (atomic_load_explicit(&initialized, memory_order_acquire)) {
+		mib[0] = atomic_load_explicit(&mib0[0], memory_order_relaxed);
+		mib[1] = atomic_load_explicit(&mib0[1], memory_order_relaxed);
+		mib[2] = atomic_load_explicit(&mib0[2], memory_order_relaxed);
+	} else {
+		size_t nmib = __arraycount(mib);
+
+		if (sysctlnametomib("kern.entropy.epoch", mib, &nmib) == -1)
+			return -1;
+		if (nmib != __arraycount(mib))
+			return -1;
+		atomic_store_explicit(&mib0[0], mib[0], memory_order_relaxed);
+		atomic_store_explicit(&mib0[1], mib[1], memory_order_relaxed);
+		atomic_store_explicit(&mib0[2], mib[2], memory_order_relaxed);
+		atomic_store_explicit(&initialized, true,
+		memory_order_release);
+	}
+
+	if (sysctl(mib, __arraycount(mib), &epoch, &epochlen, NULL, 0) == -1)
+		return -1;
+	if (epochlen != sizeof(epoch))
+		return -1;
+
+	return epoch;
+}
+
 /* arc4random state: per-thread, per-process (zeroed in child on fork) */
 
 struct arc4random_prng {
 	struct crypto_prng	arc4_prng;
-	bool			arc4_seeded;
+	unsigned		arc4_epoch;
 };
 
 static void
@@ -413,6 +470,7 @@ arc4random_prng_addrandom(struct arc4ran
 	SHA256_CTX ctx;
 	uint8_t buf[crypto_prng_SEEDBYTES];
 	size_t buflen = sizeof buf;
+	unsigned epoch = entropy_epoch();
 
 	__CTASSERT(sizeof buf == SHA256_DIGEST_LENGTH);
 
@@ -436,7 +494,7 @@ arc4random_prng_addrandom(struct arc4ran
 	/* reseed(SHA256(prng() || sysctl(KERN_ARND) || data)) */
 	crypto_prng_seed(&prng->arc4_prng, buf);
 	(void)explicit_memset(buf, 0, sizeof buf);
-	prng->arc4_seeded = true;
+	prng->arc4_epoch = epoch;
 }
 
 #ifdef _REENTRANT
@@ -567,7 +625,7 @@ arc4random_prng_get(void)
 	}
 
 	/* Guarantee the PRNG 

CVS commit: src/lib/libc/gen

2024-08-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 26 15:19:22 UTC 2024

Modified Files:
src/lib/libc/gen: arc4random.c

Log Message:
arc4random(3): Reseed if system entropy epoch changes.

This can happen, for example, if the system is a VM instance, and the
VM is cloned.

This incurs the cost of a system call on every arc4random call, which
is unfortunate, but

1. we don't currently have a (machine-independent) mechanism for
   exposing a read-only page to userland shared by the kernel to
   enable a cheaper access path to the entropy epoch; and

2. the algorithm here -- a simple application of ChaCha -- is likely
   also a bottleneck and could be much cheaper by

   (a) using sys/crypto/chacha for machine-dependent vectorized
   ChaCha code, and

   (b) filling a buffer (somewhere between a cipher block and a page)
   in a batch at a time, instead of running ChaCha to generate
   only 32 bytes at a time.

So although this might be a performance hit, the security benefit is
worthwhile and we have a clear path to do better than reversing the
performance hit later.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/libc/gen/arc4random.c

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



CVS commit: src/lib/libc/resolv

2024-08-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 24 22:37:41 UTC 2024

Modified Files:
src/lib/libc/resolv: res_query.c

Log Message:
Not a bug, but avoid using a possibly negative index anyway (CID-603941)


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/resolv/res_query.c

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

Modified files:

Index: src/lib/libc/resolv/res_query.c
diff -u src/lib/libc/resolv/res_query.c:1.17 src/lib/libc/resolv/res_query.c:1.18
--- src/lib/libc/resolv/res_query.c:1.17	Tue Aug  1 04:47:25 2023
+++ src/lib/libc/resolv/res_query.c	Sat Aug 24 18:37:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: res_query.c,v 1.17 2023/08/01 08:47:25 mrg Exp $	*/
+/*	$NetBSD: res_query.c,v 1.18 2024/08/24 22:37:41 christos Exp $	*/
 
 /*
  * Portions Copyright (C) 2004, 2005, 2008  Internet Systems Consortium, Inc. ("ISC")
@@ -89,7 +89,7 @@
 static const char sccsid[] = "@(#)res_query.c	8.1 (Berkeley) 6/4/93";
 static const char rcsid[] = "Id: res_query.c,v 1.11 2008/11/14 02:36:51 marka Exp";
 #else
-__RCSID("$NetBSD: res_query.c,v 1.17 2023/08/01 08:47:25 mrg Exp $");
+__RCSID("$NetBSD: res_query.c,v 1.18 2024/08/24 22:37:41 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -151,7 +151,6 @@ res_nquery(res_state statp,
 	u_char buf[MAXPACKET];
 	HEADER *hp = (HEADER *)(void *)answer;
 	u_int oflags;
-	u_char *rdata;
 	int n;
 
 	oflags = statp->_flags;
@@ -169,10 +168,9 @@ again:
 	if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 &&
 	(statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC|RES_NSID)) != 0U) {
 		n = res_nopt(statp, n, buf, (int)sizeof(buf), anslen);
-		rdata = &buf[n];
 		if (n > 0 && (statp->options & RES_NSID) != 0U) {
 			n = res_nopt_rdata(statp, n, buf, (int)sizeof(buf),
-			rdata, NS_OPT_NSID, 0, NULL);
+			buf + n, NS_OPT_NSID, 0, NULL);
 		}
 	}
 #endif



CVS commit: src/lib/libc/resolv

2024-08-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 24 22:37:41 UTC 2024

Modified Files:
src/lib/libc/resolv: res_query.c

Log Message:
Not a bug, but avoid using a possibly negative index anyway (CID-603941)


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/resolv/res_query.c

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



CVS commit: src/lib/libcurses

2024-08-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 24 22:27:03 UTC 2024

Modified Files:
src/lib/libcurses: get_wch.c

Log Message:
Check for returning ERR to avoid negative array index later (CID-1617248)


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libcurses/get_wch.c

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

Modified files:

Index: src/lib/libcurses/get_wch.c
diff -u src/lib/libcurses/get_wch.c:1.26 src/lib/libcurses/get_wch.c:1.27
--- src/lib/libcurses/get_wch.c:1.26	Mon Sep  6 03:45:48 2021
+++ src/lib/libcurses/get_wch.c	Sat Aug 24 18:27:03 2024
@@ -1,4 +1,4 @@
-/*   $NetBSD: get_wch.c,v 1.26 2021/09/06 07:45:48 rin Exp $ */
+/*   $NetBSD: get_wch.c,v 1.27 2024/08/24 22:27:03 christos Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: get_wch.c,v 1.26 2021/09/06 07:45:48 rin Exp $");
+__RCSID("$NetBSD: get_wch.c,v 1.27 2024/08/24 22:27:03 christos Exp $");
 #endif		  /* not lint */
 
 #include 
@@ -135,7 +135,7 @@ inkey(wchar_t *wc, int to, int delay)
 			}
 
 			c = __fgetc_resize(infd);
-			if (ferror(infd)) {
+			if (c == ERR || ferror(infd)) {
 clearerr(infd);
 return c;
 			}
@@ -179,7 +179,7 @@ inkey(wchar_t *wc, int to, int delay)
 			}
 
 			c = __fgetc_resize(infd);
-			if (ferror(infd)) {
+			if (c == ERR || ferror(infd)) {
 clearerr(infd);
 return c;
 			}



CVS commit: src/lib/libcurses

2024-08-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 24 22:27:03 UTC 2024

Modified Files:
src/lib/libcurses: get_wch.c

Log Message:
Check for returning ERR to avoid negative array index later (CID-1617248)


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libcurses/get_wch.c

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



CVS commit: src/lib/libc/locale

2024-08-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 23 12:59:49 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc16.3 mbrtoc32.3 mbrtoc8.3

Log Message:
mbrtoc8(3), mbrtoc16(3), mbrtoc32(3): Say 0 for zero code unit.

Rather than deal with differences between C11 and C23 in notation,
'\0' vs L'\0' vs u8'\0' vs u'\0' vs U'\0'.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/locale/mbrtoc16.3
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/mbrtoc32.3
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/mbrtoc8.3

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

Modified files:

Index: src/lib/libc/locale/mbrtoc16.3
diff -u src/lib/libc/locale/mbrtoc16.3:1.9 src/lib/libc/locale/mbrtoc16.3:1.10
--- src/lib/libc/locale/mbrtoc16.3:1.9	Sat Aug 17 12:37:05 2024
+++ src/lib/libc/locale/mbrtoc16.3	Fri Aug 23 12:59:49 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc16.3,v 1.9 2024/08/17 12:37:05 riastradh Exp $
+.\"	$NetBSD: mbrtoc16.3,v 1.10 2024/08/23 12:59:49 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -245,8 +245,8 @@ while (n) {
 
 len = mbrtoc16(&c16, s, n, &mbs);
 switch (len) {
-case 0: /* null terminator */
-assert(c16 == L'\e0');
+case 0: /* NUL terminator */
+assert(c16 == 0);
 goto out;
 default:/* scalar value or high surrogate */
 printf("U+%04"PRIx16"\en", (uint16_t)c16);

Index: src/lib/libc/locale/mbrtoc32.3
diff -u src/lib/libc/locale/mbrtoc32.3:1.8 src/lib/libc/locale/mbrtoc32.3:1.9
--- src/lib/libc/locale/mbrtoc32.3:1.8	Sat Aug 17 01:52:51 2024
+++ src/lib/libc/locale/mbrtoc32.3	Fri Aug 23 12:59:49 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc32.3,v 1.8 2024/08/17 01:52:51 riastradh Exp $
+.\"	$NetBSD: mbrtoc32.3,v 1.9 2024/08/23 12:59:49 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -216,8 +216,8 @@ while (n) {
 
 len = mbrtoc32(&c32, s, n, &mbs);
 switch (len) {
-case 0: /* null terminator */
-assert(c32 == L'\e0');
+case 0: /* NUL terminator */
+assert(c32 == 0);
 goto out;
 default:/* scalar value */
 printf("U+%04"PRIx32"\en", (uint32_t)c32);

Index: src/lib/libc/locale/mbrtoc8.3
diff -u src/lib/libc/locale/mbrtoc8.3:1.6 src/lib/libc/locale/mbrtoc8.3:1.7
--- src/lib/libc/locale/mbrtoc8.3:1.6	Sat Aug 17 12:37:29 2024
+++ src/lib/libc/locale/mbrtoc8.3	Fri Aug 23 12:59:49 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc8.3,v 1.6 2024/08/17 12:37:29 riastradh Exp $
+.\"	$NetBSD: mbrtoc8.3,v 1.7 2024/08/23 12:59:49 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -244,8 +244,8 @@ while (n) {
 
 len = mbrtoc8(&c8, s, n, &mbs);
 switch (len) {
-case 0: /* null terminator */
-assert(c8 == '\e0');
+case 0: /* NUL terminator */
+assert(c8 == 0);
 goto out;
 default:/* consumed input and yielded a byte c8 */
 printf("0x%02hhx\en", c8);



CVS commit: src/lib/libc/locale

2024-08-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 23 12:59:49 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc16.3 mbrtoc32.3 mbrtoc8.3

Log Message:
mbrtoc8(3), mbrtoc16(3), mbrtoc32(3): Say 0 for zero code unit.

Rather than deal with differences between C11 and C23 in notation,
'\0' vs L'\0' vs u8'\0' vs u'\0' vs U'\0'.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/locale/mbrtoc16.3
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/mbrtoc32.3
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/mbrtoc8.3

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



CVS commit: src/lib/libc/locale

2024-08-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Aug 21 18:42:35 UTC 2024

Modified Files:
src/lib/libc/locale: duplocale.3

Log Message:
duplocale.3: fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/duplocale.3

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

Modified files:

Index: src/lib/libc/locale/duplocale.3
diff -u src/lib/libc/locale/duplocale.3:1.3 src/lib/libc/locale/duplocale.3:1.4
--- src/lib/libc/locale/duplocale.3:1.3	Mon Feb 15 15:38:43 2021
+++ src/lib/libc/locale/duplocale.3	Wed Aug 21 18:42:34 2024
@@ -1,4 +1,5 @@
-.\" $NetBSD: duplocale.3,v 1.3 2021/02/15 15:38:43 wiz Exp $
+.\" $NetBSD: duplocale.3,v 1.4 2024/08/21 18:42:34 rillig Exp $
+.\"
 .\" Copyright (c) 2011 The FreeBSD Foundation
 .\" All rights reserved.
 .\"
@@ -33,7 +34,7 @@
 .Os
 .Sh NAME
 .Nm duplocale
-.Nd duplicate an locale
+.Nd duplicate a locale
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS



CVS commit: src/lib/libc/locale

2024-08-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Aug 21 18:42:35 UTC 2024

Modified Files:
src/lib/libc/locale: duplocale.3

Log Message:
duplocale.3: fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/duplocale.3

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



CVS commit: src/lib/libc/locale

2024-08-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Aug 21 18:36:11 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.c c32rtomb.c mbrtoc8.c

Log Message:
c16rtomb, c32rtomb, mbrtoc8: fix page numbers in comments


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/c16rtomb.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/c32rtomb.c
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/locale/mbrtoc8.c

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



CVS commit: src/lib/libc/locale

2024-08-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Aug 21 18:36:11 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.c c32rtomb.c mbrtoc8.c

Log Message:
c16rtomb, c32rtomb, mbrtoc8: fix page numbers in comments


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/c16rtomb.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/c32rtomb.c
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/locale/mbrtoc8.c

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

Modified files:

Index: src/lib/libc/locale/c16rtomb.c
diff -u src/lib/libc/locale/c16rtomb.c:1.6 src/lib/libc/locale/c16rtomb.c:1.7
--- src/lib/libc/locale/c16rtomb.c:1.6	Sun Aug 18 02:19:35 2024
+++ src/lib/libc/locale/c16rtomb.c	Wed Aug 21 18:36:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c16rtomb.c,v 1.6 2024/08/18 02:19:35 riastradh Exp $	*/
+/*	$NetBSD: c16rtomb.c,v 1.7 2024/08/21 18:36:11 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  * References:
  *
  *	The Unicode Standard, Version 15.0 -- Core Specification, The
- *	Unicode Consortium, Sec. 3.8 `Surrogates', p. 119.
+ *	Unicode Consortium, Sec. 3.8 `Surrogates', p. 118.
  *	https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
  *	https://web.archive.org/web/20240718101254/https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
  *
@@ -66,7 +66,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: c16rtomb.c,v 1.6 2024/08/18 02:19:35 riastradh Exp $");
+__RCSID("$NetBSD: c16rtomb.c,v 1.7 2024/08/21 18:36:11 rillig Exp $");
 
 #include "namespace.h"
 

Index: src/lib/libc/locale/c32rtomb.c
diff -u src/lib/libc/locale/c32rtomb.c:1.5 src/lib/libc/locale/c32rtomb.c:1.6
--- src/lib/libc/locale/c32rtomb.c:1.5	Tue Aug 20 17:43:41 2024
+++ src/lib/libc/locale/c32rtomb.c	Wed Aug 21 18:36:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c32rtomb.c,v 1.5 2024/08/20 17:43:41 riastradh Exp $	*/
+/*	$NetBSD: c32rtomb.c,v 1.6 2024/08/21 18:36:11 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -43,13 +43,13 @@
  * References:
  *
  *	The Unicode Standard, Version 15.0 -- Core Specification, The
- *	Unicode Consortium, Sec. 3.8 `Surrogates', p. 119.
- *	https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf
- *	https://web.archive.org/web/20240718101254/https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf
+ *	Unicode Consortium, Sec. 3.8 `Surrogates', p. 118.
+ *	https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
+ *	https://web.archive.org/web/20240718101254/https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
  */
 
 #include 
-__RCSID("$NetBSD: c32rtomb.c,v 1.5 2024/08/20 17:43:41 riastradh Exp $");
+__RCSID("$NetBSD: c32rtomb.c,v 1.6 2024/08/21 18:36:11 rillig Exp $");
 
 #include "namespace.h"
 

Index: src/lib/libc/locale/mbrtoc8.c
diff -u src/lib/libc/locale/mbrtoc8.c:1.7 src/lib/libc/locale/mbrtoc8.c:1.8
--- src/lib/libc/locale/mbrtoc8.c:1.7	Sun Aug 18 19:46:53 2024
+++ src/lib/libc/locale/mbrtoc8.c	Wed Aug 21 18:36:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbrtoc8.c,v 1.7 2024/08/18 19:46:53 rillig Exp $	*/
+/*	$NetBSD: mbrtoc8.c,v 1.8 2024/08/21 18:36:11 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  * References:
  *
  *	The Unicode Standard, Version 15.0 -- Core Specification, The
- *	Unicode Consortium, Sec. 3.8 `Surrogates', p. 119.
+ *	Unicode Consortium, Sec. 3.8 `Surrogates', p. 118.
  *	https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
  *	https://web.archive.org/web/20240718101254/https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
  *
@@ -72,7 +72,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: mbrtoc8.c,v 1.7 2024/08/18 19:46:53 rillig Exp $");
+__RCSID("$NetBSD: mbrtoc8.c,v 1.8 2024/08/21 18:36:11 rillig Exp $");
 
 #include "namespace.h"
 



CVS commit: src/lib/libc/locale

2024-08-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 20 20:36:30 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.3 c32rtomb.3 c8rtomb.3

Log Message:
c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case.

This ignores c8/c16/c32, produces no output anywhere, and just resets
ps to the initial conversion state.

Also just use 0 in the example, not '\0' or L'\0'.  This works for
C11, which prefers '\0' and L'\0', for and C23, which introduced the
new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32).


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/locale/c16rtomb.3 \
src/lib/libc/locale/c32rtomb.3
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/c8rtomb.3

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



CVS commit: src/lib/libc/locale

2024-08-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 20 20:36:30 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.3 c32rtomb.3 c8rtomb.3

Log Message:
c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case.

This ignores c8/c16/c32, produces no output anywhere, and just resets
ps to the initial conversion state.

Also just use 0 in the example, not '\0' or L'\0'.  This works for
C11, which prefers '\0' and L'\0', for and C23, which introduced the
new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32).


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/locale/c16rtomb.3 \
src/lib/libc/locale/c32rtomb.3
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/c8rtomb.3

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

Modified files:

Index: src/lib/libc/locale/c16rtomb.3
diff -u src/lib/libc/locale/c16rtomb.3:1.10 src/lib/libc/locale/c16rtomb.3:1.11
--- src/lib/libc/locale/c16rtomb.3:1.10	Tue Aug 20 20:04:45 2024
+++ src/lib/libc/locale/c16rtomb.3	Tue Aug 20 20:36:30 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c16rtomb.3,v 1.10 2024/08/20 20:04:45 riastradh Exp $
+.\"	$NetBSD: c16rtomb.3,v 1.11 2024/08/20 20:36:30 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -71,9 +71,17 @@ to denote error.
 .Pp
 If
 .Fa s
-is a null pointer, no output is stored, but the effects on
+is a null pointer,
+no output is produced and
+.Fa ps
+is reset to the initial conversion state, as if the call had been
+.Fo c8rtomb
+.Va buf ,
+.Li 0 ,
 .Fa ps
-and the return value are unchanged.
+.Fc
+for some internal buffer
+.Va buf .
 .Pp
 If
 .Fa c16
@@ -132,7 +140,7 @@ for (i = 0; i < __arraycount(c16); i++) 
 assert(len < sizeof(buf) - (s - buf));
 s += len;
 }
-len = c16rtomb(s, L'\e0', &mbs); /* NUL-terminate */
+len = c16rtomb(s, 0, &mbs); /* NUL-terminate */
 if (len == (size_t)-1)
 err(1, "c16rtomb");
 assert(len <= sizeof(buf) - (s - buf));
Index: src/lib/libc/locale/c32rtomb.3
diff -u src/lib/libc/locale/c32rtomb.3:1.10 src/lib/libc/locale/c32rtomb.3:1.11
--- src/lib/libc/locale/c32rtomb.3:1.10	Tue Aug 20 20:04:45 2024
+++ src/lib/libc/locale/c32rtomb.3	Tue Aug 20 20:36:30 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c32rtomb.3,v 1.10 2024/08/20 20:04:45 riastradh Exp $
+.\"	$NetBSD: c32rtomb.3,v 1.11 2024/08/20 20:36:30 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -79,9 +79,17 @@ is an integer either in [0,0xd7ff] or in
 .Pp
 If
 .Fa s
-is a null pointer, no output is stored, but the effects on
+is a null pointer,
+no output is produced and
+.Fa ps
+is reset to the initial conversion state, as if the call had been
+.Fo c8rtomb
+.Va buf ,
+.Li 0 ,
 .Fa ps
-and the return value are unchanged.
+.Fc
+for some internal buffer
+.Va buf .
 .Pp
 If
 .Fa c32
@@ -138,7 +146,7 @@ for (i = 0; i < __arraycount(c32); i++) 
 assert(len < sizeof(buf) - (s - buf));
 s += len;
 }
-len = c32rtomb(s, L'\e0', &mbs); /* NUL-terminate */
+len = c32rtomb(s, 0, &mbs); /* NUL-terminate */
 if (len == (size_t)-1)
 err(1, "c32rtomb");
 assert(len <= sizeof(buf) - (s - buf));

Index: src/lib/libc/locale/c8rtomb.3
diff -u src/lib/libc/locale/c8rtomb.3:1.8 src/lib/libc/locale/c8rtomb.3:1.9
--- src/lib/libc/locale/c8rtomb.3:1.8	Tue Aug 20 20:04:45 2024
+++ src/lib/libc/locale/c8rtomb.3	Tue Aug 20 20:36:30 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c8rtomb.3,v 1.8 2024/08/20 20:04:45 riastradh Exp $
+.\"	$NetBSD: c8rtomb.3,v 1.9 2024/08/20 20:36:30 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -71,9 +71,17 @@ to denote error.
 .Pp
 If
 .Fa s
-is a null pointer, no output is stored, but the effects on
+is a null pointer,
+no output is produced and
+.Fa ps
+is reset to the initial conversion state, as if the call had been
+.Fo c8rtomb
+.Va buf ,
+.Li 0 ,
 .Fa ps
-and the return value are unchanged.
+.Fc
+for some internal buffer
+.Va buf .
 .Pp
 If
 .Fa c8
@@ -132,7 +140,7 @@ for (i = 0; i < __arraycount(c8); i++) {
 assert(len < sizeof(buf) - (s - buf));
 s += len;
 }
-len = c8rtomb(s, '\e0', &mbs);   /* NUL-terminate */
+len = c8rtomb(s, 0, &mbs);  /* NUL-terminate */
 if (len == (size_t)-1)
 err(1, "c16rtomb");
 assert(len <= sizeof(buf) - (s - buf));



CVS commit: src/lib/libc/locale

2024-08-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 20 20:04:45 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.3 c32rtomb.3 c8rtomb.3

Log Message:
c8rtomb(3), c16rtomb(3), c32rtomb(3): Attempt to simplify language.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/locale/c16rtomb.3 \
src/lib/libc/locale/c32rtomb.3
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/locale/c8rtomb.3

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



CVS commit: src/lib/libc/locale

2024-08-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 20 20:04:45 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.3 c32rtomb.3 c8rtomb.3

Log Message:
c8rtomb(3), c16rtomb(3), c32rtomb(3): Attempt to simplify language.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/locale/c16rtomb.3 \
src/lib/libc/locale/c32rtomb.3
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/locale/c8rtomb.3

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

Modified files:

Index: src/lib/libc/locale/c16rtomb.3
diff -u src/lib/libc/locale/c16rtomb.3:1.9 src/lib/libc/locale/c16rtomb.3:1.10
--- src/lib/libc/locale/c16rtomb.3:1.9	Tue Aug 20 17:14:05 2024
+++ src/lib/libc/locale/c16rtomb.3	Tue Aug 20 20:04:45 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c16rtomb.3,v 1.9 2024/08/20 17:14:05 riastradh Exp $
+.\"	$NetBSD: c16rtomb.3,v 1.10 2024/08/20 20:04:45 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -50,8 +50,8 @@
 The
 .Nm
 function decodes UTF-16 and converts it to multibyte characters in the
-current locale, keeping state so it can restart after incremental
-progress.
+current locale, keeping state to remember incremental progress if
+restarted.
 .Pp
 Each call to
 .Nm
@@ -69,27 +69,6 @@ or
 .Li (size_t)-1
 to denote error.
 .Pp
-Over successive calls to
-.Nm
-with the same state
-.Fa ps ,
-the sequence of
-.Fa c16
-values must be a well-formed UTF-16 code unit sequence, or an
-incomplete UTF-16 code unit sequence followed by null.
-If
-.Fa c16 ,
-when appended to the sequence of code units passed in previous calls,
-is not null and does not form a well-formed UTF-16 code unit sequence,
-then
-.Nm
-returns
-.Li (size_t)-1
-with
-.Xr errno 2
-set to
-.Er EILSEQ .
-.Pp
 If
 .Fa s
 is a null pointer, no output is stored, but the effects on
@@ -98,12 +77,12 @@ and the return value are unchanged.
 .Pp
 If
 .Fa c16
-is null,
+is zero,
 .Nm
 discards any pending incomplete UTF-16 code unit sequence in
 .Fa ps ,
 outputs a (possibly empty) shift sequence to restore the initial state
-followed by a null byte, and resets
+followed by a NUL byte, and resets
 .Fa ps
 to the initial conversion state.
 .Pp
@@ -117,13 +96,8 @@ object with static storage duration, dis
 .Vt mbstate_t
 objects
 .Po
-including those used by
-.Xr mbrtoc8 3 ,
-.Xr mbrtoc16 3 ,
-.Xr mbrtoc32 3 ,
-.Xr c8rtomb 3 ,
-and
-.Xr c32rtomb 3
+including those used by other functions such as
+.Xr mbrtoc16 3
 .Pc ,
 which is initialized at program startup to the initial conversion
 state.
@@ -173,12 +147,12 @@ which is a constant upper bound on the l
 .Sh ERRORS
 .Bl -tag -width Bq
 .It Bq Er EILSEQ
-The
 .Fa c16
-input sequence does not encode a Unicode scalar value in UTF-16.
+is invalid as the next code unit in the conversion state
+.Fa ps .
 .It Bq Er EILSEQ
-The Unicode scalar value requested cannot be encoded as a multibyte
-sequence in the current locale.
+The input cannot be encoded as a multibyte sequence in the current
+locale.
 .It Bq Er EIO
 An error occurred in loading the locale's character conversions.
 .El
@@ -220,12 +194,13 @@ function first appeared in
 .Nx 11.0 .
 .\"
 .Sh BUGS
-The standard requires that a null code unit unconditionally reset the
-conversion state and output null:
+The standard requires that passing zero as
+.Fa c16
+unconditionally reset the conversion state and output a NUL byte:
 .Bd -filled -offset indent
 If
-.Fa c8
-is a null character, a null byte is stored, preceded by any shift
+.Fa c16
+is a null wide character, a null byte is stored, preceded by any shift
 sequence needed to restore the initial shift state; the resulting state
 described is the initial conversion state.
 .Ed
@@ -233,7 +208,7 @@ described is the initial conversion stat
 However, some implementations such as
 .Fx 14.0 ,
 .Ox 7.4 ,
-and glibc 2.36 ignore this clause and, if the null was preceded by an
+and glibc 2.36 ignore this clause and, if the zero was preceded by an
 incomplete UTF-16 code unit sequence, fail with
 .Er EILSEQ
 instead.
Index: src/lib/libc/locale/c32rtomb.3
diff -u src/lib/libc/locale/c32rtomb.3:1.9 src/lib/libc/locale/c32rtomb.3:1.10
--- src/lib/libc/locale/c32rtomb.3:1.9	Tue Aug 20 17:14:05 2024
+++ src/lib/libc/locale/c32rtomb.3	Tue Aug 20 20:04:45 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c32rtomb.3,v 1.9 2024/08/20 17:14:05 riastradh Exp $
+.\"	$NetBSD: c32rtomb.3,v 1.10 2024/08/20 20:04:45 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -50,8 +50,8 @@
 The
 .Nm
 function converts Unicode scalar values to multibyte characters in the
-current locale, keeping state so it can restart after incremental
-progress.
+current locale, keeping state to remember incremental progress if
+restarted.
 .Pp
 Each call to
 .Nm
@@ -71,9 +71,11 @@ to denote error.
 .Pp
 The input
 .Fa 

CVS commit: src/lib/libc/locale

2024-08-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 20 17:43:41 UTC 2024

Modified Files:
src/lib/libc/locale: c32rtomb.c

Log Message:
c32rtomb(3): Fix type of wcrtomb_l return value.

This was from `int wctomb_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to wcrtomb_l.  Caught by
lint.

`wc_len' mirrors `mb_len' in the complementary code in mbrtoc32(3) to
avoid clash with standard C function mblen(3).

PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/c32rtomb.c

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

Modified files:

Index: src/lib/libc/locale/c32rtomb.c
diff -u src/lib/libc/locale/c32rtomb.c:1.4 src/lib/libc/locale/c32rtomb.c:1.5
--- src/lib/libc/locale/c32rtomb.c:1.4	Mon Aug 19 16:22:10 2024
+++ src/lib/libc/locale/c32rtomb.c	Tue Aug 20 17:43:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c32rtomb.c,v 1.4 2024/08/19 16:22:10 riastradh Exp $	*/
+/*	$NetBSD: c32rtomb.c,v 1.5 2024/08/20 17:43:41 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: c32rtomb.c,v 1.4 2024/08/19 16:22:10 riastradh Exp $");
+__RCSID("$NetBSD: c32rtomb.c,v 1.5 2024/08/20 17:43:41 riastradh Exp $");
 
 #include "namespace.h"
 
@@ -98,7 +98,7 @@ c32rtomb_l(char *restrict s, char32_t c3
 	size_t srcleft, dstleft, inval;
 	mbstate_t mbrtowcstate = {0};
 	wchar_t wc;
-	int wlen;
+	size_t wc_len;
 	size_t len;
 	int error, errno_save;
 
@@ -194,16 +194,17 @@ c32rtomb_l(char *restrict s, char32_t c3
 	 *
 	 * XXX What about combining characters?
 	 */
-	wlen = mbrtowc_l(&wc, buf, len, &mbrtowcstate, loc);
-	switch (wlen) {
-	case -1:		/* error, with errno set */
+	wc_len = mbrtowc_l(&wc, buf, len, &mbrtowcstate, loc);
+	switch (wc_len) {
+	case (size_t)-1:	/* error, with errno set */
+		len = (size_t)-1;
 		goto out;
 	case 0:			/* decoded NUL */
 		wc = 0;		/* paranoia */
+		len = wc_len;
 		break;
 	default:		/* decoded wc */
-		_DIAGASSERT(wlen > 0);
-		_DIAGASSERT((size_t)wlen <= len);
+		_DIAGASSERT(wc_len <= len);
 	}
 
 	/*



CVS commit: src/lib/libc/locale

2024-08-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 20 17:43:41 UTC 2024

Modified Files:
src/lib/libc/locale: c32rtomb.c

Log Message:
c32rtomb(3): Fix type of wcrtomb_l return value.

This was from `int wctomb_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to wcrtomb_l.  Caught by
lint.

`wc_len' mirrors `mb_len' in the complementary code in mbrtoc32(3) to
avoid clash with standard C function mblen(3).

PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/c32rtomb.c

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



CVS commit: src/lib/libc/locale

2024-08-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 20 17:43:24 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc32.c

Log Message:
mbrtoc32(3): Fix name and type of mbrtowc_l return value.

This was from `int mbtowc_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to mbrtowc_l.  Caught by
lint.

`mb_len' avoids (harmless) clash with standard C function mblen(3).

PR lib/58618: mbrtocN(3) fails to keep shift state


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/mbrtoc32.c

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

Modified files:

Index: src/lib/libc/locale/mbrtoc32.c
diff -u src/lib/libc/locale/mbrtoc32.c:1.8 src/lib/libc/locale/mbrtoc32.c:1.9
--- src/lib/libc/locale/mbrtoc32.c:1.8	Tue Aug 20 17:43:09 2024
+++ src/lib/libc/locale/mbrtoc32.c	Tue Aug 20 17:43:24 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbrtoc32.c,v 1.8 2024/08/20 17:43:09 riastradh Exp $	*/
+/*	$NetBSD: mbrtoc32.c,v 1.9 2024/08/20 17:43:24 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: mbrtoc32.c,v 1.8 2024/08/20 17:43:09 riastradh Exp $");
+__RCSID("$NetBSD: mbrtoc32.c,v 1.9 2024/08/20 17:43:24 riastradh Exp $");
 
 #include "namespace.h"
 
@@ -106,7 +106,7 @@ mbrtoc32_l(char32_t *restrict pc32, cons
 	wchar_t wc;
 	mbstate_t wcrtombstate = {0};
 	char mb[MB_LEN_MAX];
-	int mblen;
+	size_t mb_len;
 	char utf32le[MB_LEN_MAX];
 	const char *src;
 	char *dst;
@@ -191,7 +191,7 @@ mbrtoc32_l(char32_t *restrict pc32, cons
 	 * we can pass that through iconv to get a Unicode scalar
 	 * value.
 	 */
-	if ((mblen = wcrtomb_l(mb, wc, &wcrtombstate, loc)) == -1) {
+	if ((mb_len = wcrtomb_l(mb, wc, &wcrtombstate, loc)) == (size_t)-1) {
 		len = (size_t)-1;
 		goto out;
 	}
@@ -200,7 +200,7 @@ mbrtoc32_l(char32_t *restrict pc32, cons
 	 * Convert the multibyte sequence to UTF-16LE.
 	 */
 	src = mb;
-	srcleft = (size_t)mblen;
+	srcleft = mb_len;
 	dst = utf32le;
 	dstleft = sizeof(utf32le);
 	error = _citrus_iconv_convert(iconv, &src, &srcleft, &dst, &dstleft,



CVS commit: src/lib/libc/locale

2024-08-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 20 17:43:24 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc32.c

Log Message:
mbrtoc32(3): Fix name and type of mbrtowc_l return value.

This was from `int mbtowc_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to mbrtowc_l.  Caught by
lint.

`mb_len' avoids (harmless) clash with standard C function mblen(3).

PR lib/58618: mbrtocN(3) fails to keep shift state


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/mbrtoc32.c

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



CVS commit: src/lib/libc/locale

2024-08-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 20 17:14:05 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.3 c32rtomb.3 c8rtomb.3

Log Message:
c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example.

This way it avoids variable-length arrays, by always allocating the
maximum space that could be occupied by MB_CUR_MAX.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/c16rtomb.3 \
src/lib/libc/locale/c32rtomb.3
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/c8rtomb.3

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

Modified files:

Index: src/lib/libc/locale/c16rtomb.3
diff -u src/lib/libc/locale/c16rtomb.3:1.8 src/lib/libc/locale/c16rtomb.3:1.9
--- src/lib/libc/locale/c16rtomb.3:1.8	Sun Aug 18 02:19:35 2024
+++ src/lib/libc/locale/c16rtomb.3	Tue Aug 20 17:14:05 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c16rtomb.3,v 1.8 2024/08/18 02:19:35 riastradh Exp $
+.\"	$NetBSD: c16rtomb.3,v 1.9 2024/08/20 17:14:05 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -145,7 +145,7 @@ NUL-terminate it (with any shift sequenc
 state), and print it:
 .Bd -literal -offset indent
 char16_t c16[] = { 0xd83d, 0xdca9 };
-char buf[(__arraycount(c16) + 1)*MB_CUR_MAX], *s = buf;
+char buf[(__arraycount(c16) + 1)*MB_LEN_MAX], *s = buf;
 size_t i;
 mbstate_t mbs = {0};/* initial conversion state */
 
@@ -164,6 +164,11 @@ if (len == (size_t)-1)
 assert(len <= sizeof(buf) - (s - buf));
 printf("%s\en", buf);
 .Ed
+.Pp
+To avoid a variable-length array, this code uses
+.Dv MB_LEN_MAX ,
+which is a constant upper bound on the locale-dependent
+.Dv MB_CUR_MAX .
 .\"
 .Sh ERRORS
 .Bl -tag -width Bq
Index: src/lib/libc/locale/c32rtomb.3
diff -u src/lib/libc/locale/c32rtomb.3:1.8 src/lib/libc/locale/c32rtomb.3:1.9
--- src/lib/libc/locale/c32rtomb.3:1.8	Sun Aug 18 02:19:35 2024
+++ src/lib/libc/locale/c32rtomb.3	Tue Aug 20 17:14:05 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c32rtomb.3,v 1.8 2024/08/18 02:19:35 riastradh Exp $
+.\"	$NetBSD: c32rtomb.3,v 1.9 2024/08/20 17:14:05 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -128,7 +128,7 @@ NUL-terminate it (with any shift sequenc
 state), and print it:
 .Bd -literal -offset indent
 char32_t c32[] = { 0x1f4a9, 0x20ac, 0x21 };
-char buf[(__arraycount(c32) + 1)*MB_CUR_MAX], *s = buf;
+char buf[(__arraycount(c32) + 1)*MB_LEN_MAX], *s = buf;
 size_t i;
 mbstate_t mbs = {0};/* initial conversion state */
 
@@ -147,6 +147,10 @@ if (len == (size_t)-1)
 assert(len <= sizeof(buf) - (s - buf));
 printf("%s\en", buf);
 .Ed
+To avoid a variable-length array, this code uses
+.Dv MB_LEN_MAX ,
+which is a constant upper bound on the locale-dependent
+.Dv MB_CUR_MAX .
 .\"
 .Sh ERRORS
 .Bl -tag -width Bq

Index: src/lib/libc/locale/c8rtomb.3
diff -u src/lib/libc/locale/c8rtomb.3:1.6 src/lib/libc/locale/c8rtomb.3:1.7
--- src/lib/libc/locale/c8rtomb.3:1.6	Sun Aug 18 02:19:35 2024
+++ src/lib/libc/locale/c8rtomb.3	Tue Aug 20 17:14:05 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c8rtomb.3,v 1.6 2024/08/18 02:19:35 riastradh Exp $
+.\"	$NetBSD: c8rtomb.3,v 1.7 2024/08/20 17:14:05 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -145,7 +145,7 @@ NUL-terminate it (with any shift sequenc
 state), and print it:
 .Bd -literal -offset indent
 char8_t c8[] = { 0xf0, 0x9f, 0x92, 0xa9 };
-char buf[(__arraycount(c8) + 1)*MB_CUR_MAX], *s = buf;
+char buf[(__arraycount(c8) + 1)*MB_LEN_MAX], *s = buf;
 size_t i;
 mbstate_t mbs = {0};/* initial conversion state */
 
@@ -164,6 +164,11 @@ if (len == (size_t)-1)
 assert(len <= sizeof(buf) - (s - buf));
 printf("%s\en", buf);
 .Ed
+.Pp
+To avoid a variable-length array, this code uses
+.Dv MB_LEN_MAX ,
+which is a constant upper bound on the locale-dependent
+.Dv MB_CUR_MAX .
 .\"
 .Sh ERRORS
 .Bl -tag -width Bq



CVS commit: src/lib/libc/locale

2024-08-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 20 17:14:05 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.3 c32rtomb.3 c8rtomb.3

Log Message:
c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example.

This way it avoids variable-length arrays, by always allocating the
maximum space that could be occupied by MB_CUR_MAX.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/c16rtomb.3 \
src/lib/libc/locale/c32rtomb.3
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/c8rtomb.3

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



Re: CVS commit: src/lib/libc/locale

2024-08-19 Thread Taylor R Campbell
> Date: Sun, 18 Aug 2024 19:55:10 +0200
> From: Roland Illig 
> 
> Am 18.08.2024 um 15:39 schrieb Taylor R Campbell:
> > Please revert the casts and use `LINTFLAGS.mbrtoc8.c+= -X 132' instead
> > until it is fixed.
> 
> It is fixed.

Awesome, thanks!


CVS commit: src/lib/libc/locale

2024-08-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug 18 20:06:05 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc16.c mbrtoc32.c

Log Message:
mbrtoc16, mbrtoc32: fix comments, remove lint-specific workarounds

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/mbrtoc16.c \
src/lib/libc/locale/mbrtoc32.c

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

Modified files:

Index: src/lib/libc/locale/mbrtoc16.c
diff -u src/lib/libc/locale/mbrtoc16.c:1.6 src/lib/libc/locale/mbrtoc16.c:1.7
--- src/lib/libc/locale/mbrtoc16.c:1.6	Sat Aug 17 21:24:54 2024
+++ src/lib/libc/locale/mbrtoc16.c	Sun Aug 18 20:06:05 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbrtoc16.c,v 1.6 2024/08/17 21:24:54 riastradh Exp $	*/
+/*	$NetBSD: mbrtoc16.c,v 1.7 2024/08/18 20:06:05 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  * References:
  *
  *	The Unicode Standard, Version 15.0 -- Core Specification, The
- *	Unicode Consortium, Sec. 3.8 `Surrogates', p. 119.
+ *	Unicode Consortium, Sec. 3.8 `Surrogates', p. 118.
  *	https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
  *	https://web.archive.org/web/20240718101254/https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
  *
@@ -73,7 +73,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: mbrtoc16.c,v 1.6 2024/08/17 21:24:54 riastradh Exp $");
+__RCSID("$NetBSD: mbrtoc16.c,v 1.7 2024/08/18 20:06:05 rillig Exp $");
 
 #include "namespace.h"
 
@@ -196,10 +196,8 @@ mbrtoc16_l(char16_t *restrict pc16, cons
 		_DIAGASSERT(S->surrogate == 0);
 	} else {
 		c32 -= 0x1;
-		const char16_t w1 = (char16_t)(
-		0xd800 | __SHIFTOUT(c32, __BITS(19,10)));
-		const char16_t w2 = (char16_t)(
-		0xdc00 | __SHIFTOUT(c32, __BITS(9,0)));
+		const char16_t w1 = 0xd800 | __SHIFTOUT(c32, __BITS(19,10));
+		const char16_t w2 = 0xdc00 | __SHIFTOUT(c32, __BITS(9,0));
 		if (pc16)
 			*pc16 = w1;
 		S->surrogate = w2;
Index: src/lib/libc/locale/mbrtoc32.c
diff -u src/lib/libc/locale/mbrtoc32.c:1.6 src/lib/libc/locale/mbrtoc32.c:1.7
--- src/lib/libc/locale/mbrtoc32.c:1.6	Sat Aug 17 21:24:54 2024
+++ src/lib/libc/locale/mbrtoc32.c	Sun Aug 18 20:06:05 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbrtoc32.c,v 1.6 2024/08/17 21:24:54 riastradh Exp $	*/
+/*	$NetBSD: mbrtoc32.c,v 1.7 2024/08/18 20:06:05 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -46,13 +46,13 @@
  * References:
  *
  *	The Unicode Standard, Version 15.0 -- Core Specification, The
- *	Unicode Consortium, Sec. 3.8 `Surrogates', p. 119.
- *	https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf
- *	https://web.archive.org/web/20240718101254/https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf
+ *	Unicode Consortium, Sec. 3.8 `Surrogates', p. 118.
+ *	https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
+ *	https://web.archive.org/web/20240718101254/https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
  */
 
 #include 
-__RCSID("$NetBSD: mbrtoc32.c,v 1.6 2024/08/17 21:24:54 riastradh Exp $");
+__RCSID("$NetBSD: mbrtoc32.c,v 1.7 2024/08/18 20:06:05 rillig Exp $");
 
 #include "namespace.h"
 



CVS commit: src/lib/libc/locale

2024-08-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug 18 20:06:05 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc16.c mbrtoc32.c

Log Message:
mbrtoc16, mbrtoc32: fix comments, remove lint-specific workarounds

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/mbrtoc16.c \
src/lib/libc/locale/mbrtoc32.c

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



CVS commit: src/lib/libc/locale

2024-08-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug 18 19:46:53 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.c

Log Message:
mbrtoc8: fix comments


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/mbrtoc8.c

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

Modified files:

Index: src/lib/libc/locale/mbrtoc8.c
diff -u src/lib/libc/locale/mbrtoc8.c:1.6 src/lib/libc/locale/mbrtoc8.c:1.7
--- src/lib/libc/locale/mbrtoc8.c:1.6	Sun Aug 18 19:35:19 2024
+++ src/lib/libc/locale/mbrtoc8.c	Sun Aug 18 19:46:53 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbrtoc8.c,v 1.6 2024/08/18 19:35:19 rillig Exp $	*/
+/*	$NetBSD: mbrtoc8.c,v 1.7 2024/08/18 19:46:53 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  *	scalar value at c8.
  *
  *	If the UTF-8 representation of that scalar value is multiple
- *	bytes long, mbrtoc8 will yield leading byte in one call that
+ *	bytes long, mbrtoc8 will yield the leading byte in one call that
  *	consumes input, and will yield the trailing bytes in subsequent
  *	calls without consuming any input and returning (size_t)-3
  *	instead.
@@ -61,7 +61,7 @@
  *	https://web.archive.org/web/20240718101254/https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=144
  *
  *	The Unicode Standard, Version 15.0 -- Core Specification, The
- *	Unicode Consortium, Sec. 3.9 `Unicode Encoding Forms': UTF-16,
+ *	Unicode Consortium, Sec. 3.9 `Unicode Encoding Forms': UTF-8,
  *	p. 124.
  *	https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=150
  *	https://web.archive.org/web/20240718101254/https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf#page=150
@@ -72,7 +72,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: mbrtoc8.c,v 1.6 2024/08/18 19:35:19 rillig Exp $");
+__RCSID("$NetBSD: mbrtoc8.c,v 1.7 2024/08/18 19:46:53 rillig Exp $");
 
 #include "namespace.h"
 



CVS commit: src/lib/libc/locale

2024-08-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug 18 19:46:53 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.c

Log Message:
mbrtoc8: fix comments


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/mbrtoc8.c

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



CVS commit: src/lib/libc/locale

2024-08-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug 18 19:35:19 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.c

Log Message:
mbrtoc8: remove lint-specific workarounds

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/mbrtoc8.c

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

Modified files:

Index: src/lib/libc/locale/mbrtoc8.c
diff -u src/lib/libc/locale/mbrtoc8.c:1.5 src/lib/libc/locale/mbrtoc8.c:1.6
--- src/lib/libc/locale/mbrtoc8.c:1.5	Sun Aug 18 13:35:11 2024
+++ src/lib/libc/locale/mbrtoc8.c	Sun Aug 18 19:35:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbrtoc8.c,v 1.5 2024/08/18 13:35:11 riastradh Exp $	*/
+/*	$NetBSD: mbrtoc8.c,v 1.6 2024/08/18 19:35:19 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -72,7 +72,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: mbrtoc8.c,v 1.5 2024/08/18 13:35:11 riastradh Exp $");
+__RCSID("$NetBSD: mbrtoc8.c,v 1.6 2024/08/18 19:35:19 rillig Exp $");
 
 #include "namespace.h"
 
@@ -195,32 +195,23 @@ mbrtoc8_l(char8_t *restrict pc8, const c
 		break;
 	case 0x0080 ... 0x07ff:
 		if (pc8)
-			*pc8 = (char8_t)(
-			0xc0 | __SHIFTOUT(c32, __BITS(10,6)));
-		S->buf[2] = (char8_t)(
-		0x80 | __SHIFTOUT(c32, __BITS(5,0)));
+			*pc8 = 0xc0 | __SHIFTOUT(c32, __BITS(10,6));
+		S->buf[2] = 0x80 | __SHIFTOUT(c32, __BITS(5,0));
 		S->nleft = 1;
 		break;
 	case 0x0800 ... 0x:
 		if (pc8)
-			*pc8 = (char8_t)(
-			0xe0 | __SHIFTOUT(c32, __BITS(15,12)));
-		S->buf[1] = (char8_t)(
-		0x80 | __SHIFTOUT(c32, __BITS(11,6)));
-		S->buf[2] = (char8_t)(
-		0x80 | __SHIFTOUT(c32, __BITS(5,0)));
+			*pc8 = 0xe0 | __SHIFTOUT(c32, __BITS(15,12));
+		S->buf[1] = 0x80 | __SHIFTOUT(c32, __BITS(11,6));
+		S->buf[2] = 0x80 | __SHIFTOUT(c32, __BITS(5,0));
 		S->nleft = 2;
 		break;
 	case 0x1 ... 0x10:
 		if (pc8)
-			*pc8 = (char8_t)(
-			0xf0 | __SHIFTOUT(c32, __BITS(20,18)));
-		S->buf[0] = (char8_t)(
-		0x80 | __SHIFTOUT(c32, __BITS(17,12)));
-		S->buf[1] = (char8_t)(
-		0x80 | __SHIFTOUT(c32, __BITS(11,6)));
-		S->buf[2] = (char8_t)(
-		0x80 | __SHIFTOUT(c32, __BITS(5,0)));
+			*pc8 = 0xf0 | __SHIFTOUT(c32, __BITS(20,18));
+		S->buf[0] = 0x80 | __SHIFTOUT(c32, __BITS(17,12));
+		S->buf[1] = 0x80 | __SHIFTOUT(c32, __BITS(11,6));
+		S->buf[2] = 0x80 | __SHIFTOUT(c32, __BITS(5,0));
 		S->nleft = 3;
 		break;
 	default:



CVS commit: src/lib/libc/locale

2024-08-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug 18 19:35:19 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.c

Log Message:
mbrtoc8: remove lint-specific workarounds

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/mbrtoc8.c

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



CVS commit: src/lib/libc/stdlib

2024-08-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Aug 18 18:47:20 UTC 2024

Modified Files:
src/lib/libc/stdlib: aligned_alloc.c

Log Message:
aligned_alloc(3): Nix trailing whitespace.  Add RCS id.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/aligned_alloc.c

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

Modified files:

Index: src/lib/libc/stdlib/aligned_alloc.c
diff -u src/lib/libc/stdlib/aligned_alloc.c:1.2 src/lib/libc/stdlib/aligned_alloc.c:1.3
--- src/lib/libc/stdlib/aligned_alloc.c:1.2	Fri Jul 27 13:08:47 2018
+++ src/lib/libc/stdlib/aligned_alloc.c	Sun Aug 18 18:47:20 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: aligned_alloc.c,v 1.2 2018/07/27 13:08:47 maya Exp $ */
+/* $NetBSD: aligned_alloc.c,v 1.3 2024/08/18 18:47:20 riastradh Exp $ */
 
 /*-
  * Copyright (C) 2015 The NetBSD Foundation, Inc.
@@ -32,6 +32,9 @@
  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include 
+__RCSID("$NetBSD: aligned_alloc.c,v 1.3 2024/08/18 18:47:20 riastradh Exp $");
+
 #include 
 #include 
 
@@ -40,7 +43,7 @@ aligned_alloc(size_t alignment, size_t s
 {
 void *memptr;
 int err;
-	
+
 /*
  * Check that alignment is a power of 2.
  */
@@ -48,7 +51,7 @@ aligned_alloc(size_t alignment, size_t s
 errno = EINVAL;
 return NULL;
 }
-	
+
 /*
  * Adjust alignment to satisfy posix_memalign,
  * larger alignments satisfy smaller alignments.
@@ -56,13 +59,12 @@ aligned_alloc(size_t alignment, size_t s
 while (alignment < sizeof(void *)) {
 alignment <<= 1;
 }
-	
+
 err = posix_memalign(&memptr, alignment, size);
-	
 if (err) {
 errno = err;
 return NULL;
 }
-	
+
 return memptr;
 }



CVS commit: src/lib/libc/stdlib

2024-08-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Aug 18 18:47:20 UTC 2024

Modified Files:
src/lib/libc/stdlib: aligned_alloc.c

Log Message:
aligned_alloc(3): Nix trailing whitespace.  Add RCS id.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/aligned_alloc.c

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



Re: CVS commit: src/lib/libc/locale

2024-08-18 Thread Roland Illig
Am 18.08.2024 um 15:39 schrieb Taylor R Campbell:
>> Date: Sat, 17 Aug 2024 17:55:28 -0400
>> From: Christos Zoulas 
>>
>> There is only one bug. I have sent mail to Roland about it and will revert 
>> once it is fixed.
>>
>> The rest are:
>> - cast through (void *)
>> - add casts because __BITS returns uintmax_t which is wider than the 
>> destination types.
>
> To track this bug, I filed PR toolchain/58617: lint spuriously warns
> about impossible __SHIFTOUT/__BITS truncation
> (https://gnats.NetBSD.org/58617).
>
> Please revert the casts and use `LINTFLAGS.mbrtoc8.c+= -X 132' instead
> until it is fixed.

It is fixed.


CVS commit: src/lib/libintl

2024-08-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Aug 18 17:46:24 UTC 2024

Modified Files:
src/lib/libintl: gettext.c

Log Message:
Avoid undefined behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libintl/gettext.c

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

Modified files:

Index: src/lib/libintl/gettext.c
diff -u src/lib/libintl/gettext.c:1.32 src/lib/libintl/gettext.c:1.33
--- src/lib/libintl/gettext.c:1.32	Fri Apr 12 22:01:38 2024
+++ src/lib/libintl/gettext.c	Sun Aug 18 13:46:24 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: gettext.c,v 1.32 2024/04/13 02:01:38 christos Exp $	*/
+/*	$NetBSD: gettext.c,v 1.33 2024/08/18 17:46:24 christos Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2001 Citrus Project,
@@ -29,7 +29,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: gettext.c,v 1.32 2024/04/13 02:01:38 christos Exp $");
+__RCSID("$NetBSD: gettext.c,v 1.33 2024/08/18 17:46:24 christos Exp $");
 
 #include 
 #include 
@@ -174,11 +174,13 @@ pgettext_impl(const char *domainname, co
 
 	translation = dcngettext(domainname, msgctxt_id,
 		msgid2, n, category);
-	free(msgctxt_id);
 
-	if (translation == msgctxt_id)
+	if (translation == msgctxt_id) {
+		free(msgctxt_id);
 		return msgid1;
+	}
 
+	free(msgctxt_id);
 	p = strchr(translation, '\004');
 	if (p)
 		return p + 1;



CVS commit: src/lib/libintl

2024-08-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Aug 18 17:46:24 UTC 2024

Modified Files:
src/lib/libintl: gettext.c

Log Message:
Avoid undefined behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libintl/gettext.c

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



Re: CVS commit: src/lib/libc/locale

2024-08-18 Thread Taylor R Campbell
> Date: Sat, 17 Aug 2024 17:55:28 -0400
> From: Christos Zoulas 
> 
> There is only one bug. I have sent mail to Roland about it and will revert 
> once it is fixed.
> 
> The rest are:
> - cast through (void *) 
> - add casts because __BITS returns uintmax_t which is wider than the 
> destination types.

To track this bug, I filed PR toolchain/58617: lint spuriously warns
about impossible __SHIFTOUT/__BITS truncation
(https://gnats.NetBSD.org/58617).

Please revert the casts and use `LINTFLAGS.mbrtoc8.c+= -X 132' instead
until it is fixed.


CVS commit: src/lib/libc/locale

2024-08-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Aug 18 13:35:11 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.c

Log Message:
mbrtoc8(3): Fix pasto in comment at top.

No functional change intended.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/mbrtoc8.c

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

Modified files:

Index: src/lib/libc/locale/mbrtoc8.c
diff -u src/lib/libc/locale/mbrtoc8.c:1.4 src/lib/libc/locale/mbrtoc8.c:1.5
--- src/lib/libc/locale/mbrtoc8.c:1.4	Sat Aug 17 21:24:54 2024
+++ src/lib/libc/locale/mbrtoc8.c	Sun Aug 18 13:35:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbrtoc8.c,v 1.4 2024/08/17 21:24:54 riastradh Exp $	*/
+/*	$NetBSD: mbrtoc8.c,v 1.5 2024/08/18 13:35:11 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 /*
- * mbrtoc16(&c16, s, n, ps)
+ * mbrtoc8(&c8, s, n, ps)
  *
  *	Decode a Unicode scalar value from up to n bytes out of the
  *	multibyte string s, using multibyte encoding state ps, and
@@ -72,7 +72,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: mbrtoc8.c,v 1.4 2024/08/17 21:24:54 riastradh Exp $");
+__RCSID("$NetBSD: mbrtoc8.c,v 1.5 2024/08/18 13:35:11 riastradh Exp $");
 
 #include "namespace.h"
 



CVS commit: src/lib/libc/locale

2024-08-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Aug 18 13:35:11 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.c

Log Message:
mbrtoc8(3): Fix pasto in comment at top.

No functional change intended.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/mbrtoc8.c

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



CVS commit: src/lib/libc/locale

2024-08-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Aug 18 12:41:38 UTC 2024

Modified Files:
src/lib/libc/locale: c8rtomb.c

Log Message:
c8rtomb(3): Nix __CTASSERT after case label.

I put this in to make it (machine-verifiably) clear that zeroing the
state is the same as returning to the initial conversion state, as
the standard requires, but this is causing build trouble (and will
likely cause more trouble if pulled up) because some definitions of
__CTASSERT make a declaration which is forbidden after a label, so
let's remove it.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/c8rtomb.c

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

Modified files:

Index: src/lib/libc/locale/c8rtomb.c
diff -u src/lib/libc/locale/c8rtomb.c:1.5 src/lib/libc/locale/c8rtomb.c:1.6
--- src/lib/libc/locale/c8rtomb.c:1.5	Sun Aug 18 02:19:35 2024
+++ src/lib/libc/locale/c8rtomb.c	Sun Aug 18 12:41:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c8rtomb.c,v 1.5 2024/08/18 02:19:35 riastradh Exp $	*/
+/*	$NetBSD: c8rtomb.c,v 1.6 2024/08/18 12:41:38 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: c8rtomb.c,v 1.5 2024/08/18 02:19:35 riastradh Exp $");
+__RCSID("$NetBSD: c8rtomb.c,v 1.6 2024/08/18 12:41:38 riastradh Exp $");
 
 #include "namespace.h"
 
@@ -222,10 +222,6 @@ c8rtomb_l(char *restrict s, char8_t c8, 
 		 * We have a scalar value.  Clear the state and output
 		 * the scalar value.
 		 */
-#ifndef __lint__
-		// XXX: lint does not grok struct decl after case label!
-		__CTASSERT(UTF8_ACCEPT == 0);
-#endif
 		S->state_c32 = 0;
 		return c32rtomb_l(s, c32, &S->mbs, loc);
 	}



CVS commit: src/lib/libc/locale

2024-08-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Aug 18 12:41:38 UTC 2024

Modified Files:
src/lib/libc/locale: c8rtomb.c

Log Message:
c8rtomb(3): Nix __CTASSERT after case label.

I put this in to make it (machine-verifiably) clear that zeroing the
state is the same as returning to the initial conversion state, as
the standard requires, but this is causing build trouble (and will
likely cause more trouble if pulled up) because some definitions of
__CTASSERT make a declaration which is forbidden after a label, so
let's remove it.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/c8rtomb.c

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



Re: CVS commit: src/lib/libc/locale

2024-08-17 Thread Rin Okuyama

Hi,

For __CTASSERT v.s. case label:

https://nxr.netbsd.org/xref/src/lib/libc/locale/c8rtomb.c#225

not only lint(1), but also GCC 10.5 does not accept this, which
results in build failures for platforms still using gcc.old:

https://releng.netbsd.org/builds/HEAD/202408171750Z/

Can we just drop this __CTASSERT, as the same condition is
already asserted several lines above?:

https://nxr.netbsd.org/xref/src/lib/libc/locale/c8rtomb.c#195

Thanks,
rin


Re: CVS commit: src/lib/libc/locale

2024-08-17 Thread Taylor R Campbell
> Date: Sat, 17 Aug 2024 17:55:28 -0400
> From: Christos Zoulas 
> 
> There is only one bug. I have sent mail to Roland about it and will revert 
> once it is fixed.
> 
> The rest are:
> - cast through (void *) 

There is no need to cast through (void *) -- not in C, not in KNF, and
not for any other reason I know of.  It's not a big deal to leave in,
but it's also unnecessary clutter and I would rather remove it.

> - add casts because __BITS returns uintmax_t which is wider than the 
> destination types.

I'm sympathetic to the proposition that implicit integer conversions
can conceal scary bugs in C.  But in this case, the output is
trivially guaranteed to lie within the desired range, so it is obvious
that the integer conversion never loses anything even though the
intermediate types are larger -- that's a big part of the point of the
convenience and legibility of __BITS and __SHIFTIN/__SHIFTOUT.

If lint complains because it can't figure this out, that's a lint bug.
And the casts make the code much harder to read.  Please revert this
and let's make lint serve our needs, not make us serve lint's needs.

if (pc8)
*pc8 = 0xf0 | __SHIFTOUT(c32, __BITS(20,18));
S->buf[0] = 0x80 | __SHIFTOUT(c32, __BITS(17,12));
S->buf[1] = 0x80 | __SHIFTOUT(c32, __BITS(11,6));
S->buf[2] = 0x80 | __SHIFTOUT(c32, __BITS(5,0));

versus

if (pc8)
*pc8 = (char8_t)(
0xf0 | __SHIFTOUT(c32, __BITS(20,18)));
S->buf[0] = (char8_t)(
0x80 | __SHIFTOUT(c32, __BITS(17,12)));
S->buf[1] = (char8_t)(
0x80 | __SHIFTOUT(c32, __BITS(11,6)));
S->buf[2] = (char8_t)(
0x80 | __SHIFTOUT(c32, __BITS(5,0)));


Re: CVS commit: src/lib/libc/locale

2024-08-17 Thread Christos Zoulas
There is only one bug. I have sent mail to Roland about it and will revert once 
it is fixed.

The rest are:
- cast through (void *) 
- add casts because __BITS returns uintmax_t which is wider than the 
destination types.

christos

> On Aug 17, 2024, at 5:29 PM, Taylor R Campbell  wrote:
> 
>> Module Name:src
>> Committed By:   christos
>> Date:   Sat Aug 17 20:08:13 UTC 2024
>> 
>> Modified Files:
>>src/lib/libc/locale: c16rtomb.c c8rtomb.c mbrtoc16.c mbrtoc32.c
>>mbrtoc8.c
>> 
>> Log Message:
>> pass lint, XXX see lint bug.
> 
> Can you please arrange to fix the lint bugs, and revert this clutter?



Re: CVS commit: src/lib/libc/locale

2024-08-17 Thread Taylor R Campbell
> Module Name:src
> Committed By:   christos
> Date:   Sat Aug 17 20:08:13 UTC 2024
> 
> Modified Files:
> src/lib/libc/locale: c16rtomb.c c8rtomb.c mbrtoc16.c mbrtoc32.c
> mbrtoc8.c
> 
> Log Message:
> pass lint, XXX see lint bug.

Can you please arrange to fix the lint bugs, and revert this clutter?


CVS commit: src/lib/libc/locale

2024-08-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 17 20:08:13 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.c c8rtomb.c mbrtoc16.c mbrtoc32.c
mbrtoc8.c

Log Message:
pass lint, XXX see lint bug.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/c16rtomb.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/locale/c8rtomb.c \
src/lib/libc/locale/mbrtoc8.c
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/mbrtoc16.c \
src/lib/libc/locale/mbrtoc32.c

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

Modified files:

Index: src/lib/libc/locale/c16rtomb.c
diff -u src/lib/libc/locale/c16rtomb.c:1.3 src/lib/libc/locale/c16rtomb.c:1.4
--- src/lib/libc/locale/c16rtomb.c:1.3	Thu Aug 15 18:22:35 2024
+++ src/lib/libc/locale/c16rtomb.c	Sat Aug 17 16:08:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c16rtomb.c,v 1.3 2024/08/15 22:22:35 riastradh Exp $	*/
+/*	$NetBSD: c16rtomb.c,v 1.4 2024/08/17 20:08:13 christos Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: c16rtomb.c,v 1.3 2024/08/15 22:22:35 riastradh Exp $");
+__RCSID("$NetBSD: c16rtomb.c,v 1.4 2024/08/17 20:08:13 christos Exp $");
 
 #include "namespace.h"
 
@@ -124,7 +124,7 @@ c16rtomb(char *restrict s, char16_t c16,
 	/*
 	 * Open the private UTF-16 decoding state.
 	 */
-	S = (struct c16rtombstate *)ps;
+	S = (struct c16rtombstate *)(void *)ps;
 
 #if 0
 	/*
@@ -163,8 +163,9 @@ c16rtomb(char *restrict s, char16_t c16,
 		}
 		const char16_t w1 = S->surrogate;
 		const char16_t w2 = c16;
-		c32 = __SHIFTIN(__SHIFTOUT(w1, __BITS(9,0)), __BITS(19,10)) |
-		__SHIFTIN(__SHIFTOUT(w2, __BITS(9,0)), __BITS(9,0));
+		c32 = (char32_t)(
+		__SHIFTIN(__SHIFTOUT(w1, __BITS(9,0)), __BITS(19,10)) |
+		__SHIFTIN(__SHIFTOUT(w2, __BITS(9,0)), __BITS(9,0)));
 		c32 += 0x1;
 		S->surrogate = 0;
 	} else if (c16 >= 0xd800 && c16 <= 0xdbff) { /* 2. high surrogate */

Index: src/lib/libc/locale/c8rtomb.c
diff -u src/lib/libc/locale/c8rtomb.c:1.2 src/lib/libc/locale/c8rtomb.c:1.3
--- src/lib/libc/locale/c8rtomb.c:1.2	Thu Aug 15 18:23:17 2024
+++ src/lib/libc/locale/c8rtomb.c	Sat Aug 17 16:08:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c8rtomb.c,v 1.2 2024/08/15 22:23:17 riastradh Exp $	*/
+/*	$NetBSD: c8rtomb.c,v 1.3 2024/08/17 20:08:13 christos Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: c8rtomb.c,v 1.2 2024/08/15 22:23:17 riastradh Exp $");
+__RCSID("$NetBSD: c8rtomb.c,v 1.3 2024/08/17 20:08:13 christos Exp $");
 
 #include "namespace.h"
 
@@ -158,7 +158,7 @@ c8rtomb(char *restrict s, char8_t c8, mb
 	/*
 	 * Open the private UTF-8 decoding state.
 	 */
-	S = (struct c8rtombstate *)ps;
+	S = (struct c8rtombstate *)(void *)ps;
 
 #if 0
 	/*
@@ -181,8 +181,8 @@ c8rtomb(char *restrict s, char8_t c8, mb
 	 * Get the current state and buffer.
 	 */
 	__CTASSERT(UTF8_ACCEPT == 0); /* initial conversion state */
-	state = __SHIFTOUT(S->state_c32, __BITS(31,24));
-	c32 = __SHIFTOUT(S->state_c32, __BITS(23,0));
+	state = (utf8_state_t)__SHIFTOUT(S->state_c32, __BITS(31,24));
+	c32 = (char32_t)__SHIFTOUT(S->state_c32, __BITS(23,0));
 
 	/*
 	 * Feed the byte into the state machine to update the state.
@@ -200,15 +200,19 @@ c8rtomb(char *restrict s, char8_t c8, mb
 		 * Valid UTF-8 so far but incomplete.  Update state and
 		 * output nothing.
 		 */
-		S->state_c32 = __SHIFTIN(state, __BITS(31,24)) |
-		__SHIFTIN(c32, __BITS(23,0));
+		S->state_c32 = (char32_t)(
+		__SHIFTIN(state, __BITS(31,24)) |
+		__SHIFTIN(c32, __BITS(23,0)));
 		return 0;
 	case UTF8_ACCEPT:
 		/*
 		 * We have a scalar value.  Clear the state and output
 		 * the scalar value.
 		 */
+#ifndef __lint__
+		// XXX: lint does not grok struct decl after case label!
 		__CTASSERT(UTF8_ACCEPT == 0);
+#endif
 		S->state_c32 = 0;
 		return c32rtomb(s, c32, &S->mbs);
 	}
Index: src/lib/libc/locale/mbrtoc8.c
diff -u src/lib/libc/locale/mbrtoc8.c:1.2 src/lib/libc/locale/mbrtoc8.c:1.3
--- src/lib/libc/locale/mbrtoc8.c:1.2	Thu Aug 15 18:23:17 2024
+++ src/lib/libc/locale/mbrtoc8.c	Sat Aug 17 16:08:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbrtoc8.c,v 1.2 2024/08/15 22:23:17 riastradh Exp $	*/
+/*	$NetBSD: mbrtoc8.c,v 1.3 2024/08/17 20:08:13 christos Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -72,7 +72,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: mbrtoc8.c,v 1.2 2024/08/15 22:23:17 riastradh Exp $");
+__RCSID("$NetBSD: mbrtoc8.c,v 1.3 2024/08/17 20:08:13 christos Exp $");
 
 #include "namespace.h"
 
@@ -133,7 +133,7 @@ mbrtoc8(char8_t *restrict pc8, const cha
 	/*
 	 * Get the private conversion state.
 	 */
-	S = (struct mbrtoc8state *)ps;
+	S = (struct mbrtoc8state *)(void *)ps;
 
 	/*
 	 * If there are pending trailing bytes, yield them and return
@@ -181,23 +181,32 @@ mbrtoc8(char8_t *restrict pc8, const cha
 		break;
 	

CVS commit: src/lib/libc/locale

2024-08-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 17 20:08:13 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.c c8rtomb.c mbrtoc16.c mbrtoc32.c
mbrtoc8.c

Log Message:
pass lint, XXX see lint bug.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/c16rtomb.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/locale/c8rtomb.c \
src/lib/libc/locale/mbrtoc8.c
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/mbrtoc16.c \
src/lib/libc/locale/mbrtoc32.c

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



CVS commit: src/lib/libc/locale

2024-08-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 17 12:37:29 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.3

Log Message:
mbrtoc8(3): Clarify how many bytes are consumed in special cases.

Fix overlap in RETURN VALUES section.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/mbrtoc8.3

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

Modified files:

Index: src/lib/libc/locale/mbrtoc8.3
diff -u src/lib/libc/locale/mbrtoc8.3:1.5 src/lib/libc/locale/mbrtoc8.3:1.6
--- src/lib/libc/locale/mbrtoc8.3:1.5	Fri Aug 16 23:25:18 2024
+++ src/lib/libc/locale/mbrtoc8.3	Sat Aug 17 12:37:29 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc8.3,v 1.5 2024/08/16 23:25:18 riastradh Exp $
+.\"	$NetBSD: mbrtoc8.3,v 1.6 2024/08/17 12:37:29 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -100,6 +100,9 @@ saves its state in
 .Fa ps
 after all the input so far and returns
 .Li "(size_t)-2".
+.Sy All
+.Fa n
+bytes of input are consumed in this case.
 .It
 If
 .Nm
@@ -109,6 +112,8 @@ unit at
 .Li * Ns Fa pc8
 and returns
 .Li "(size_t)-3" .
+.Sy \&No
+input is consumed in this case.
 .It
 If
 .Nm
@@ -193,7 +198,7 @@ decoded a null multibyte character.
 .It Ar i
 .Bq code unit
 where
-.Li 0
+.Li 1
 \*(Le
 .Ar i
 \*(Le



CVS commit: src/lib/libc/locale

2024-08-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 17 12:37:29 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.3

Log Message:
mbrtoc8(3): Clarify how many bytes are consumed in special cases.

Fix overlap in RETURN VALUES section.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/mbrtoc8.3

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



CVS commit: src/lib/libc/locale

2024-08-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 17 12:37:05 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc16.3

Log Message:
mbrtoc16(3): Clarify how many bytes are consumed in special cases.

Fix overlap in RETURN VALUES section.

PR lib/52374:  missing


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/mbrtoc16.3

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

Modified files:

Index: src/lib/libc/locale/mbrtoc16.3
diff -u src/lib/libc/locale/mbrtoc16.3:1.8 src/lib/libc/locale/mbrtoc16.3:1.9
--- src/lib/libc/locale/mbrtoc16.3:1.8	Sat Aug 17 01:52:51 2024
+++ src/lib/libc/locale/mbrtoc16.3	Sat Aug 17 12:37:05 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc16.3,v 1.8 2024/08/17 01:52:51 riastradh Exp $
+.\"	$NetBSD: mbrtoc16.3,v 1.9 2024/08/17 12:37:05 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -100,6 +100,9 @@ saves its state in
 .Fa ps
 after all the input so far and returns
 .Li "(size_t)-2".
+.Sy All
+.Fa n
+bytes of input are consumed in this case.
 .It
 If
 .Nm
@@ -109,6 +112,8 @@ code unit at
 .Li * Ns Fa pc16
 and returns
 .Li "(size_t)-3" .
+.Sy \&No
+bytes of input are consumed in this case.
 .It
 If
 .Nm
@@ -194,7 +199,7 @@ decoded a null multibyte character.
 .It Ar i
 .Bq code unit
 where
-.Li 0
+.Li 1
 \*(Le
 .Ar i
 \*(Le



CVS commit: src/lib/libc/locale

2024-08-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 17 12:37:05 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc16.3

Log Message:
mbrtoc16(3): Clarify how many bytes are consumed in special cases.

Fix overlap in RETURN VALUES section.

PR lib/52374:  missing


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/mbrtoc16.3

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



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 17 01:52:51 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.3 c32rtomb.3 mbrtoc16.3 mbrtoc32.3

Log Message:
c16rtomb(3), c32rtomb(3), mbrtoc16(3), mbrtoc32(3): xref c8 versions.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/c16rtomb.3 \
src/lib/libc/locale/c32rtomb.3
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/locale/mbrtoc16.3 \
src/lib/libc/locale/mbrtoc32.3

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

Modified files:

Index: src/lib/libc/locale/c16rtomb.3
diff -u src/lib/libc/locale/c16rtomb.3:1.6 src/lib/libc/locale/c16rtomb.3:1.7
--- src/lib/libc/locale/c16rtomb.3:1.6	Sat Aug 17 00:29:21 2024
+++ src/lib/libc/locale/c16rtomb.3	Sat Aug 17 01:52:51 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c16rtomb.3,v 1.6 2024/08/17 00:29:21 riastradh Exp $
+.\"	$NetBSD: c16rtomb.3,v 1.7 2024/08/17 01:52:51 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -163,8 +163,10 @@ An error occurred in loading the locale'
 .\"
 .Sh SEE ALSO
 .Xr c32rtomb 3 ,
+.Xr c8rtomb 3 ,
 .Xr mbrtoc16 3 ,
 .Xr mbrtoc32 3 ,
+.Xr mbrtoc8 3 ,
 .Xr uchar 3
 .Rs
 .%B The Unicode Standard
Index: src/lib/libc/locale/c32rtomb.3
diff -u src/lib/libc/locale/c32rtomb.3:1.6 src/lib/libc/locale/c32rtomb.3:1.7
--- src/lib/libc/locale/c32rtomb.3:1.6	Sat Aug 17 00:29:21 2024
+++ src/lib/libc/locale/c32rtomb.3	Sat Aug 17 01:52:51 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c32rtomb.3,v 1.6 2024/08/17 00:29:21 riastradh Exp $
+.\"	$NetBSD: c32rtomb.3,v 1.7 2024/08/17 01:52:51 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -151,8 +151,10 @@ An error occurred in loading the locale'
 .\"
 .Sh SEE ALSO
 .Xr c16rtomb 3 ,
+.Xr c8rtomb 3 ,
 .Xr mbrtoc16 3 ,
 .Xr mbrtoc32 3 ,
+.Xr mbrtoc8 3 ,
 .Xr uchar 3
 .Rs
 .%B The Unicode Standard

Index: src/lib/libc/locale/mbrtoc16.3
diff -u src/lib/libc/locale/mbrtoc16.3:1.7 src/lib/libc/locale/mbrtoc16.3:1.8
--- src/lib/libc/locale/mbrtoc16.3:1.7	Fri Aug 16 23:25:00 2024
+++ src/lib/libc/locale/mbrtoc16.3	Sat Aug 17 01:52:51 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc16.3,v 1.7 2024/08/16 23:25:00 riastradh Exp $
+.\"	$NetBSD: mbrtoc16.3,v 1.8 2024/08/17 01:52:51 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -273,7 +273,9 @@ An error occurred in loading the locale'
 .Sh SEE ALSO
 .Xr c16rtomb 3 ,
 .Xr c32rtomb 3 ,
+.Xr c8rtomb 3 ,
 .Xr mbrtoc32 3 ,
+.Xr mbrtoc8 3 ,
 .Xr uchar 3
 .Rs
 .%B The Unicode Standard
Index: src/lib/libc/locale/mbrtoc32.3
diff -u src/lib/libc/locale/mbrtoc32.3:1.7 src/lib/libc/locale/mbrtoc32.3:1.8
--- src/lib/libc/locale/mbrtoc32.3:1.7	Fri Aug 16 23:25:00 2024
+++ src/lib/libc/locale/mbrtoc32.3	Sat Aug 17 01:52:51 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc32.3,v 1.7 2024/08/16 23:25:00 riastradh Exp $
+.\"	$NetBSD: mbrtoc32.3,v 1.8 2024/08/17 01:52:51 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -246,7 +246,9 @@ An error occurred in loading the locale'
 .Sh SEE ALSO
 .Xr c16rtomb 3 ,
 .Xr c32rtomb 3 ,
+.Xr c8rtomb 3 ,
 .Xr mbrtoc16 3 ,
+.Xr mbrtoc8 3 ,
 .Xr uchar 3
 .Rs
 .%B The Unicode Standard



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 17 01:52:51 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.3 c32rtomb.3 mbrtoc16.3 mbrtoc32.3

Log Message:
c16rtomb(3), c32rtomb(3), mbrtoc16(3), mbrtoc32(3): xref c8 versions.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/c16rtomb.3 \
src/lib/libc/locale/c32rtomb.3
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/locale/mbrtoc16.3 \
src/lib/libc/locale/mbrtoc32.3

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



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 17 00:32:19 UTC 2024

Modified Files:
src/lib/libc/locale: c8rtomb.3

Log Message:
c8rtomb(3): Clarify prose and fix example in caveat.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/c8rtomb.3

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



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 17 00:32:19 UTC 2024

Modified Files:
src/lib/libc/locale: c8rtomb.3

Log Message:
c8rtomb(3): Clarify prose and fix example in caveat.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/c8rtomb.3

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

Modified files:

Index: src/lib/libc/locale/c8rtomb.3
diff -u src/lib/libc/locale/c8rtomb.3:1.4 src/lib/libc/locale/c8rtomb.3:1.5
--- src/lib/libc/locale/c8rtomb.3:1.4	Fri Aug 16 23:34:25 2024
+++ src/lib/libc/locale/c8rtomb.3	Sat Aug 17 00:32:19 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c8rtomb.3,v 1.4 2024/08/16 23:34:25 riastradh Exp $
+.\"	$NetBSD: c8rtomb.3,v 1.5 2024/08/17 00:32:19 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -30,7 +30,7 @@
 .\"
 .Sh NAME
 .Nm c8rtomb
-.Nd Restartable UTF-8 code unit to multibyte conversion
+.Nd Restartable UTF-8 to multibyte conversion
 .\"
 .Sh LIBRARY
 .Lb libc
@@ -49,37 +49,52 @@
 .Sh DESCRIPTION
 The
 .Nm
-function attempts to encode Unicode input as a multibyte character
-sequence output at
-.Fa s
-in the current locale, writing anywhere between zero and
-.Dv MB_CUR_MAX
-bytes, inclusive, to
-.Fa s ,
-depending on the inputs and conversion state
-.Fa ps .
+function decodes UTF-8 and converts it to multibyte characters in the
+current locale, keeping state so it can restart after incremental
+progress.
 .Pp
-The input
-.Fa c8
-is a UTF-8 code unit.
-Successive calls to
+Each call to
 .Nm
-must provide well-formed UTF-8 code unit sequences.
-If
+updates the conversion state
+.Fa ps
+with a UTF-8 code unit
 .Fa c8 ,
-when appended to the sequence of code units passed in previous calls
+writes up to
+.Dv MB_CUR_MAX
+bytes to
+.Fa s
+(possibly none), and returns either the number of bytes written to
+.Fa s
+or
+.Li (size_t)-1
+to denote error.
+.Pp
+Over successive calls to
+.Nm
 with the same state
 .Fa ps ,
+the sequence of
+.Fa c8
+values must be a well-formed UTF-8 code unit sequence.
+If
+.Fa c8 ,
+when appended to the sequence of code units passed in previous calls,
 does not form a well-formed UTF-8 code unit sequence, then
 .Nm
-will return
+returns
 .Li (size_t)-1
-to denote failure with
+with
 .Xr errno 2
 set to
 .Er EILSEQ .
 .Pp
 If
+.Fa s
+is a null pointer, no output is stored, but the effects on
+.Fa ps
+and the return value are unchanged.
+.Pp
+If
 .Fa ps
 is a null pointer,
 .Nm
@@ -191,14 +206,14 @@ followed by a NUL:
 c8rtomb(s, 0xf0, ps);
 c8rtomb(s, 0x9f, ps);
 c8rtomb(s, 0x92, ps);
-c8rtomb(s, L'\e0', ps);
+c8rtomb(s, '\e0', ps);
 .Ed
 .Pp
 Currently this fails with
 .Er EILSEQ
 which matches other implementations, but this is at odds with language
 in the standard which suggests that passing
-.Li L'\e0'
+.Li '\e0'
 should unconditionally store a null byte and reset
 .Fa ps
 to the initial conversion state:



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 17 00:29:21 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.3 c32rtomb.3

Log Message:
c16rtomb(3), c32rtomb(3): Attempt a deturgidification pass.

Limit the jargon around surrogates.

PR lib/52374:  missing


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/c16rtomb.3 \
src/lib/libc/locale/c32rtomb.3

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

Modified files:

Index: src/lib/libc/locale/c16rtomb.3
diff -u src/lib/libc/locale/c16rtomb.3:1.5 src/lib/libc/locale/c16rtomb.3:1.6
--- src/lib/libc/locale/c16rtomb.3:1.5	Fri Aug 16 19:39:51 2024
+++ src/lib/libc/locale/c16rtomb.3	Sat Aug 17 00:29:21 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c16rtomb.3,v 1.5 2024/08/16 19:39:51 riastradh Exp $
+.\"	$NetBSD: c16rtomb.3,v 1.6 2024/08/17 00:29:21 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -30,7 +30,7 @@
 .\"
 .Sh NAME
 .Nm c16rtomb
-.Nd Restartable UTF-16 code unit to multibyte conversion
+.Nd Restartable UTF-16 to multibyte conversion
 .\"
 .Sh LIBRARY
 .Lb libc
@@ -49,49 +49,52 @@
 .Sh DESCRIPTION
 The
 .Nm
-function attempts to encode Unicode input as a multibyte character
-sequence output at
-.Fa s
-in the current locale, writing anywhere between zero and
-.Dv MB_CUR_MAX
-bytes, inclusive, to
-.Fa s ,
-depending on the inputs and conversion state
-.Fa ps .
-.Pp
-The input
-.Fa c16
-is a UTF-16 code unit, which can be either:
-.Bl -bullet
-.It
-a Unicode scalar value in the Basic Multilingual Plane (BMP), that is,
-a 16-bit code unit outside the interval [0xd800,0xdfff]; or,
-.It
-over the course of two consecutive calls to
-.Nm ,
-the high and low surrogate code points of a Unicode scalar value
-outside the BMP.
-.El
+function decodes UTF-16 and converts it to multibyte characters in the
+current locale, keeping state so it can restart after incremental
+progress.
 .Pp
-If a low surrogate code point, that is, a value of
-.Fa c16
-in [0xdc00,0xdfff], is passed to
+Each call to
 .Nm
-without the preceding call to it with the same
+updates the conversion state
 .Fa ps
-having been passed a high surrogate code point, that is, a value of
+with a UTF-16 code unit
+.Fa c16 ,
+writes up to
+.Dv MB_CUR_MAX
+bytes to
+.Fa s
+(possibly none), and returns either the number of bytes written to
+.Fa s
+or
+.Li (size_t)-1
+to denote error.
+.Pp
+Over successive calls to
+.Nm
+with the same state
+.Fa ps ,
+the sequence of
 .Fa c16
-in [0xd800,0xdbff], or if a high surrogate was passed in the previous
-call and anything other than a low surrogate is passed, then
+values must be a well-formed UTF-16 code unit sequence.
+If
+.Fa c16 ,
+when appended to the sequence of code units passed in previous calls,
+does not form a well-formed UTF-16 code unit sequence, then
 .Nm
-will return
+returns
 .Li (size_t)-1
-to denote failure with
+with
 .Xr errno 2
 set to
 .Er EILSEQ .
 .Pp
 If
+.Fa s
+is a null pointer, no output is stored, but the effects on
+.Fa ps
+and the return value are unchanged.
+.Pp
+If
 .Fa ps
 is a null pointer,
 .Nm
@@ -148,9 +151,9 @@ printf("%s\en", buf);
 .Sh ERRORS
 .Bl -tag -width Bq
 .It Bq Er EILSEQ
-A surrogate code point was passed as
+The
 .Fa c16
-when it is inappropriate.
+input sequence does not encode a Unicode scalar value in UTF-16.
 .It Bq Er EILSEQ
 The Unicode scalar value requested cannot be encoded as a multibyte
 sequence in the current locale.
Index: src/lib/libc/locale/c32rtomb.3
diff -u src/lib/libc/locale/c32rtomb.3:1.5 src/lib/libc/locale/c32rtomb.3:1.6
--- src/lib/libc/locale/c32rtomb.3:1.5	Fri Aug 16 19:39:51 2024
+++ src/lib/libc/locale/c32rtomb.3	Sat Aug 17 00:29:21 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c32rtomb.3,v 1.5 2024/08/16 19:39:51 riastradh Exp $
+.\"	$NetBSD: c32rtomb.3,v 1.6 2024/08/17 00:29:21 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -30,7 +30,7 @@
 .\"
 .Sh NAME
 .Nm c32rtomb
-.Nd Restartable UTF-32 code unit to multibyte conversion
+.Nd Restartable UTF-32 to multibyte conversion
 .\"
 .Sh LIBRARY
 .Lb libc
@@ -49,30 +49,37 @@
 .Sh DESCRIPTION
 The
 .Nm
-function attempts to encode Unicode input as a multibyte character
-sequence output at
-.Fa s
-in the current locale, writing anywhere between zero and
+function converts Unicode scalar values to multibyte characters in the
+current locale, keeping state so it can restart after incremental
+progress.
+.Pp
+Each call to
+.Nm
+updates the conversion state
+.Fa ps
+with a UTF-32 code unit
+.Fa c32 ,
+writes up to
 .Dv MB_CUR_MAX
-bytes

CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 17 00:29:21 UTC 2024

Modified Files:
src/lib/libc/locale: c16rtomb.3 c32rtomb.3

Log Message:
c16rtomb(3), c32rtomb(3): Attempt a deturgidification pass.

Limit the jargon around surrogates.

PR lib/52374:  missing


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/c16rtomb.3 \
src/lib/libc/locale/c32rtomb.3

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



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 16 23:34:25 UTC 2024

Modified Files:
src/lib/libc/locale: c8rtomb.3

Log Message:
c8rtomb(3): Fix possible error descriptions.

The argument c8 can't be a surrogate code point itself (they're in
the range [0xd800,0xdfff], beyond 8-bit values), but the bits of a
surrogate code point could be forced into the UTF-8 format, which is
also invalid.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/c8rtomb.3

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

Modified files:

Index: src/lib/libc/locale/c8rtomb.3
diff -u src/lib/libc/locale/c8rtomb.3:1.3 src/lib/libc/locale/c8rtomb.3:1.4
--- src/lib/libc/locale/c8rtomb.3:1.3	Fri Aug 16 19:39:09 2024
+++ src/lib/libc/locale/c8rtomb.3	Fri Aug 16 23:34:25 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: c8rtomb.3,v 1.3 2024/08/16 19:39:09 riastradh Exp $
+.\"	$NetBSD: c8rtomb.3,v 1.4 2024/08/16 23:34:25 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -136,12 +136,12 @@ printf("%s\en", buf);
 .Sh ERRORS
 .Bl -tag -width Bq
 .It Bq Er EILSEQ
-A surrogate code point was passed as
+The
 .Fa c8
-when it is inappropriate.
+input sequence does not encode a Unicode scalar value in UTF-8.
 .It Bq Er EILSEQ
-The Unicode scalar value requested cannot be encoded as a multibyte
-sequence in the current locale.
+The Unicode scalar value cannot be encoded as a multibyte sequence in
+the current locale.
 .It Bq Er EIO
 An error occurred in loading the locale's character conversions.
 .El



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 16 23:34:25 UTC 2024

Modified Files:
src/lib/libc/locale: c8rtomb.3

Log Message:
c8rtomb(3): Fix possible error descriptions.

The argument c8 can't be a surrogate code point itself (they're in
the range [0xd800,0xdfff], beyond 8-bit values), but the bits of a
surrogate code point could be forced into the UTF-8 format, which is
also invalid.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/c8rtomb.3

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



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 16 23:25:18 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.3

Log Message:
mbrtoc8(3): Restore word accidentally removed.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/mbrtoc8.3

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



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 16 23:25:18 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.3

Log Message:
mbrtoc8(3): Restore word accidentally removed.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/mbrtoc8.3

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

Modified files:

Index: src/lib/libc/locale/mbrtoc8.3
diff -u src/lib/libc/locale/mbrtoc8.3:1.4 src/lib/libc/locale/mbrtoc8.3:1.5
--- src/lib/libc/locale/mbrtoc8.3:1.4	Fri Aug 16 23:12:17 2024
+++ src/lib/libc/locale/mbrtoc8.3	Fri Aug 16 23:25:18 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc8.3,v 1.4 2024/08/16 23:12:17 riastradh Exp $
+.\"	$NetBSD: mbrtoc8.3,v 1.5 2024/08/16 23:25:18 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -50,8 +50,9 @@
 .Sh DESCRIPTION
 The
 .Nm
-decodes multibyte characters in the current locale and converts them to
-UTF-8, keeping state so it can restart after incremental progress.
+function decodes multibyte characters in the current locale and
+converts them to UTF-8, keeping state so it can restart after
+incremental progress.
 .Pp
 Each call to
 .Nm :



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 16 23:25:00 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc16.3 mbrtoc32.3

Log Message:
mbrtoc16(3), mbrtoc32(3): Restore word accidentally removed.

PR lib/52374:  missing


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/mbrtoc16.3 \
src/lib/libc/locale/mbrtoc32.3

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

Modified files:

Index: src/lib/libc/locale/mbrtoc16.3
diff -u src/lib/libc/locale/mbrtoc16.3:1.6 src/lib/libc/locale/mbrtoc16.3:1.7
--- src/lib/libc/locale/mbrtoc16.3:1.6	Fri Aug 16 23:11:02 2024
+++ src/lib/libc/locale/mbrtoc16.3	Fri Aug 16 23:25:00 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc16.3,v 1.6 2024/08/16 23:11:02 riastradh Exp $
+.\"	$NetBSD: mbrtoc16.3,v 1.7 2024/08/16 23:25:00 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -50,8 +50,9 @@
 .Sh DESCRIPTION
 The
 .Nm
-decodes multibyte characters in the current locale and converts them to
-UTF-16, keeping state so it can restart after incremental progress.
+function decodes multibyte characters in the current locale and
+converts them to UTF-16, keeping state so it can restart after
+incremental progress.
 .Pp
 Each call to
 .Nm :
Index: src/lib/libc/locale/mbrtoc32.3
diff -u src/lib/libc/locale/mbrtoc32.3:1.6 src/lib/libc/locale/mbrtoc32.3:1.7
--- src/lib/libc/locale/mbrtoc32.3:1.6	Fri Aug 16 23:11:03 2024
+++ src/lib/libc/locale/mbrtoc32.3	Fri Aug 16 23:25:00 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc32.3,v 1.6 2024/08/16 23:11:03 riastradh Exp $
+.\"	$NetBSD: mbrtoc32.3,v 1.7 2024/08/16 23:25:00 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -50,9 +50,9 @@
 .Sh DESCRIPTION
 The
 .Nm
-decodes multibyte characters in the current locale and converts them to
-Unicode scalar values (i.e., to UTF-32), keeping state so it can
-restart after incremental progress.
+function decodes multibyte characters in the current locale and
+converts them to Unicode scalar values (i.e., to UTF-32), keeping state
+so it can restart after incremental progress.
 .Pp
 Each call to
 .Nm :



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 16 23:25:00 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc16.3 mbrtoc32.3

Log Message:
mbrtoc16(3), mbrtoc32(3): Restore word accidentally removed.

PR lib/52374:  missing


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/mbrtoc16.3 \
src/lib/libc/locale/mbrtoc32.3

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



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 16 23:12:17 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.3

Log Message:
mbrtoc8(3): Work on deturgidifying prose.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/mbrtoc8.3

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

Modified files:

Index: src/lib/libc/locale/mbrtoc8.3
diff -u src/lib/libc/locale/mbrtoc8.3:1.3 src/lib/libc/locale/mbrtoc8.3:1.4
--- src/lib/libc/locale/mbrtoc8.3:1.3	Fri Aug 16 19:31:48 2024
+++ src/lib/libc/locale/mbrtoc8.3	Fri Aug 16 23:12:17 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc8.3,v 1.3 2024/08/16 19:31:48 riastradh Exp $
+.\"	$NetBSD: mbrtoc8.3,v 1.4 2024/08/16 23:12:17 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -30,7 +30,7 @@
 .\"
 .Sh NAME
 .Nm mbrtoc8
-.Nd Restartable multibyte to UTF-8 code unit conversion
+.Nd Restartable multibyte to UTF-8 conversion
 .\"
 .Sh LIBRARY
 .Lb libc
@@ -50,20 +50,37 @@
 .Sh DESCRIPTION
 The
 .Nm
-function attempts to decode a multibyte character sequence at
-.Fa s
-of up to
+decodes multibyte characters in the current locale and converts them to
+UTF-8, keeping state so it can restart after incremental progress.
+.Pp
+Each call to
+.Nm :
+.Bl -enum -compact
+.It
+examines up to
 .Fa n
-bytes in the current locale, and yield the content as UTF-8 code
-units via the output parameter
-.Fa pc8 .
-.Fa pc8
-may be null, in which case no output is stored.
+bytes starting at
+.Fa s ,
+.It
+yields a UTF-8 code unit if available by storing it at
+.Li * Ns Fa pc8 ,
+.It
+saves state at
+.Fa ps ,
+and
+.It
+returns either the number of bytes consumed if any or a special return
+value.
+.El
+.Pp
+Specifically:
 .Bl -bullet
 .It
 If the multibyte sequence at
 .Fa s
-is invalid or an error occurs in decoding,
+is invalid after any previous input saved at
+.Fa ps ,
+or if an error occurs in decoding,
 .Nm
 returns
 .Li (size_t)-1
@@ -75,7 +92,7 @@ If the multibyte sequence at
 .Fa s
 is still incomplete after
 .Fa n
-bytes, including any previously processed input saved in
+bytes, including any previous input saved in
 .Fa ps ,
 .Nm
 saves its state in
@@ -85,53 +102,33 @@ after all the input so far and returns
 .It
 If
 .Nm
-finds the null scalar value at
-.Fa s ,
-then it stores zero at
+had previously decoded a multibyte character but has not yet yielded
+all the code units of its UTF-8 encoding, it stores the next UTF-8 code
+unit at
 .Li * Ns Fa pc8
-and returns zero.
+and returns
+.Li "(size_t)-3" .
 .It
 If
 .Nm
-finds a nonnull scalar value in the US-ASCII range, i.e., a 7-bit
-scalar value, then it stores the scalar value at
-.Li * Ns Fa pc8 ,
-and returns the number of bytes it read from the input.
+decodes the null multibyte character, then it stores zero at
+.Li * Ns Fa pc8
+and returns zero.
 .It
-If
+Otherwise,
 .Nm
-finds a scalar value outside the US-ASCII range, it:
-.Bl -dash -compact
-.It
-stores the leading byte in the scalar value's UTF-8 encoding at
-.Li * Ns Fa pc8 ;
-.It
-stores conversion state in
-.Fa ps
-to remember the rest of the pending scalar value; and
-.It
-returns the number of bytes it read from the input.
+decodes a single multibyte character, stores the first (and possibly
+only) code unit in its UTF-8 encoding at
+.Li * Ns Fa pc8 ,
+and returns the number of bytes consumed to decode the first multibyte
+character.
 .El
-.It
+.Pp
 If
-.Nm
-had previously found a scalar value outside the US-ASCII range, then,
-instead of any of the above options, it:
-.Bl -dash -compact
-.It
-stores the next byte in the scalar value's UTF-8 encoding at
-.Li * Ns Fa pc8 ;
-.It
-updates the conversion state in
+.Fa pc8
+is a null pointer, nothing is stored, but the effects on
 .Fa ps
-to consume this byte; and
-.It
-returns
-.Li (size_t)-3
-to indicate that no bytes were consumed but a code unit was yielded
-nevertheless.
-.El
-.El
+and the return value are unchanged.
 .Pp
 If
 .Fa s
@@ -174,6 +171,14 @@ and
 which is initialized at program startup to the initial conversion
 state.
 .\"
+.Sh IMPLEMENTATION NOTES
+On well-formed input, the
+.Nm
+function yields either a Unicode scalar value in US-ASCII range, i.e.,
+a 7-bit Unicode code point, or, over two to four successive calls, the
+leading and trailing code units in order of the UTF-8 encoding of a
+Unicode scalar value outside the US-ASCII range.
+.\"
 .Sh RETURN VALUES
 The
 .Nm
@@ -197,26 +202,21 @@ if
 consumed
 .Ar i
 bytes of input to decode the next multibyte character, yie

CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 16 23:12:17 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc8.3

Log Message:
mbrtoc8(3): Work on deturgidifying prose.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/mbrtoc8.3

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



CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 16 23:11:03 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc16.3 mbrtoc32.3

Log Message:
mbrtoc16(3), mbrtoc32(3): Work on deturgidifying prose.

Still maybe not great but at least there's less jargon in most of the
text, without really losing any content.

PR lib/52374:  missing


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/mbrtoc16.3 \
src/lib/libc/locale/mbrtoc32.3

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

Modified files:

Index: src/lib/libc/locale/mbrtoc16.3
diff -u src/lib/libc/locale/mbrtoc16.3:1.5 src/lib/libc/locale/mbrtoc16.3:1.6
--- src/lib/libc/locale/mbrtoc16.3:1.5	Fri Aug 16 13:37:43 2024
+++ src/lib/libc/locale/mbrtoc16.3	Fri Aug 16 23:11:02 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mbrtoc16.3,v 1.5 2024/08/16 13:37:43 riastradh Exp $
+.\"	$NetBSD: mbrtoc16.3,v 1.6 2024/08/16 23:11:02 riastradh Exp $
 .\"
 .\" Copyright (c) 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -30,7 +30,7 @@
 .\"
 .Sh NAME
 .Nm mbrtoc16
-.Nd Restartable multibyte to UTF-16 code unit conversion
+.Nd Restartable multibyte to UTF-16 conversion
 .\"
 .Sh LIBRARY
 .Lb libc
@@ -50,20 +50,37 @@
 .Sh DESCRIPTION
 The
 .Nm
-function attempts to decode a multibyte character sequence at
-.Fa s
-of up to
+decodes multibyte characters in the current locale and converts them to
+UTF-16, keeping state so it can restart after incremental progress.
+.Pp
+Each call to
+.Nm :
+.Bl -enum -compact
+.It
+examines up to
 .Fa n
-bytes in the current locale, and yield the content as UTF-16 code
-units via the output parameter
-.Fa pc16 .
-.Fa pc16
-may be null, in which case no output is stored.
+bytes starting at
+.Fa s ,
+.It
+yields a UTF-16 code unit if available by storing it at
+.Li * Ns Fa pc16 ,
+.It
+saves state at
+.Fa ps ,
+and
+.It
+returns either the number of bytes consumed if any or a special return
+value.
+.El
+.Pp
+Specifically:
 .Bl -bullet
 .It
 If the multibyte sequence at
 .Fa s
-is invalid or an error occurs in decoding,
+is invalid after any previous input saved at
+.Fa ps ,
+or if an error occurs in decoding,
 .Nm
 returns
 .Li (size_t)-1
@@ -75,7 +92,7 @@ If the multibyte sequence at
 .Fa s
 is still incomplete after
 .Fa n
-bytes, including any previously processed input saved in
+bytes, including any previous input saved in
 .Fa ps ,
 .Nm
 saves its state in
@@ -85,53 +102,33 @@ after all the input so far and returns
 .It
 If
 .Nm
-finds the null scalar value at
-.Fa s ,
-then it stores zero at
+had previously decoded a multibyte character but has not yet yielded
+all the code units of its UTF-16 encoding, it stores the next UTF-16
+code unit at
 .Li * Ns Fa pc16
-and returns zero.
+and returns
+.Li "(size_t)-3" .
 .It
 If
 .Nm
-finds a nonnull scalar value in the Basic Multilingual Plane (BMP),
-i.e., a 16-bit scalar value, then it stores the scalar value at
-.Li * Ns Fa pc16 ,
-and returns the number of bytes it read from the input.
+decodes the null multibyte character, then it stores zero at
+.Li * Ns Fa pc16
+and returns zero.
 .It
-If
+Otherwise,
 .Nm
-finds a scalar value outside the BMP, then it:
-.Bl -dash -compact
-.It
-stores the scalar value's high surrogate code point at
-.Li * Ns Fa pc16 ;
-.It
-stores conversion state in
-.Fa ps
-to remember the rest of the pending scalar value; and
-.It
-returns the number of bytes it read from the input.
+decodes a single multibyte character, stores the first (and possibly
+only) code unit in its UTF-16 encoding at
+.Li * Ns Fa pc16 ,
+and returns the number of bytes consumed to decode the first multibyte
+character.
 .El
-.It
+.Pp
 If
-.Nm
-had previously found a scalar value outside the BMP, then, instead of
-any of the above options, it:
-.Bl -dash -compact
-.It
-stores the scalar value's low surrogate code point at
-.Li * Ns Fa pc16 ;
-.It
-consumes rest of the pending scalar value from the conversion state
-.Fa ps ;
-and
-.It
-returns
-.Li (size_t)-3
-to indicate that no bytes were consumed but a code unit was yielded
-nevertheless.
-.El
-.El
+.Fa pc16
+is a null pointer, nothing is stored, but the effects on
+.Fa ps
+and the return value are unchanged.
 .Pp
 If
 .Fa s
@@ -174,6 +171,15 @@ and
 which is initialized at program startup to the initial conversion
 state.
 .\"
+.Sh IMPLEMENTATION NOTES
+On well-formed input, the
+.Nm
+function yields either a Unicode scalar value in the Basic Multilingual
+Plane (BMP), i.e., a 16-bit Unicode code point that is not a surrogate
+code point, or, over two successive calls, yields the high and low
+surrogate code points (in that order) of a Unicode scalar value outside
+the BMP.
+.\

CVS commit: src/lib/libc/locale

2024-08-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 16 23:11:03 UTC 2024

Modified Files:
src/lib/libc/locale: mbrtoc16.3 mbrtoc32.3

Log Message:
mbrtoc16(3), mbrtoc32(3): Work on deturgidifying prose.

Still maybe not great but at least there's less jargon in most of the
text, without really losing any content.

PR lib/52374:  missing


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/mbrtoc16.3 \
src/lib/libc/locale/mbrtoc32.3

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



  1   2   3   4   5   6   7   8   9   10   >