Index | Thread | Search

From:
Tobias Stoeckmann <tobias@stoeckmann.org>
Subject:
wprintf(3): Fix errno value and document it
To:
tech@openbsd.org
Date:
Fri, 16 May 2025 22:42:59 +0200

Download raw body.

Thread
Hi,

in 2016 two adjustments have been made to vfprintf. For one, a bug fix
has been integrated to return EOVERFLOW if the return value would be
larger than INT_MAX. And the manual page was adjusted to contain an
ERRORS section.

https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/vfprintf.c#rev1.73
https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/printf.3#rev1.75

Back in 2011, vfwprintf.c and wprintf.3 were created based on the code
and documentation ofvfprintf.c and printf.3 of that time.

So, this fixes the same issue and adds the same documentation to the
wide character versions.

Okay?

Tobias


Index: vfwprintf.c
===================================================================
RCS file: /cvs/src/lib/libc/stdio/vfwprintf.c,v
diff -u -p -u -p -r1.23 vfwprintf.c
--- vfwprintf.c	6 Oct 2023 16:41:02 -0000	1.23
+++ vfwprintf.c	16 May 2025 20:31:18 -0000
@@ -1059,7 +1059,7 @@ error:
 	goto finish;
 
 overflow:
-	errno = ENOMEM;
+	errno = EOVERFLOW;
 	ret = -1;
 
 finish:
Index: wprintf.3
===================================================================
RCS file: /cvs/src/lib/libc/stdio/wprintf.3,v
diff -u -p -u -p -r1.10 wprintf.3
--- wprintf.3	31 Mar 2022 17:27:16 -0000	1.10
+++ wprintf.3	16 May 2025 20:31:18 -0000
@@ -584,6 +584,21 @@ In no case does a non-existent or small 
 a numeric field; if the result of a conversion is wider than the field
 width, the
 field is expanded to contain the conversion result.
+.Sh ERRORS
+In addition to the errors documented for the
+.Xr write 2
+system call, the
+.Fn wprintf
+family of functions may fail if:
+.Bl -tag -width Er
+.It Bq Er EILSEQ
+An invalid wide character code was encountered.
+.It Bq Er ENOMEM
+Insufficient storage space is available.
+.It Bq Er EOVERFLOW
+The return value would be too large to be represented by an
+.Vt int .
+.El
 .Sh SEE ALSO
 .Xr btowc 3 ,
 .Xr fputws 3 ,