aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r--lib/libc/stdio/Makefile.inc120
-rw-r--r--lib/libc/stdio/Symbol.map5
-rw-r--r--lib/libc/stdio/_flock_stub.c1
-rw-r--r--lib/libc/stdio/asprintf.c1
-rw-r--r--lib/libc/stdio/clrerr.c4
-rw-r--r--lib/libc/stdio/dprintf.c1
-rw-r--r--lib/libc/stdio/fclose.37
-rw-r--r--lib/libc/stdio/fclose.c4
-rw-r--r--lib/libc/stdio/fcloseall.c1
-rw-r--r--lib/libc/stdio/fdopen.c22
-rw-r--r--lib/libc/stdio/feof.c4
-rw-r--r--lib/libc/stdio/ferror.322
-rw-r--r--lib/libc/stdio/ferror.c4
-rw-r--r--lib/libc/stdio/fflush.32
-rw-r--r--lib/libc/stdio/fflush.c31
-rw-r--r--lib/libc/stdio/fgetc.c4
-rw-r--r--lib/libc/stdio/fgetln.32
-rw-r--r--lib/libc/stdio/fgetln.c4
-rw-r--r--lib/libc/stdio/fgetpos.c4
-rw-r--r--lib/libc/stdio/fgets.35
-rw-r--r--lib/libc/stdio/fgets.c6
-rw-r--r--lib/libc/stdio/fgetwc.c1
-rw-r--r--lib/libc/stdio/fgetwln.32
-rw-r--r--lib/libc/stdio/fgetwln.c1
-rw-r--r--lib/libc/stdio/fgetws.32
-rw-r--r--lib/libc/stdio/fgetws.c1
-rw-r--r--lib/libc/stdio/fileno.c29
-rw-r--r--lib/libc/stdio/findfp.c4
-rw-r--r--lib/libc/stdio/flags.c4
-rw-r--r--lib/libc/stdio/floatio.h2
-rw-r--r--lib/libc/stdio/fmemopen.c11
-rw-r--r--lib/libc/stdio/fopen.32
-rw-r--r--lib/libc/stdio/fopen.c4
-rw-r--r--lib/libc/stdio/fopencookie.c1
-rw-r--r--lib/libc/stdio/fprintf.c4
-rw-r--r--lib/libc/stdio/fpurge.c4
-rw-r--r--lib/libc/stdio/fputc.c4
-rw-r--r--lib/libc/stdio/fputs.32
-rw-r--r--lib/libc/stdio/fputs.c4
-rw-r--r--lib/libc/stdio/fputwc.c1
-rw-r--r--lib/libc/stdio/fputws.32
-rw-r--r--lib/libc/stdio/fputws.c1
-rw-r--r--lib/libc/stdio/fread.32
-rw-r--r--lib/libc/stdio/fread.c8
-rw-r--r--lib/libc/stdio/freopen.c14
-rw-r--r--lib/libc/stdio/fscanf.c4
-rw-r--r--lib/libc/stdio/fseek.32
-rw-r--r--lib/libc/stdio/fseek.c4
-rw-r--r--lib/libc/stdio/fsetpos.c4
-rw-r--r--lib/libc/stdio/ftell.c4
-rw-r--r--lib/libc/stdio/funopen.32
-rw-r--r--lib/libc/stdio/funopen.c4
-rw-r--r--lib/libc/stdio/fvwrite.c18
-rw-r--r--lib/libc/stdio/fvwrite.h2
-rw-r--r--lib/libc/stdio/fwalk.c4
-rw-r--r--lib/libc/stdio/fwide.c1
-rw-r--r--lib/libc/stdio/fwprintf.c1
-rw-r--r--lib/libc/stdio/fwrite.c4
-rw-r--r--lib/libc/stdio/fwscanf.c1
-rw-r--r--lib/libc/stdio/getc.32
-rw-r--r--lib/libc/stdio/getc.c4
-rw-r--r--lib/libc/stdio/getchar.c4
-rw-r--r--lib/libc/stdio/getdelim.c1
-rw-r--r--lib/libc/stdio/getline.c1
-rw-r--r--lib/libc/stdio/gets.c4
-rw-r--r--lib/libc/stdio/gets_s.c4
-rw-r--r--lib/libc/stdio/getw.c4
-rw-r--r--lib/libc/stdio/getwc.32
-rw-r--r--lib/libc/stdio/getwc.c1
-rw-r--r--lib/libc/stdio/getwchar.c1
-rw-r--r--lib/libc/stdio/glue.h2
-rw-r--r--lib/libc/stdio/local.h4
-rw-r--r--lib/libc/stdio/makebuf.c4
-rw-r--r--lib/libc/stdio/mktemp.320
-rw-r--r--lib/libc/stdio/mktemp.c6
-rw-r--r--lib/libc/stdio/open_memstream.c1
-rw-r--r--lib/libc/stdio/open_wmemstream.c1
-rw-r--r--lib/libc/stdio/perror.c4
-rw-r--r--lib/libc/stdio/printf-pos.c4
-rw-r--r--lib/libc/stdio/printf.312
-rw-r--r--lib/libc/stdio/printf.c4
-rw-r--r--lib/libc/stdio/printflocal.h1
-rw-r--r--lib/libc/stdio/putc.32
-rw-r--r--lib/libc/stdio/putc.c4
-rw-r--r--lib/libc/stdio/putchar.c4
-rw-r--r--lib/libc/stdio/puts.c4
-rw-r--r--lib/libc/stdio/putw.c4
-rw-r--r--lib/libc/stdio/putwc.32
-rw-r--r--lib/libc/stdio/putwc.c1
-rw-r--r--lib/libc/stdio/putwchar.c1
-rw-r--r--lib/libc/stdio/refill.c4
-rw-r--r--lib/libc/stdio/remove.32
-rw-r--r--lib/libc/stdio/remove.c4
-rw-r--r--lib/libc/stdio/rewind.c4
-rw-r--r--lib/libc/stdio/rget.c4
-rw-r--r--lib/libc/stdio/scanf.332
-rw-r--r--lib/libc/stdio/scanf.c4
-rw-r--r--lib/libc/stdio/setbuf.32
-rw-r--r--lib/libc/stdio/setbuf.c4
-rw-r--r--lib/libc/stdio/setbuffer.c4
-rw-r--r--lib/libc/stdio/setvbuf.c4
-rw-r--r--lib/libc/stdio/snprintf.c20
-rw-r--r--lib/libc/stdio/sprintf.c6
-rw-r--r--lib/libc/stdio/sscanf.c4
-rw-r--r--lib/libc/stdio/stdio.34
-rw-r--r--lib/libc/stdio/stdio.c4
-rw-r--r--lib/libc/stdio/swprintf.c1
-rw-r--r--lib/libc/stdio/swscanf.c1
-rw-r--r--lib/libc/stdio/tempnam.c4
-rw-r--r--lib/libc/stdio/tmpfile.c4
-rw-r--r--lib/libc/stdio/tmpnam.32
-rw-r--r--lib/libc/stdio/tmpnam.c7
-rw-r--r--lib/libc/stdio/ungetc.32
-rw-r--r--lib/libc/stdio/ungetc.c4
-rw-r--r--lib/libc/stdio/ungetwc.32
-rw-r--r--lib/libc/stdio/ungetwc.c1
-rw-r--r--lib/libc/stdio/vasprintf.c6
-rw-r--r--lib/libc/stdio/vdprintf.c4
-rw-r--r--lib/libc/stdio/vfprintf.c82
-rw-r--r--lib/libc/stdio/vfscanf.c44
-rw-r--r--lib/libc/stdio/vfwprintf.c58
-rw-r--r--lib/libc/stdio/vfwscanf.c46
-rw-r--r--lib/libc/stdio/vprintf.c4
-rw-r--r--lib/libc/stdio/vscanf.c4
-rw-r--r--lib/libc/stdio/vsnprintf.c13
-rw-r--r--lib/libc/stdio/vsprintf.c16
-rw-r--r--lib/libc/stdio/vsscanf.c4
-rw-r--r--lib/libc/stdio/vswprintf.c4
-rw-r--r--lib/libc/stdio/vswscanf.c7
-rw-r--r--lib/libc/stdio/vwprintf.c1
-rw-r--r--lib/libc/stdio/vwscanf.c1
-rw-r--r--lib/libc/stdio/wbuf.c16
-rw-r--r--lib/libc/stdio/wprintf.32
-rw-r--r--lib/libc/stdio/wprintf.c1
-rw-r--r--lib/libc/stdio/wscanf.32
-rw-r--r--lib/libc/stdio/wscanf.c1
-rw-r--r--lib/libc/stdio/wsetup.c4
-rw-r--r--lib/libc/stdio/xprintf_errno.c13
138 files changed, 453 insertions, 546 deletions
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc
index 0fc0a6bfd68c..a3d76c0ea795 100644
--- a/lib/libc/stdio/Makefile.inc
+++ b/lib/libc/stdio/Makefile.inc
@@ -1,5 +1,3 @@
-# @(#)Makefile.inc 8.3 (Berkeley) 4/17/94
-
# stdio sources
.PATH: ${LIBC_SRCTOP}/stdio
@@ -42,50 +40,102 @@ MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetwln.3 fgetws.3 \
stdio.3 tmpnam.3 \
ungetc.3 ungetwc.3 wprintf.3 wscanf.3
-MLINKS+=fclose.3 fcloseall.3 fclose.3 fdclose.3
+MLINKS+=fclose.3 fcloseall.3 \
+ fclose.3 fdclose.3
MLINKS+=ferror.3 ferror_unlocked.3 \
- ferror.3 clearerr.3 ferror.3 clearerr_unlocked.3 \
- ferror.3 feof.3 ferror.3 feof_unlocked.3 \
- ferror.3 fileno.3 ferror.3 fileno_unlocked.3
+ ferror.3 clearerr.3 \
+ ferror.3 clearerr_unlocked.3 \
+ ferror.3 feof.3 \
+ ferror.3 feof_unlocked.3 \
+ ferror.3 fileno.3 \
+ ferror.3 fileno_unlocked.3
MLINKS+=fflush.3 fflush_unlocked.3 \
fflush.3 fpurge.3
MLINKS+=fgets.3 gets.3
MLINKS+=fgets.3 gets_s.3
-MLINKS+=flockfile.3 ftrylockfile.3 flockfile.3 funlockfile.3
-MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3 fopen.3 fmemopen.3
+MLINKS+=flockfile.3 ftrylockfile.3 \
+ flockfile.3 funlockfile.3
+MLINKS+=fopen.3 fdopen.3 \
+ fopen.3 freopen.3 \
+ fopen.3 fmemopen.3
MLINKS+=fputs.3 fputs_unlocked.3 \
fputs.3 puts.3
MLINKS+=fread.3 fread_unlocked.3 \
fread.3 fwrite.3 \
fread.3 fwrite_unlocked.3
-MLINKS+=fseek.3 fgetpos.3 fseek.3 fseeko.3 fseek.3 fsetpos.3 fseek.3 ftell.3 \
- fseek.3 ftello.3 fseek.3 rewind.3
-MLINKS+=funopen.3 fropen.3 funopen.3 fwopen.3
-MLINKS+=getc.3 fgetc.3 getc.3 getc_unlocked.3 getc.3 getchar.3 \
- getc.3 getchar_unlocked.3 getc.3 getw.3
+MLINKS+=fseek.3 fgetpos.3 \
+ fseek.3 fseeko.3 \
+ fseek.3 fsetpos.3 \
+ fseek.3 ftell.3 \
+ fseek.3 ftello.3 \
+ fseek.3 rewind.3
+MLINKS+=funopen.3 fropen.3 \
+ funopen.3 fwopen.3
+MLINKS+=getc.3 fgetc.3 \
+ getc.3 getc_unlocked.3 \
+ getc.3 getchar.3 \
+ getc.3 getchar_unlocked.3 \
+ getc.3 getw.3
MLINKS+=getline.3 getdelim.3
-MLINKS+=getwc.3 fgetwc.3 getwc.3 getwchar.3
-MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3 mktemp.3 mkstemps.3 \
- mktemp.3 mkostemp.3 mktemp.3 mkostemps.3 mktemp.3 mkostempsat.3
+MLINKS+=getwc.3 fgetwc.3 \
+ getwc.3 getwchar.3
+MLINKS+=mktemp.3 mkdtemp.3 \
+ mktemp.3 mkstemp.3 \
+ mktemp.3 mkstemps.3 \
+ mktemp.3 mkostemp.3 \
+ mktemp.3 mkostemps.3 \
+ mktemp.3 mkostempsat.3
MLINKS+=open_memstream.3 open_wmemstream.3
-MLINKS+=printf.3 asprintf.3 printf.3 dprintf.3 printf.3 fprintf.3 \
- printf.3 snprintf.3 printf.3 sprintf.3 \
- printf.3 vasprintf.3 printf.3 vdprintf.3 \
- printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \
+MLINKS+=printf.3 asprintf.3 \
+ printf.3 dprintf.3 \
+ printf.3 fprintf.3 \
+ printf.3 snprintf.3 \
+ printf.3 sprintf.3 \
+ printf.3 vasprintf.3 \
+ printf.3 vdprintf.3 \
+ printf.3 vfprintf.3 \
+ printf.3 vprintf.3 \
+ printf.3 vsnprintf.3 \
printf.3 vsprintf.3
-MLINKS+=printf_l.3 asprintf_l.3 printf_l.3 fprintf_l.3 printf_l.3 snprintf_l.3 \
- printf_l.3 sprintf_l.3 printf_l.3 vasprintf_l.3 printf_l.3 vfprintf_l.3 \
- printf_l.3 vprintf_l.3 printf_l.3 vsnprintf_l.3 printf_l.3 vsprintf_l.3
-MLINKS+=putc.3 fputc.3 putc.3 putc_unlocked.3 putc.3 putchar.3 \
- putc.3 putchar_unlocked.3 putc.3 putw.3
-MLINKS+=putwc.3 fputwc.3 putwc.3 putwchar.3
-MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \
+MLINKS+=printf_l.3 asprintf_l.3 \
+ printf_l.3 fprintf_l.3 \
+ printf_l.3 snprintf_l.3 \
+ printf_l.3 sprintf_l.3 \
+ printf_l.3 vasprintf_l.3 \
+ printf_l.3 vfprintf_l.3 \
+ printf_l.3 vprintf_l.3 \
+ printf_l.3 vsnprintf_l.3 \
+ printf_l.3 vsprintf_l.3
+MLINKS+=putc.3 fputc.3 \
+ putc.3 fputc_unlocked.3 \
+ putc.3 putc_unlocked.3 \
+ putc.3 putchar.3 \
+ putc.3 putchar_unlocked.3 \
+ putc.3 putw.3
+MLINKS+=putwc.3 fputwc.3 \
+ putwc.3 putwchar.3
+MLINKS+=scanf.3 fscanf.3 \
+ scanf.3 sscanf.3 \
+ scanf.3 vfscanf.3 \
+ scanf.3 vscanf.3 \
scanf.3 vsscanf.3
-MLINKS+=scanf_l.3 fscanf_l.3 scanf_l.3 sscanf_l.3 scanf_l.3 vfscanf_l.3 \
- scanf_l.3 vscanf_l.3 scanf_l.3 vsscanf_l.3
-MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3
-MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3
-MLINKS+=wprintf.3 fwprintf.3 wprintf.3 swprintf.3 \
- wprintf.3 vwprintf.3 wprintf.3 vfwprintf.3 wprintf.3 vswprintf.3
-MLINKS+=wscanf.3 fwscanf.3 wscanf.3 swscanf.3 wscanf.3 vwscanf.3 \
- wscanf.3 vswscanf.3 wscanf.3 vfwscanf.3
+MLINKS+=scanf_l.3 fscanf_l.3 \
+ scanf_l.3 sscanf_l.3 \
+ scanf_l.3 vfscanf_l.3 \
+ scanf_l.3 vscanf_l.3 \
+ scanf_l.3 vsscanf_l.3
+MLINKS+=setbuf.3 setbuffer.3 \
+ setbuf.3 setlinebuf.3 \
+ setbuf.3 setvbuf.3
+MLINKS+=tmpnam.3 tempnam.3 \
+ tmpnam.3 tmpfile.3
+MLINKS+=wprintf.3 fwprintf.3 \
+ wprintf.3 swprintf.3 \
+ wprintf.3 vwprintf.3 \
+ wprintf.3 vfwprintf.3 \
+ wprintf.3 vswprintf.3
+MLINKS+=wscanf.3 fwscanf.3 \
+ wscanf.3 swscanf.3 \
+ wscanf.3 vwscanf.3 \
+ wscanf.3 vswscanf.3 \
+ wscanf.3 vfwscanf.3
diff --git a/lib/libc/stdio/Symbol.map b/lib/libc/stdio/Symbol.map
index 575dc3cd923c..e44ea6554d46 100644
--- a/lib/libc/stdio/Symbol.map
+++ b/lib/libc/stdio/Symbol.map
@@ -1,6 +1,3 @@
-/*
- */
-
FBSD_1.0 {
flockfile;
ftrylockfile;
@@ -21,7 +18,6 @@ FBSD_1.0 {
fgetwln;
fgetws;
fileno;
- __sF;
__stdinp;
__stdoutp;
__stderrp;
@@ -48,7 +44,6 @@ FBSD_1.0 {
fwscanf;
getc;
getchar;
- gets;
getw;
getwc;
getwchar;
diff --git a/lib/libc/stdio/_flock_stub.c b/lib/libc/stdio/_flock_stub.c
index 674e88c512bd..5f81f29ac232 100644
--- a/lib/libc/stdio/_flock_stub.c
+++ b/lib/libc/stdio/_flock_stub.c
@@ -36,7 +36,6 @@
*
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libc/stdio/asprintf.c b/lib/libc/stdio/asprintf.c
index 123345490c43..f0e898c92c0c 100644
--- a/lib/libc/stdio/asprintf.c
+++ b/lib/libc/stdio/asprintf.c
@@ -37,7 +37,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdio.h>
#include <stdarg.h>
#include <xlocale.h>
diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c
index 780172ef3f6d..01ce88654c09 100644
--- a/lib/libc/stdio/clrerr.c
+++ b/lib/libc/stdio/clrerr.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
diff --git a/lib/libc/stdio/dprintf.c b/lib/libc/stdio/dprintf.c
index 07e20f0709ef..9e976b37379f 100644
--- a/lib/libc/stdio/dprintf.c
+++ b/lib/libc/stdio/dprintf.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdarg.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/fclose.3 b/lib/libc/stdio/fclose.3
index 1171105598f0..524ff9754bb4 100644
--- a/lib/libc/stdio/fclose.3
+++ b/lib/libc/stdio/fclose.3
@@ -30,9 +30,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fclose.3 8.1 (Berkeley) 6/4/93
-.\"
-.Dd July 4, 2015
+.Dd February 13, 2024
.Dt FCLOSE 3
.Os
.Sh NAME
@@ -71,9 +69,6 @@ If
is not
.Dv NULL ,
the file descriptor will be written to it.
-If the
-.Fa fdp
-argument will be different then NULL the file descriptor will be returned in it,
If the stream does not have an associated file descriptor,
.Fa fdp
will be set to -1.
diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c
index 7a925f1a1661..ba527f6e7108 100644
--- a/lib/libc/stdio/fclose.c
+++ b/lib/libc/stdio/fclose.c
@@ -33,10 +33,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdbool.h>
diff --git a/lib/libc/stdio/fcloseall.c b/lib/libc/stdio/fcloseall.c
index 83dc8d697bf1..ae6bd151ca9c 100644
--- a/lib/libc/stdio/fcloseall.c
+++ b/lib/libc/stdio/fcloseall.c
@@ -25,7 +25,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdio.h>
#include "local.h"
diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c
index 7512e2d4dbba..49ec97eda39d 100644
--- a/lib/libc/stdio/fdopen.c
+++ b/lib/libc/stdio/fdopen.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/types.h>
#include <fcntl.h>
@@ -50,7 +46,7 @@ FILE *
fdopen(int fd, const char *mode)
{
FILE *fp;
- int flags, oflags, fdflags, tmp;
+ int flags, oflags, fdflags, rc, tmp;
/*
* File descriptors are a full int, but _file is only a short.
@@ -80,9 +76,19 @@ fdopen(int fd, const char *mode)
if ((fp = __sfp()) == NULL)
return (NULL);
- if ((oflags & O_CLOEXEC) && _fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
- fp->_flags = 0;
- return (NULL);
+ if ((oflags & O_CLOEXEC) != 0) {
+ tmp = _fcntl(fd, F_GETFD, 0);
+ if (tmp == -1) {
+ fp->_flags = 0;
+ return (NULL);
+ }
+ if ((tmp & FD_CLOEXEC) == 0) {
+ rc = _fcntl(fd, F_SETFD, tmp | FD_CLOEXEC);
+ if (rc == -1) {
+ fp->_flags = 0;
+ return (NULL);
+ }
+ }
}
fp->_flags = flags;
diff --git a/lib/libc/stdio/feof.c b/lib/libc/stdio/feof.c
index f224e1d6d6ba..aefffcd36c70 100644
--- a/lib/libc/stdio/feof.c
+++ b/lib/libc/stdio/feof.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
diff --git a/lib/libc/stdio/ferror.3 b/lib/libc/stdio/ferror.3
index 1529c002fb7f..b921c4280607 100644
--- a/lib/libc/stdio/ferror.3
+++ b/lib/libc/stdio/ferror.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)ferror.3 8.2 (Berkeley) 4/19/94
-.\"
.Dd April 2, 2022
.Dt FERROR 3
.Os
@@ -112,9 +110,25 @@ before calling them.
These functions may be used to avoid the overhead of locking the stream
and to prevent races when multiple threads are operating on the same stream.
.Sh ERRORS
-These functions should not fail and do not set the external
-variable
+These functions, except
+.Fn fileno ,
+should not fail and do not set the external variable
.Va errno .
+.Pp
+On error,
+.Fn fileno
+returns \-1 and sets
+.Va errno
+to one of the following values:
+.Bl -tag -width Er
+.It Bq Er EBADF
+The stream is not associated with a file.
+.It Bq Er EBADF
+The file descriptor underlying stream is not a valid file descriptor.
+.Pp
+Note that detection of this condition is not reliable, the error might
+be not reported.
+.El
.Sh SEE ALSO
.Xr open 2 ,
.Xr fdopen 3 ,
diff --git a/lib/libc/stdio/ferror.c b/lib/libc/stdio/ferror.c
index bf3b2deaf299..15f6f5a69e25 100644
--- a/lib/libc/stdio/ferror.c
+++ b/lib/libc/stdio/ferror.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
diff --git a/lib/libc/stdio/fflush.3 b/lib/libc/stdio/fflush.3
index 9ca57e749d84..c311b7f473c5 100644
--- a/lib/libc/stdio/fflush.3
+++ b/lib/libc/stdio/fflush.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fflush.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd May 1, 2020
.Dt FFLUSH 3
.Os
diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c
index a7f9348def50..84cba7619866 100644
--- a/lib/libc/stdio/fflush.c
+++ b/lib/libc/stdio/fflush.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdio.h>
@@ -103,11 +99,11 @@ __weak_reference(__fflush, fflush_unlocked);
int
__sflush(FILE *fp)
{
- unsigned char *p, *old_p;
- int n, t, old_w;
+ unsigned char *p;
+ int n, f, t;
- t = fp->_flags;
- if ((t & __SWR) == 0)
+ f = fp->_flags;
+ if ((f & __SWR) == 0)
return (0);
if ((p = fp->_bf._base) == NULL)
@@ -119,26 +115,19 @@ __sflush(FILE *fp)
* Set these immediately to avoid problems with longjmp and to allow
* exchange buffering (via setvbuf) in user write function.
*/
- old_p = fp->_p;
fp->_p = p;
- old_w = fp->_w;
- fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
+ fp->_w = f & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
for (; n > 0; n -= t, p += t) {
t = _swrite(fp, (char *)p, n);
if (t <= 0) {
- /* Reset _p and _w. */
- if (p > fp->_p) {
+ if (p > fp->_p)
/* Some was written. */
memmove(fp->_p, p, n);
- fp->_p += n;
- if ((fp->_flags & (__SLBF | __SNBF)) == 0)
- fp->_w -= n;
- /* conditional to handle setvbuf */
- } else if (p == fp->_p && errno == EINTR) {
- fp->_p = old_p;
- fp->_w = old_w;
- }
+ /* Reset _p and _w. */
+ fp->_p += n;
+ if ((fp->_flags & __SNBF) == 0)
+ fp->_w -= n;
fp->_flags |= __SERR;
return (EOF);
}
diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c
index 2919fe31b826..d05d9de3cc9f 100644
--- a/lib/libc/stdio/fgetc.c
+++ b/lib/libc/stdio/fgetc.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
diff --git a/lib/libc/stdio/fgetln.3 b/lib/libc/stdio/fgetln.3
index 007a73c37213..09fd014cde00 100644
--- a/lib/libc/stdio/fgetln.3
+++ b/lib/libc/stdio/fgetln.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94
-.\"
.Dd June 11, 2020
.Dt FGETLN 3
.Os
diff --git a/lib/libc/stdio/fgetln.c b/lib/libc/stdio/fgetln.c
index a66919711050..ad37a2e15c61 100644
--- a/lib/libc/stdio/fgetln.c
+++ b/lib/libc/stdio/fgetln.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <limits.h>
diff --git a/lib/libc/stdio/fgetpos.c b/lib/libc/stdio/fgetpos.c
index 4cbd5e1f6e76..930e26b762f5 100644
--- a/lib/libc/stdio/fgetpos.c
+++ b/lib/libc/stdio/fgetpos.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
int
diff --git a/lib/libc/stdio/fgets.3 b/lib/libc/stdio/fgets.3
index 6533c218a789..1ae5888f5983 100644
--- a/lib/libc/stdio/fgets.3
+++ b/lib/libc/stdio/fgets.3
@@ -29,9 +29,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fgets.3 8.1 (Berkeley) 6/4/93
-.\"
-.Dd April 2, 2022
+.Dd December 6, 2024
.Dt FGETS 3
.Os
.Sh NAME
@@ -44,6 +42,7 @@
.In stdio.h
.Ft char *
.Fn fgets "char * restrict str" "int size" "FILE * restrict stream"
+.Fd #define __STDC_WANT_LIB_EXT1__ 1
.Ft char *
.Fn gets_s "char *str" "rsize_t size"
.Sh DESCRIPTION
diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c
index adac5dc3d6a0..504338c012a2 100644
--- a/lib/libc/stdio/fgets.c
+++ b/lib/libc/stdio/fgets.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdio.h>
@@ -44,6 +40,8 @@ static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93";
#include "local.h"
#include "libc_private.h"
+#undef fgets /* _FORTIFY_SOURCE */
+
/*
* Read at most n-1 characters from the given file.
* Stop when a newline has been read, or the count runs out.
diff --git a/lib/libc/stdio/fgetwc.c b/lib/libc/stdio/fgetwc.c
index 949d93f67007..53d1f9564fe2 100644
--- a/lib/libc/stdio/fgetwc.c
+++ b/lib/libc/stdio/fgetwc.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/fgetwln.3 b/lib/libc/stdio/fgetwln.3
index d84a2740837f..9e863a1bd460 100644
--- a/lib/libc/stdio/fgetwln.3
+++ b/lib/libc/stdio/fgetwln.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94
-.\"
.Dd July 16, 2004
.Dt FGETWLN 3
.Os
diff --git a/lib/libc/stdio/fgetwln.c b/lib/libc/stdio/fgetwln.c
index 8d74f9d8f3da..3a8e12b30c07 100644
--- a/lib/libc/stdio/fgetwln.c
+++ b/lib/libc/stdio/fgetwln.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/fgetws.3 b/lib/libc/stdio/fgetws.3
index 77c0ba4c9e97..5da940525d24 100644
--- a/lib/libc/stdio/fgetws.3
+++ b/lib/libc/stdio/fgetws.3
@@ -28,8 +28,6 @@
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
-.\"
-.\" @(#)fgets.3 8.1 (Berkeley) 6/4/93
.\" FreeBSD: src/lib/libc/stdio/fgets.3,v 1.16 2002/05/31 05:01:17 archie Exp
.\"
.Dd August 6, 2002
diff --git a/lib/libc/stdio/fgetws.c b/lib/libc/stdio/fgetws.c
index 1eaeed708ef1..1aa94e50f186 100644
--- a/lib/libc/stdio/fgetws.c
+++ b/lib/libc/stdio/fgetws.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/fileno.c b/lib/libc/stdio/fileno.c
index 272a46abb74a..0ba242c1aed3 100644
--- a/lib/libc/stdio/fileno.c
+++ b/lib/libc/stdio/fileno.c
@@ -32,11 +32,8 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
+#include <errno.h>
#include <stdio.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -44,14 +41,29 @@ static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93";
#undef fileno
#undef fileno_unlocked
+static int
+__fileno_impl(FILE *fp)
+{
+ int fd;
+
+ fd = fp->_file;
+ if (fd == -1)
+ errno = EBADF;
+ return (fd);
+}
+
int
fileno(FILE *fp)
{
int fd;
- FLOCKFILE(fp);
- fd = __sfileno(fp);
- FUNLOCKFILE(fp);
+ if (__isthreaded) {
+ FLOCKFILE(fp);
+ fd = __fileno_impl(fp);
+ FUNLOCKFILE(fp);
+ } else {
+ fd = __fileno_impl(fp);
+ }
return (fd);
}
@@ -59,6 +71,5 @@ fileno(FILE *fp)
int
fileno_unlocked(FILE *fp)
{
-
- return (__sfileno(fp));
+ return (__fileno_impl(fp));
}
diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c
index cf4eccf8807e..3729adf8d8dc 100644
--- a/lib/libc/stdio/findfp.c
+++ b/lib/libc/stdio/findfp.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)findfp.c 8.2 (Berkeley) 1/4/94";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <machine/atomic.h>
#include <unistd.h>
diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c
index 04b67f127986..ef7ee38b8e2a 100644
--- a/lib/libc/stdio/flags.c
+++ b/lib/libc/stdio/flags.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)flags.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/file.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/floatio.h b/lib/libc/stdio/floatio.h
index 4abf972f5f40..ef8c0fa84528 100644
--- a/lib/libc/stdio/floatio.h
+++ b/lib/libc/stdio/floatio.h
@@ -30,8 +30,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * @(#)floatio.h 8.1 (Berkeley) 6/4/93
*/
/*
diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c
index 295592ac896f..dc323921d93a 100644
--- a/lib/libc/stdio/fmemopen.c
+++ b/lib/libc/stdio/fmemopen.c
@@ -25,7 +25,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
@@ -75,10 +74,9 @@ fmemopen(void * __restrict buf, size_t size, const char * __restrict mode)
}
/*
- * There's no point in requiring an automatically allocated buffer
- * in write-only mode.
+ * An automatically allocated buffer is only allowed in read-write mode.
*/
- if (!(flags & O_RDWR) && buf == NULL) {
+ if ((flags & O_ACCMODE) != O_RDWR && buf == NULL) {
errno = EINVAL;
return (NULL);
}
@@ -137,9 +135,10 @@ fmemopen(void * __restrict buf, size_t size, const char * __restrict mode)
break;
}
+ /* Disable read in O_WRONLY mode, and write in O_RDONLY mode. */
f = funopen(ck,
- flags & O_WRONLY ? NULL : fmemopen_read,
- flags & O_RDONLY ? NULL : fmemopen_write,
+ (flags & O_ACCMODE) == O_WRONLY ? NULL : fmemopen_read,
+ (flags & O_ACCMODE) == O_RDONLY ? NULL : fmemopen_write,
fmemopen_seek, fmemopen_close);
if (f == NULL) {
diff --git a/lib/libc/stdio/fopen.3 b/lib/libc/stdio/fopen.3
index 6f03443caf42..3d69dc1fec13 100644
--- a/lib/libc/stdio/fopen.3
+++ b/lib/libc/stdio/fopen.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fopen.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd September 1, 2023
.Dt FOPEN 3
.Os
diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c
index 2f2de15345c4..f76f0fb09087 100644
--- a/lib/libc/stdio/fopen.c
+++ b/lib/libc/stdio/fopen.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/lib/libc/stdio/fopencookie.c b/lib/libc/stdio/fopencookie.c
index 9c295ff7bfed..ef49d3d10f16 100644
--- a/lib/libc/stdio/fopencookie.c
+++ b/lib/libc/stdio/fopencookie.c
@@ -24,7 +24,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <sys/fcntl.h>
#include <errno.h>
diff --git a/lib/libc/stdio/fprintf.c b/lib/libc/stdio/fprintf.c
index c1df55872aa3..9b2cbb0849a7 100644
--- a/lib/libc/stdio/fprintf.c
+++ b/lib/libc/stdio/fprintf.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fprintf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
#include <stdarg.h>
#include "xlocale_private.h"
diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c
index 4ca6a5373050..0914b977ad49 100644
--- a/lib/libc/stdio/fpurge.c
+++ b/lib/libc/stdio/fpurge.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c
index 54476b8f2bea..3d8409c465b8 100644
--- a/lib/libc/stdio/fputc.c
+++ b/lib/libc/stdio/fputc.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
diff --git a/lib/libc/stdio/fputs.3 b/lib/libc/stdio/fputs.3
index c9e0ca3f30ed..dc85113dd791 100644
--- a/lib/libc/stdio/fputs.3
+++ b/lib/libc/stdio/fputs.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fputs.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd January 23, 2020
.Dt FPUTS 3
.Os
diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c
index 1b611d50017b..8bafa23d4131 100644
--- a/lib/libc/stdio/fputs.c
+++ b/lib/libc/stdio/fputs.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <limits.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/fputwc.c b/lib/libc/stdio/fputwc.c
index 197c57cc374a..7955a4e811b2 100644
--- a/lib/libc/stdio/fputwc.c
+++ b/lib/libc/stdio/fputwc.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <limits.h>
diff --git a/lib/libc/stdio/fputws.3 b/lib/libc/stdio/fputws.3
index cdf01e22f96b..920d0e0cf658 100644
--- a/lib/libc/stdio/fputws.3
+++ b/lib/libc/stdio/fputws.3
@@ -28,8 +28,6 @@
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
-.\"
-.\" @(#)fputs.3 8.1 (Berkeley) 6/4/93
.\" FreeBSD: src/lib/libc/stdio/fputs.3,v 1.8 2001/10/01 16:08:59 ru Exp
.\"
.Dd August 6, 2002
diff --git a/lib/libc/stdio/fputws.c b/lib/libc/stdio/fputws.c
index c77393886e72..105fc426cb9c 100644
--- a/lib/libc/stdio/fputws.c
+++ b/lib/libc/stdio/fputws.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <limits.h>
diff --git a/lib/libc/stdio/fread.3 b/lib/libc/stdio/fread.3
index cc278781acf5..dfa7c8df18a3 100644
--- a/lib/libc/stdio/fread.3
+++ b/lib/libc/stdio/fread.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fread.3 8.2 (Berkeley) 3/8/94
-.\"
.Dd April 2, 2022
.Dt FREAD 3
.Os
diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c
index 13776382fbb7..65d9ecf94366 100644
--- a/lib/libc/stdio/fread.c
+++ b/lib/libc/stdio/fread.c
@@ -32,15 +32,12 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
+#include <ssp/ssp.h>
#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"
@@ -50,7 +47,8 @@ static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93";
*/
size_t
-fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp)
+__ssp_real(fread)(void * __restrict buf, size_t size, size_t count,
+ FILE * __restrict fp)
{
size_t ret;
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c
index 2f3f96c1d92a..048fd30b3193 100644
--- a/lib/libc/stdio/freopen.c
+++ b/lib/libc/stdio/freopen.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)freopen.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -59,7 +55,7 @@ freopen(const char * __restrict file, const char * __restrict mode,
FILE * __restrict fp)
{
int f;
- int dflags, flags, isopen, oflags, sverrno, wantfd;
+ int dflags, fdflags, flags, isopen, oflags, sverrno, wantfd;
if ((flags = __sflags(mode, &oflags)) == 0) {
sverrno = errno;
@@ -117,8 +113,12 @@ freopen(const char * __restrict file, const char * __restrict mode,
(void) ftruncate(fp->_file, (off_t)0);
if (!(oflags & O_APPEND))
(void) _sseek(fp, (fpos_t)0, SEEK_SET);
- if (oflags & O_CLOEXEC)
- (void) _fcntl(fp->_file, F_SETFD, FD_CLOEXEC);
+ if ((oflags & O_CLOEXEC) != 0) {
+ fdflags = _fcntl(fp->_file, F_GETFD, 0);
+ if (fdflags != -1 && (fdflags & FD_CLOEXEC) == 0)
+ (void) _fcntl(fp->_file, F_SETFD,
+ fdflags | FD_CLOEXEC);
+ }
f = fp->_file;
isopen = 0;
wantfd = -1;
diff --git a/lib/libc/stdio/fscanf.c b/lib/libc/stdio/fscanf.c
index f274cb98ef3c..f2dc9cf6e787 100644
--- a/lib/libc/stdio/fscanf.c
+++ b/lib/libc/stdio/fscanf.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fscanf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <stdarg.h>
diff --git a/lib/libc/stdio/fseek.3 b/lib/libc/stdio/fseek.3
index a1be3149a6ca..521ded3a09d7 100644
--- a/lib/libc/stdio/fseek.3
+++ b/lib/libc/stdio/fseek.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fseek.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd April 2, 2022
.Dt FSEEK 3
.Os
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c
index 21f1079b6458..c19d682ec667 100644
--- a/lib/libc/stdio/fseek.c
+++ b/lib/libc/stdio/fseek.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/lib/libc/stdio/fsetpos.c b/lib/libc/stdio/fsetpos.c
index 4f985e249a32..caca58dad710 100644
--- a/lib/libc/stdio/fsetpos.c
+++ b/lib/libc/stdio/fsetpos.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index 4cb038df1d76..c74ae03ec7db 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/types.h>
#include <errno.h>
diff --git a/lib/libc/stdio/funopen.3 b/lib/libc/stdio/funopen.3
index cbc1500931e3..f3234af229f7 100644
--- a/lib/libc/stdio/funopen.3
+++ b/lib/libc/stdio/funopen.3
@@ -27,8 +27,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)funopen.3 8.1 (Berkeley) 6/9/93
-.\"
.Dd May 9, 2016
.Dt FUNOPEN 3
.Os
diff --git a/lib/libc/stdio/funopen.c b/lib/libc/stdio/funopen.c
index 376721d33eb3..87a3179f5908 100644
--- a/lib/libc/stdio/funopen.c
+++ b/lib/libc/stdio/funopen.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
#include <errno.h>
diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c
index 81e7ba89a644..2d5aaf3c5dc8 100644
--- a/lib/libc/stdio/fvwrite.c
+++ b/lib/libc/stdio/fvwrite.c
@@ -32,11 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -53,7 +48,6 @@ int
__sfvwrite(FILE *fp, struct __suio *uio)
{
size_t len;
- unsigned char *old_p;
char *p;
struct __siov *iov;
int w, s;
@@ -137,12 +131,8 @@ __sfvwrite(FILE *fp, struct __suio *uio)
COPY(w);
/* fp->_w -= w; */ /* unneeded */
fp->_p += w;
- old_p = fp->_p;
- if (__fflush(fp) == EOF) {
- if (old_p == fp->_p && errno == EINTR)
- fp->_p -= w;
+ if (__fflush(fp))
goto err;
- }
} else if (len >= (w = fp->_bf._size)) {
/* write directly */
w = _swrite(fp, p, w);
@@ -181,12 +171,8 @@ __sfvwrite(FILE *fp, struct __suio *uio)
COPY(w);
/* fp->_w -= w; */
fp->_p += w;
- old_p = fp->_p;
- if (__fflush(fp) == EOF) {
- if (old_p == fp->_p && errno == EINTR)
- fp->_p -= w;
+ if (__fflush(fp))
goto err;
- }
} else if (s >= (w = fp->_bf._size)) {
w = _swrite(fp, p, w);
if (w <= 0)
diff --git a/lib/libc/stdio/fvwrite.h b/lib/libc/stdio/fvwrite.h
index f9e89dfd2454..ce6dc67a6ed2 100644
--- a/lib/libc/stdio/fvwrite.h
+++ b/lib/libc/stdio/fvwrite.h
@@ -30,8 +30,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * @(#)fvwrite.h 8.1 (Berkeley) 6/4/93
*/
/*
diff --git a/lib/libc/stdio/fwalk.c b/lib/libc/stdio/fwalk.c
index 0e2c48234a75..fc93ee075051 100644
--- a/lib/libc/stdio/fwalk.c
+++ b/lib/libc/stdio/fwalk.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <stdio.h>
#include "local.h"
diff --git a/lib/libc/stdio/fwide.c b/lib/libc/stdio/fwide.c
index d413d4518d2a..86eb5b5299f8 100644
--- a/lib/libc/stdio/fwide.c
+++ b/lib/libc/stdio/fwide.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/fwprintf.c b/lib/libc/stdio/fwprintf.c
index 7550bb8eb69b..f2a28ad4b08a 100644
--- a/lib/libc/stdio/fwprintf.c
+++ b/lib/libc/stdio/fwprintf.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c
index d0663c93a2a2..bbe2afb683c3 100644
--- a/lib/libc/stdio/fwrite.c
+++ b/lib/libc/stdio/fwrite.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdint.h>
diff --git a/lib/libc/stdio/fwscanf.c b/lib/libc/stdio/fwscanf.c
index b0f2d02e748d..833a31a8f1b9 100644
--- a/lib/libc/stdio/fwscanf.c
+++ b/lib/libc/stdio/fwscanf.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/getc.3 b/lib/libc/stdio/getc.3
index 86852aea7f21..02f0f2f06f4a 100644
--- a/lib/libc/stdio/getc.3
+++ b/lib/libc/stdio/getc.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getc.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd April 4, 2020
.Dt GETC 3
.Os
diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c
index 61fb4fe88c88..61b184115004 100644
--- a/lib/libc/stdio/getc.c
+++ b/lib/libc/stdio/getc.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c
index 197e135f8cbf..02ac4893b5e8 100644
--- a/lib/libc/stdio/getchar.c
+++ b/lib/libc/stdio/getchar.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
/*
* A subroutine version of the macro getchar.
*/
diff --git a/lib/libc/stdio/getdelim.c b/lib/libc/stdio/getdelim.c
index 5a1a3cd3dfb8..7543fefc3a57 100644
--- a/lib/libc/stdio/getdelim.c
+++ b/lib/libc/stdio/getdelim.c
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/param.h>
#include <errno.h>
diff --git a/lib/libc/stdio/getline.c b/lib/libc/stdio/getline.c
index 7e62829ecf4c..371341d6ea8e 100644
--- a/lib/libc/stdio/getline.c
+++ b/lib/libc/stdio/getline.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdio.h>
ssize_t
diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c
index 7f3e165f0bff..b92ce188e2b5 100644
--- a/lib/libc/stdio/gets.c
+++ b/lib/libc/stdio/gets.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)gets.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <unistd.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/gets_s.c b/lib/libc/stdio/gets_s.c
index cf839f8abed9..41e379507483 100644
--- a/lib/libc/stdio/gets_s.c
+++ b/lib/libc/stdio/gets_s.c
@@ -34,12 +34,12 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
+#include <ssp/ssp.h>
#include "un-namespace.h"
#include "libc_private.h"
#include "local.h"
@@ -78,7 +78,7 @@ _gets_s(char *buf, rsize_t n)
/* ISO/IEC 9899:2011 K.3.7.4.1 */
char *
-gets_s(char *buf, rsize_t n)
+__ssp_real(gets_s)(char *buf, rsize_t n)
{
char *ret;
if (buf == NULL) {
diff --git a/lib/libc/stdio/getw.c b/lib/libc/stdio/getw.c
index f48395d7dc7c..2986220461e9 100644
--- a/lib/libc/stdio/getw.c
+++ b/lib/libc/stdio/getw.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getw.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
int
diff --git a/lib/libc/stdio/getwc.3 b/lib/libc/stdio/getwc.3
index 2efa0c4de113..734e5c0b4259 100644
--- a/lib/libc/stdio/getwc.3
+++ b/lib/libc/stdio/getwc.3
@@ -31,8 +31,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getc.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd March 3, 2004
.Dt GETWC 3
.Os
diff --git a/lib/libc/stdio/getwc.c b/lib/libc/stdio/getwc.c
index ccac10db228f..ae56ff7d6dd3 100644
--- a/lib/libc/stdio/getwc.c
+++ b/lib/libc/stdio/getwc.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/getwchar.c b/lib/libc/stdio/getwchar.c
index 9294a952357e..335a975ba6e8 100644
--- a/lib/libc/stdio/getwchar.c
+++ b/lib/libc/stdio/getwchar.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/glue.h b/lib/libc/stdio/glue.h
index 3fcb52316133..948ef537e5d6 100644
--- a/lib/libc/stdio/glue.h
+++ b/lib/libc/stdio/glue.h
@@ -30,8 +30,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * @(#)glue.h 8.1 (Berkeley) 6/4/93
*/
/*
diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h
index a5c465bcdcba..da08fa246833 100644
--- a/lib/libc/stdio/local.h
+++ b/lib/libc/stdio/local.h
@@ -35,8 +35,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * @(#)local.h 8.3 (Berkeley) 7/3/94
*/
#ifndef _STDIO_LOCAL_H
@@ -80,7 +78,7 @@ extern int __swsetup(FILE *);
extern int __sflags(const char *, int *);
extern int __ungetc(int, FILE *);
extern wint_t __ungetwc(wint_t, FILE *, locale_t);
-extern int __vfprintf(FILE *, locale_t, const char *, __va_list);
+extern int __vfprintf(FILE *, locale_t, int, const char *, __va_list);
extern int __vfscanf(FILE *, const char *, __va_list);
extern int __vfwprintf(FILE *, locale_t, const wchar_t *, __va_list);
extern int __vfwscanf(FILE * __restrict, locale_t, const wchar_t * __restrict,
diff --git a/lib/libc/stdio/makebuf.c b/lib/libc/stdio/makebuf.c
index f499651880ca..036682870cfa 100644
--- a/lib/libc/stdio/makebuf.c
+++ b/lib/libc/stdio/makebuf.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)makebuf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/lib/libc/stdio/mktemp.3 b/lib/libc/stdio/mktemp.3
index cfb6f79be251..8d38dd2cd57e 100644
--- a/lib/libc/stdio/mktemp.3
+++ b/lib/libc/stdio/mktemp.3
@@ -25,9 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)mktemp.3 8.1 (Berkeley) 6/4/93
-.\"
-.Dd July 29, 2019
+.Dd July 07, 2025
.Dt MKTEMP 3
.Os
.Sh NAME
@@ -65,7 +63,7 @@ The template may be any file name with some number of
.Ql X Ns s
appended
to it, for example
-.Pa /tmp/temp.XXXXXX .
+.Pa /tmp/temp.XXXXXXXXXX .
The trailing
.Ql X Ns s
are replaced with a
@@ -103,9 +101,10 @@ The permitted flags are
.Dv O_DIRECT ,
.Dv O_SHLOCK ,
.Dv O_EXLOCK ,
-.Dv O_SYNC
+.Dv O_SYNC ,
+.Dv O_CLOEXEC
and
-.Dv O_CLOEXEC .
+.Dv O_CLOFORK .
.Pp
The
.Fn mkstemps
@@ -118,7 +117,7 @@ and
respectively,
except they permit a suffix to exist in the template.
The template should be of the form
-.Pa /tmp/tmpXXXXXXsuffix .
+.Pa /tmp/tmpXXXXXXXXXXsuffix .
The
.Fn mkstemps
and
@@ -245,7 +244,7 @@ compilers were common.
For example, calling
.Fn mkstemp
with an argument of
-.Qq /tmp/tempfile.XXXXXX
+.Qq /tmp/tempfile.XXXXXXXXXX
will result in a core dump due to
.Fn mkstemp
attempting to modify the string constant that was given.
@@ -277,7 +276,10 @@ function is expected to conform to
and is not specified by
.St -p1003.1-2008 .
The
-.Fn mkostemp ,
+.Fn mkostemp
+function conforms to
+.St -p1003.1-2024 .
+The
.Fn mkstemps ,
.Fn mkostemps
and
diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c
index bbefc2b28cfd..a2f80ee7b0dd 100644
--- a/lib/libc/stdio/mktemp.c
+++ b/lib/libc/stdio/mktemp.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/param.h>
#include <sys/stat.h>
@@ -125,7 +121,7 @@ _gettemp(int dfd, char *path, int *doopen, int domkdir, int slen, int oflags)
if ((doopen != NULL && domkdir) || slen < 0 ||
(oflags & ~(O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC |
- O_CLOEXEC)) != 0) {
+ O_CLOEXEC | O_CLOFORK)) != 0) {
errno = EINVAL;
return (0);
}
diff --git a/lib/libc/stdio/open_memstream.c b/lib/libc/stdio/open_memstream.c
index 7dabc737db8c..371022adf6b3 100644
--- a/lib/libc/stdio/open_memstream.c
+++ b/lib/libc/stdio/open_memstream.c
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <assert.h>
#include <errno.h>
diff --git a/lib/libc/stdio/open_wmemstream.c b/lib/libc/stdio/open_wmemstream.c
index bc746ebf8073..213d61fcd4dd 100644
--- a/lib/libc/stdio/open_wmemstream.c
+++ b/lib/libc/stdio/open_wmemstream.c
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <assert.h>
#include <errno.h>
diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c
index a16820f83b26..36052e8a8689 100644
--- a/lib/libc/stdio/perror.c
+++ b/lib/libc/stdio/perror.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)perror.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/types.h>
#include <sys/uio.h>
diff --git a/lib/libc/stdio/printf-pos.c b/lib/libc/stdio/printf-pos.c
index 534ac9cd4b78..edbd4e379699 100644
--- a/lib/libc/stdio/printf-pos.c
+++ b/lib/libc/stdio/printf-pos.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
/*
* This is the code responsible for handling positional arguments
* (%m$ and %m$.n$) for vfprintf() and vfwprintf().
diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3
index 110851e2a421..b421a2a0985d 100644
--- a/lib/libc/stdio/printf.3
+++ b/lib/libc/stdio/printf.3
@@ -29,9 +29,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
-.\"
-.Dd August 21, 2023
+.Dd September 5, 2023
.Dt PRINTF 3
.Os
.Sh NAME
@@ -342,6 +340,8 @@ conversion:
.It Cm ll No (ell ell) Ta Vt "long long" Ta Vt "unsigned long long" Ta Vt "long long *"
.It Cm j Ta Vt intmax_t Ta Vt uintmax_t Ta Vt "intmax_t *"
.It Cm t Ta Vt ptrdiff_t Ta (see note) Ta Vt "ptrdiff_t *"
+.It Cm w Ns Ar N Ta Vt intN_t Ta Vt uintN_t Ta Vt "intN_t *"
+.It Cm wf Ns Ar N Ta Vt int_fastN_t Ta Vt uint_fastN_t Ta Vt "int_fastN_t *"
.It Cm z Ta (see note) Ta Vt size_t Ta (see note)
.It Cm q Em (deprecated) Ta Vt quad_t Ta Vt u_quad_t Ta Vt "quad_t *"
.El
@@ -828,6 +828,12 @@ and
.Fn vdprintf
conform to
.St -p1003.1-2008 .
+The functions
+.Fn asprintf
+and
+.Fn vasprintf
+conform to
+.St -p1003.1-2024 .
.Sh HISTORY
The functions
.Fn asprintf
diff --git a/lib/libc/stdio/printf.c b/lib/libc/stdio/printf.c
index 20e5b7b0e3cd..f67e3d51a398 100644
--- a/lib/libc/stdio/printf.c
+++ b/lib/libc/stdio/printf.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)printf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
#include <stdarg.h>
#include <xlocale.h>
diff --git a/lib/libc/stdio/printflocal.h b/lib/libc/stdio/printflocal.h
index 3594f75d0050..f3d0d3e9e216 100644
--- a/lib/libc/stdio/printflocal.h
+++ b/lib/libc/stdio/printflocal.h
@@ -49,6 +49,7 @@
#define PTRDIFFT 0x800 /* ptrdiff_t */
#define INTMAXT 0x1000 /* intmax_t */
#define CHARINT 0x2000 /* print char using int format */
+#define FASTINT 0x4000 /* int_fastN_t */
/*
* Macros for converting digits to letters and vice versa
diff --git a/lib/libc/stdio/putc.3 b/lib/libc/stdio/putc.3
index a010046f89ef..7bdf87e31769 100644
--- a/lib/libc/stdio/putc.3
+++ b/lib/libc/stdio/putc.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)putc.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd January 23, 2020
.Dt PUTC 3
.Os
diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c
index 54735da59527..6942239e0c78 100644
--- a/lib/libc/stdio/putc.c
+++ b/lib/libc/stdio/putc.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c
index dd8ea0271b94..87980ca0d052 100644
--- a/lib/libc/stdio/putchar.c
+++ b/lib/libc/stdio/putchar.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
diff --git a/lib/libc/stdio/puts.c b/lib/libc/stdio/puts.c
index b97807fe1255..f0cf58fab5b5 100644
--- a/lib/libc/stdio/puts.c
+++ b/lib/libc/stdio/puts.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)puts.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <string.h>
diff --git a/lib/libc/stdio/putw.c b/lib/libc/stdio/putw.c
index 7e7c87c99ba2..417030f13360 100644
--- a/lib/libc/stdio/putw.c
+++ b/lib/libc/stdio/putw.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)putw.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
diff --git a/lib/libc/stdio/putwc.3 b/lib/libc/stdio/putwc.3
index a4add5516175..6d09c575c022 100644
--- a/lib/libc/stdio/putwc.3
+++ b/lib/libc/stdio/putwc.3
@@ -31,8 +31,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)putc.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd March 3, 2004
.Dt PUTWC 3
.Os
diff --git a/lib/libc/stdio/putwc.c b/lib/libc/stdio/putwc.c
index 386023924440..435da69dec6a 100644
--- a/lib/libc/stdio/putwc.c
+++ b/lib/libc/stdio/putwc.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/putwchar.c b/lib/libc/stdio/putwchar.c
index 1c5ab256125a..f109a5f6b1dd 100644
--- a/lib/libc/stdio/putwchar.c
+++ b/lib/libc/stdio/putwchar.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/refill.c b/lib/libc/stdio/refill.c
index afc0526441aa..13d85d71af22 100644
--- a/lib/libc/stdio/refill.c
+++ b/lib/libc/stdio/refill.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/remove.3 b/lib/libc/stdio/remove.3
index ea1e82bf44a8..65ec58bf8b6d 100644
--- a/lib/libc/stdio/remove.3
+++ b/lib/libc/stdio/remove.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)remove.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd June 4, 1993
.Dt REMOVE 3
.Os
diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c
index 1e9dd98e1841..2c9ef61b12de 100644
--- a/lib/libc/stdio/remove.c
+++ b/lib/libc/stdio/remove.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c
index 8e6fc877c401..4bbd06976034 100644
--- a/lib/libc/stdio/rewind.c
+++ b/lib/libc/stdio/rewind.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rewind.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/rget.c b/lib/libc/stdio/rget.c
index a25ae3bdcea1..6f57ad4bc0f3 100644
--- a/lib/libc/stdio/rget.c
+++ b/lib/libc/stdio/rget.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rget.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
#include "local.h"
diff --git a/lib/libc/stdio/scanf.3 b/lib/libc/stdio/scanf.3
index 6cefdb133983..04664c5f2bbd 100644
--- a/lib/libc/stdio/scanf.3
+++ b/lib/libc/stdio/scanf.3
@@ -29,9 +29,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)scanf.3 8.2 (Berkeley) 12/11/93
-.\"
-.Dd August 21, 2023
+.Dd September 5, 2023
.Dt SCANF 3
.Os
.Sh NAME
@@ -217,6 +215,34 @@ and the next pointer is a pointer to a
.Vt ptrdiff_t
(rather than
.Vt int ) .
+.It Cm w Ns Ar N
+.Po
+where
+.Ar N
+is 8, 16, 32, or 64
+.Pc
+Indicates that the conversion will be one of
+.Cm bdioux
+or
+.Cm n
+and the next pointer is a pointer to a
+.Vt intN_t
+(rather than
+.Vt int ) .
+.It Cm wf Ns Ar N
+.Po
+where
+.Ar N
+is 8, 16, 32, or 64
+.Pc
+Indicates that the conversion will be one of
+.Cm bdioux
+or
+.Cm n
+and the next pointer is a pointer to a
+.Vt int_fastN_t
+(rather than
+.Vt int ) .
.It Cm z
Indicates that the conversion will be one of
.Cm bdioux
diff --git a/lib/libc/stdio/scanf.c b/lib/libc/stdio/scanf.c
index 1f84f9ab6542..c0bd4dfe0c01 100644
--- a/lib/libc/stdio/scanf.c
+++ b/lib/libc/stdio/scanf.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <stdarg.h>
diff --git a/lib/libc/stdio/setbuf.3 b/lib/libc/stdio/setbuf.3
index 0f17e52fa36f..027564cadfb4 100644
--- a/lib/libc/stdio/setbuf.3
+++ b/lib/libc/stdio/setbuf.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)setbuf.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd May 1, 2020
.Dt SETBUF 3
.Os
diff --git a/lib/libc/stdio/setbuf.c b/lib/libc/stdio/setbuf.c
index 71f0ee4ae7dc..ec3c741947d8 100644
--- a/lib/libc/stdio/setbuf.c
+++ b/lib/libc/stdio/setbuf.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setbuf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
#include "local.h"
diff --git a/lib/libc/stdio/setbuffer.c b/lib/libc/stdio/setbuffer.c
index 96c498f95e73..1838b84c1653 100644
--- a/lib/libc/stdio/setbuffer.c
+++ b/lib/libc/stdio/setbuffer.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setbuffer.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
void
diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c
index 9714818bc57f..554d558e73df 100644
--- a/lib/libc/stdio/setvbuf.c
+++ b/lib/libc/stdio/setvbuf.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setvbuf.c 8.2 (Berkeley) 11/16/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <limits.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c
index 45a9e3d7d622..da5032f10e6a 100644
--- a/lib/libc/stdio/snprintf.c
+++ b/lib/libc/stdio/snprintf.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
@@ -49,13 +45,16 @@ static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
#include "local.h"
+#undef snprintf /* _FORTIFY_SOURCE */
+
int
snprintf(char * __restrict str, size_t n, char const * __restrict fmt, ...)
{
+ FILE f = FAKE_FILE;
+ va_list ap;
size_t on;
+ int serrno = errno;
int ret;
- va_list ap;
- FILE f = FAKE_FILE;
on = n;
if (n != 0)
@@ -69,7 +68,7 @@ snprintf(char * __restrict str, size_t n, char const * __restrict fmt, ...)
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n;
- ret = __vfprintf(&f, __get_locale(), fmt, ap);
+ ret = __vfprintf(&f, __get_locale(), serrno, fmt, ap);
if (on > 0)
*f._p = '\0';
va_end(ap);
@@ -79,10 +78,11 @@ int
snprintf_l(char * __restrict str, size_t n, locale_t locale,
char const * __restrict fmt, ...)
{
+ FILE f = FAKE_FILE;
+ va_list ap;
size_t on;
+ int serrno = errno;
int ret;
- va_list ap;
- FILE f = FAKE_FILE;
FIX_LOCALE(locale);
on = n;
@@ -97,7 +97,7 @@ snprintf_l(char * __restrict str, size_t n, locale_t locale,
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n;
- ret = __vfprintf(&f, locale, fmt, ap);
+ ret = __vfprintf(&f, locale, serrno, fmt, ap);
if (on > 0)
*f._p = '\0';
va_end(ap);
diff --git a/lib/libc/stdio/sprintf.c b/lib/libc/stdio/sprintf.c
index c83efdb3f357..1cac21e98a46 100644
--- a/lib/libc/stdio/sprintf.c
+++ b/lib/libc/stdio/sprintf.c
@@ -37,16 +37,14 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)sprintf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include "local.h"
#include "xlocale_private.h"
+#undef sprintf /* _FORTIFY_SOURCE */
+
int
sprintf(char * __restrict str, char const * __restrict fmt, ...)
{
diff --git a/lib/libc/stdio/sscanf.c b/lib/libc/stdio/sscanf.c
index a06aac85a676..5dc9d2b13697 100644
--- a/lib/libc/stdio/sscanf.c
+++ b/lib/libc/stdio/sscanf.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)sscanf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
diff --git a/lib/libc/stdio/stdio.3 b/lib/libc/stdio/stdio.3
index 4447ca1b2b87..cbb8a49df2c6 100644
--- a/lib/libc/stdio/stdio.3
+++ b/lib/libc/stdio/stdio.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)stdio.3 8.7 (Berkeley) 4/19/94
-.\"
.Dd March 3, 2009
.Dt STDIO 3
.Os
@@ -254,7 +252,7 @@ library conforms to
.It "fgets get a line from a stream"
.It "fgetwc get next wide character from input stream"
.It "fgetws get a line of wide characters from a stream"
-.It "fileno check and reset stream status"
+.It "fileno map a stream pointer to a file descriptor"
.It "fopen stream open functions"
.It "fprintf formatted output conversion"
.It "fpurge flush a stream"
diff --git a/lib/libc/stdio/stdio.c b/lib/libc/stdio/stdio.c
index 40677118bea2..bffd7b1bfc3c 100644
--- a/lib/libc/stdio/stdio.c
+++ b/lib/libc/stdio/stdio.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <fcntl.h>
diff --git a/lib/libc/stdio/swprintf.c b/lib/libc/stdio/swprintf.c
index 4c4db2accb76..278f0e37d117 100644
--- a/lib/libc/stdio/swprintf.c
+++ b/lib/libc/stdio/swprintf.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/swscanf.c b/lib/libc/stdio/swscanf.c
index 20bf266dc772..9b91acf56685 100644
--- a/lib/libc/stdio/swscanf.c
+++ b/lib/libc/stdio/swscanf.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/tempnam.c b/lib/libc/stdio/tempnam.c
index 06dceec153bf..a3e6c6e3cf01 100644
--- a/lib/libc/stdio/tempnam.c
+++ b/lib/libc/stdio/tempnam.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <errno.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/tmpfile.c b/lib/libc/stdio/tmpfile.c
index afe45595eac8..d3331b8c2c2d 100644
--- a/lib/libc/stdio/tmpfile.c
+++ b/lib/libc/stdio/tmpfile.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/types.h>
#include <signal.h>
diff --git a/lib/libc/stdio/tmpnam.3 b/lib/libc/stdio/tmpnam.3
index c5269a674278..3b9d93280e72 100644
--- a/lib/libc/stdio/tmpnam.3
+++ b/lib/libc/stdio/tmpnam.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)tmpnam.3 8.2 (Berkeley) 11/17/93
-.\"
.Dd August 7, 2020
.Dt TMPFILE 3
.Os
diff --git a/lib/libc/stdio/tmpnam.c b/lib/libc/stdio/tmpnam.c
index 8fc057dea868..fab4253e2834 100644
--- a/lib/libc/stdio/tmpnam.c
+++ b/lib/libc/stdio/tmpnam.c
@@ -32,14 +32,11 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)tmpnam.c 8.3 (Berkeley) 3/28/94";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
+#include <ssp/ssp.h>
__warn_references(tmpnam,
"warning: tmpnam() possibly used unsafely; consider using mkstemp()");
@@ -47,7 +44,7 @@ __warn_references(tmpnam,
extern char *_mktemp(char *);
char *
-tmpnam(char *s)
+__ssp_real(tmpnam)(char *s)
{
static u_long tmpcount;
static char buf[L_tmpnam];
diff --git a/lib/libc/stdio/ungetc.3 b/lib/libc/stdio/ungetc.3
index 9ce4712551c0..946eceed9428 100644
--- a/lib/libc/stdio/ungetc.3
+++ b/lib/libc/stdio/ungetc.3
@@ -29,8 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)ungetc.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd June 4, 1993
.Dt UNGETC 3
.Os
diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c
index d5c91626dfa1..b494d462a19a 100644
--- a/lib/libc/stdio/ungetc.c
+++ b/lib/libc/stdio/ungetc.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libc/stdio/ungetwc.3 b/lib/libc/stdio/ungetwc.3
index 2b7427e99ccf..e5d5560417a0 100644
--- a/lib/libc/stdio/ungetwc.3
+++ b/lib/libc/stdio/ungetwc.3
@@ -31,8 +31,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)ungetc.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd March 3, 2004
.Dt UNGETWC 3
.Os
diff --git a/lib/libc/stdio/ungetwc.c b/lib/libc/stdio/ungetwc.c
index a4c71d012be0..0a72b6ea1705 100644
--- a/lib/libc/stdio/ungetwc.c
+++ b/lib/libc/stdio/ungetwc.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <limits.h>
diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c
index 2e5f8dd4107a..62d8f09fc954 100644
--- a/lib/libc/stdio/vasprintf.c
+++ b/lib/libc/stdio/vasprintf.c
@@ -34,10 +34,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-#include <errno.h>
#include "xlocale_private.h"
#include "local.h"
@@ -45,6 +44,7 @@ int
vasprintf_l(char **str, locale_t locale, const char *fmt, __va_list ap)
{
FILE f = FAKE_FILE;
+ int serrno = errno;
int ret;
FIX_LOCALE(locale);
@@ -56,7 +56,7 @@ vasprintf_l(char **str, locale_t locale, const char *fmt, __va_list ap)
return (-1);
}
f._bf._size = f._w = 127; /* Leave room for the NUL */
- ret = __vfprintf(&f, locale, fmt, ap);
+ ret = __vfprintf(&f, locale, serrno, fmt, ap);
if (ret < 0) {
free(f._bf._base);
*str = NULL;
diff --git a/lib/libc/stdio/vdprintf.c b/lib/libc/stdio/vdprintf.c
index a84efaa14b4d..39fb55420953 100644
--- a/lib/libc/stdio/vdprintf.c
+++ b/lib/libc/stdio/vdprintf.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <limits.h>
@@ -47,6 +46,7 @@ vdprintf(int fd, const char * __restrict fmt, va_list ap)
{
FILE f = FAKE_FILE;
unsigned char buf[BUFSIZ];
+ int serrno = errno;
int ret;
if (fd > SHRT_MAX) {
@@ -63,7 +63,7 @@ vdprintf(int fd, const char * __restrict fmt, va_list ap)
f._bf._base = buf;
f._bf._size = sizeof(buf);
- if ((ret = __vfprintf(&f, __get_locale(), fmt, ap)) < 0)
+ if ((ret = __vfprintf(&f, __get_locale(), serrno, fmt, ap)) < 0)
return (ret);
return (__fflush(&f) ? EOF : ret);
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index 5e5a9b5e31c1..2dc8d9022179 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
/*
* Actual printf innards.
*
@@ -72,7 +68,8 @@ static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
#include "printflocal.h"
static int __sprint(FILE *, struct __suio *, locale_t);
-static int __sbprintf(FILE *, locale_t, const char *, va_list) __printflike(3, 0)
+static int __sbprintf(FILE *, locale_t, int, const char *, va_list)
+ __printflike(4, 0)
__noinline;
static char *__wcsconv(wchar_t *, int);
@@ -173,7 +170,7 @@ __sprint(FILE *fp, struct __suio *uio, locale_t locale)
* worries about ungetc buffers and so forth.
*/
static int
-__sbprintf(FILE *fp, locale_t locale, const char *fmt, va_list ap)
+__sbprintf(FILE *fp, locale_t locale, int serrno, const char *fmt, va_list ap)
{
int ret;
FILE fake = FAKE_FILE;
@@ -197,7 +194,7 @@ __sbprintf(FILE *fp, locale_t locale, const char *fmt, va_list ap)
fake._lbfsize = 0; /* not actually used, but Just In Case */
/* do the work, then copy any error status */
- ret = __vfprintf(&fake, locale, fmt, ap);
+ ret = __vfprintf(&fake, locale, serrno, fmt, ap);
if (ret >= 0 && __fflush(&fake))
ret = EOF;
if (fake._flags & __SERR)
@@ -269,8 +266,9 @@ __wcsconv(wchar_t *wcsarg, int prec)
*/
int
vfprintf_l(FILE * __restrict fp, locale_t locale, const char * __restrict fmt0,
- va_list ap)
+ va_list ap)
{
+ int serrno = errno;
int ret;
FIX_LOCALE(locale);
@@ -278,9 +276,9 @@ vfprintf_l(FILE * __restrict fp, locale_t locale, const char * __restrict fmt0,
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
fp->_file >= 0)
- ret = __sbprintf(fp, locale, fmt0, ap);
+ ret = __sbprintf(fp, locale, serrno, fmt0, ap);
else
- ret = __vfprintf(fp, locale, fmt0, ap);
+ ret = __vfprintf(fp, locale, serrno, fmt0, ap);
FUNLOCKFILE_CANCELSAFE();
return (ret);
}
@@ -293,19 +291,15 @@ vfprintf(FILE * __restrict fp, const char * __restrict fmt0, va_list ap)
/*
* The size of the buffer we use as scratch space for integer
* conversions, among other things. We need enough space to
- * write a uintmax_t in octal (plus one byte).
+ * write a uintmax_t in binary.
*/
-#if UINTMAX_MAX <= UINT64_MAX
-#define BUF 32
-#else
-#error "BUF must be large enough to format a uintmax_t"
-#endif
+#define BUF (sizeof(uintmax_t) * CHAR_BIT)
/*
* Non-MT-safe version
*/
int
-__vfprintf(FILE *fp, locale_t locale, const char *fmt0, va_list ap)
+__vfprintf(FILE *fp, locale_t locale, int serrno, const char *fmt0, va_list ap)
{
char *fmt; /* format string */
int ch; /* character from fmt */
@@ -315,7 +309,8 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0, va_list ap)
int ret; /* return value accumulator */
int width; /* width from format (%8d), or 0 */
int prec; /* precision from format; <0 for N/A */
- int saved_errno;
+ int error;
+ char errnomsg[NL_TEXTMAX];
char sign; /* sign prefix (' ', '+', '-', or \0) */
struct grouping_state gs; /* thousands' grouping info */
@@ -451,8 +446,6 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0, va_list ap)
val = GETARG (int); \
}
- if (__use_xprintf == 0 && getenv("USE_XPRINTF"))
- __use_xprintf = 1;
if (__use_xprintf > 0)
return (__xvprintf(fp, fmt0, ap));
@@ -465,7 +458,6 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0, va_list ap)
savserr = fp->_flags & __SERR;
fp->_flags &= ~__SERR;
- saved_errno = errno;
convbuf = NULL;
fmt = (char *)fmt0;
argtable = NULL;
@@ -610,6 +602,49 @@ reswitch: switch (ch) {
case 't':
flags |= PTRDIFFT;
goto rflag;
+ case 'w':
+ /*
+ * Fixed-width integer types. On all platforms we
+ * support, int8_t is equivalent to char, int16_t
+ * is equivalent to short, int32_t is equivalent
+ * to int, int64_t is equivalent to long long int.
+ * Furthermore, int_fast8_t, int_fast16_t and
+ * int_fast32_t are equivalent to int, and
+ * int_fast64_t is equivalent to long long int.
+ */
+ flags &= ~(CHARINT|SHORTINT|LONGINT|LLONGINT|INTMAXT);
+ if (fmt[0] == 'f') {
+ flags |= FASTINT;
+ fmt++;
+ } else {
+ flags &= ~FASTINT;
+ }
+ if (fmt[0] == '8') {
+ if (!(flags & FASTINT))
+ flags |= CHARINT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 1;
+ } else if (fmt[0] == '1' && fmt[1] == '6') {
+ if (!(flags & FASTINT))
+ flags |= SHORTINT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '3' && fmt[1] == '2') {
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '6' && fmt[1] == '4') {
+ flags |= LLONGINT;
+ fmt += 2;
+ } else {
+ if (flags & FASTINT) {
+ flags &= ~FASTINT;
+ fmt--;
+ }
+ goto invalid;
+ }
+ goto rflag;
case 'z':
flags |= SIZET;
goto rflag;
@@ -790,7 +825,9 @@ fp_common:
break;
#endif /* !NO_FLOATING_POINT */
case 'm':
- cp = strerror(saved_errno);
+ error = __strerror_rl(serrno, errnomsg,
+ sizeof(errnomsg), locale);
+ cp = error == 0 ? errnomsg : "<strerror failure>";
size = (prec >= 0) ? strnlen(cp, prec) : strlen(cp);
sign = '\0';
break;
@@ -932,6 +969,7 @@ number: if ((dprec = prec) >= 0)
default: /* "%?" prints ?, unless ? is NUL */
if (ch == '\0')
goto done;
+invalid:
/* pretend it was %c with argument ch */
cp = buf;
*cp = ch;
diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c
index 9727c9e70c34..a678710e1ecb 100644
--- a/lib/libc/stdio/vfscanf.c
+++ b/lib/libc/stdio/vfscanf.c
@@ -39,10 +39,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <ctype.h>
#include <inttypes.h>
@@ -75,6 +71,7 @@ static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
#define SUPPRESS 0x08 /* *: suppress assignment */
#define POINTER 0x10 /* p: void * (as hex) */
#define NOSKIP 0x20 /* [ or c: do not skip blanks */
+#define FASTINT 0x200 /* wfN: int_fastN_t */
#define LONGLONG 0x400 /* ll: long long (+ deprecated q: quad) */
#define INTMAXT 0x800 /* j: intmax_t */
#define PTRDIFFT 0x1000 /* t: ptrdiff_t */
@@ -555,6 +552,45 @@ literal:
case 't':
flags |= PTRDIFFT;
goto again;
+ case 'w':
+ /*
+ * Fixed-width integer types. On all platforms we
+ * support, int8_t is equivalent to char, int16_t
+ * is equivalent to short, int32_t is equivalent
+ * to int, int64_t is equivalent to long long int.
+ * Furthermore, int_fast8_t, int_fast16_t and
+ * int_fast32_t are equivalent to int, and
+ * int_fast64_t is equivalent to long long int.
+ */
+ flags &= ~(SHORTSHORT|SHORT|LONG|LONGLONG|SIZET|INTMAXT|PTRDIFFT);
+ if (fmt[0] == 'f') {
+ flags |= FASTINT;
+ fmt++;
+ } else {
+ flags &= ~FASTINT;
+ }
+ if (fmt[0] == '8') {
+ if (!(flags & FASTINT))
+ flags |= SHORTSHORT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 1;
+ } else if (fmt[0] == '1' && fmt[1] == '6') {
+ if (!(flags & FASTINT))
+ flags |= SHORT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '3' && fmt[1] == '2') {
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '6' && fmt[1] == '4') {
+ flags |= LONGLONG;
+ fmt += 2;
+ } else {
+ goto match_failure;
+ }
+ goto again;
case 'z':
flags |= SIZET;
goto again;
diff --git a/lib/libc/stdio/vfwprintf.c b/lib/libc/stdio/vfwprintf.c
index 259a86467ea7..0d77bd74567e 100644
--- a/lib/libc/stdio/vfwprintf.c
+++ b/lib/libc/stdio/vfwprintf.c
@@ -37,12 +37,6 @@
* SUCH DAMAGE.
*/
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#endif
-#include <sys/cdefs.h>
/*
* Actual wprintf innards.
*
@@ -375,13 +369,9 @@ vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, va_list ap)
/*
* The size of the buffer we use as scratch space for integer
* conversions, among other things. We need enough space to
- * write a uintmax_t in octal (plus one byte).
+ * write a uintmax_t in binary.
*/
-#if UINTMAX_MAX <= UINT64_MAX
-#define BUF 32
-#else
-#error "BUF must be large enough to format a uintmax_t"
-#endif
+#define BUF (sizeof(uintmax_t) * CHAR_BIT)
/*
* Non-MT-safe version
@@ -681,6 +671,49 @@ reswitch: switch (ch) {
case 't':
flags |= PTRDIFFT;
goto rflag;
+ case 'w':
+ /*
+ * Fixed-width integer types. On all platforms we
+ * support, int8_t is equivalent to char, int16_t
+ * is equivalent to short, int32_t is equivalent
+ * to int, int64_t is equivalent to long long int.
+ * Furthermore, int_fast8_t, int_fast16_t and
+ * int_fast32_t are equivalent to int, and
+ * int_fast64_t is equivalent to long long int.
+ */
+ flags &= ~(CHARINT|SHORTINT|LONGINT|LLONGINT|INTMAXT);
+ if (fmt[0] == 'f') {
+ flags |= FASTINT;
+ fmt++;
+ } else {
+ flags &= ~FASTINT;
+ }
+ if (fmt[0] == '8') {
+ if (!(flags & FASTINT))
+ flags |= CHARINT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 1;
+ } else if (fmt[0] == '1' && fmt[1] == '6') {
+ if (!(flags & FASTINT))
+ flags |= SHORTINT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '3' && fmt[1] == '2') {
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '6' && fmt[1] == '4') {
+ flags |= LLONGINT;
+ fmt += 2;
+ } else {
+ if (flags & FASTINT) {
+ flags &= ~FASTINT;
+ fmt--;
+ }
+ goto invalid;
+ }
+ goto rflag;
case 'z':
flags |= SIZET;
goto rflag;
@@ -993,6 +1026,7 @@ number: if ((dprec = prec) >= 0)
default: /* "%?" prints ?, unless ? is NUL */
if (ch == '\0')
goto done;
+invalid:
/* pretend it was %c with argument ch */
cp = buf;
*cp = ch;
diff --git a/lib/libc/stdio/vfwscanf.c b/lib/libc/stdio/vfwscanf.c
index b03c9dba0699..57206a8407d5 100644
--- a/lib/libc/stdio/vfwscanf.c
+++ b/lib/libc/stdio/vfwscanf.c
@@ -39,12 +39,6 @@
* SUCH DAMAGE.
*/
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#endif
-#include <sys/cdefs.h>
#include "namespace.h"
#include <ctype.h>
#include <inttypes.h>
@@ -73,6 +67,7 @@ static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
#define SUPPRESS 0x08 /* *: suppress assignment */
#define POINTER 0x10 /* p: void * (as hex) */
#define NOSKIP 0x20 /* [ or c: do not skip blanks */
+#define FASTINT 0x200 /* wfN: int_fastN_t */
#define LONGLONG 0x400 /* ll: long long (+ deprecated q: quad) */
#define INTMAXT 0x800 /* j: intmax_t */
#define PTRDIFFT 0x1000 /* t: ptrdiff_t */
@@ -539,6 +534,45 @@ literal:
case 't':
flags |= PTRDIFFT;
goto again;
+ case 'w':
+ /*
+ * Fixed-width integer types. On all platforms we
+ * support, int8_t is equivalent to char, int16_t
+ * is equivalent to short, int32_t is equivalent
+ * to int, int64_t is equivalent to long long int.
+ * Furthermore, int_fast8_t, int_fast16_t and
+ * int_fast32_t are equivalent to int, and
+ * int_fast64_t is equivalent to long long int.
+ */
+ flags &= ~(SHORTSHORT|SHORT|LONG|LONGLONG|SIZET|INTMAXT|PTRDIFFT);
+ if (fmt[0] == 'f') {
+ flags |= FASTINT;
+ fmt++;
+ } else {
+ flags &= ~FASTINT;
+ }
+ if (fmt[0] == '8') {
+ if (!(flags & FASTINT))
+ flags |= SHORTSHORT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 1;
+ } else if (fmt[0] == '1' && fmt[1] == '6') {
+ if (!(flags & FASTINT))
+ flags |= SHORT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '3' && fmt[1] == '2') {
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '6' && fmt[1] == '4') {
+ flags |= LONGLONG;
+ fmt += 2;
+ } else {
+ goto match_failure;
+ }
+ goto again;
case 'z':
flags |= SIZET;
goto again;
diff --git a/lib/libc/stdio/vprintf.c b/lib/libc/stdio/vprintf.c
index 604870b93b1e..f49f3d5daff0 100644
--- a/lib/libc/stdio/vprintf.c
+++ b/lib/libc/stdio/vprintf.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vprintf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
#include <xlocale.h>
diff --git a/lib/libc/stdio/vscanf.c b/lib/libc/stdio/vscanf.c
index 58fd2a455389..9011a44c8e25 100644
--- a/lib/libc/stdio/vscanf.c
+++ b/lib/libc/stdio/vscanf.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vscanf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c
index 8fc7f9fdf725..45e4fb529be7 100644
--- a/lib/libc/stdio/vsnprintf.c
+++ b/lib/libc/stdio/vsnprintf.c
@@ -37,24 +37,23 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include "local.h"
#include "xlocale_private.h"
+#undef vsnprintf /* _FORTIFY_SOURCE */
+
int
vsnprintf_l(char * __restrict str, size_t n, locale_t locale,
- const char * __restrict fmt, __va_list ap)
+ const char * __restrict fmt, __va_list ap)
{
+ FILE f = FAKE_FILE;
size_t on;
+ int serrno = errno;
int ret;
char dummy[2];
- FILE f = FAKE_FILE;
FIX_LOCALE(locale);
on = n;
@@ -75,7 +74,7 @@ vsnprintf_l(char * __restrict str, size_t n, locale_t locale,
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n;
- ret = __vfprintf(&f, locale, fmt, ap);
+ ret = __vfprintf(&f, locale, serrno, fmt, ap);
if (on > 0)
*f._p = '\0';
return (ret);
diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c
index 68a2f70469f4..23c18264fa50 100644
--- a/lib/libc/stdio/vsprintf.c
+++ b/lib/libc/stdio/vsprintf.c
@@ -37,27 +37,27 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vsprintf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <stdio.h>
+#include <errno.h>
#include <limits.h>
+#include <stdio.h>
#include "local.h"
#include "xlocale_private.h"
+#undef vsprintf /* _FORTIFY_SOURCE */
+
int
vsprintf_l(char * __restrict str, locale_t locale,
- const char * __restrict fmt, __va_list ap)
+ const char * __restrict fmt, __va_list ap)
{
- int ret;
FILE f = FAKE_FILE;
+ int serrno = errno;
+ int ret;
FIX_LOCALE(locale);
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = INT_MAX;
- ret = __vfprintf(&f, locale, fmt, ap);
+ ret = __vfprintf(&f, locale, serrno, fmt, ap);
*f._p = 0;
return (ret);
}
diff --git a/lib/libc/stdio/vsscanf.c b/lib/libc/stdio/vsscanf.c
index 0751f0e95b0b..f77928725f92 100644
--- a/lib/libc/stdio/vsscanf.c
+++ b/lib/libc/stdio/vsscanf.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <stdio.h>
#include <string.h>
#include "local.h"
diff --git a/lib/libc/stdio/vswprintf.c b/lib/libc/stdio/vswprintf.c
index db1b5d30d09d..e90a05c4cc14 100644
--- a/lib/libc/stdio/vswprintf.c
+++ b/lib/libc/stdio/vswprintf.c
@@ -34,10 +34,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-#if 0
-__FBSDID("FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.16 2002/08/21 16:19:57 mike Exp ");
-#endif
#include <errno.h>
#include <limits.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/vswscanf.c b/lib/libc/stdio/vswscanf.c
index ecdafbefdc75..be21f4a53f7b 100644
--- a/lib/libc/stdio/vswscanf.c
+++ b/lib/libc/stdio/vswscanf.c
@@ -37,13 +37,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-__FBSDID("FreeBSD: src/lib/libc/stdio/vsscanf.c,v 1.11 2002/08/21 16:19:57 mike Exp ");
-#endif
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
diff --git a/lib/libc/stdio/vwprintf.c b/lib/libc/stdio/vwprintf.c
index b0e9ac26d3c6..0647130f9732 100644
--- a/lib/libc/stdio/vwprintf.c
+++ b/lib/libc/stdio/vwprintf.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/vwscanf.c b/lib/libc/stdio/vwscanf.c
index e2e16ac91e53..b4906184e2c0 100644
--- a/lib/libc/stdio/vwscanf.c
+++ b/lib/libc/stdio/vwscanf.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c
index acbe379ad90e..7993f3e3d38f 100644
--- a/lib/libc/stdio/wbuf.c
+++ b/lib/libc/stdio/wbuf.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <errno.h>
#include <stdio.h>
#include "local.h"
@@ -50,7 +46,6 @@ static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93";
int
__swbuf(int c, FILE *fp)
{
- unsigned char *old_p;
int n;
/*
@@ -86,15 +81,8 @@ __swbuf(int c, FILE *fp)
}
fp->_w--;
*fp->_p++ = c;
- old_p = fp->_p;
- if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) {
- if (__fflush(fp) != 0) {
- if (fp->_p == old_p && errno == EINTR) {
- fp->_p--;
- fp->_w++;
- }
+ if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))
+ if (__fflush(fp) != 0)
return (EOF);
- }
- }
return (c);
}
diff --git a/lib/libc/stdio/wprintf.3 b/lib/libc/stdio/wprintf.3
index e694a26f1fcf..d1d2bdfaffd4 100644
--- a/lib/libc/stdio/wprintf.3
+++ b/lib/libc/stdio/wprintf.3
@@ -28,8 +28,6 @@
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
-.\"
-.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
.\" FreeBSD: src/lib/libc/stdio/printf.3,v 1.47 2002/09/06 11:23:55 tjr Exp
.\"
.Dd July 5, 2003
diff --git a/lib/libc/stdio/wprintf.c b/lib/libc/stdio/wprintf.c
index c45640021927..0aa33cc78770 100644
--- a/lib/libc/stdio/wprintf.c
+++ b/lib/libc/stdio/wprintf.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/wscanf.3 b/lib/libc/stdio/wscanf.3
index d3c8cd8ac1a0..6b428452e6aa 100644
--- a/lib/libc/stdio/wscanf.3
+++ b/lib/libc/stdio/wscanf.3
@@ -28,8 +28,6 @@
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
-.\"
-.\" @(#)scanf.3 8.2 (Berkeley) 12/11/93
.\" FreeBSD: src/lib/libc/stdio/scanf.3,v 1.24 2003/06/28 09:03:25 das Exp
.\"
.Dd July 5, 2003
diff --git a/lib/libc/stdio/wscanf.c b/lib/libc/stdio/wscanf.c
index 9527fcd27767..8e2019c2c490 100644
--- a/lib/libc/stdio/wscanf.c
+++ b/lib/libc/stdio/wscanf.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
diff --git a/lib/libc/stdio/wsetup.c b/lib/libc/stdio/wsetup.c
index b0dd89637b75..61797b035b33 100644
--- a/lib/libc/stdio/wsetup.c
+++ b/lib/libc/stdio/wsetup.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libc/stdio/xprintf_errno.c b/lib/libc/stdio/xprintf_errno.c
index db897328f0fe..f1e5421f60c8 100644
--- a/lib/libc/stdio/xprintf_errno.c
+++ b/lib/libc/stdio/xprintf_errno.c
@@ -27,6 +27,7 @@
*/
#include <namespace.h>
+#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -38,7 +39,8 @@
#include "printf.h"
int
-__printf_arginfo_errno(const struct printf_info *pi __unused, size_t n, int *argt)
+__printf_arginfo_errno(const struct printf_info *pi __unused, size_t n,
+ int *argt)
{
assert(n >= 1);
@@ -47,17 +49,18 @@ __printf_arginfo_errno(const struct printf_info *pi __unused, size_t n, int *arg
}
int
-__printf_render_errno(struct __printf_io *io, const struct printf_info *pi __unused, const void *const *arg)
+__printf_render_errno(struct __printf_io *io, const struct printf_info *pi
+ __unused, const void *const *arg)
{
int ret, error;
char buf[64];
- const char *p;
+ char errnomsg[NL_TEXTMAX];
ret = 0;
error = *((const int *)arg[0]);
if (error >= 0 && error < __hidden_sys_nerr) {
- p = strerror(error);
- return (__printf_out(io, pi, p, strlen(p)));
+ strerror_r(error, errnomsg, sizeof(errnomsg));
+ return (__printf_out(io, pi, errnomsg, strlen(errnomsg)));
}
sprintf(buf, "errno=%d/0x%x", error, error);
ret += __printf_out(io, pi, buf, strlen(buf));