[Midnightbsd-cvs] src [10559] trunk/lib/libc/stdio: sync with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Thu Jun 7 20:59:18 EDT 2018
Revision: 10559
http://svnweb.midnightbsd.org/src/?rev=10559
Author: laffer1
Date: 2018-06-07 20:59:17 -0400 (Thu, 07 Jun 2018)
Log Message:
-----------
sync with freebsd
Modified Paths:
--------------
trunk/lib/libc/stdio/Makefile.inc
trunk/lib/libc/stdio/Symbol.map
trunk/lib/libc/stdio/_flock_stub.c
trunk/lib/libc/stdio/asprintf.c
trunk/lib/libc/stdio/clrerr.c
trunk/lib/libc/stdio/dprintf.c
trunk/lib/libc/stdio/fclose.3
trunk/lib/libc/stdio/fclose.c
trunk/lib/libc/stdio/fcloseall.c
trunk/lib/libc/stdio/fdopen.c
trunk/lib/libc/stdio/feof.c
trunk/lib/libc/stdio/ferror.3
trunk/lib/libc/stdio/ferror.c
trunk/lib/libc/stdio/fflush.3
trunk/lib/libc/stdio/fflush.c
trunk/lib/libc/stdio/fgetc.c
trunk/lib/libc/stdio/fgetln.3
trunk/lib/libc/stdio/fgetln.c
trunk/lib/libc/stdio/fgetpos.c
trunk/lib/libc/stdio/fgets.3
trunk/lib/libc/stdio/fgets.c
trunk/lib/libc/stdio/fgetwc.c
trunk/lib/libc/stdio/fgetwln.3
trunk/lib/libc/stdio/fgetwln.c
trunk/lib/libc/stdio/fgetws.3
trunk/lib/libc/stdio/fgetws.c
trunk/lib/libc/stdio/fileno.c
trunk/lib/libc/stdio/findfp.c
trunk/lib/libc/stdio/flags.c
trunk/lib/libc/stdio/floatio.h
trunk/lib/libc/stdio/flockfile.3
trunk/lib/libc/stdio/fopen.3
trunk/lib/libc/stdio/fopen.c
trunk/lib/libc/stdio/fprintf.c
trunk/lib/libc/stdio/fpurge.c
trunk/lib/libc/stdio/fputc.c
trunk/lib/libc/stdio/fputs.3
trunk/lib/libc/stdio/fputs.c
trunk/lib/libc/stdio/fputwc.c
trunk/lib/libc/stdio/fputws.3
trunk/lib/libc/stdio/fputws.c
trunk/lib/libc/stdio/fread.3
trunk/lib/libc/stdio/fread.c
trunk/lib/libc/stdio/freopen.c
trunk/lib/libc/stdio/fscanf.c
trunk/lib/libc/stdio/fseek.3
trunk/lib/libc/stdio/fseek.c
trunk/lib/libc/stdio/fsetpos.c
trunk/lib/libc/stdio/ftell.c
trunk/lib/libc/stdio/funopen.3
trunk/lib/libc/stdio/funopen.c
trunk/lib/libc/stdio/fvwrite.c
trunk/lib/libc/stdio/fvwrite.h
trunk/lib/libc/stdio/fwalk.c
trunk/lib/libc/stdio/fwide.3
trunk/lib/libc/stdio/fwide.c
trunk/lib/libc/stdio/fwprintf.c
trunk/lib/libc/stdio/fwrite.c
trunk/lib/libc/stdio/fwscanf.c
trunk/lib/libc/stdio/getc.3
trunk/lib/libc/stdio/getc.c
trunk/lib/libc/stdio/getchar.c
trunk/lib/libc/stdio/getdelim.c
trunk/lib/libc/stdio/getline.3
trunk/lib/libc/stdio/getline.c
trunk/lib/libc/stdio/gets.c
trunk/lib/libc/stdio/getw.c
trunk/lib/libc/stdio/getwc.3
trunk/lib/libc/stdio/getwc.c
trunk/lib/libc/stdio/getwchar.c
trunk/lib/libc/stdio/glue.h
trunk/lib/libc/stdio/local.h
trunk/lib/libc/stdio/makebuf.c
trunk/lib/libc/stdio/mktemp.3
trunk/lib/libc/stdio/mktemp.c
trunk/lib/libc/stdio/perror.c
trunk/lib/libc/stdio/printf-pos.c
trunk/lib/libc/stdio/printf.3
trunk/lib/libc/stdio/printf.c
trunk/lib/libc/stdio/printf_l.3
trunk/lib/libc/stdio/printfcommon.h
trunk/lib/libc/stdio/printflocal.h
trunk/lib/libc/stdio/putc.3
trunk/lib/libc/stdio/putc.c
trunk/lib/libc/stdio/putchar.c
trunk/lib/libc/stdio/puts.c
trunk/lib/libc/stdio/putw.c
trunk/lib/libc/stdio/putwc.3
trunk/lib/libc/stdio/putwc.c
trunk/lib/libc/stdio/putwchar.c
trunk/lib/libc/stdio/refill.c
trunk/lib/libc/stdio/remove.3
trunk/lib/libc/stdio/remove.c
trunk/lib/libc/stdio/rewind.c
trunk/lib/libc/stdio/rget.c
trunk/lib/libc/stdio/scanf.3
trunk/lib/libc/stdio/scanf.c
trunk/lib/libc/stdio/scanf_l.3
trunk/lib/libc/stdio/setbuf.3
trunk/lib/libc/stdio/setbuf.c
trunk/lib/libc/stdio/setbuffer.c
trunk/lib/libc/stdio/setvbuf.c
trunk/lib/libc/stdio/snprintf.c
trunk/lib/libc/stdio/sprintf.c
trunk/lib/libc/stdio/sscanf.c
trunk/lib/libc/stdio/stdio.3
trunk/lib/libc/stdio/stdio.c
trunk/lib/libc/stdio/swprintf.c
trunk/lib/libc/stdio/swscanf.c
trunk/lib/libc/stdio/tempnam.c
trunk/lib/libc/stdio/tmpfile.c
trunk/lib/libc/stdio/tmpnam.3
trunk/lib/libc/stdio/tmpnam.c
trunk/lib/libc/stdio/ungetc.3
trunk/lib/libc/stdio/ungetc.c
trunk/lib/libc/stdio/ungetwc.3
trunk/lib/libc/stdio/ungetwc.c
trunk/lib/libc/stdio/unlocked.c
trunk/lib/libc/stdio/vasprintf.c
trunk/lib/libc/stdio/vdprintf.c
trunk/lib/libc/stdio/vfprintf.c
trunk/lib/libc/stdio/vfscanf.c
trunk/lib/libc/stdio/vfwprintf.c
trunk/lib/libc/stdio/vfwscanf.c
trunk/lib/libc/stdio/vprintf.c
trunk/lib/libc/stdio/vscanf.c
trunk/lib/libc/stdio/vsnprintf.c
trunk/lib/libc/stdio/vsprintf.c
trunk/lib/libc/stdio/vsscanf.c
trunk/lib/libc/stdio/vswprintf.c
trunk/lib/libc/stdio/vswscanf.c
trunk/lib/libc/stdio/vwprintf.c
trunk/lib/libc/stdio/vwscanf.c
trunk/lib/libc/stdio/wbuf.c
trunk/lib/libc/stdio/wprintf.3
trunk/lib/libc/stdio/wprintf.c
trunk/lib/libc/stdio/wscanf.3
trunk/lib/libc/stdio/wscanf.c
trunk/lib/libc/stdio/wsetup.c
Added Paths:
-----------
trunk/lib/libc/stdio/fmemopen.c
trunk/lib/libc/stdio/open_memstream.3
trunk/lib/libc/stdio/open_memstream.c
trunk/lib/libc/stdio/open_wmemstream.c
Property Changed:
----------------
trunk/lib/libc/stdio/Makefile.inc
trunk/lib/libc/stdio/Symbol.map
trunk/lib/libc/stdio/fclose.3
trunk/lib/libc/stdio/ferror.3
trunk/lib/libc/stdio/fflush.3
trunk/lib/libc/stdio/fgetln.3
trunk/lib/libc/stdio/fgets.3
trunk/lib/libc/stdio/fgetwln.3
trunk/lib/libc/stdio/fgetws.3
trunk/lib/libc/stdio/flockfile.3
trunk/lib/libc/stdio/fopen.3
trunk/lib/libc/stdio/fputs.3
trunk/lib/libc/stdio/fputws.3
trunk/lib/libc/stdio/fread.3
trunk/lib/libc/stdio/fseek.3
trunk/lib/libc/stdio/funopen.3
trunk/lib/libc/stdio/fwide.3
trunk/lib/libc/stdio/getc.3
trunk/lib/libc/stdio/getline.3
trunk/lib/libc/stdio/getwc.3
trunk/lib/libc/stdio/mktemp.3
trunk/lib/libc/stdio/printf.3
trunk/lib/libc/stdio/printf_l.3
trunk/lib/libc/stdio/putc.3
trunk/lib/libc/stdio/putwc.3
trunk/lib/libc/stdio/remove.3
trunk/lib/libc/stdio/scanf.3
trunk/lib/libc/stdio/scanf_l.3
trunk/lib/libc/stdio/setbuf.3
trunk/lib/libc/stdio/stdio.3
trunk/lib/libc/stdio/tmpnam.3
trunk/lib/libc/stdio/ungetc.3
trunk/lib/libc/stdio/ungetwc.3
trunk/lib/libc/stdio/wprintf.3
trunk/lib/libc/stdio/wscanf.3
Modified: trunk/lib/libc/stdio/Makefile.inc
===================================================================
--- trunk/lib/libc/stdio/Makefile.inc 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/Makefile.inc 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,5 +1,6 @@
# @(#)Makefile.inc 8.3 (Berkeley) 4/17/94
-# $FreeBSD$
+# $FreeBSD: stable/10/lib/libc/stdio/Makefile.inc 254151 2013-08-09 17:24:23Z jilles $
+# $MidnightBSD$
# stdio sources
.PATH: ${.CURDIR}/stdio
@@ -8,11 +9,13 @@
fclose.c fcloseall.c fdopen.c \
feof.c ferror.c fflush.c fgetc.c fgetln.c fgetpos.c fgets.c fgetwc.c \
fgetwln.c fgetws.c \
- fileno.c findfp.c flags.c fopen.c fprintf.c fpurge.c fputc.c fputs.c \
+ fileno.c findfp.c flags.c fmemopen.c fopen.c fprintf.c fpurge.c \
+ fputc.c fputs.c \
fputwc.c fputws.c fread.c freopen.c fscanf.c fseek.c fsetpos.c \
ftell.c funopen.c fvwrite.c fwalk.c fwide.c fwprintf.c fwscanf.c \
fwrite.c getc.c getchar.c getdelim.c getline.c \
gets.c getw.c getwc.c getwchar.c makebuf.c mktemp.c \
+ open_memstream.c open_wmemstream.c \
perror.c printf.c printf-pos.c putc.c putchar.c \
puts.c putw.c putwc.c putwchar.c \
refill.c remove.c rewind.c rget.c scanf.c setbuf.c setbuffer.c \
@@ -35,7 +38,7 @@
flockfile.3 \
fopen.3 fputs.3 \
fputws.3 fread.3 fseek.3 funopen.3 fwide.3 getc.3 \
- getline.3 getwc.3 mktemp.3 \
+ getline.3 getwc.3 mktemp.3 open_memstream.3 \
printf.3 printf_l.3 putc.3 putwc.3 remove.3 scanf.3 scanf_l.3 setbuf.3 \
stdio.3 tmpnam.3 \
ungetc.3 ungetwc.3 wprintf.3 wscanf.3
@@ -48,7 +51,7 @@
MLINKS+=fflush.3 fpurge.3
MLINKS+=fgets.3 gets.3
MLINKS+=flockfile.3 ftrylockfile.3 flockfile.3 funlockfile.3
-MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3
+MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3 fopen.3 fmemopen.3
MLINKS+=fputs.3 puts.3
MLINKS+=fread.3 fwrite.3
MLINKS+=fseek.3 fgetpos.3 fseek.3 fseeko.3 fseek.3 fsetpos.3 fseek.3 ftell.3 \
@@ -58,7 +61,9 @@
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
+MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3 mktemp.3 mkstemps.3 \
+ mktemp.3 mkostemp.3 mktemp.3 mkostemps.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 \
Property changes on: trunk/lib/libc/stdio/Makefile.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/Symbol.map
===================================================================
--- trunk/lib/libc/stdio/Symbol.map 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/Symbol.map 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,5 +1,5 @@
-/*
- * $FreeBSD$
+/* $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libc/stdio/Symbol.map 291602 2015-12-01 18:19:23Z ngie $
*/
FBSD_1.0 {
@@ -155,8 +155,17 @@
getwchar_l;
putwc_l;
putwchar_l;
+ fmemopen;
+ open_memstream;
+ open_wmemstream;
+ mkostemp;
+ mkostemps;
};
+FBSD_1.4 {
+ fdclose;
+};
+
FBSDprivate_1.0 {
_flockfile;
_flockfile_debug_stub;
Property changes on: trunk/lib/libc/stdio/Symbol.map
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/_flock_stub.c
===================================================================
--- trunk/lib/libc/stdio/_flock_stub.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/_flock_stub.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 1998 John Birrell <jb at cimlogic.com.au>.
* All rights reserved.
@@ -35,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/_flock_stub.c 291336 2015-11-25 21:43:05Z ngie $");
#include "namespace.h"
#include <stdio.h>
@@ -55,6 +56,9 @@
__weak_reference(_ftrylockfile, ftrylockfile);
__weak_reference(_funlockfile, funlockfile);
+void _flockfile_debug_stub(FILE *, char *, int);
+int _ftrylockfile(FILE *);
+
void
_flockfile(FILE *fp)
{
Modified: trunk/lib/libc/stdio/asprintf.c
===================================================================
--- trunk/lib/libc/stdio/asprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/asprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -36,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/asprintf.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include <stdarg.h>
Modified: trunk/lib/libc/stdio/clrerr.c
===================================================================
--- trunk/lib/libc/stdio/clrerr.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/clrerr.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/clrerr.c 249810 2013-04-23 14:36:44Z emaste $");
#include "namespace.h"
#include <stdio.h>
@@ -45,8 +46,7 @@
#undef clearerr_unlocked
void
-clearerr(fp)
- FILE *fp;
+clearerr(FILE *fp)
{
FLOCKFILE(fp);
__sclearerr(fp);
Modified: trunk/lib/libc/stdio/dprintf.c
===================================================================
--- trunk/lib/libc/stdio/dprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/dprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2009 David Schultz <das at FreeBSD.org>
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/dprintf.c 189356 2009-03-04 03:38:51Z das $");
#define _WITH_DPRINTF
#include "namespace.h"
Modified: trunk/lib/libc/stdio/fclose.3
===================================================================
--- trunk/lib/libc/stdio/fclose.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fclose.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,5 +1,7 @@
-.\" Copyright (c) 1990, 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
+.\" $MidnightBSD$
+.\" Copyright (c) 1990, 1991, 1993 The Regents of the University of California.
+.\" Copyright (c) 2015 Mariusz Zaborski <oshogbo at FreeBSD.org>
+.\" All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Chris Torek and the American National Standards Committee X3,
@@ -30,13 +32,14 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)fclose.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fclose.3 291602 2015-12-01 18:19:23Z ngie $
.\"
-.Dd April 22, 2006
+.Dd July 4, 2015
.Dt FCLOSE 3
.Os
.Sh NAME
.Nm fclose ,
+.Nm fdclose ,
.Nm fcloseall
.Nd close a stream
.Sh LIBRARY
@@ -45,6 +48,8 @@
.In stdio.h
.Ft int
.Fn fclose "FILE *stream"
+.Ft int
+.Fn fdclose "FILE *stream" "int *fdp"
.Ft void
.Fn fcloseall void
.Sh DESCRIPTION
@@ -59,36 +64,77 @@
.Xr fflush 3 .
.Pp
The
+.Fn fdclose
+function is equivalent to
+.Fn fclose
+except that it does not close the underlying file descriptor.
+If
+.Fa fdp
+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.
+This type of stream is created with functions such as
+.Xr fmemopen 3 ,
+.Xr funopen 3 ,
+or
+.Xr open_memstream 3 .
+.Pp
+The
.Fn fcloseall
function calls
.Fn fclose
on all open streams.
.Sh RETURN VALUES
-Upon successful completion 0 is returned.
+.Fn fcloseall
+does not return a value.
+.Pp
+Upon successful completion the
+.Fn fclose
+and
+.Fn fdclose
+functions return 0.
Otherwise,
.Dv EOF
is returned and the global variable
.Va errno
is set to indicate the error.
-In either case no further access to the stream is possible.
.Sh ERRORS
+.Fn fdclose
+fails if:
+.Bl -tag -width Er
+.It Bq Er EOPNOTSUPP
+The stream does not have an associated file descriptor.
+.El
+.Pp
The
.Fn fclose
-function
-may also fail and set
+and
+.Fn fdclose
+functions may also fail and set
.Va errno
-for any of the errors specified for the routines
-.Xr close 2
-or
+for any of the errors specified for
.Xr fflush 3 .
+.Pp
+The
+.Fn fclose
+function may also fail and set errno for any of the errors specified for
+.Xr close 2 .
.Sh NOTES
The
.Fn fclose
-function
-does not handle NULL arguments; they will result in a segmentation
-violation.
-This is intentional - it makes it easier to make sure programs written
-under
+and
+.Fn fdclose
+functions do not handle NULL arguments in the
+.Fa stream
+variable; this will result in a segmentation violation.
+This is intentional.
+It makes it easier to make sure programs written under
.Fx
are bug free.
This behaviour is an implementation detail, and programs should not
@@ -104,8 +150,13 @@
function
conforms to
.St -isoC .
-.Pp
+.Sh HISTORY
The
.Fn fcloseall
function first appeared in
.Fx 7.0 .
+.Pp
+The
+.Fn fdclose
+function first appeared in
+.Fx 11.0 .
Property changes on: trunk/lib/libc/stdio/fclose.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fclose.c
===================================================================
--- trunk/lib/libc/stdio/fclose.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fclose.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,6 +1,8 @@
+/* $MidnightBSD$ */
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990, 1993 The Regents of the University of California.
+ * Copyright (c) 2013 Mariusz Zaborski <oshogbo at FreeBSD.org>
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
@@ -13,7 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,10 +36,11 @@
static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fclose.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "un-namespace.h"
@@ -45,19 +48,17 @@
#include "libc_private.h"
#include "local.h"
-int
-fclose(FILE *fp)
+static int
+cleanfile(FILE *fp, bool c)
{
int r;
- if (fp->_flags == 0) { /* not open! */
- errno = EBADF;
- return (EOF);
+ r = fp->_flags & __SWR ? __sflush(fp) : 0;
+ if (c) {
+ if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0)
+ r = EOF;
}
- FLOCKFILE(fp);
- r = fp->_flags & __SWR ? __sflush(fp) : 0;
- if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0)
- r = EOF;
+
if (fp->_flags & __SMBF)
free((char *)fp->_bf._base);
if (HASUB(fp))
@@ -80,6 +81,59 @@
STDIO_THREAD_LOCK();
fp->_flags = 0; /* Release this FILE for reuse. */
STDIO_THREAD_UNLOCK();
- FUNLOCKFILE(fp);
+
return (r);
}
+
+int
+fdclose(FILE *fp, int *fdp)
+{
+ int r, err;
+
+ if (fdp != NULL)
+ *fdp = -1;
+
+ if (fp->_flags == 0) { /* not open! */
+ errno = EBADF;
+ return (EOF);
+ }
+
+ FLOCKFILE_CANCELSAFE(fp);
+ r = 0;
+ if (fp->_close != __sclose) {
+ r = EOF;
+ errno = EOPNOTSUPP;
+ } else if (fp->_file < 0) {
+ r = EOF;
+ errno = EBADF;
+ }
+ if (r == EOF) {
+ err = errno;
+ (void)cleanfile(fp, true);
+ errno = err;
+ } else {
+ if (fdp != NULL)
+ *fdp = fp->_file;
+ r = cleanfile(fp, false);
+ }
+ FUNLOCKFILE_CANCELSAFE();
+
+ return (r);
+}
+
+int
+fclose(FILE *fp)
+{
+ int r;
+
+ if (fp->_flags == 0) { /* not open! */
+ errno = EBADF;
+ return (EOF);
+ }
+
+ FLOCKFILE_CANCELSAFE(fp);
+ r = cleanfile(fp, true);
+ FUNLOCKFILE_CANCELSAFE();
+
+ return (r);
+}
Modified: trunk/lib/libc/stdio/fcloseall.c
===================================================================
--- trunk/lib/libc/stdio/fcloseall.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fcloseall.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (C) 2006 Daniel M. Eischen. All rights reserved.
*
@@ -24,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fcloseall.c 157963 2006-04-22 16:47:59Z deischen $");
#include <stdio.h>
#include "local.h"
Modified: trunk/lib/libc/stdio/fdopen.c
===================================================================
--- trunk/lib/libc/stdio/fdopen.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fdopen.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fdopen.c 291293 2015-11-25 08:19:01Z ngie $");
#include "namespace.h"
#include <sys/types.h>
@@ -47,9 +48,7 @@
#include "local.h"
FILE *
-fdopen(fd, mode)
- int fd;
- const char *mode;
+fdopen(int fd, const char *mode)
{
FILE *fp;
int flags, oflags, fdflags, tmp;
@@ -72,7 +71,8 @@
/* Make sure the mode the user wants is a subset of the actual mode. */
if ((fdflags = _fcntl(fd, F_GETFL, 0)) < 0)
return (NULL);
- tmp = fdflags & O_ACCMODE;
+ /* Work around incorrect O_ACCMODE. */
+ tmp = fdflags & (O_ACCMODE | O_EXEC);
if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) {
errno = EINVAL;
return (NULL);
@@ -80,6 +80,12 @@
if ((fp = __sfp()) == NULL)
return (NULL);
+
+ if ((oflags & O_CLOEXEC) && _fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
+ fp->_flags = 0;
+ return (NULL);
+ }
+
fp->_flags = flags;
/*
* If opened for appending, but underlying descriptor does not have
@@ -86,7 +92,9 @@
* O_APPEND bit set, assert __SAPP so that __swrite() caller
* will _sseek() to the end before write.
*/
- if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
+ if (fdflags & O_APPEND)
+ fp->_flags2 |= __S2OAP;
+ else if (oflags & O_APPEND)
fp->_flags |= __SAPP;
fp->_file = fd;
fp->_cookie = fp;
Modified: trunk/lib/libc/stdio/feof.c
===================================================================
--- trunk/lib/libc/stdio/feof.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/feof.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/feof.c 249808 2013-04-23 13:33:13Z emaste $");
#include "namespace.h"
#include <stdio.h>
Modified: trunk/lib/libc/stdio/ferror.3
===================================================================
--- trunk/lib/libc/stdio/ferror.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/ferror.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)ferror.3 8.2 (Berkeley) 4/19/94
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/ferror.3 187823 2009-01-28 14:38:41Z trhodes $
.\"
.Dd January 28, 2009
.Dt FERROR 3
Property changes on: trunk/lib/libc/stdio/ferror.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/ferror.c
===================================================================
--- trunk/lib/libc/stdio/ferror.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/ferror.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/ferror.c 249808 2013-04-23 13:33:13Z emaste $");
#include "namespace.h"
#include <stdio.h>
Modified: trunk/lib/libc/stdio/fflush.3
===================================================================
--- trunk/lib/libc/stdio/fflush.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fflush.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)fflush.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fflush.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd June 4, 1993
.Dt FFLUSH 3
Property changes on: trunk/lib/libc/stdio/fflush.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fflush.c
===================================================================
--- trunk/lib/libc/stdio/fflush.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fflush.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fflush.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
@@ -56,11 +57,11 @@
if (fp == NULL)
return (_fwalk(sflush_locked));
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
/*
* There is disagreement about the correct behaviour of fflush()
- * when passed a file which is not open for reading. According to
+ * when passed a file which is not open for writing. According to
* the ISO C standard, the behaviour is undefined.
* Under linux, such an fflush returns success and has no effect;
* under Windows, such an fflush is documented as behaving instead
@@ -68,13 +69,15 @@
* Given that applications may be written with the expectation of
* either of these two behaviours, the only safe (non-astonishing)
* option is to return EBADF and ask that applications be fixed.
+ * SUSv3 now requires that fflush() returns success on a read-only
+ * stream.
+ *
*/
- if ((fp->_flags & (__SWR | __SRW)) == 0) {
- errno = EBADF;
- retval = EOF;
- } else
+ if ((fp->_flags & (__SWR | __SRW)) == 0)
+ retval = 0;
+ else
retval = __sflush(fp);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
@@ -89,10 +92,9 @@
if (fp == NULL)
return (_fwalk(sflush_locked));
- if ((fp->_flags & (__SWR | __SRW)) == 0) {
- errno = EBADF;
- retval = EOF;
- } else
+ if ((fp->_flags & (__SWR | __SRW)) == 0)
+ retval = 0;
+ else
retval = __sflush(fp);
return (retval);
}
@@ -122,6 +124,14 @@
for (; n > 0; n -= t, p += t) {
t = _swrite(fp, (char *)p, n);
if (t <= 0) {
+ /* Reset _p and _w. */
+ if (p > fp->_p) {
+ /* Some was written. */
+ memmove(fp->_p, p, n);
+ fp->_p += n;
+ if ((fp->_flags & (__SLBF | __SNBF)) == 0)
+ fp->_w -= n;
+ }
fp->_flags |= __SERR;
return (EOF);
}
@@ -134,8 +144,8 @@
{
int ret;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ret = __sflush(fp);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
Modified: trunk/lib/libc/stdio/fgetc.c
===================================================================
--- trunk/lib/libc/stdio/fgetc.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgetc.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fgetc.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -43,14 +44,13 @@
#include "local.h"
int
-fgetc(fp)
- FILE *fp;
+fgetc(FILE *fp)
{
int retval;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
/* Orientation set by __sgetc() when buffer is empty. */
/* ORIENT(fp, -1); */
retval = __sgetc(fp);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
Modified: trunk/lib/libc/stdio/fgetln.3
===================================================================
--- trunk/lib/libc/stdio/fgetln.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgetln.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -26,9 +27,9 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fgetln.3 304816 2016-08-25 19:55:31Z ache $
.\"
-.Dd April 19, 1994
+.Dd February 15, 2016
.Dt FGETLN 3
.Os
.Sh NAME
@@ -97,6 +98,9 @@
The argument
.Fa stream
is not a stream open for reading.
+.It Bq Er ENOMEM
+The internal line buffer could not be expanded due to lack of available memory,
+or because it would need to expand beyond INT_MAX in size.
.El
.Pp
The
Property changes on: trunk/lib/libc/stdio/fgetln.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fgetln.c
===================================================================
--- trunk/lib/libc/stdio/fgetln.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgetln.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,9 +35,11 @@
static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fgetln.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
+#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -61,6 +64,10 @@
#endif
if (fp->_lb._size >= newsize)
return (0);
+ if (newsize > INT_MAX) {
+ errno = ENOMEM;
+ return (-1);
+ }
if ((p = realloc(fp->_lb._base, newsize)) == NULL)
return (-1);
fp->_lb._base = p;
@@ -79,22 +86,21 @@
fgetln(FILE *fp, size_t *lenp)
{
unsigned char *p;
+ char *ret;
size_t len;
size_t off;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, -1);
/* make sure there is input */
if (fp->_r <= 0 && __srefill(fp)) {
*lenp = 0;
- FUNLOCKFILE(fp);
- return (NULL);
+ ret = NULL;
+ goto end;
}
/* look for a newline in the input */
if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) {
- char *ret;
-
/*
* Found one. Flag buffer as modified to keep fseek from
* `optimising' a backward seek, in case the user stomps on
@@ -106,8 +112,7 @@
fp->_flags |= __SMOD;
fp->_r -= len;
fp->_p = p;
- FUNLOCKFILE(fp);
- return (ret);
+ goto end;
}
/*
@@ -115,7 +120,7 @@
* As a bonus, though, we can leave off the __SMOD.
*
* OPTIMISTIC is length that we (optimistically) expect will
- * accomodate the `rest' of the string, on each trip through the
+ * accommodate the `rest' of the string, on each trip through the
* loop below.
*/
#define OPTIMISTIC 80
@@ -133,8 +138,11 @@
(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
len - off);
off = len;
- if (__srefill(fp))
- break; /* EOF or error: return partial line */
+ if (__srefill(fp)) {
+ if (__sfeof(fp))
+ break;
+ goto error;
+ }
if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL)
continue;
@@ -152,13 +160,16 @@
}
*lenp = len;
#ifdef notdef
- fp->_lb._base[len] = 0;
+ fp->_lb._base[len] = '\0';
#endif
- FUNLOCKFILE(fp);
- return ((char *)fp->_lb._base);
+ ret = (char *)fp->_lb._base;
+end:
+ FUNLOCKFILE_CANCELSAFE();
+ return (ret);
error:
*lenp = 0; /* ??? */
- FUNLOCKFILE(fp);
- return (NULL); /* ??? */
+ fp->_flags |= __SERR;
+ ret = NULL;
+ goto end;
}
Modified: trunk/lib/libc/stdio/fgetpos.c
===================================================================
--- trunk/lib/libc/stdio/fgetpos.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgetpos.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fgetpos.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
Modified: trunk/lib/libc/stdio/fgets.3
===================================================================
--- trunk/lib/libc/stdio/fgets.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgets.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)fgets.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fgets.3 235202 2012-05-09 17:27:49Z eadler $
.\"
.Dd May 5, 2012
.Dt FGETS 3
Property changes on: trunk/lib/libc/stdio/fgets.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fgets.c
===================================================================
--- trunk/lib/libc/stdio/fgets.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgets.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,9 +35,10 @@
static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fgets.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
+#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "un-namespace.h"
@@ -49,20 +51,22 @@
* Return first argument, or NULL if no characters were read.
*/
char *
-fgets(buf, n, fp)
- char *buf;
- int n;
- FILE *fp;
+fgets(char * __restrict buf, int n, FILE * __restrict fp)
{
size_t len;
- char *s;
+ char *s, *ret;
unsigned char *p, *t;
- if (n <= 0) /* sanity check */
- return (NULL);
+ FLOCKFILE_CANCELSAFE(fp);
+ ORIENT(fp, -1);
- FLOCKFILE(fp);
- ORIENT(fp, -1);
+ if (n <= 0) { /* sanity check */
+ fp->_flags |= __SERR;
+ errno = EINVAL;
+ ret = NULL;
+ goto end;
+ }
+
s = buf;
n--; /* leave space for NUL */
while (n != 0) {
@@ -72,9 +76,9 @@
if ((len = fp->_r) <= 0) {
if (__srefill(fp)) {
/* EOF/error: stop with partial or no line */
- if (s == buf) {
- FUNLOCKFILE(fp);
- return (NULL);
+ if (!__sfeof(fp) || s == buf) {
+ ret = NULL;
+ goto end;
}
break;
}
@@ -97,8 +101,8 @@
fp->_p = t;
(void)memcpy((void *)s, (void *)p, len);
s[len] = 0;
- FUNLOCKFILE(fp);
- return (buf);
+ ret = buf;
+ goto end;
}
fp->_r -= len;
fp->_p += len;
@@ -107,6 +111,8 @@
n -= len;
}
*s = 0;
- FUNLOCKFILE(fp);
- return (buf);
+ ret = buf;
+end:
+ FUNLOCKFILE_CANCELSAFE();
+ return (ret);
}
Modified: trunk/lib/libc/stdio/fgetwc.c
===================================================================
--- trunk/lib/libc/stdio/fgetwc.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgetwc.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fgetwc.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
@@ -52,13 +53,14 @@
wint_t r;
FIX_LOCALE(locale);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, 1);
r = __fgetwc(fp, locale);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (r);
}
+
wint_t
fgetwc(FILE *fp)
{
@@ -66,44 +68,43 @@
}
/*
- * Non-MT-safe version.
+ * Internal (non-MPSAFE) version of fgetwc(). This version takes an
+ * mbstate_t argument specifying the initial conversion state. For
+ * wide streams, this should always be fp->_mbstate. On return, *nread
+ * is set to the number of bytes read.
*/
-wint_t
-__fgetwc(FILE *fp, locale_t locale)
+wint_t
+__fgetwc_mbs(FILE *fp, mbstate_t *mbs, int *nread, locale_t locale)
{
wchar_t wc;
size_t nconv;
struct xlocale_ctype *l = XLOCALE_CTYPE(locale);
+ *nread = 0;
if (fp->_r <= 0 && __srefill(fp))
return (WEOF);
- if (MB_CUR_MAX == 1) {
- /* Fast path for single-byte encodings. */
- wc = *fp->_p++;
- fp->_r--;
- return (wc);
- }
do {
- nconv = l->__mbrtowc(&wc, fp->_p, fp->_r, &fp->_mbstate);
- if (nconv == (size_t)-1)
- break;
- else if (nconv == (size_t)-2)
+ nconv = l->__mbrtowc(&wc, fp->_p, fp->_r, mbs);
+ if (nconv == (size_t)-1) {
+ fp->_flags |= __SERR;
+ return (WEOF);
+ } else if (nconv == (size_t)-2)
continue;
else if (nconv == 0) {
- /*
- * Assume that the only valid representation of
- * the null wide character is a single null byte.
- */
fp->_p++;
fp->_r--;
+ (*nread)++;
return (L'\0');
} else {
fp->_p += nconv;
fp->_r -= nconv;
+ *nread += nconv;
return (wc);
}
} while (__srefill(fp) == 0);
- fp->_flags |= __SERR;
- errno = EILSEQ;
+ if (__sfeof(fp)) {
+ fp->_flags |= __SERR;
+ errno = EILSEQ;
+ }
return (WEOF);
}
Modified: trunk/lib/libc/stdio/fgetwln.3
===================================================================
--- trunk/lib/libc/stdio/fgetwln.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgetwln.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -26,7 +27,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fgetwln.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd July 16, 2004
.Dt FGETWLN 3
Property changes on: trunk/lib/libc/stdio/fgetwln.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fgetwln.c
===================================================================
--- trunk/lib/libc/stdio/fgetwln.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgetwln.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fgetwln.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -40,38 +41,56 @@
#include "local.h"
#include "xlocale_private.h"
+wchar_t *fgetwln_l(FILE * __restrict, size_t *, locale_t);
+
wchar_t *
fgetwln_l(FILE * __restrict fp, size_t *lenp, locale_t locale)
{
+ wchar_t *ret;
wint_t wc;
size_t len;
+ int savserr;
+
FIX_LOCALE(locale);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, 1);
+ savserr = fp->_flags & __SERR;
+ fp->_flags &= ~__SERR;
+
len = 0;
while ((wc = __fgetwc(fp, locale)) != WEOF) {
#define GROW 512
if (len * sizeof(wchar_t) >= fp->_lb._size &&
- __slbexpand(fp, (len + GROW) * sizeof(wchar_t)))
+ __slbexpand(fp, (len + GROW) * sizeof(wchar_t))) {
+ fp->_flags |= __SERR;
goto error;
+ }
*((wchar_t *)fp->_lb._base + len++) = wc;
if (wc == L'\n')
break;
}
+ /* fgetwc(3) may set both __SEOF and __SERR at once. */
+ if (__sferror(fp))
+ goto error;
+
+ fp->_flags |= savserr;
if (len == 0)
goto error;
- FUNLOCKFILE(fp);
*lenp = len;
- return ((wchar_t *)fp->_lb._base);
+ ret = (wchar_t *)fp->_lb._base;
+end:
+ FUNLOCKFILE_CANCELSAFE();
+ return (ret);
error:
- FUNLOCKFILE(fp);
*lenp = 0;
- return (NULL);
+ ret = NULL;
+ goto end;
}
+
wchar_t *
fgetwln(FILE * __restrict fp, size_t *lenp)
{
Modified: trunk/lib/libc/stdio/fgetws.3
===================================================================
--- trunk/lib/libc/stdio/fgetws.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgetws.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -31,7 +32,7 @@
.\"
.\" @(#)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
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fgetws.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd August 6, 2002
.Dt FGETWS 3
Property changes on: trunk/lib/libc/stdio/fgetws.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fgetws.c
===================================================================
--- trunk/lib/libc/stdio/fgetws.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fgetws.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fgetws.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
@@ -45,7 +46,8 @@
wchar_t *
fgetws_l(wchar_t * __restrict ws, int n, FILE * __restrict fp, locale_t locale)
{
- wchar_t *wsp;
+ int sret;
+ wchar_t *wsp, *ret;
size_t nconv;
const char *src;
unsigned char *nl;
@@ -52,18 +54,24 @@
FIX_LOCALE(locale);
struct xlocale_ctype *l = XLOCALE_CTYPE(locale);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, 1);
if (n <= 0) {
+ fp->_flags |= __SERR;
errno = EINVAL;
goto error;
}
+ wsp = ws;
+ if (n == 1)
+ goto ok;
+
if (fp->_r <= 0 && __srefill(fp))
- /* EOF */
+ /* EOF or ferror */
goto error;
- wsp = ws;
+
+ sret = 0;
do {
src = fp->_p;
nl = memchr(fp->_p, '\n', fp->_r);
@@ -70,9 +78,11 @@
nconv = l->__mbsnrtowcs(wsp, &src,
nl != NULL ? (nl - fp->_p + 1) : fp->_r,
n - 1, &fp->_mbstate);
- if (nconv == (size_t)-1)
+ if (nconv == (size_t)-1) {
/* Conversion error */
+ fp->_flags |= __SERR;
goto error;
+ }
if (src == NULL) {
/*
* We hit a null byte. Increment the character count,
@@ -88,23 +98,32 @@
fp->_p = (unsigned char *)src;
n -= nconv;
wsp += nconv;
- } while (wsp[-1] != L'\n' && n > 1 && (fp->_r > 0 ||
- __srefill(fp) == 0));
+ } while ((wsp == ws || wsp[-1] != L'\n') && n > 1 && (fp->_r > 0 ||
+ (sret = __srefill(fp)) == 0));
+ if (sret && !__sfeof(fp))
+ /* ferror */
+ goto error;
+ if (!l->__mbsinit(&fp->_mbstate)) {
+ /* Incomplete character */
+ fp->_flags |= __SERR;
+ errno = EILSEQ;
+ goto error;
+ }
if (wsp == ws)
/* EOF */
goto error;
- if (!l->__mbsinit(&fp->_mbstate))
- /* Incomplete character */
- goto error;
+ok:
*wsp = L'\0';
- FUNLOCKFILE(fp);
+ ret = ws;
+end:
+ FUNLOCKFILE_CANCELSAFE();
+ return (ret);
- return (ws);
-
error:
- FUNLOCKFILE(fp);
- return (NULL);
+ ret = NULL;
+ goto end;
}
+
wchar_t *
fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
{
Modified: trunk/lib/libc/stdio/fileno.c
===================================================================
--- trunk/lib/libc/stdio/fileno.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fileno.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fileno.c 249808 2013-04-23 13:33:13Z emaste $");
#include "namespace.h"
#include <stdio.h>
Modified: trunk/lib/libc/stdio/findfp.c
===================================================================
--- trunk/lib/libc/stdio/findfp.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/findfp.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)findfp.c 8.2 (Berkeley) 1/4/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/findfp.c 291336 2015-11-25 21:43:05Z ngie $");
#include <sys/param.h>
#include <machine/atomic.h>
@@ -91,8 +92,7 @@
#endif
static struct glue *
-moreglue(n)
- int n;
+moreglue(int n)
{
struct glue *g;
static FILE empty = { ._fl_mutex = PTHREAD_MUTEX_INITIALIZER };
@@ -114,7 +114,7 @@
* Find a free FILE for fopen et al.
*/
FILE *
-__sfp()
+__sfp(void)
{
FILE *fp;
int n;
@@ -156,6 +156,7 @@
/* fp->_fl_mutex = NULL; */ /* once set always set (reused) */
fp->_orientation = 0;
memset(&fp->_mbstate, 0, sizeof(mbstate_t));
+ fp->_flags2 = 0;
return (fp);
}
@@ -165,6 +166,7 @@
*/
__warn_references(f_prealloc,
"warning: this program uses f_prealloc(), which is not recommended.");
+void f_prealloc(void);
void
f_prealloc(void)
@@ -196,7 +198,7 @@
* The name `_cleanup' is, alas, fairly well known outside stdio.
*/
void
-_cleanup()
+_cleanup(void)
{
/* (void) _fwalk(fclose); */
(void) _fwalk(__sflush); /* `cheating' */
@@ -206,7 +208,7 @@
* __sinit() is called whenever stdio's internal variables must be set up.
*/
void
-__sinit()
+__sinit(void)
{
/* Make sure we clean up on exit. */
Modified: trunk/lib/libc/stdio/flags.c
===================================================================
--- trunk/lib/libc/stdio/flags.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/flags.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)flags.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/flags.c 255303 2013-09-06 13:47:16Z jilles $");
#include <sys/types.h>
#include <sys/file.h>
@@ -49,11 +50,9 @@
* Return 0 on error.
*/
int
-__sflags(mode, optr)
- const char *mode;
- int *optr;
+__sflags(const char *mode, int *optr)
{
- int ret, m, o;
+ int ret, m, o, known;
switch (*mode++) {
@@ -80,30 +79,36 @@
return (0);
}
- /* 'b' (binary) is ignored */
- if (*mode == 'b')
- mode++;
+ do {
+ known = 1;
+ switch (*mode++) {
+ case 'b':
+ /* 'b' (binary) is ignored */
+ break;
+ case '+':
+ /* [rwa][b]\+ means read and write */
+ ret = __SRW;
+ m = O_RDWR;
+ break;
+ case 'x':
+ /* 'x' means exclusive (fail if the file exists) */
+ o |= O_EXCL;
+ break;
+ case 'e':
+ /* set close-on-exec */
+ o |= O_CLOEXEC;
+ break;
+ default:
+ known = 0;
+ break;
+ }
+ } while (known);
- /* [rwa][b]\+ means read and write */
- if (*mode == '+') {
- mode++;
- ret = __SRW;
- m = O_RDWR;
+ if ((o & O_EXCL) != 0 && m == O_RDONLY) {
+ errno = EINVAL;
+ return (0);
}
- /* 'b' (binary) can appear here, too -- and is ignored again */
- if (*mode == 'b')
- mode++;
-
- /* 'x' means exclusive (fail if the file exists) */
- if (*mode == 'x') {
- if (m == O_RDONLY) {
- errno = EINVAL;
- return (0);
- }
- o |= O_EXCL;
- }
-
*optr = m | o;
return (ret);
}
Modified: trunk/lib/libc/stdio/floatio.h
===================================================================
--- trunk/lib/libc/stdio/floatio.h 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/floatio.h 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)floatio.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libc/stdio/floatio.h 165903 2007-01-09 00:28:16Z imp $
*/
/*
Modified: trunk/lib/libc/stdio/flockfile.3
===================================================================
--- trunk/lib/libc/stdio/flockfile.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/flockfile.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 2003 Tim J. Robbins
.\" All rights reserved.
.\"
@@ -22,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/flockfile.3 109154 2003-01-13 01:29:14Z tjr $
.\"
.Dd January 10, 2003
.Dt FLOCKFILE 3
Property changes on: trunk/lib/libc/stdio/flockfile.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: trunk/lib/libc/stdio/fmemopen.c
===================================================================
--- trunk/lib/libc/stdio/fmemopen.c (rev 0)
+++ trunk/lib/libc/stdio/fmemopen.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -0,0 +1,263 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (C) 2013 Pietro Cerutti <gahr at FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fmemopen.c 290544 2015-11-08 13:37:16Z ache $");
+
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "local.h"
+
+struct fmemopen_cookie
+{
+ char *buf; /* pointer to the memory region */
+ bool own; /* did we allocate the buffer ourselves? */
+ char bin; /* is this a binary buffer? */
+ size_t size; /* buffer length in bytes */
+ size_t len; /* data length in bytes */
+ size_t off; /* current offset into the buffer */
+};
+
+static int fmemopen_read(void *cookie, char *buf, int nbytes);
+static int fmemopen_write(void *cookie, const char *buf, int nbytes);
+static fpos_t fmemopen_seek(void *cookie, fpos_t offset, int whence);
+static int fmemopen_close(void *cookie);
+
+FILE *
+fmemopen(void * __restrict buf, size_t size, const char * __restrict mode)
+{
+ struct fmemopen_cookie *ck;
+ FILE *f;
+ int flags, rc;
+
+ /*
+ * POSIX says we shall return EINVAL if size is 0.
+ */
+ if (size == 0) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /*
+ * Retrieve the flags as used by open(2) from the mode argument, and
+ * validate them.
+ */
+ rc = __sflags(mode, &flags);
+ if (rc == 0) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /*
+ * There's no point in requiring an automatically allocated buffer
+ * in write-only mode.
+ */
+ if (!(flags & O_RDWR) && buf == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ ck = malloc(sizeof(struct fmemopen_cookie));
+ if (ck == NULL) {
+ return (NULL);
+ }
+
+ ck->off = 0;
+ ck->size = size;
+
+ /* Check whether we have to allocate the buffer ourselves. */
+ ck->own = ((ck->buf = buf) == NULL);
+ if (ck->own) {
+ ck->buf = malloc(size);
+ if (ck->buf == NULL) {
+ free(ck);
+ return (NULL);
+ }
+ }
+
+ /*
+ * POSIX distinguishes between w+ and r+, in that w+ is supposed to
+ * truncate the buffer.
+ */
+ if (ck->own || mode[0] == 'w') {
+ ck->buf[0] = '\0';
+ }
+
+ /* Check for binary mode. */
+ ck->bin = strchr(mode, 'b') != NULL;
+
+ /*
+ * The size of the current buffer contents is set depending on the
+ * mode:
+ *
+ * for append (text-mode), the position of the first NULL byte, or the
+ * size of the buffer if none is found
+ *
+ * for append (binary-mode), the size of the buffer
+ *
+ * for read, the size of the buffer
+ *
+ * for write, 0
+ */
+ switch (mode[0]) {
+ case 'a':
+ ck->off = ck->len = strnlen(ck->buf, ck->size);
+ break;
+ case 'r':
+ ck->len = size;
+ break;
+ case 'w':
+ ck->len = 0;
+ break;
+ }
+
+ f = funopen(ck,
+ flags & O_WRONLY ? NULL : fmemopen_read,
+ flags & O_RDONLY ? NULL : fmemopen_write,
+ fmemopen_seek, fmemopen_close);
+
+ if (f == NULL) {
+ if (ck->own)
+ free(ck->buf);
+ free(ck);
+ return (NULL);
+ }
+
+ if (mode[0] == 'a')
+ f->_flags |= __SAPP;
+
+ /*
+ * Turn off buffering, so a write past the end of the buffer
+ * correctly returns a short object count.
+ */
+ setvbuf(f, NULL, _IONBF, 0);
+
+ return (f);
+}
+
+static int
+fmemopen_read(void *cookie, char *buf, int nbytes)
+{
+ struct fmemopen_cookie *ck = cookie;
+
+ if (nbytes > ck->len - ck->off)
+ nbytes = ck->len - ck->off;
+
+ if (nbytes == 0)
+ return (0);
+
+ memcpy(buf, ck->buf + ck->off, nbytes);
+
+ ck->off += nbytes;
+
+ return (nbytes);
+}
+
+static int
+fmemopen_write(void *cookie, const char *buf, int nbytes)
+{
+ struct fmemopen_cookie *ck = cookie;
+
+ if (nbytes > ck->size - ck->off)
+ nbytes = ck->size - ck->off;
+
+ if (nbytes == 0)
+ return (0);
+
+ memcpy(ck->buf + ck->off, buf, nbytes);
+
+ ck->off += nbytes;
+
+ if (ck->off > ck->len)
+ ck->len = ck->off;
+
+ /*
+ * We append a NULL byte if all these conditions are met:
+ * - the buffer is not binary
+ * - the buffer is not full
+ * - the data just written doesn't already end with a NULL byte
+ */
+ if (!ck->bin && ck->off < ck->size && ck->buf[ck->off - 1] != '\0')
+ ck->buf[ck->off] = '\0';
+
+ return (nbytes);
+}
+
+static fpos_t
+fmemopen_seek(void *cookie, fpos_t offset, int whence)
+{
+ struct fmemopen_cookie *ck = cookie;
+
+
+ switch (whence) {
+ case SEEK_SET:
+ if (offset > ck->size) {
+ errno = EINVAL;
+ return (-1);
+ }
+ ck->off = offset;
+ break;
+
+ case SEEK_CUR:
+ if (ck->off + offset > ck->size) {
+ errno = EINVAL;
+ return (-1);
+ }
+ ck->off += offset;
+ break;
+
+ case SEEK_END:
+ if (offset > 0 || -offset > ck->len) {
+ errno = EINVAL;
+ return (-1);
+ }
+ ck->off = ck->len + offset;
+ break;
+
+ default:
+ errno = EINVAL;
+ return (-1);
+ }
+
+ return (ck->off);
+}
+
+static int
+fmemopen_close(void *cookie)
+{
+ struct fmemopen_cookie *ck = cookie;
+
+ if (ck->own)
+ free(ck->buf);
+
+ free(ck);
+
+ return (0);
+}
Property changes on: trunk/lib/libc/stdio/fmemopen.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fopen.3
===================================================================
--- trunk/lib/libc/stdio/fopen.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fopen.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,15 +31,16 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)fopen.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fopen.3 321120 2017-07-18 08:33:29Z ngie $
.\"
-.Dd October 17, 2011
+.Dd January 30, 2013
.Dt FOPEN 3
.Os
.Sh NAME
.Nm fopen ,
.Nm fdopen ,
-.Nm freopen
+.Nm freopen ,
+.Nm fmemopen
.Nd stream open functions
.Sh LIBRARY
.Lb libc
@@ -50,6 +52,8 @@
.Fn fdopen "int fildes" "const char *mode"
.Ft FILE *
.Fn freopen "const char *path" "const char *mode" "FILE *stream"
+.Ft FILE *
+.Fn fmemopen "void *restrict *buf" "size_t size" "const char * restrict mode"
.Sh DESCRIPTION
The
.Fn fopen
@@ -97,6 +101,14 @@
causes the
.Fn fopen
call to fail if the file already exists.
+An optional
+.Dq Li e
+following the above
+causes the
+.Fn fopen
+call to set the
+.Dv FD_CLOEXEC
+flag on the underlying file descriptor.
.Pp
The
.Fa mode
@@ -107,7 +119,11 @@
or the first letter.
This is strictly for compatibility with
.St -isoC
-and has no effect; the ``b'' is ignored.
+and has effect only for
+.Fn fmemopen
+; otherwise
+.Dq Li b
+is ignored.
.Pp
Any created files will have mode
.Do Dv S_IRUSR
@@ -144,6 +160,11 @@
The
.Dq Li x
mode option is ignored.
+If the
+.Dq Li e
+mode option is present, the
+.Dv FD_CLOEXEC
+flag is set, otherwise it remains unchanged.
When the stream is closed via
.Xr fclose 3 ,
.Fa fildes
@@ -189,6 +210,41 @@
.Dv ( stderr , stdin ,
or
.Dv stdout ) .
+.Pp
+The
+.Fn fmemopen
+function
+associates the buffer given by the
+.Fa buf
+and
+.Fa size
+arguments with a stream.
+The
+.Fa buf
+argument is either a null pointer or point to a buffer that
+is at least
+.Fa size
+bytes long.
+If a null pointer is specified as the
+.Fa buf
+argument,
+.Fn fmemopen
+allocates
+.Fa size
+bytes of memory.
+This buffer is automatically freed when the stream is closed.
+Buffers can be opened in text-mode (default) or binary-mode
+(if
+.Dq Li b
+is present in the second or third position of the
+.Fa mode
+argument).
+Buffers opened in text-mode make sure that writes are terminated with a
+.Dv NULL
+byte, if the last write hasn't filled up the whole buffer.
+Buffers opened in binary-mode never append a
+.Dv NULL
+byte.
.Sh RETURN VALUES
Upon successful completion
.Fn fopen ,
@@ -212,16 +268,18 @@
to
.Fn fopen ,
.Fn fdopen ,
+.Fn freopen ,
or
-.Fn freopen
+.Fn fmemopen
was invalid.
.El
.Pp
The
.Fn fopen ,
-.Fn fdopen
+.Fn fdopen ,
+.Fn freopen
and
-.Fn freopen
+.Fn fmemopen
functions
may also fail and set
.Va errno
@@ -254,6 +312,15 @@
.Xr fclose 3
and
.Xr fflush 3 .
+.Pp
+The
+.Fn fmemopen
+function
+may also fail and set
+.Va errno
+if the
+.Fa size
+argument is 0.
.Sh SEE ALSO
.Xr open 2 ,
.Xr fclose 3 ,
@@ -277,3 +344,16 @@
function
conforms to
.St -p1003.1-88 .
+The
+.Dq Li e
+mode option does not conform to any standard
+but is also supported by glibc.
+The
+.Fn fmemopen
+function
+conforms to
+.St -p1003.1-2008 .
+The
+.Dq Li b
+mode does not conform to any standard
+but is also supported by glibc.
Property changes on: trunk/lib/libc/stdio/fopen.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fopen.c
===================================================================
--- trunk/lib/libc/stdio/fopen.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fopen.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fopen.c 290544 2015-11-08 13:37:16Z ache $");
#include "namespace.h"
#include <sys/types.h>
@@ -49,9 +50,7 @@
#include "local.h"
FILE *
-fopen(file, mode)
- const char * __restrict file;
- const char * __restrict mode;
+fopen(const char * __restrict file, const char * __restrict mode)
{
FILE *fp;
int f;
@@ -93,7 +92,9 @@
* we can do about this. (We could set __SAPP and check in
* fseek and ftell.)
*/
- if (oflags & O_APPEND)
+ if (oflags & O_APPEND) {
+ fp->_flags2 |= __S2OAP;
(void)_sseek(fp, (fpos_t)0, SEEK_END);
+ }
return (fp);
}
Modified: trunk/lib/libc/stdio/fprintf.c
===================================================================
--- trunk/lib/libc/stdio/fprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)fprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fprintf.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include <stdarg.h>
Modified: trunk/lib/libc/stdio/fpurge.c
===================================================================
--- trunk/lib/libc/stdio/fpurge.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fpurge.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fpurge.c 249810 2013-04-23 14:36:44Z emaste $");
#include "namespace.h"
#include <errno.h>
@@ -49,8 +50,7 @@
* given FILE's buffer empty.
*/
int
-fpurge(fp)
- FILE *fp;
+fpurge(FILE *fp)
{
int retval;
FLOCKFILE(fp);
Modified: trunk/lib/libc/stdio/fputc.c
===================================================================
--- trunk/lib/libc/stdio/fputc.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fputc.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fputc.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -43,15 +44,13 @@
#include "libc_private.h"
int
-fputc(c, fp)
- int c;
- FILE *fp;
+fputc(int c, FILE *fp)
{
int retval;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
/* Orientation set by __sputc() when buffer is full. */
/* ORIENT(fp, -1); */
retval = __sputc(c, fp);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
Modified: trunk/lib/libc/stdio/fputs.3
===================================================================
--- trunk/lib/libc/stdio/fputs.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fputs.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)fputs.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fputs.3 168862 2007-04-19 14:01:04Z phk $
.\"
.Dd June 4, 1993
.Dt FPUTS 3
Property changes on: trunk/lib/libc/stdio/fputs.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fputs.c
===================================================================
--- trunk/lib/libc/stdio/fputs.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fputs.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fputs.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -48,9 +49,7 @@
* Write the given string to the given file.
*/
int
-fputs(s, fp)
- const char * __restrict s;
- FILE * __restrict fp;
+fputs(const char * __restrict s, FILE * __restrict fp)
{
int retval;
struct __suio uio;
@@ -57,12 +56,12 @@
struct __siov iov;
iov.iov_base = (void *)s;
- iov.iov_len = uio.uio_resid = strlen(s);
+ uio.uio_resid = iov.iov_len = strlen(s);
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, -1);
retval = __sfvwrite(fp, &uio);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
Modified: trunk/lib/libc/stdio/fputwc.c
===================================================================
--- trunk/lib/libc/stdio/fputwc.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fputwc.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fputwc.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
@@ -53,19 +54,9 @@
size_t i, len;
struct xlocale_ctype *l = XLOCALE_CTYPE(locale);
- if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) {
- /*
- * Assume single-byte locale with no special encoding.
- * A more careful test would be to check
- * _CurrentRuneLocale->encoding.
- */
- *buf = (unsigned char)wc;
- len = 1;
- } else {
- if ((len = l->__wcrtomb(buf, wc, &fp->_mbstate)) == (size_t)-1) {
- fp->_flags |= __SERR;
- return (WEOF);
- }
+ if ((len = l->__wcrtomb(buf, wc, &fp->_mbstate)) == (size_t)-1) {
+ fp->_flags |= __SERR;
+ return (WEOF);
}
for (i = 0; i < len; i++)
@@ -84,10 +75,10 @@
wint_t r;
FIX_LOCALE(locale);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, 1);
r = __fputwc(wc, fp, locale);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (r);
}
Modified: trunk/lib/libc/stdio/fputws.3
===================================================================
--- trunk/lib/libc/stdio/fputws.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fputws.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -31,7 +32,7 @@
.\"
.\" @(#)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
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fputws.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd August 6, 2002
.Dt FPUTWS 3
Property changes on: trunk/lib/libc/stdio/fputws.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fputws.c
===================================================================
--- trunk/lib/libc/stdio/fputws.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fputws.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fputws.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
@@ -53,11 +54,13 @@
const wchar_t *wsp;
FIX_LOCALE(locale);
struct xlocale_ctype *l = XLOCALE_CTYPE(locale);
+ int ret;
- FLOCKFILE(fp);
+ ret = -1;
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, 1);
if (prepwrite(fp) != 0)
- goto error;
+ goto end;
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
iov.iov_base = buf;
@@ -66,17 +69,15 @@
nbytes = l->__wcsnrtombs(buf, &wsp, SIZE_T_MAX, sizeof(buf),
&fp->_mbstate);
if (nbytes == (size_t)-1)
- goto error;
- iov.iov_len = uio.uio_resid = nbytes;
+ goto end;
+ uio.uio_resid = iov.iov_len = nbytes;
if (__sfvwrite(fp, &uio) != 0)
- goto error;
+ goto end;
} while (wsp != NULL);
- FUNLOCKFILE(fp);
- return (0);
-
-error:
- FUNLOCKFILE(fp);
- return (-1);
+ ret = 0;
+end:
+ FUNLOCKFILE_CANCELSAFE();
+ return (ret);
}
int
Modified: trunk/lib/libc/stdio/fread.3
===================================================================
--- trunk/lib/libc/stdio/fread.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fread.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)fread.3 8.2 (Berkeley) 3/8/94
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fread.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd March 8, 1994
.Dt FREAD 3
Property changes on: trunk/lib/libc/stdio/fread.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fread.c
===================================================================
--- trunk/lib/libc/stdio/fread.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fread.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fread.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
@@ -54,9 +55,9 @@
{
size_t ret;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ret = __fread(buf, size, count, fp);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
Modified: trunk/lib/libc/stdio/freopen.c
===================================================================
--- trunk/lib/libc/stdio/freopen.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/freopen.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)freopen.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/freopen.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <sys/types.h>
@@ -55,10 +56,8 @@
* all possible, no matter what.
*/
FILE *
-freopen(file, mode, fp)
- const char * __restrict file;
- const char * __restrict mode;
- FILE *fp;
+freopen(const char * __restrict file, const char * __restrict mode,
+ FILE * __restrict fp)
{
int f;
int dflags, flags, isopen, oflags, sverrno, wantfd;
@@ -70,7 +69,7 @@
return (NULL);
}
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
if (!__sdidinit)
__sinit();
@@ -83,23 +82,24 @@
if (file == NULL) {
/* See comment below regarding freopen() of closed files. */
if (fp->_flags == 0) {
- FUNLOCKFILE(fp);
errno = EINVAL;
- return (NULL);
+ fp = NULL;
+ goto end;
}
if ((dflags = _fcntl(fp->_file, F_GETFL)) < 0) {
sverrno = errno;
fclose(fp);
- FUNLOCKFILE(fp);
errno = sverrno;
- return (NULL);
+ fp = NULL;
+ goto end;
}
- if ((dflags & O_ACCMODE) != O_RDWR && (dflags & O_ACCMODE) !=
- (oflags & O_ACCMODE)) {
+ /* Work around incorrect O_ACCMODE. */
+ if ((dflags & O_ACCMODE) != O_RDWR &&
+ (dflags & (O_ACCMODE | O_EXEC)) != (oflags & O_ACCMODE)) {
fclose(fp);
- FUNLOCKFILE(fp);
- errno = EINVAL;
- return (NULL);
+ errno = EBADF;
+ fp = NULL;
+ goto end;
}
if (fp->_flags & __SWR)
(void) __sflush(fp);
@@ -109,9 +109,9 @@
if (_fcntl(fp->_file, F_SETFL, dflags) < 0) {
sverrno = errno;
fclose(fp);
- FUNLOCKFILE(fp);
errno = sverrno;
- return (NULL);
+ fp = NULL;
+ goto end;
}
}
if (oflags & O_TRUNC)
@@ -118,6 +118,8 @@
(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);
f = fp->_file;
isopen = 0;
wantfd = -1;
@@ -150,6 +152,14 @@
/* Get a new descriptor to refer to the new file. */
f = _open(file, oflags, DEFFILEMODE);
+ /* If out of fd's close the old one and try again. */
+ if (f < 0 && isopen && wantfd > STDERR_FILENO &&
+ (errno == ENFILE || errno == EMFILE)) {
+ (void) (*fp->_close)(fp->_cookie);
+ isopen = 0;
+ wantfd = -1;
+ f = _open(file, oflags, DEFFILEMODE);
+ }
sverrno = errno;
finish:
@@ -178,14 +188,15 @@
fp->_lb._size = 0;
fp->_orientation = 0;
memset(&fp->_mbstate, 0, sizeof(mbstate_t));
+ fp->_flags2 = 0;
if (f < 0) { /* did not get it after all */
if (isopen)
(void) (*fp->_close)(fp->_cookie);
fp->_flags = 0; /* set it free */
- FUNLOCKFILE(fp);
errno = sverrno; /* restore in case _close clobbered */
- return (NULL);
+ fp = NULL;
+ goto end;
}
/*
@@ -194,7 +205,8 @@
* assume stderr is always fd STDERR_FILENO, even if being freopen'd.
*/
if (wantfd >= 0) {
- if (_dup2(f, wantfd) >= 0) {
+ if ((oflags & O_CLOEXEC ? _fcntl(f, F_DUP2FD_CLOEXEC, wantfd) :
+ _dup2(f, wantfd)) >= 0) {
(void)_close(f);
f = wantfd;
} else
@@ -210,9 +222,9 @@
*/
if (f > SHRT_MAX) {
fp->_flags = 0; /* set it free */
- FUNLOCKFILE(fp);
errno = EMFILE;
- return (NULL);
+ fp = NULL;
+ goto end;
}
fp->_flags = flags;
@@ -230,8 +242,11 @@
* we can do about this. (We could set __SAPP and check in
* fseek and ftell.)
*/
- if (oflags & O_APPEND)
+ if (oflags & O_APPEND) {
+ fp->_flags2 |= __S2OAP;
(void) _sseek(fp, (fpos_t)0, SEEK_END);
- FUNLOCKFILE(fp);
+ }
+end:
+ FUNLOCKFILE_CANCELSAFE();
return (fp);
}
Modified: trunk/lib/libc/stdio/fscanf.c
===================================================================
--- trunk/lib/libc/stdio/fscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)fscanf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fscanf.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -56,10 +57,10 @@
va_list ap;
va_start(ap, fmt);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ret = __svfscanf(fp, __get_locale(), fmt, ap);
va_end(ap);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
int
@@ -70,9 +71,9 @@
FIX_LOCALE(locale);
va_start(ap, fmt);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ret = __svfscanf(fp, locale, fmt, ap);
va_end(ap);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
Modified: trunk/lib/libc/stdio/fseek.3
===================================================================
--- trunk/lib/libc/stdio/fseek.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fseek.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)fseek.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fseek.3 170908 2007-06-18 02:13:04Z ache $
.\"
.Dd March 19, 2004
.Dt FSEEK 3
Property changes on: trunk/lib/libc/stdio/fseek.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fseek.c
===================================================================
--- trunk/lib/libc/stdio/fseek.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fseek.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fseek.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <sys/types.h>
@@ -51,10 +52,7 @@
#define POS_ERR (-(fpos_t)1)
int
-fseek(fp, offset, whence)
- FILE *fp;
- long offset;
- int whence;
+fseek(FILE *fp, long offset, int whence)
{
int ret;
int serrno = errno;
@@ -63,9 +61,9 @@
if (!__sdidinit)
__sinit();
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ret = _fseeko(fp, (off_t)offset, whence, 1);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
if (ret == 0)
errno = serrno;
return (ret);
@@ -72,10 +70,7 @@
}
int
-fseeko(fp, offset, whence)
- FILE *fp;
- off_t offset;
- int whence;
+fseeko(FILE *fp, off_t offset, int whence)
{
int ret;
int serrno = errno;
@@ -84,9 +79,9 @@
if (!__sdidinit)
__sinit();
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ret = _fseeko(fp, offset, whence, 0);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
if (ret == 0)
errno = serrno;
return (ret);
@@ -97,11 +92,7 @@
* `Whence' must be one of the three SEEK_* macros.
*/
int
-_fseeko(fp, offset, whence, ltest)
- FILE *fp;
- off_t offset;
- int whence;
- int ltest;
+_fseeko(FILE *fp, off_t offset, int whence, int ltest)
{
fpos_t (*seekfn)(void *, fpos_t, int);
fpos_t target, curoff, ret;
Modified: trunk/lib/libc/stdio/fsetpos.c
===================================================================
--- trunk/lib/libc/stdio/fsetpos.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fsetpos.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fsetpos.c 249810 2013-04-23 14:36:44Z emaste $");
#include <sys/types.h>
#include <stdio.h>
@@ -43,9 +44,7 @@
* fsetpos: like fseek.
*/
int
-fsetpos(iop, pos)
- FILE *iop;
- const fpos_t *pos;
+fsetpos(FILE *iop, const fpos_t *pos)
{
return (fseeko(iop, (off_t)*pos, SEEK_SET));
}
Modified: trunk/lib/libc/stdio/ftell.c
===================================================================
--- trunk/lib/libc/stdio/ftell.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/ftell.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/ftell.c 291050 2015-11-19 02:04:16Z ache $");
#include "namespace.h"
#include <sys/types.h>
@@ -49,8 +50,7 @@
* standard ftell function.
*/
long
-ftell(fp)
- FILE *fp;
+ftell(FILE *fp)
{
off_t rv;
@@ -66,8 +66,7 @@
* ftello: return current offset.
*/
off_t
-ftello(fp)
- FILE *fp;
+ftello(FILE *fp)
{
fpos_t rv;
int ret;
@@ -85,9 +84,7 @@
}
int
-_ftello(fp, offset)
- FILE *fp;
- fpos_t *offset;
+_ftello(FILE *fp, fpos_t *offset)
{
fpos_t pos;
size_t n;
@@ -101,7 +98,13 @@
* Find offset of underlying I/O object, then
* adjust for buffered bytes.
*/
- if (fp->_flags & __SOFF)
+ if (!(fp->_flags & __SRD) && (fp->_flags & __SWR) &&
+ fp->_p != NULL && fp->_p - fp->_bf._base > 0 &&
+ ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP))) {
+ pos = _sseek(fp, (fpos_t)0, SEEK_END);
+ if (pos == -1)
+ return (1);
+ } else if (fp->_flags & __SOFF)
pos = fp->_offset;
else {
pos = _sseek(fp, (fpos_t)0, SEEK_CUR);
@@ -121,13 +124,13 @@
}
if (HASUB(fp))
pos -= fp->_r; /* Can be negative at this point. */
- } else if ((fp->_flags & __SWR) && fp->_p != NULL) {
+ } else if ((fp->_flags & __SWR) && fp->_p != NULL &&
+ (n = fp->_p - fp->_bf._base) > 0) {
/*
* Writing. Any buffered characters cause the
* position to be greater than that in the
* underlying object.
*/
- n = fp->_p - fp->_bf._base;
if (pos > OFF_MAX - n) {
errno = EOVERFLOW;
return (1);
Modified: trunk/lib/libc/stdio/funopen.3
===================================================================
--- trunk/lib/libc/stdio/funopen.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/funopen.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -28,7 +29,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)funopen.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/funopen.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd March 19, 2004
.Dt FUNOPEN 3
Property changes on: trunk/lib/libc/stdio/funopen.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/funopen.c
===================================================================
--- trunk/lib/libc/stdio/funopen.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/funopen.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/funopen.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include <errno.h>
Modified: trunk/lib/libc/stdio/fvwrite.c
===================================================================
--- trunk/lib/libc/stdio/fvwrite.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fvwrite.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fvwrite.c 249810 2013-04-23 14:36:44Z emaste $");
#include <stdio.h>
#include <stdlib.h>
@@ -49,9 +50,7 @@
* to the three different kinds of output buffering is handled here.
*/
int
-__sfvwrite(fp, uio)
- FILE *fp;
- struct __suio *uio;
+__sfvwrite(FILE *fp, struct __suio *uio)
{
size_t len;
char *p;
Modified: trunk/lib/libc/stdio/fvwrite.h
===================================================================
--- trunk/lib/libc/stdio/fvwrite.h 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fvwrite.h 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)fvwrite.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libc/stdio/fvwrite.h 165903 2007-01-09 00:28:16Z imp $
*/
/*
Modified: trunk/lib/libc/stdio/fwalk.c
===================================================================
--- trunk/lib/libc/stdio/fwalk.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fwalk.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,17 +35,15 @@
static char sccsid[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fwalk.c 249810 2013-04-23 14:36:44Z emaste $");
#include <sys/types.h>
-#include <machine/atomic.h>
#include <stdio.h>
#include "local.h"
#include "glue.h"
int
-_fwalk(function)
- int (*function)(FILE *);
+_fwalk(int (*function)(FILE *))
{
FILE *fp;
int n, ret;
Modified: trunk/lib/libc/stdio/fwide.3
===================================================================
--- trunk/lib/libc/stdio/fwide.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fwide.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $NetBSD: fwide.3,v 1.3 2002/02/07 07:00:25 ross Exp $
.\"
.\" Copyright (c)2001 Citrus Project,
@@ -25,7 +26,7 @@
.\" SUCH DAMAGE.
.\"
.\" $Citrus: xpg4dl/FreeBSD/lib/libc/stdio/fwide.3,v 1.2 2001/12/07 04:47:08 yamt Exp $
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/fwide.3 108037 2002-12-18 12:45:11Z ru $
.\"
.Dd October 24, 2001
.Dt FWIDE 3
Property changes on: trunk/lib/libc/stdio/fwide.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/fwide.c
===================================================================
--- trunk/lib/libc/stdio/fwide.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fwide.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins.
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fwide.c 178287 2008-04-17 22:17:54Z jhb $");
#include "namespace.h"
#include <errno.h>
Modified: trunk/lib/libc/stdio/fwprintf.c
===================================================================
--- trunk/lib/libc/stdio/fwprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fwprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fwprintf.c 227753 2011-11-20 14:45:42Z theraven $");
#include <stdarg.h>
#include <stdio.h>
Modified: trunk/lib/libc/stdio/fwrite.c
===================================================================
--- trunk/lib/libc/stdio/fwrite.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fwrite.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fwrite.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
@@ -50,10 +51,7 @@
* Return the number of whole objects written.
*/
size_t
-fwrite(buf, size, count, fp)
- const void * __restrict buf;
- size_t size, count;
- FILE * __restrict fp;
+fwrite(const void * __restrict buf, size_t size, size_t count, FILE * __restrict fp)
{
size_t n;
struct __suio uio;
@@ -68,7 +66,7 @@
/*
* Check for integer overflow. As an optimization, first check that
* at least one of {count, size} is at least 2^16, since if both
- * values are less than that, their product can't possible overflow
+ * values are less than that, their product can't possibly overflow
* (size_t is always at least 32 bits on FreeBSD).
*/
if (((count | size) > 0xFFFF) &&
@@ -85,7 +83,7 @@
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, -1);
/*
* The usual case is success (__sfvwrite returns 0);
@@ -94,6 +92,6 @@
*/
if (__sfvwrite(fp, &uio) != 0)
count = (n - uio.uio_resid) / size;
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (count);
}
Modified: trunk/lib/libc/stdio/fwscanf.c
===================================================================
--- trunk/lib/libc/stdio/fwscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/fwscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/fwscanf.c 227753 2011-11-20 14:45:42Z theraven $");
#include <stdarg.h>
#include <stdio.h>
Modified: trunk/lib/libc/stdio/getc.3
===================================================================
--- trunk/lib/libc/stdio/getc.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/getc.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)getc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/getc.3 201836 2010-01-08 22:02:42Z brueffer $
.\"
.Dd January 10, 2003
.Dt GETC 3
Property changes on: trunk/lib/libc/stdio/getc.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/getc.c
===================================================================
--- trunk/lib/libc/stdio/getc.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/getc.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/getc.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -49,11 +50,11 @@
getc(FILE *fp)
{
int retval;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
/* Orientation set by __sgetc() when buffer is empty. */
/* ORIENT(fp, -1); */
retval = __sgetc(fp);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
Modified: trunk/lib/libc/stdio/getchar.c
===================================================================
--- trunk/lib/libc/stdio/getchar.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/getchar.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/getchar.c 321074 2017-07-17 14:09:34Z kib $");
/*
* A subroutine version of the macro getchar.
@@ -49,14 +50,14 @@
#undef getchar_unlocked
int
-getchar()
+getchar(void)
{
int retval;
- FLOCKFILE(stdin);
+ FLOCKFILE_CANCELSAFE(stdin);
/* Orientation set by __sgetc() when buffer is empty. */
/* ORIENT(stdin, -1); */
retval = __sgetc(stdin);
- FUNLOCKFILE(stdin);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
Modified: trunk/lib/libc/stdio/getdelim.c
===================================================================
--- trunk/lib/libc/stdio/getdelim.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/getdelim.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2009 David Schultz <das at FreeBSD.org>
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/getdelim.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <sys/param.h>
@@ -112,7 +113,7 @@
u_char *endp;
size_t linelen;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, -1);
if (linep == NULL || linecapp == NULL) {
@@ -125,11 +126,11 @@
if (fp->_r <= 0 && __srefill(fp)) {
/* If fp is at EOF already, we just need space for the NUL. */
- if (__sferror(fp) || expandtofit(linep, 1, linecapp))
+ if (!__sfeof(fp) || expandtofit(linep, 1, linecapp))
goto error;
- FUNLOCKFILE(fp);
(*linep)[0] = '\0';
- return (-1);
+ linelen = -1;
+ goto end;
}
linelen = 0;
@@ -137,7 +138,7 @@
if (sappend(linep, &linelen, linecapp, fp->_p, fp->_r))
goto error;
if (__srefill(fp)) {
- if (__sferror(fp))
+ if (!__sfeof(fp))
goto error;
goto done; /* hit EOF */
}
@@ -150,11 +151,12 @@
done:
/* Invariant: *linep has space for at least linelen+1 bytes. */
(*linep)[linelen] = '\0';
- FUNLOCKFILE(fp);
+end:
+ FUNLOCKFILE_CANCELSAFE();
return (linelen);
error:
fp->_flags |= __SERR;
- FUNLOCKFILE(fp);
- return (-1);
+ linelen = -1;
+ goto end;
}
Modified: trunk/lib/libc/stdio/getline.3
===================================================================
--- trunk/lib/libc/stdio/getline.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/getline.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 2009 David Schultz <das at FreeBSD.org>
.\" All rights reserved.
.\"
@@ -22,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/getline.3 291572 2015-12-01 07:16:05Z ngie $
.\"
.Dd November 30, 2012
.Dt GETLINE 3
@@ -95,6 +96,7 @@
ssize_t linelen;
while ((linelen = getline(&line, &linecap, fp)) > 0)
fwrite(line, linelen, 1, stdout);
+free(line);
.Ed
.Sh COMPATIBILITY
Many application writers used the name
Property changes on: trunk/lib/libc/stdio/getline.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/getline.c
===================================================================
--- trunk/lib/libc/stdio/getline.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/getline.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2009 David Schultz <das at FreeBSD.org>
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/getline.c 189136 2009-02-28 06:00:58Z das $");
#define _WITH_GETLINE
#include <stdio.h>
Modified: trunk/lib/libc/stdio/gets.c
===================================================================
--- trunk/lib/libc/stdio/gets.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/gets.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,12 +35,11 @@
static char sccsid[] = "@(#)gets.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/gets.c 325381 2017-11-04 05:17:03Z cy $");
#include "namespace.h"
#include <unistd.h>
#include <stdio.h>
-#include <sys/cdefs.h>
#include "un-namespace.h"
#include "libc_private.h"
#include "local.h"
@@ -47,31 +47,33 @@
__warn_references(gets, "warning: this program uses gets(), which is unsafe.");
char *
-gets(buf)
- char *buf;
+gets(char *buf)
{
int c;
- char *s;
+ char *s, *ret;
static int warned;
- static char w[] =
+ static const char w[] =
"warning: this program uses gets(), which is unsafe.\n";
- FLOCKFILE(stdin);
+ FLOCKFILE_CANCELSAFE(stdin);
ORIENT(stdin, -1);
if (!warned) {
(void) _write(STDERR_FILENO, w, sizeof(w) - 1);
warned = 1;
}
- for (s = buf; (c = __sgetc(stdin)) != '\n';)
+ for (s = buf; (c = __sgetc(stdin)) != '\n'; ) {
if (c == EOF)
if (s == buf) {
- FUNLOCKFILE(stdin);
- return (NULL);
+ ret = NULL;
+ goto end;
} else
break;
else
*s++ = c;
+ }
*s = 0;
- FUNLOCKFILE(stdin);
- return (buf);
+ ret = buf;
+end:
+ FUNLOCKFILE_CANCELSAFE();
+ return (ret);
}
Modified: trunk/lib/libc/stdio/getw.c
===================================================================
--- trunk/lib/libc/stdio/getw.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/getw.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,13 +35,12 @@
static char sccsid[] = "@(#)getw.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/getw.c 249810 2013-04-23 14:36:44Z emaste $");
#include <stdio.h>
int
-getw(fp)
- FILE *fp;
+getw(FILE *fp)
{
int x;
Modified: trunk/lib/libc/stdio/getwc.3
===================================================================
--- trunk/lib/libc/stdio/getwc.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/getwc.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $NetBSD: getwc.3,v 1.3 2002/02/07 07:00:26 ross Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
@@ -32,7 +33,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)getc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/getwc.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd March 3, 2004
.Dt GETWC 3
Property changes on: trunk/lib/libc/stdio/getwc.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/getwc.c
===================================================================
--- trunk/lib/libc/stdio/getwc.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/getwc.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins.
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/getwc.c 227753 2011-11-20 14:45:42Z theraven $");
#include "namespace.h"
#include <stdio.h>
Modified: trunk/lib/libc/stdio/getwchar.c
===================================================================
--- trunk/lib/libc/stdio/getwchar.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/getwchar.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins.
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/getwchar.c 227753 2011-11-20 14:45:42Z theraven $");
#include "namespace.h"
#include <stdio.h>
Modified: trunk/lib/libc/stdio/glue.h
===================================================================
--- trunk/lib/libc/stdio/glue.h 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/glue.h 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)glue.h 8.1 (Berkeley) 6/4/93
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libc/stdio/glue.h 165903 2007-01-09 00:28:16Z imp $
*/
/*
Modified: trunk/lib/libc/stdio/local.h
===================================================================
--- trunk/lib/libc/stdio/local.h 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/local.h 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -35,9 +36,12 @@
* SUCH DAMAGE.
*
* @(#)local.h 8.3 (Berkeley) 7/3/94
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libc/stdio/local.h 321074 2017-07-17 14:09:34Z kib $
*/
+#ifndef _STDIO_LOCAL_H
+#define _STDIO_LOCAL_H
+
#include <sys/types.h> /* for off_t */
#include <pthread.h>
#include <string.h>
@@ -56,7 +60,7 @@
extern int _fseeko(FILE *, off_t, int, int);
extern int __fflush(FILE *fp);
extern void __fcloseall(void);
-extern wint_t __fgetwc(FILE *, locale_t);
+extern wint_t __fgetwc_mbs(FILE *, mbstate_t *, int *, locale_t);
extern wint_t __fputwc(wchar_t, FILE *, locale_t);
extern int __sflush(FILE *);
extern FILE *__sfp(void);
@@ -85,7 +89,14 @@
FILE * __restrict fp);
extern int __sdidinit;
+static inline wint_t
+__fgetwc(FILE *fp, locale_t locale)
+{
+ int nread;
+ return (__fgetwc_mbs(fp, &fp->_mbstate, &nread, locale));
+}
+
/*
* Prepare the given FILE for writing, and return 0 iff it
* can be written now. Otherwise, return EOF and set errno.
@@ -131,3 +142,26 @@
if ((fp)->_orientation == 0) \
(fp)->_orientation = (o); \
} while (0)
+
+void __stdio_cancel_cleanup(void *);
+#define FLOCKFILE_CANCELSAFE(fp) \
+ { \
+ struct _pthread_cleanup_info __cleanup_info__; \
+ if (__isthreaded) { \
+ _FLOCKFILE(fp); \
+ ___pthread_cleanup_push_imp( \
+ __stdio_cancel_cleanup, (fp), \
+ &__cleanup_info__); \
+ } else { \
+ ___pthread_cleanup_push_imp( \
+ __stdio_cancel_cleanup, NULL, \
+ &__cleanup_info__); \
+ } \
+ {
+#define FUNLOCKFILE_CANCELSAFE() \
+ (void)0; \
+ } \
+ ___pthread_cleanup_pop_imp(1); \
+ }
+
+#endif /* _STDIO_LOCAL_H */
Modified: trunk/lib/libc/stdio/makebuf.c
===================================================================
--- trunk/lib/libc/stdio/makebuf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/makebuf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)makebuf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/makebuf.c 249810 2013-04-23 14:36:44Z emaste $");
#include "namespace.h"
#include <sys/types.h>
@@ -55,8 +56,7 @@
* optimisation) right after the _fstat() that finds the buffer size.
*/
void
-__smakebuf(fp)
- FILE *fp;
+__smakebuf(FILE *fp)
{
void *p;
int flags;
@@ -88,10 +88,7 @@
* Internal routine to determine `proper' buffering for a file.
*/
int
-__swhatbuf(fp, bufsize, couldbetty)
- FILE *fp;
- size_t *bufsize;
- int *couldbetty;
+__swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty)
{
struct stat st;
Modified: trunk/lib/libc/stdio/mktemp.3
===================================================================
--- trunk/lib/libc/stdio/mktemp.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/mktemp.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -26,9 +27,9 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)mktemp.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/mktemp.3 254151 2013-08-09 17:24:23Z jilles $
.\"
-.Dd March 4, 2012
+.Dd August 8, 2013
.Dt MKTEMP 3
.Os
.Sh NAME
@@ -37,15 +38,20 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In unistd.h
+.In stdlib.h
.Ft char *
.Fn mktemp "char *template"
.Ft int
.Fn mkstemp "char *template"
.Ft int
-.Fn mkstemps "char *template" "int suffixlen"
+.Fn mkostemp "char *template" "int oflags"
+.Ft int
+.Fn mkostemps "char *template" "int suffixlen" "int oflags"
.Ft char *
.Fn mkdtemp "char *template"
+.In unistd.h
+.Ft int
+.Fn mkstemps "char *template" "int suffixlen"
.Sh DESCRIPTION
The
.Fn mktemp
@@ -84,16 +90,41 @@
for use.
.Pp
The
+.Fn mkostemp
+function
+is like
+.Fn mkstemp
+but allows specifying additional
+.Xr open 2
+flags (defined in
+.In fcntl.h ) .
+The permitted flags are
+.Dv O_APPEND ,
+.Dv O_DIRECT ,
+.Dv O_SHLOCK ,
+.Dv O_EXLOCK ,
+.Dv O_SYNC
+and
+.Dv O_CLOEXEC .
+.Pp
+The
.Fn mkstemps
-function acts the same as
-.Fn mkstemp ,
-except it permits a suffix to exist in the template.
+and
+.Fn mkostemps
+functions act the same as
+.Fn mkstemp
+and
+.Fn mkostemp
+respectively,
+except they permit a suffix to exist in the template.
The template should be of the form
.Pa /tmp/tmpXXXXXXsuffix .
The
.Fn mkstemps
+and
+.Fn mkostemps
function
-is told the length of the suffix string.
+are told the length of the suffix string.
.Pp
The
.Fn mkdtemp
@@ -109,9 +140,11 @@
.Dv NULL
on failure.
The
-.Fn mkstemp
+.Fn mkstemp ,
+.Fn mkostemp
+.Fn mkstemps
and
-.Fn mkstemps
+.Fn mkostemps
functions
return \-1 if no suitable file could be created.
If either call fails an error code is placed in the global variable
@@ -119,7 +152,9 @@
.Sh ERRORS
The
.Fn mkstemp ,
-.Fn mkstemps
+.Fn mkostemp ,
+.Fn mkstemps ,
+.Fn mkostemps
and
.Fn mkdtemp
functions
@@ -132,8 +167,25 @@
.El
.Pp
The
+.Fn mkostemp
+and
+.Fn mkostemps
+functions
+may also set
+.Va errno
+to the following value:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The
+.Fa oflags
+argument is invalid.
+.El
+.Pp
+The
.Fn mkstemp ,
-.Fn mkstemps
+.Fn mkostemp ,
+.Fn mkstemps ,
+.Fn mkostemps
and
.Fn mkdtemp
functions
@@ -144,9 +196,11 @@
function.
.Pp
The
-.Fn mkstemp
+.Fn mkstemp ,
+.Fn mkostemp ,
+.Fn mkstemps
and
-.Fn mkstemps
+.Fn mkostemps
functions
may also set
.Va errno
@@ -180,6 +234,14 @@
will result in a core dump due to
.Fn mkstemp
attempting to modify the string constant that was given.
+.Pp
+The
+.Fn mkdtemp ,
+.Fn mkstemp
+and
+.Fn mktemp
+function prototypes are also available from
+.In unistd.h .
.Sh SEE ALSO
.Xr chmod 2 ,
.Xr getpid 2 ,
@@ -186,6 +248,25 @@
.Xr mkdir 2 ,
.Xr open 2 ,
.Xr stat 2
+.Sh STANDARDS
+The
+.Fn mkstemp
+and
+.Fn mkdtemp
+functions are expected to conform to
+.St -p1003.1-2008 .
+The
+.Fn mktemp
+function is expected to conform to
+.St -p1003.1-2001
+and is not specified by
+.St -p1003.1-2008 .
+The
+.Fn mkostemp ,
+.Fn mkstemps
+and
+.Fn mkostemps
+functions do not conform to any standard.
.Sh HISTORY
A
.Fn mktemp
@@ -207,6 +288,12 @@
.Ox 2.4 ,
and later in
.Fx 3.4 .
+The
+.Fn mkostemp
+and
+.Fn mkostemps
+functions appeared in
+.Fx 10.0 .
.Sh BUGS
This family of functions produces filenames which can be guessed,
though the risk is minimized when large numbers of
@@ -223,6 +310,8 @@
particularly dangerous from a security perspective.
Whenever it is possible,
.Fn mkstemp
+or
+.Fn mkostemp
should be used instead, since it does not have the race condition.
If
.Fn mkstemp
Property changes on: trunk/lib/libc/stdio/mktemp.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/mktemp.c
===================================================================
--- trunk/lib/libc/stdio/mktemp.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/mktemp.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
@@ -10,7 +11,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -31,7 +32,7 @@
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/mktemp.c 254151 2013-08-09 17:24:23Z jilles $");
#include "namespace.h"
#include <sys/param.h>
@@ -47,42 +48,53 @@
char *_mktemp(char *);
-static int _gettemp(char *, int *, int, int);
+static int _gettemp(char *, int *, int, int, int);
static const unsigned char padchar[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int
-mkstemps(path, slen)
- char *path;
- int slen;
+mkostemps(char *path, int slen, int oflags)
{
int fd;
- return (_gettemp(path, &fd, 0, slen) ? fd : -1);
+ return (_gettemp(path, &fd, 0, slen, oflags) ? fd : -1);
}
int
-mkstemp(path)
- char *path;
+mkstemps(char *path, int slen)
{
int fd;
- return (_gettemp(path, &fd, 0, 0) ? fd : -1);
+ return (_gettemp(path, &fd, 0, slen, 0) ? fd : -1);
}
+int
+mkostemp(char *path, int oflags)
+{
+ int fd;
+
+ return (_gettemp(path, &fd, 0, 0, oflags) ? fd : -1);
+}
+
+int
+mkstemp(char *path)
+{
+ int fd;
+
+ return (_gettemp(path, &fd, 0, 0, 0) ? fd : -1);
+}
+
char *
-mkdtemp(path)
- char *path;
+mkdtemp(char *path)
{
- return (_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL);
+ return (_gettemp(path, (int *)NULL, 1, 0, 0) ? path : (char *)NULL);
}
char *
-_mktemp(path)
- char *path;
+_mktemp(char *path)
{
- return (_gettemp(path, (int *)NULL, 0, 0) ? path : (char *)NULL);
+ return (_gettemp(path, (int *)NULL, 0, 0, 0) ? path : (char *)NULL);
}
__warn_references(mktemp,
@@ -89,18 +101,13 @@
"warning: mktemp() possibly used unsafely; consider using mkstemp()");
char *
-mktemp(path)
- char *path;
+mktemp(char *path)
{
return (_mktemp(path));
}
static int
-_gettemp(path, doopen, domkdir, slen)
- char *path;
- int *doopen;
- int domkdir;
- int slen;
+_gettemp(char *path, int *doopen, int domkdir, int slen, int oflags)
{
char *start, *trv, *suffp, *carryp;
char *pad;
@@ -109,7 +116,9 @@
uint32_t rand;
char carrybuf[MAXPATHLEN];
- if ((doopen != NULL && domkdir) || slen < 0) {
+ if ((doopen != NULL && domkdir) || slen < 0 ||
+ (oflags & ~(O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC |
+ O_CLOEXEC)) != 0) {
errno = EINVAL;
return (0);
}
@@ -161,7 +170,8 @@
for (;;) {
if (doopen) {
if ((*doopen =
- _open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0)
+ _open(path, O_CREAT|O_EXCL|O_RDWR|oflags, 0600)) >=
+ 0)
return (1);
if (errno != EEXIST)
return (0);
Added: trunk/lib/libc/stdio/open_memstream.3
===================================================================
--- trunk/lib/libc/stdio/open_memstream.3 (rev 0)
+++ trunk/lib/libc/stdio/open_memstream.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -0,0 +1,156 @@
+.\" $MidnightBSD$
+.\" Copyright (c) 2013 Hudson River Trading LLC
+.\" Written by: John H. Baldwin <jhb at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD: stable/10/lib/libc/stdio/open_memstream.3 288464 2015-10-01 21:57:15Z jhb $
+.\"
+.Dd August 1, 2015
+.Dt OPEN_MEMSTREAM 3
+.Os
+.Sh NAME
+.Nm open_memstream ,
+.Nm open_wmemstream
+.Nd dynamic memory buffer stream open functions
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.Ft FILE *
+.Fn open_memstream "char **bufp" "size_t *sizep"
+.In wchar.h
+.Ft FILE *
+.Fn open_wmemstream "wchar_t **bufp" "size_t *sizep"
+.Sh DESCRIPTION
+The
+.Fn open_memstream
+and
+.Fn open_wmemstream
+functions create a write-only, seekable stream backed by a dynamically
+allocated memory buffer.
+The
+.Fn open_memstream
+function creates a byte-oriented stream,
+while the
+.Fn open_wmemstream
+function creates a wide-oriented stream.
+.Pp
+Each stream maintains a current position and size.
+Initially,
+the position and size are set to zero.
+Each write begins at the current position and advances it the number of
+successfully written bytes for
+.Fn open_memstream
+or wide characters for
+.Fn open_wmemstream .
+If a write moves the current position beyond the length of the buffer,
+the length of the buffer is extended and a null character is appended to the
+buffer.
+.Pp
+A stream's buffer always contains a null character at the end of the buffer
+that is not included in the current length.
+.Pp
+If a stream's current position is moved beyond the current length via a
+seek operation and a write is performed,
+the characters between the current length and the current position are filled
+with null characters before the write is performed.
+.Pp
+After a successful call to
+.Xr fclose 3
+or
+.Xr fflush 3 ,
+the pointer referenced by
+.Fa bufp
+will contain the start of the memory buffer and the variable referenced by
+.Fa sizep
+will contain the smaller of the current position and the current buffer length.
+.Pp
+After a successful call to
+.Xr fflush 3 ,
+the pointer referenced by
+.Fa bufp
+and the variable referenced by
+.Fa sizep
+are only valid until the next write operation or a call to
+.Xr fclose 3 .
+.Pp
+Once a stream is closed,
+the allocated buffer referenced by
+.Fa bufp
+should be released via a call to
+.Xr free 3
+when it is no longer needed.
+.Sh IMPLEMENTATION NOTES
+Internally all I/O streams are effectively byte-oriented,
+so using wide-oriented operations to write to a stream opened via
+.Fn open_wmemstream
+results in wide characters being expanded to a stream of multibyte characters
+in stdio's internal buffers.
+These multibyte characters are then converted back to wide characters when
+written into the stream.
+As a result,
+the wide-oriented streams maintain an internal multibyte character conversion
+state that is cleared on any seek opertion that changes the current position.
+This should have no effect as long as wide-oriented output operations are used
+on a wide-oriented stream.
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn open_memstream
+and
+.Fn open_wmemstream
+return a
+.Tn FILE
+pointer.
+Otherwise,
+.Dv NULL
+is returned and the global variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The
+.Fa bufp
+or
+.Fa sizep
+argument was
+.Dv NULL .
+.It Bq Er ENOMEM
+Memory for the stream or buffer could not be allocated.
+.El
+.Sh SEE ALSO
+.Xr fclose 3 ,
+.Xr fflush 3 ,
+.Xr fopen 3 ,
+.Xr free 3 ,
+.Xr fseek 3 ,
+.Xr sbuf 3 ,
+.Xr stdio 3
+.Sh STANDARDS
+The
+.Fn open_memstream
+and
+.Fn open_wmemstream
+functions conform to
+.St -p1003.1-2008 .
Property changes on: trunk/lib/libc/stdio/open_memstream.3
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/stdio/open_memstream.c
===================================================================
--- trunk/lib/libc/stdio/open_memstream.c (rev 0)
+++ trunk/lib/libc/stdio/open_memstream.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -0,0 +1,213 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2013 Hudson River Trading LLC
+ * Written by: John H. Baldwin <jhb at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/open_memstream.c 292150 2015-12-13 04:24:15Z ngie $");
+
+#include "namespace.h"
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#ifdef DEBUG
+#include <stdint.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "un-namespace.h"
+
+/* XXX: There is no FPOS_MAX. This assumes fpos_t is an off_t. */
+#define FPOS_MAX OFF_MAX
+
+struct memstream {
+ char **bufp;
+ size_t *sizep;
+ ssize_t len;
+ fpos_t offset;
+};
+
+static int
+memstream_grow(struct memstream *ms, fpos_t newoff)
+{
+ char *buf;
+ ssize_t newsize;
+
+ if (newoff < 0 || newoff >= SSIZE_MAX)
+ newsize = SSIZE_MAX - 1;
+ else
+ newsize = newoff;
+ if (newsize > ms->len) {
+ buf = realloc(*ms->bufp, newsize + 1);
+ if (buf != NULL) {
+#ifdef DEBUG
+ fprintf(stderr, "MS: %p growing from %zd to %zd\n",
+ ms, ms->len, newsize);
+#endif
+ memset(buf + ms->len + 1, 0, newsize - ms->len);
+ *ms->bufp = buf;
+ ms->len = newsize;
+ return (1);
+ }
+ return (0);
+ }
+ return (1);
+}
+
+static void
+memstream_update(struct memstream *ms)
+{
+
+ assert(ms->len >= 0 && ms->offset >= 0);
+ *ms->sizep = ms->len < ms->offset ? ms->len : ms->offset;
+}
+
+static int
+memstream_write(void *cookie, const char *buf, int len)
+{
+ struct memstream *ms;
+ ssize_t tocopy;
+
+ ms = cookie;
+ if (!memstream_grow(ms, ms->offset + len))
+ return (-1);
+ tocopy = ms->len - ms->offset;
+ if (len < tocopy)
+ tocopy = len;
+ memcpy(*ms->bufp + ms->offset, buf, tocopy);
+ ms->offset += tocopy;
+ memstream_update(ms);
+#ifdef DEBUG
+ fprintf(stderr, "MS: write(%p, %d) = %zd\n", ms, len, tocopy);
+#endif
+ return (tocopy);
+}
+
+static fpos_t
+memstream_seek(void *cookie, fpos_t pos, int whence)
+{
+ struct memstream *ms;
+#ifdef DEBUG
+ fpos_t old;
+#endif
+
+ ms = cookie;
+#ifdef DEBUG
+ old = ms->offset;
+#endif
+ switch (whence) {
+ case SEEK_SET:
+ /* _fseeko() checks for negative offsets. */
+ assert(pos >= 0);
+ ms->offset = pos;
+ break;
+ case SEEK_CUR:
+ /* This is only called by _ftello(). */
+ assert(pos == 0);
+ break;
+ case SEEK_END:
+ if (pos < 0) {
+ if (pos + ms->len < 0) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "MS: bad SEEK_END: pos %jd, len %zd\n",
+ (intmax_t)pos, ms->len);
+#endif
+ errno = EINVAL;
+ return (-1);
+ }
+ } else {
+ if (FPOS_MAX - ms->len < pos) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "MS: bad SEEK_END: pos %jd, len %zd\n",
+ (intmax_t)pos, ms->len);
+#endif
+ errno = EOVERFLOW;
+ return (-1);
+ }
+ }
+ ms->offset = ms->len + pos;
+ break;
+ }
+ memstream_update(ms);
+#ifdef DEBUG
+ fprintf(stderr, "MS: seek(%p, %jd, %d) %jd -> %jd\n", ms, (intmax_t)pos,
+ whence, (intmax_t)old, (intmax_t)ms->offset);
+#endif
+ return (ms->offset);
+}
+
+static int
+memstream_close(void *cookie)
+{
+
+ free(cookie);
+ return (0);
+}
+
+FILE *
+open_memstream(char **bufp, size_t *sizep)
+{
+ struct memstream *ms;
+ int save_errno;
+ FILE *fp;
+
+ if (bufp == NULL || sizep == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ *bufp = calloc(1, 1);
+ if (*bufp == NULL)
+ return (NULL);
+ ms = malloc(sizeof(*ms));
+ if (ms == NULL) {
+ save_errno = errno;
+ free(*bufp);
+ *bufp = NULL;
+ errno = save_errno;
+ return (NULL);
+ }
+ ms->bufp = bufp;
+ ms->sizep = sizep;
+ ms->len = 0;
+ ms->offset = 0;
+ memstream_update(ms);
+ fp = funopen(ms, NULL, memstream_write, memstream_seek,
+ memstream_close);
+ if (fp == NULL) {
+ save_errno = errno;
+ free(ms);
+ free(*bufp);
+ *bufp = NULL;
+ errno = save_errno;
+ return (NULL);
+ }
+ fwide(fp, -1);
+ return (fp);
+}
Property changes on: trunk/lib/libc/stdio/open_memstream.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/stdio/open_wmemstream.c
===================================================================
--- trunk/lib/libc/stdio/open_wmemstream.c (rev 0)
+++ trunk/lib/libc/stdio/open_wmemstream.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -0,0 +1,275 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2013 Hudson River Trading LLC
+ * Written by: John H. Baldwin <jhb at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/open_wmemstream.c 292150 2015-12-13 04:24:15Z ngie $");
+
+#include "namespace.h"
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#ifdef DEBUG
+#include <stdint.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "un-namespace.h"
+
+/* XXX: There is no FPOS_MAX. This assumes fpos_t is an off_t. */
+#define FPOS_MAX OFF_MAX
+
+struct wmemstream {
+ wchar_t **bufp;
+ size_t *sizep;
+ ssize_t len;
+ fpos_t offset;
+ mbstate_t mbstate;
+};
+
+static int
+wmemstream_grow(struct wmemstream *ms, fpos_t newoff)
+{
+ wchar_t *buf;
+ ssize_t newsize;
+
+ if (newoff < 0 || newoff >= SSIZE_MAX / sizeof(wchar_t))
+ newsize = SSIZE_MAX / sizeof(wchar_t) - 1;
+ else
+ newsize = newoff;
+ if (newsize > ms->len) {
+ buf = realloc(*ms->bufp, (newsize + 1) * sizeof(wchar_t));
+ if (buf != NULL) {
+#ifdef DEBUG
+ fprintf(stderr, "WMS: %p growing from %zd to %zd\n",
+ ms, ms->len, newsize);
+#endif
+ wmemset(buf + ms->len + 1, 0, newsize - ms->len);
+ *ms->bufp = buf;
+ ms->len = newsize;
+ return (1);
+ }
+ return (0);
+ }
+ return (1);
+}
+
+static void
+wmemstream_update(struct wmemstream *ms)
+{
+
+ assert(ms->len >= 0 && ms->offset >= 0);
+ *ms->sizep = ms->len < ms->offset ? ms->len : ms->offset;
+}
+
+/*
+ * Based on a starting multibyte state and an input buffer, determine
+ * how many wchar_t's would be output. This doesn't use mbsnrtowcs()
+ * so that it can handle embedded null characters.
+ */
+static size_t
+wbuflen(const mbstate_t *state, const char *buf, int len)
+{
+ mbstate_t lenstate;
+ size_t charlen, count;
+
+ count = 0;
+ lenstate = *state;
+ while (len > 0) {
+ charlen = mbrlen(buf, len, &lenstate);
+ if (charlen == (size_t)-1)
+ return (-1);
+ if (charlen == (size_t)-2)
+ break;
+ if (charlen == 0)
+ /* XXX: Not sure how else to handle this. */
+ charlen = 1;
+ len -= charlen;
+ buf += charlen;
+ count++;
+ }
+ return (count);
+}
+
+static int
+wmemstream_write(void *cookie, const char *buf, int len)
+{
+ struct wmemstream *ms;
+ ssize_t consumed, wlen;
+ size_t charlen;
+
+ ms = cookie;
+ wlen = wbuflen(&ms->mbstate, buf, len);
+ if (wlen < 0) {
+ errno = EILSEQ;
+ return (-1);
+ }
+ if (!wmemstream_grow(ms, ms->offset + wlen))
+ return (-1);
+
+ /*
+ * This copies characters one at a time rather than using
+ * mbsnrtowcs() so it can properly handle embedded null
+ * characters.
+ */
+ consumed = 0;
+ while (len > 0 && ms->offset < ms->len) {
+ charlen = mbrtowc(*ms->bufp + ms->offset, buf, len,
+ &ms->mbstate);
+ if (charlen == (size_t)-1) {
+ if (consumed == 0) {
+ errno = EILSEQ;
+ return (-1);
+ }
+ /* Treat it as a successful short write. */
+ break;
+ }
+ if (charlen == 0)
+ /* XXX: Not sure how else to handle this. */
+ charlen = 1;
+ if (charlen == (size_t)-2) {
+ consumed += len;
+ len = 0;
+ } else {
+ consumed += charlen;
+ buf += charlen;
+ len -= charlen;
+ ms->offset++;
+ }
+ }
+ wmemstream_update(ms);
+#ifdef DEBUG
+ fprintf(stderr, "WMS: write(%p, %d) = %zd\n", ms, len, consumed);
+#endif
+ return (consumed);
+}
+
+static fpos_t
+wmemstream_seek(void *cookie, fpos_t pos, int whence)
+{
+ struct wmemstream *ms;
+ fpos_t old;
+
+ ms = cookie;
+ old = ms->offset;
+ switch (whence) {
+ case SEEK_SET:
+ /* _fseeko() checks for negative offsets. */
+ assert(pos >= 0);
+ ms->offset = pos;
+ break;
+ case SEEK_CUR:
+ /* This is only called by _ftello(). */
+ assert(pos == 0);
+ break;
+ case SEEK_END:
+ if (pos < 0) {
+ if (pos + ms->len < 0) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "WMS: bad SEEK_END: pos %jd, len %zd\n",
+ (intmax_t)pos, ms->len);
+#endif
+ errno = EINVAL;
+ return (-1);
+ }
+ } else {
+ if (FPOS_MAX - ms->len < pos) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "WMS: bad SEEK_END: pos %jd, len %zd\n",
+ (intmax_t)pos, ms->len);
+#endif
+ errno = EOVERFLOW;
+ return (-1);
+ }
+ }
+ ms->offset = ms->len + pos;
+ break;
+ }
+ /* Reset the multibyte state if a seek changes the position. */
+ if (ms->offset != old)
+ memset(&ms->mbstate, 0, sizeof(ms->mbstate));
+ wmemstream_update(ms);
+#ifdef DEBUG
+ fprintf(stderr, "WMS: seek(%p, %jd, %d) %jd -> %jd\n", ms,
+ (intmax_t)pos, whence, (intmax_t)old, (intmax_t)ms->offset);
+#endif
+ return (ms->offset);
+}
+
+static int
+wmemstream_close(void *cookie)
+{
+
+ free(cookie);
+ return (0);
+}
+
+FILE *
+open_wmemstream(wchar_t **bufp, size_t *sizep)
+{
+ struct wmemstream *ms;
+ int save_errno;
+ FILE *fp;
+
+ if (bufp == NULL || sizep == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ *bufp = calloc(1, sizeof(wchar_t));
+ if (*bufp == NULL)
+ return (NULL);
+ ms = malloc(sizeof(*ms));
+ if (ms == NULL) {
+ save_errno = errno;
+ free(*bufp);
+ *bufp = NULL;
+ errno = save_errno;
+ return (NULL);
+ }
+ ms->bufp = bufp;
+ ms->sizep = sizep;
+ ms->len = 0;
+ ms->offset = 0;
+ memset(&ms->mbstate, 0, sizeof(mbstate_t));
+ wmemstream_update(ms);
+ fp = funopen(ms, NULL, wmemstream_write, wmemstream_seek,
+ wmemstream_close);
+ if (fp == NULL) {
+ save_errno = errno;
+ free(ms);
+ free(*bufp);
+ *bufp = NULL;
+ errno = save_errno;
+ return (NULL);
+ }
+ fwide(fp, 1);
+ return (fp);
+}
Property changes on: trunk/lib/libc/stdio/open_wmemstream.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/lib/libc/stdio/perror.c
===================================================================
--- trunk/lib/libc/stdio/perror.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/perror.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
@@ -10,7 +11,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -31,7 +32,7 @@
static char sccsid[] = "@(#)perror.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/perror.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <sys/types.h>
@@ -46,8 +47,7 @@
#include "local.h"
void
-perror(s)
- const char *s;
+perror(const char *s)
{
char msgbuf[NL_TEXTMAX];
struct iovec *v;
@@ -68,9 +68,9 @@
v++;
v->iov_base = "\n";
v->iov_len = 1;
- FLOCKFILE(stderr);
+ FLOCKFILE_CANCELSAFE(stderr);
__sflush(stderr);
(void)_writev(stderr->_file, iov, (v - iov) + 1);
stderr->_flags &= ~__SOFF;
- FUNLOCKFILE(stderr);
+ FUNLOCKFILE_CANCELSAFE();
}
Modified: trunk/lib/libc/stdio/printf-pos.c
===================================================================
--- trunk/lib/libc/stdio/printf-pos.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/printf-pos.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/printf-pos.c 249808 2013-04-23 13:33:13Z emaste $");
/*
* This is the code responsible for handling positional arguments
Modified: trunk/lib/libc/stdio/printf.3
===================================================================
--- trunk/lib/libc/stdio/printf.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/printf.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/printf.3 242738 2012-11-08 02:01:04Z grog $
.\"
.Dd December 2, 2009
.Dt PRINTF 3
@@ -113,20 +114,6 @@
.Xr stdarg 3 )
are converted for output.
.Pp
-These functions return the number of characters printed
-(not including the trailing
-.Ql \e0
-used to end output to strings) or a negative value if an output error occurs,
-except for
-.Fn snprintf
-and
-.Fn vsnprintf ,
-which return the number of characters that would have been printed if the
-.Fa size
-were unlimited
-(again, not including the final
-.Ql \e0 ) .
-.Pp
The
.Fn asprintf
and
@@ -164,7 +151,9 @@
.Fa size
argument, the string was too short
and some of the printed characters were discarded.
-The output is always null-terminated.
+The output is always null-terminated, unless
+.Fa size
+is 0.
.Pp
The
.Fn sprintf
@@ -171,8 +160,10 @@
and
.Fn vsprintf
functions
-effectively assume an infinite
-.Fa size .
+effectively assume a
+.Fa size
+of
+.Dv INT_MAX + 1.
.Pp
The format string is composed of zero or more directives:
ordinary
@@ -670,6 +661,21 @@
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 RETURN VALUES
+These functions return the number of characters printed
+(not including the trailing
+.Ql \e0
+used to end output to strings),
+except for
+.Fn snprintf
+and
+.Fn vsnprintf ,
+which return the number of characters that would have been printed if the
+.Fa size
+were unlimited
+(again, not including the final
+.Ql \e0 ) .
+These functions return a negative value if an error occurs.
.Sh EXAMPLES
To print a date and time in the form
.Dq Li "Sunday, July 3, 10:02" ,
@@ -771,6 +777,13 @@
An invalid wide character code was encountered.
.It Bq Er ENOMEM
Insufficient storage space is available.
+.It Bq Er EOVERFLOW
+The
+.Fa size
+argument exceeds
+.Dv INT_MAX + 1 ,
+or the return value would be too large to be represented by an
+.Vt int .
.El
.Sh SEE ALSO
.Xr printf 1 ,
Property changes on: trunk/lib/libc/stdio/printf.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/printf.c
===================================================================
--- trunk/lib/libc/stdio/printf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/printf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)printf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/printf.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include <stdarg.h>
Modified: trunk/lib/libc/stdio/printf_l.3
===================================================================
--- trunk/lib/libc/stdio/printf_l.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/printf_l.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 2012 Isabell Long <issyl0 at FreeBSD.org>
.\" All rights reserved.
.\"
@@ -22,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/printf_l.3 291294 2015-11-25 08:51:43Z ngie $
.\"
.Dd April 7, 2012
.Dt PRINTF_L 3
@@ -43,6 +44,7 @@
.Lb libc
.Sh SYNOPSIS
.In stdio.h
+.In xlocale.h
.Ft int
.Fn printf_l "locale_t loc" "const char * restrict format" "..."
.Ft int
Property changes on: trunk/lib/libc/stdio/printf_l.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/printfcommon.h
===================================================================
--- trunk/lib/libc/stdio/printfcommon.h 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/printfcommon.h 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -34,7 +35,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libc/stdio/printfcommon.h 227753 2011-11-20 14:45:42Z theraven $
*/
/*
Modified: trunk/lib/libc/stdio/printflocal.h
===================================================================
--- trunk/lib/libc/stdio/printflocal.h 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/printflocal.h 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -29,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libc/stdio/printflocal.h 189268 2009-03-02 04:07:58Z das $
*/
/*
Modified: trunk/lib/libc/stdio/putc.3
===================================================================
--- trunk/lib/libc/stdio/putc.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/putc.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)putc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/putc.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd January 10, 2003
.Dt PUTC 3
Property changes on: trunk/lib/libc/stdio/putc.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/putc.c
===================================================================
--- trunk/lib/libc/stdio/putc.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/putc.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/putc.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -46,16 +47,14 @@
#undef putc_unlocked
int
-putc(c, fp)
- int c;
- FILE *fp;
+putc(int c, FILE *fp)
{
int retval;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
/* Orientation set by __sputc() when buffer is full. */
/* ORIENT(fp, -1); */
retval = __sputc(c, fp);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
Modified: trunk/lib/libc/stdio/putchar.c
===================================================================
--- trunk/lib/libc/stdio/putchar.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/putchar.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/putchar.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -49,17 +50,16 @@
* A subroutine version of the macro putchar
*/
int
-putchar(c)
- int c;
+putchar(int c)
{
int retval;
FILE *so = stdout;
- FLOCKFILE(so);
+ FLOCKFILE_CANCELSAFE(so);
/* Orientation set by __sputc() when buffer is full. */
/* ORIENT(so, -1); */
retval = __sputc(c, so);
- FUNLOCKFILE(so);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
Modified: trunk/lib/libc/stdio/puts.c
===================================================================
--- trunk/lib/libc/stdio/puts.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/puts.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)puts.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/puts.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -48,24 +49,23 @@
* Write the given string to stdout, appending a newline.
*/
int
-puts(s)
- char const *s;
+puts(char const *s)
{
int retval;
- size_t c = strlen(s);
+ size_t c;
struct __suio uio;
struct __siov iov[2];
iov[0].iov_base = (void *)s;
- iov[0].iov_len = c;
+ iov[0].iov_len = c = strlen(s);
iov[1].iov_base = "\n";
iov[1].iov_len = 1;
uio.uio_resid = c + 1;
uio.uio_iov = &iov[0];
uio.uio_iovcnt = 2;
- FLOCKFILE(stdout);
+ FLOCKFILE_CANCELSAFE(stdout);
ORIENT(stdout, -1);
retval = __sfvwrite(stdout, &uio) ? EOF : '\n';
- FUNLOCKFILE(stdout);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
Modified: trunk/lib/libc/stdio/putw.c
===================================================================
--- trunk/lib/libc/stdio/putw.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/putw.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)putw.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/putw.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -41,11 +42,10 @@
#include "un-namespace.h"
#include "fvwrite.h"
#include "libc_private.h"
+#include "local.h"
int
-putw(w, fp)
- int w;
- FILE *fp;
+putw(int w, FILE *fp)
{
int retval;
struct __suio uio;
@@ -52,11 +52,11 @@
struct __siov iov;
iov.iov_base = &w;
- iov.iov_len = uio.uio_resid = sizeof(w);
+ uio.uio_resid = iov.iov_len = sizeof(w);
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
retval = __sfvwrite(fp, &uio);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
Modified: trunk/lib/libc/stdio/putwc.3
===================================================================
--- trunk/lib/libc/stdio/putwc.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/putwc.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $NetBSD: putwc.3,v 1.2 2002/02/07 07:00:26 ross Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
@@ -32,7 +33,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)putc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/putwc.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd March 3, 2004
.Dt PUTWC 3
Property changes on: trunk/lib/libc/stdio/putwc.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/putwc.c
===================================================================
--- trunk/lib/libc/stdio/putwc.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/putwc.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins.
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/putwc.c 227753 2011-11-20 14:45:42Z theraven $");
#include "namespace.h"
#include <stdio.h>
Modified: trunk/lib/libc/stdio/putwchar.c
===================================================================
--- trunk/lib/libc/stdio/putwchar.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/putwchar.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins.
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/putwchar.c 227753 2011-11-20 14:45:42Z theraven $");
#include "namespace.h"
#include <stdio.h>
Modified: trunk/lib/libc/stdio/refill.c
===================================================================
--- trunk/lib/libc/stdio/refill.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/refill.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/refill.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
@@ -53,9 +54,9 @@
int ret = 0;
if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) {
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ret = __sflush(fp);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
}
return (ret);
}
Modified: trunk/lib/libc/stdio/remove.3
===================================================================
--- trunk/lib/libc/stdio/remove.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/remove.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)remove.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/remove.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd June 4, 1993
.Dt REMOVE 3
Property changes on: trunk/lib/libc/stdio/remove.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/remove.c
===================================================================
--- trunk/lib/libc/stdio/remove.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/remove.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/remove.c 249810 2013-04-23 14:36:44Z emaste $");
#include <sys/types.h>
#include <sys/stat.h>
@@ -42,8 +43,7 @@
#include <stdio.h>
int
-remove(file)
- const char *file;
+remove(const char *file)
{
struct stat sb;
Modified: trunk/lib/libc/stdio/rewind.c
===================================================================
--- trunk/lib/libc/stdio/rewind.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/rewind.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)rewind.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/rewind.c 269482 2014-08-03 18:28:10Z pfg $");
#include "namespace.h"
#include <errno.h>
@@ -53,9 +54,8 @@
__sinit();
FLOCKFILE(fp);
- if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0) {
- clearerr_unlocked(fp);
+ if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0)
errno = serrno;
- }
+ clearerr_unlocked(fp); /* POSIX: clear stdio error regardless */
FUNLOCKFILE(fp);
}
Modified: trunk/lib/libc/stdio/rget.c
===================================================================
--- trunk/lib/libc/stdio/rget.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/rget.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)rget.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/rget.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include "local.h"
Modified: trunk/lib/libc/stdio/scanf.3
===================================================================
--- trunk/lib/libc/stdio/scanf.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/scanf.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)scanf.3 8.2 (Berkeley) 12/11/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/scanf.3 235363 2012-05-12 20:27:13Z joel $
.\"
.Dd January 4, 2003
.Dt SCANF 3
@@ -370,10 +371,10 @@
(or not in)
a particular set;
the set is defined by the characters between the open bracket
-.Cm [
+.Cm \&[
character
and a close bracket
-.Cm ]
+.Cm \&]
character.
The set
.Em excludes
Property changes on: trunk/lib/libc/stdio/scanf.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/scanf.c
===================================================================
--- trunk/lib/libc/stdio/scanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/scanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/scanf.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -56,9 +57,9 @@
va_list ap;
va_start(ap, fmt);
- FLOCKFILE(stdin);
+ FLOCKFILE_CANCELSAFE(stdin);
ret = __svfscanf(stdin, __get_locale(), fmt, ap);
- FUNLOCKFILE(stdin);
+ FUNLOCKFILE_CANCELSAFE();
va_end(ap);
return (ret);
}
@@ -70,9 +71,9 @@
FIX_LOCALE(locale);
va_start(ap, fmt);
- FLOCKFILE(stdin);
+ FLOCKFILE_CANCELSAFE(stdin);
ret = __svfscanf(stdin, locale, fmt, ap);
- FUNLOCKFILE(stdin);
+ FUNLOCKFILE_CANCELSAFE();
va_end(ap);
return (ret);
}
Modified: trunk/lib/libc/stdio/scanf_l.3
===================================================================
--- trunk/lib/libc/stdio/scanf_l.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/scanf_l.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 2012 Isabell Long <issyl0 at FreeBSD.org>
.\" All rights reserved.
.\"
@@ -22,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/scanf_l.3 291294 2015-11-25 08:51:43Z ngie $
.\"
.Dd April 8, 2012
.Dt SCANF_L 3
@@ -39,6 +40,7 @@
.Lb libc
.Sh SYNOPSIS
.In stdio.h
+.In xlocale.h
.Ft int
.Fn scanf_l "locale_t loc" "const char * restrict format" "..."
.Ft int
@@ -57,7 +59,7 @@
in the locale
.Fa loc .
They behave in the same way as the versions without the _l suffix, but use
-the specific locale rather than the the global or per-thread locale.
+the specific locale rather than the global or per-thread locale.
See the specific manual pages for more information.
.Sh SEE ALSO
.Xr scanf 3 ,
Property changes on: trunk/lib/libc/stdio/scanf_l.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/setbuf.3
===================================================================
--- trunk/lib/libc/stdio/setbuf.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/setbuf.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)setbuf.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/setbuf.3 246952 2013-02-18 22:47:59Z jilles $
.\"
.Dd February 18, 2013
.Dt SETBUF 3
Property changes on: trunk/lib/libc/stdio/setbuf.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/setbuf.c
===================================================================
--- trunk/lib/libc/stdio/setbuf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/setbuf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)setbuf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/setbuf.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include "local.h"
Modified: trunk/lib/libc/stdio/setbuffer.c
===================================================================
--- trunk/lib/libc/stdio/setbuffer.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/setbuffer.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,15 +35,12 @@
static char sccsid[] = "@(#)setbuffer.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/setbuffer.c 249810 2013-04-23 14:36:44Z emaste $");
#include <stdio.h>
void
-setbuffer(fp, buf, size)
- FILE *fp;
- char *buf;
- int size;
+setbuffer(FILE *fp, char *buf, int size)
{
(void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size);
@@ -52,8 +50,7 @@
* set line buffering
*/
int
-setlinebuf(fp)
- FILE *fp;
+setlinebuf(FILE *fp)
{
return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0));
Modified: trunk/lib/libc/stdio/setvbuf.c
===================================================================
--- trunk/lib/libc/stdio/setvbuf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/setvbuf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)setvbuf.c 8.2 (Berkeley) 11/16/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/setvbuf.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -63,7 +64,7 @@
if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0)
return (EOF);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
/*
* Write current buffer, if any. Discard unread input (including
* ungetc data), cancel line buffering, and free old buffer if
@@ -115,8 +116,7 @@
fp->_w = 0;
fp->_bf._base = fp->_p = fp->_nbuf;
fp->_bf._size = 1;
- FUNLOCKFILE(fp);
- return (ret);
+ goto end;
}
flags |= __SMBF;
}
@@ -156,6 +156,7 @@
}
__cleanup = _cleanup;
- FUNLOCKFILE(fp);
+end:
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
Modified: trunk/lib/libc/stdio/snprintf.c
===================================================================
--- trunk/lib/libc/stdio/snprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/snprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,8 +40,9 @@
static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/snprintf.c 249808 2013-04-23 13:33:13Z emaste $");
+#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdarg.h>
@@ -59,8 +61,11 @@
on = n;
if (n != 0)
n--;
- if (n > INT_MAX)
- n = INT_MAX;
+ if (n > INT_MAX) {
+ errno = EOVERFLOW;
+ *str = '\0';
+ return (EOF);
+ }
va_start(ap, fmt);
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
@@ -84,8 +89,11 @@
on = n;
if (n != 0)
n--;
- if (n > INT_MAX)
- n = INT_MAX;
+ if (n > INT_MAX) {
+ errno = EOVERFLOW;
+ *str = '\0';
+ return (EOF);
+ }
va_start(ap, fmt);
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
Modified: trunk/lib/libc/stdio/sprintf.c
===================================================================
--- trunk/lib/libc/stdio/sprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/sprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)sprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/sprintf.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include <stdarg.h>
Modified: trunk/lib/libc/stdio/sscanf.c
===================================================================
--- trunk/lib/libc/stdio/sscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/sscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)sscanf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/sscanf.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include <string.h>
Modified: trunk/lib/libc/stdio/stdio.3
===================================================================
--- trunk/lib/libc/stdio/stdio.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/stdio.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -26,7 +27,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)stdio.3 8.7 (Berkeley) 4/19/94
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/stdio.3 189356 2009-03-04 03:38:51Z das $
.\"
.Dd March 3, 2009
.Dt STDIO 3
Property changes on: trunk/lib/libc/stdio/stdio.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/stdio.c
===================================================================
--- trunk/lib/libc/stdio/stdio.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/stdio.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/stdio.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
@@ -50,10 +51,7 @@
* Small standard I/O/seek/close functions.
*/
int
-__sread(cookie, buf, n)
- void *cookie;
- char *buf;
- int n;
+__sread(void *cookie, char *buf, int n)
{
FILE *fp = cookie;
@@ -61,10 +59,7 @@
}
int
-__swrite(cookie, buf, n)
- void *cookie;
- char const *buf;
- int n;
+__swrite(void *cookie, char const *buf, int n)
{
FILE *fp = cookie;
@@ -72,10 +67,7 @@
}
fpos_t
-__sseek(cookie, offset, whence)
- void *cookie;
- fpos_t offset;
- int whence;
+__sseek(void *cookie, fpos_t offset, int whence)
{
FILE *fp = cookie;
@@ -83,8 +75,7 @@
}
int
-__sclose(cookie)
- void *cookie;
+__sclose(void *cookie)
{
return (_close(((FILE *)cookie)->_file));
@@ -94,10 +85,7 @@
* Higher level wrappers.
*/
int
-_sread(fp, buf, n)
- FILE *fp;
- char *buf;
- int n;
+_sread(FILE *fp, char *buf, int n)
{
int ret;
@@ -115,10 +103,7 @@
}
int
-_swrite(fp, buf, n)
- FILE *fp;
- char const *buf;
- int n;
+_swrite(FILE *fp, char const *buf, int n)
{
int ret;
int serrno;
@@ -133,7 +118,7 @@
ret = (*fp->_write)(fp->_cookie, buf, n);
/* __SOFF removed even on success in case O_APPEND mode is set. */
if (ret >= 0) {
- if ((fp->_flags & (__SAPP|__SOFF)) == (__SAPP|__SOFF) &&
+ if ((fp->_flags & __SOFF) && !(fp->_flags2 & __S2OAP) &&
fp->_offset <= OFF_MAX - ret)
fp->_offset += ret;
else
@@ -145,10 +130,7 @@
}
fpos_t
-_sseek(fp, offset, whence)
- FILE *fp;
- fpos_t offset;
- int whence;
+_sseek(FILE *fp, fpos_t offset, int whence)
{
fpos_t ret;
int serrno, errret;
@@ -185,3 +167,11 @@
}
return (ret);
}
+
+void
+__stdio_cancel_cleanup(void * arg)
+{
+
+ if (arg != NULL)
+ _funlockfile((FILE *)arg);
+}
Modified: trunk/lib/libc/stdio/swprintf.c
===================================================================
--- trunk/lib/libc/stdio/swprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/swprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/swprintf.c 227753 2011-11-20 14:45:42Z theraven $");
#include <stdarg.h>
#include <stdio.h>
Modified: trunk/lib/libc/stdio/swscanf.c
===================================================================
--- trunk/lib/libc/stdio/swscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/swscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/swscanf.c 227753 2011-11-20 14:45:42Z theraven $");
#include <stdarg.h>
#include <stdio.h>
Modified: trunk/lib/libc/stdio/tempnam.c
===================================================================
--- trunk/lib/libc/stdio/tempnam.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/tempnam.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
@@ -10,7 +11,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -31,7 +32,7 @@
static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/tempnam.c 249810 2013-04-23 14:36:44Z emaste $");
#include <sys/param.h>
#include <errno.h>
@@ -47,8 +48,7 @@
extern char *_mktemp(char *);
char *
-tempnam(dir, pfx)
- const char *dir, *pfx;
+tempnam(const char *dir, const char *pfx)
{
int sverrno;
char *f, *name;
Modified: trunk/lib/libc/stdio/tmpfile.c
===================================================================
--- trunk/lib/libc/stdio/tmpfile.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/tmpfile.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/tmpfile.c 287480 2015-09-05 08:55:51Z kib $");
#include "namespace.h"
#include <sys/types.h>
@@ -46,9 +47,10 @@
#include <string.h>
#include <paths.h>
#include "un-namespace.h"
+#include "libc_private.h"
FILE *
-tmpfile()
+tmpfile(void)
{
sigset_t set, oset;
FILE *fp;
@@ -69,7 +71,7 @@
return (NULL);
sigfillset(&set);
- (void)_sigprocmask(SIG_BLOCK, &set, &oset);
+ (void)__libc_sigprocmask(SIG_BLOCK, &set, &oset);
fd = mkstemp(buf);
if (fd != -1)
@@ -77,7 +79,7 @@
free(buf);
- (void)_sigprocmask(SIG_SETMASK, &oset, NULL);
+ (void)__libc_sigprocmask(SIG_SETMASK, &oset, NULL);
if (fd == -1)
return (NULL);
Modified: trunk/lib/libc/stdio/tmpnam.3
===================================================================
--- trunk/lib/libc/stdio/tmpnam.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/tmpnam.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)tmpnam.3 8.2 (Berkeley) 11/17/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/tmpnam.3 262965 2014-03-10 00:53:37Z eadler $
.\"
.Dd March 18, 2007
.Dt TMPFILE 3
@@ -244,5 +245,3 @@
It is strongly suggested that
.Xr mkstemp 3
be used in place of these functions.
-(See
-the FSA.)
Property changes on: trunk/lib/libc/stdio/tmpnam.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/tmpnam.c
===================================================================
--- trunk/lib/libc/stdio/tmpnam.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/tmpnam.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)tmpnam.c 8.3 (Berkeley) 3/28/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/tmpnam.c 249810 2013-04-23 14:36:44Z emaste $");
#include <sys/types.h>
@@ -47,8 +48,7 @@
extern char *_mktemp(char *);
char *
-tmpnam(s)
- char *s;
+tmpnam(char *s)
{
static u_long tmpcount;
static char buf[L_tmpnam];
Modified: trunk/lib/libc/stdio/ungetc.3
===================================================================
--- trunk/lib/libc/stdio/ungetc.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/ungetc.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -30,7 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)ungetc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/ungetc.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd June 4, 1993
.Dt UNGETC 3
Property changes on: trunk/lib/libc/stdio/ungetc.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/ungetc.c
===================================================================
--- trunk/lib/libc/stdio/ungetc.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/ungetc.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/ungetc.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -94,10 +95,10 @@
if (!__sdidinit)
__sinit();
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, -1);
ret = __ungetc(c, fp);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
Modified: trunk/lib/libc/stdio/ungetwc.3
===================================================================
--- trunk/lib/libc/stdio/ungetwc.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/ungetwc.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $NetBSD: ungetwc.3,v 1.3 2002/02/07 07:00:27 ross Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
@@ -32,7 +33,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)ungetc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/ungetwc.3 165903 2007-01-09 00:28:16Z imp $
.\"
.Dd March 3, 2004
.Dt UNGETWC 3
Property changes on: trunk/lib/libc/stdio/ungetwc.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/ungetwc.c
===================================================================
--- trunk/lib/libc/stdio/ungetwc.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/ungetwc.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/ungetwc.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <errno.h>
@@ -76,10 +77,10 @@
wint_t r;
FIX_LOCALE(locale);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, 1);
r = __ungetwc(wc, fp, locale);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (r);
}
Modified: trunk/lib/libc/stdio/unlocked.c
===================================================================
--- trunk/lib/libc/stdio/unlocked.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/unlocked.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2003 Tim J. Robbins.
* All rights reserved.
Modified: trunk/lib/libc/stdio/vasprintf.c
===================================================================
--- trunk/lib/libc/stdio/vasprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vasprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: vasprintf.c,v 1.4 1998/06/21 22:13:47 millert Exp $ */
/*
@@ -33,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vasprintf.c 227753 2011-11-20 14:45:42Z theraven $");
#include <stdio.h>
#include <stdlib.h>
Modified: trunk/lib/libc/stdio/vdprintf.c
===================================================================
--- trunk/lib/libc/stdio/vdprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vdprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2009 David Schultz <das at FreeBSD.org>
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vdprintf.c 227753 2011-11-20 14:45:42Z theraven $");
#include "namespace.h"
#include <errno.h>
Modified: trunk/lib/libc/stdio/vfprintf.c
===================================================================
--- trunk/lib/libc/stdio/vfprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vfprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vfprintf.c 321074 2017-07-17 14:09:34Z kib $");
/*
* Actual printf innards.
@@ -51,6 +52,7 @@
#include <sys/types.h>
#include <ctype.h>
+#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <stddef.h>
@@ -273,7 +275,7 @@
int ret;
FIX_LOCALE(locale);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
fp->_file >= 0)
@@ -280,7 +282,7 @@
ret = __sbprintf(fp, locale, fmt0, ap);
else
ret = __vfprintf(fp, locale, fmt0, ap);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
int
@@ -363,6 +365,7 @@
int nextarg; /* 1-based argument index */
va_list orgap; /* original argument pointer */
char *convbuf; /* wide to multibyte conversion result */
+ int savserr;
static const char xdigs_lower[16] = "0123456789abcdef";
static const char xdigs_upper[16] = "0123456789ABCDEF";
@@ -454,9 +457,14 @@
return (__xvprintf(fp, fmt0, ap));
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
- if (prepwrite(fp) != 0)
+ if (prepwrite(fp) != 0) {
+ errno = EBADF;
return (EOF);
+ }
+ savserr = fp->_flags & __SERR;
+ fp->_flags &= ~__SERR;
+
convbuf = NULL;
fmt = (char *)fmt0;
argtable = NULL;
@@ -480,6 +488,7 @@
if ((n = fmt - cp) != 0) {
if ((unsigned)ret + n > INT_MAX) {
ret = EOF;
+ errno = EOVERFLOW;
goto error;
}
PRINT(cp, n);
@@ -935,6 +944,7 @@
prsize = width > realsz ? width : realsz;
if ((unsigned)ret + prsize > INT_MAX) {
ret = EOF;
+ errno = EOVERFLOW;
goto error;
}
@@ -1026,6 +1036,8 @@
free(convbuf);
if (__sferror(fp))
ret = EOF;
+ else
+ fp->_flags |= savserr;
if ((argtable != NULL) && (argtable != statargtable))
free (argtable);
return (ret);
Modified: trunk/lib/libc/stdio/vfscanf.c
===================================================================
--- trunk/lib/libc/stdio/vfscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vfscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vfscanf.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <ctype.h>
@@ -107,6 +108,335 @@
__weak_reference(__vfscanf, vfscanf);
/*
+ * Conversion functions are passed a pointer to this object instead of
+ * a real parameter to indicate that the assignment-suppression (*)
+ * flag was specified. We could use a NULL pointer to indicate this,
+ * but that would mask bugs in applications that call scanf() with a
+ * NULL pointer.
+ */
+static const int suppress;
+#define SUPPRESS_PTR ((void *)&suppress)
+
+static const mbstate_t initial_mbs;
+
+/*
+ * The following conversion functions return the number of characters consumed,
+ * or -1 on input failure. Character class conversion returns 0 on match
+ * failure.
+ */
+
+static __inline int
+convert_char(FILE *fp, char * p, int width)
+{
+ int n;
+
+ if (p == SUPPRESS_PTR) {
+ size_t sum = 0;
+ for (;;) {
+ if ((n = fp->_r) < width) {
+ sum += n;
+ width -= n;
+ fp->_p += n;
+ if (__srefill(fp)) {
+ if (sum == 0)
+ return (-1);
+ break;
+ }
+ } else {
+ sum += width;
+ fp->_r -= width;
+ fp->_p += width;
+ break;
+ }
+ }
+ return (sum);
+ } else {
+ size_t r = __fread(p, 1, width, fp);
+
+ if (r == 0)
+ return (-1);
+ return (r);
+ }
+}
+
+static __inline int
+convert_wchar(FILE *fp, wchar_t *wcp, int width, locale_t locale)
+{
+ mbstate_t mbs;
+ int n, nread;
+ wint_t wi;
+
+ mbs = initial_mbs;
+ n = 0;
+ while (width-- != 0 &&
+ (wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF) {
+ if (wcp != SUPPRESS_PTR)
+ *wcp++ = (wchar_t)wi;
+ n += nread;
+ }
+ if (n == 0)
+ return (-1);
+ return (n);
+}
+
+static __inline int
+convert_ccl(FILE *fp, char * p, int width, const char *ccltab)
+{
+ char *p0;
+ int n;
+
+ if (p == SUPPRESS_PTR) {
+ n = 0;
+ while (ccltab[*fp->_p]) {
+ n++, fp->_r--, fp->_p++;
+ if (--width == 0)
+ break;
+ if (fp->_r <= 0 && __srefill(fp)) {
+ if (n == 0)
+ return (-1);
+ break;
+ }
+ }
+ } else {
+ p0 = p;
+ while (ccltab[*fp->_p]) {
+ fp->_r--;
+ *p++ = *fp->_p++;
+ if (--width == 0)
+ break;
+ if (fp->_r <= 0 && __srefill(fp)) {
+ if (p == p0)
+ return (-1);
+ break;
+ }
+ }
+ n = p - p0;
+ if (n == 0)
+ return (0);
+ *p = 0;
+ }
+ return (n);
+}
+
+static __inline int
+convert_wccl(FILE *fp, wchar_t *wcp, int width, const char *ccltab,
+ locale_t locale)
+{
+ mbstate_t mbs;
+ wint_t wi;
+ int n, nread;
+
+ mbs = initial_mbs;
+ n = 0;
+ if (wcp == SUPPRESS_PTR) {
+ while ((wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF &&
+ width-- != 0 && ccltab[wctob(wi)])
+ n += nread;
+ if (wi != WEOF)
+ __ungetwc(wi, fp, __get_locale());
+ } else {
+ while ((wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF &&
+ width-- != 0 && ccltab[wctob(wi)]) {
+ *wcp++ = (wchar_t)wi;
+ n += nread;
+ }
+ if (wi != WEOF)
+ __ungetwc(wi, fp, __get_locale());
+ if (n == 0)
+ return (0);
+ *wcp = 0;
+ }
+ return (n);
+}
+
+static __inline int
+convert_string(FILE *fp, char * p, int width)
+{
+ char *p0;
+ int n;
+
+ if (p == SUPPRESS_PTR) {
+ n = 0;
+ while (!isspace(*fp->_p)) {
+ n++, fp->_r--, fp->_p++;
+ if (--width == 0)
+ break;
+ if (fp->_r <= 0 && __srefill(fp))
+ break;
+ }
+ } else {
+ p0 = p;
+ while (!isspace(*fp->_p)) {
+ fp->_r--;
+ *p++ = *fp->_p++;
+ if (--width == 0)
+ break;
+ if (fp->_r <= 0 && __srefill(fp))
+ break;
+ }
+ *p = 0;
+ n = p - p0;
+ }
+ return (n);
+}
+
+static __inline int
+convert_wstring(FILE *fp, wchar_t *wcp, int width, locale_t locale)
+{
+ mbstate_t mbs;
+ wint_t wi;
+ int n, nread;
+
+ mbs = initial_mbs;
+ n = 0;
+ if (wcp == SUPPRESS_PTR) {
+ while ((wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF &&
+ width-- != 0 && !iswspace(wi))
+ n += nread;
+ if (wi != WEOF)
+ __ungetwc(wi, fp, __get_locale());
+ } else {
+ while ((wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF &&
+ width-- != 0 && !iswspace(wi)) {
+ *wcp++ = (wchar_t)wi;
+ n += nread;
+ }
+ if (wi != WEOF)
+ __ungetwc(wi, fp, __get_locale());
+ *wcp = '\0';
+ }
+ return (n);
+}
+
+/*
+ * Read an integer, storing it in buf. The only relevant bit in the
+ * flags argument is PFXOK.
+ *
+ * Return 0 on a match failure, and the number of characters read
+ * otherwise.
+ */
+static __inline int
+parseint(FILE *fp, char * __restrict buf, int width, int base, int flags)
+{
+ /* `basefix' is used to avoid `if' tests */
+ static const short basefix[17] =
+ { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+ char *p;
+ int c;
+
+ flags |= SIGNOK | NDIGITS | NZDIGITS;
+ for (p = buf; width; width--) {
+ c = *fp->_p;
+ /*
+ * Switch on the character; `goto ok' if we accept it
+ * as a part of number.
+ */
+ switch (c) {
+
+ /*
+ * The digit 0 is always legal, but is special. For
+ * %i conversions, if no digits (zero or nonzero) have
+ * been scanned (only signs), we will have base==0.
+ * In that case, we should set it to 8 and enable 0x
+ * prefixing. Also, if we have not scanned zero
+ * digits before this, do not turn off prefixing
+ * (someone else will turn it off if we have scanned
+ * any nonzero digits).
+ */
+ case '0':
+ if (base == 0) {
+ base = 8;
+ flags |= PFXOK;
+ }
+ if (flags & NZDIGITS)
+ flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
+ else
+ flags &= ~(SIGNOK|PFXOK|NDIGITS);
+ goto ok;
+
+ /* 1 through 7 always legal */
+ case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ base = basefix[base];
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* digits 8 and 9 ok iff decimal or hex */
+ case '8': case '9':
+ base = basefix[base];
+ if (base <= 8)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* letters ok iff hex */
+ case 'A': case 'B': case 'C':
+ case 'D': case 'E': case 'F':
+ case 'a': case 'b': case 'c':
+ case 'd': case 'e': case 'f':
+ /* no need to fix base here */
+ if (base <= 10)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* sign ok only as first character */
+ case '+': case '-':
+ if (flags & SIGNOK) {
+ flags &= ~SIGNOK;
+ flags |= HAVESIGN;
+ goto ok;
+ }
+ break;
+
+ /*
+ * x ok iff flag still set & 2nd char (or 3rd char if
+ * we have a sign).
+ */
+ case 'x': case 'X':
+ if (flags & PFXOK && p ==
+ buf + 1 + !!(flags & HAVESIGN)) {
+ base = 16; /* if %i */
+ flags &= ~PFXOK;
+ goto ok;
+ }
+ break;
+ }
+
+ /*
+ * If we got here, c is not a legal character for a
+ * number. Stop accumulating digits.
+ */
+ break;
+ ok:
+ /*
+ * c is legal: store it and look at the next.
+ */
+ *p++ = c;
+ if (--fp->_r > 0)
+ fp->_p++;
+ else if (__srefill(fp))
+ break; /* EOF */
+ }
+ /*
+ * If we had only a sign, it is no good; push back the sign.
+ * If the number ends in `x', it was [sign] '0' 'x', so push
+ * back the x and treat it as [sign] '0'.
+ */
+ if (flags & NDIGITS) {
+ if (p > buf)
+ (void) __ungetc(*(u_char *)--p, fp);
+ return (0);
+ }
+ c = ((u_char *)p)[-1];
+ if (c == 'x' || c == 'X') {
+ --p;
+ (void) __ungetc(c, fp);
+ }
+ return (p - buf);
+}
+
+/*
* __vfscanf - MT-safe version
*/
int
@@ -114,9 +444,9 @@
{
int ret;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ret = __svfscanf(fp, __get_locale(), fmt0, ap);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
int
@@ -125,9 +455,9 @@
int ret;
FIX_LOCALE(locale);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ret = __svfscanf(fp, locale, fmt0, ap);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
@@ -137,28 +467,19 @@
int
__svfscanf(FILE *fp, locale_t locale, const char *fmt0, va_list ap)
{
+#define GETARG(type) ((flags & SUPPRESS) ? SUPPRESS_PTR : va_arg(ap, type))
const u_char *fmt = (const u_char *)fmt0;
int c; /* character from format, or conversion */
size_t width; /* field width, or 0 */
- char *p; /* points into all kinds of strings */
- int n; /* handy integer */
int flags; /* flags as defined above */
- char *p0; /* saves original value of p when necessary */
int nassigned; /* number of fields assigned */
int nconversions; /* number of conversions */
+ int nr; /* characters read by the current conversion */
int nread; /* number of characters consumed from fp */
int base; /* base argument to conversion function */
char ccltab[256]; /* character class table for %[...] */
- char buf[BUF]; /* buffer for numeric and mb conversions */
- wchar_t *wcp; /* handy wide character pointer */
- size_t nconv; /* length of multibyte sequence converted */
- static const mbstate_t initial;
- mbstate_t mbs;
+ char buf[BUF]; /* buffer for numeric conversions */
- /* `basefix' is used to avoid `if' tests in the integer scanner */
- static short basefix[17] =
- { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
-
ORIENT(fp, -1);
nassigned = 0;
@@ -300,7 +621,6 @@
break;
case 'n':
- nconversions++;
if (flags & SUPPRESS) /* ??? */
continue;
if (flags & SHORTSHORT)
@@ -366,74 +686,13 @@
if (width == 0)
width = 1;
if (flags & LONG) {
- if ((flags & SUPPRESS) == 0)
- wcp = va_arg(ap, wchar_t *);
- else
- wcp = NULL;
- n = 0;
- while (width != 0) {
- if (n == MB_CUR_MAX) {
- fp->_flags |= __SERR;
- goto input_failure;
- }
- buf[n++] = *fp->_p;
- fp->_p++;
- fp->_r--;
- mbs = initial;
- nconv = mbrtowc(wcp, buf, n, &mbs);
- if (nconv == (size_t)-1) {
- fp->_flags |= __SERR;
- goto input_failure;
- }
- if (nconv == 0 && !(flags & SUPPRESS))
- *wcp = L'\0';
- if (nconv != (size_t)-2) {
- nread += n;
- width--;
- if (!(flags & SUPPRESS))
- wcp++;
- n = 0;
- }
- if (fp->_r <= 0 && __srefill(fp)) {
- if (n != 0) {
- fp->_flags |= __SERR;
- goto input_failure;
- }
- break;
- }
- }
- if (!(flags & SUPPRESS))
- nassigned++;
- } else if (flags & SUPPRESS) {
- size_t sum = 0;
- for (;;) {
- if ((n = fp->_r) < width) {
- sum += n;
- width -= n;
- fp->_p += n;
- if (__srefill(fp)) {
- if (sum == 0)
- goto input_failure;
- break;
- }
- } else {
- sum += width;
- fp->_r -= width;
- fp->_p += width;
- break;
- }
- }
- nread += sum;
+ nr = convert_wchar(fp, GETARG(wchar_t *),
+ width, locale);
} else {
- size_t r = __fread((void *)va_arg(ap, char *), 1,
- width, fp);
-
- if (r == 0)
- goto input_failure;
- nread += r;
- nassigned++;
+ nr = convert_char(fp, GETARG(char *), width);
}
- nconversions++;
+ if (nr < 0)
+ goto input_failure;
break;
case CT_CCL:
@@ -440,104 +699,19 @@
/* scan a (nonempty) character class (sets NOSKIP) */
if (width == 0)
width = (size_t)~0; /* `infinity' */
- /* take only those things in the class */
if (flags & LONG) {
- wchar_t twc;
- int nchars;
-
- if ((flags & SUPPRESS) == 0)
- wcp = va_arg(ap, wchar_t *);
- else
- wcp = &twc;
- n = 0;
- nchars = 0;
- while (width != 0) {
- if (n == MB_CUR_MAX) {
- fp->_flags |= __SERR;
- goto input_failure;
- }
- buf[n++] = *fp->_p;
- fp->_p++;
- fp->_r--;
- mbs = initial;
- nconv = mbrtowc(wcp, buf, n, &mbs);
- if (nconv == (size_t)-1) {
- fp->_flags |= __SERR;
- goto input_failure;
- }
- if (nconv == 0)
- *wcp = L'\0';
- if (nconv != (size_t)-2) {
- if (wctob(*wcp) != EOF &&
- !ccltab[wctob(*wcp)]) {
- while (n != 0) {
- n--;
- __ungetc(buf[n],
- fp);
- }
- break;
- }
- nread += n;
- width--;
- if (!(flags & SUPPRESS))
- wcp++;
- nchars++;
- n = 0;
- }
- if (fp->_r <= 0 && __srefill(fp)) {
- if (n != 0) {
- fp->_flags |= __SERR;
- goto input_failure;
- }
- break;
- }
- }
- if (n != 0) {
- fp->_flags |= __SERR;
+ nr = convert_wccl(fp, GETARG(wchar_t *), width,
+ ccltab, locale);
+ } else {
+ nr = convert_ccl(fp, GETARG(char *), width,
+ ccltab);
+ }
+ if (nr <= 0) {
+ if (nr < 0)
goto input_failure;
- }
- n = nchars;
- if (n == 0)
+ else /* nr == 0 */
goto match_failure;
- if (!(flags & SUPPRESS)) {
- *wcp = L'\0';
- nassigned++;
- }
- } else if (flags & SUPPRESS) {
- n = 0;
- while (ccltab[*fp->_p]) {
- n++, fp->_r--, fp->_p++;
- if (--width == 0)
- break;
- if (fp->_r <= 0 && __srefill(fp)) {
- if (n == 0)
- goto input_failure;
- break;
- }
- }
- if (n == 0)
- goto match_failure;
- } else {
- p0 = p = va_arg(ap, char *);
- while (ccltab[*fp->_p]) {
- fp->_r--;
- *p++ = *fp->_p++;
- if (--width == 0)
- break;
- if (fp->_r <= 0 && __srefill(fp)) {
- if (p == p0)
- goto input_failure;
- break;
- }
- }
- n = p - p0;
- if (n == 0)
- goto match_failure;
- *p = 0;
- nassigned++;
}
- nread += n;
- nconversions++;
break;
case CT_STRING:
@@ -545,82 +719,14 @@
if (width == 0)
width = (size_t)~0;
if (flags & LONG) {
- wchar_t twc;
-
- if ((flags & SUPPRESS) == 0)
- wcp = va_arg(ap, wchar_t *);
- else
- wcp = &twc;
- n = 0;
- while (!isspace(*fp->_p) && width != 0) {
- if (n == MB_CUR_MAX) {
- fp->_flags |= __SERR;
- goto input_failure;
- }
- buf[n++] = *fp->_p;
- fp->_p++;
- fp->_r--;
- mbs = initial;
- nconv = mbrtowc(wcp, buf, n, &mbs);
- if (nconv == (size_t)-1) {
- fp->_flags |= __SERR;
- goto input_failure;
- }
- if (nconv == 0)
- *wcp = L'\0';
- if (nconv != (size_t)-2) {
- if (iswspace(*wcp)) {
- while (n != 0) {
- n--;
- __ungetc(buf[n],
- fp);
- }
- break;
- }
- nread += n;
- width--;
- if (!(flags & SUPPRESS))
- wcp++;
- n = 0;
- }
- if (fp->_r <= 0 && __srefill(fp)) {
- if (n != 0) {
- fp->_flags |= __SERR;
- goto input_failure;
- }
- break;
- }
- }
- if (!(flags & SUPPRESS)) {
- *wcp = L'\0';
- nassigned++;
- }
- } else if (flags & SUPPRESS) {
- n = 0;
- while (!isspace(*fp->_p)) {
- n++, fp->_r--, fp->_p++;
- if (--width == 0)
- break;
- if (fp->_r <= 0 && __srefill(fp))
- break;
- }
- nread += n;
+ nr = convert_wstring(fp, GETARG(wchar_t *),
+ width, locale);
} else {
- p0 = p = va_arg(ap, char *);
- while (!isspace(*fp->_p)) {
- fp->_r--;
- *p++ = *fp->_p++;
- if (--width == 0)
- break;
- if (fp->_r <= 0 && __srefill(fp))
- break;
- }
- *p = 0;
- nread += p - p0;
- nassigned++;
+ nr = convert_string(fp, GETARG(char *), width);
}
- nconversions++;
- continue;
+ if (nr < 0)
+ goto input_failure;
+ break;
case CT_INT:
/* scan an integer as if by the conversion function */
@@ -633,122 +739,13 @@
width = sizeof(buf) - 2;
width++;
#endif
- flags |= SIGNOK | NDIGITS | NZDIGITS;
- for (p = buf; width; width--) {
- c = *fp->_p;
- /*
- * Switch on the character; `goto ok'
- * if we accept it as a part of number.
- */
- switch (c) {
-
- /*
- * The digit 0 is always legal, but is
- * special. For %i conversions, if no
- * digits (zero or nonzero) have been
- * scanned (only signs), we will have
- * base==0. In that case, we should set
- * it to 8 and enable 0x prefixing.
- * Also, if we have not scanned zero digits
- * before this, do not turn off prefixing
- * (someone else will turn it off if we
- * have scanned any nonzero digits).
- */
- case '0':
- if (base == 0) {
- base = 8;
- flags |= PFXOK;
- }
- if (flags & NZDIGITS)
- flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
- else
- flags &= ~(SIGNOK|PFXOK|NDIGITS);
- goto ok;
-
- /* 1 through 7 always legal */
- case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- base = basefix[base];
- flags &= ~(SIGNOK | PFXOK | NDIGITS);
- goto ok;
-
- /* digits 8 and 9 ok iff decimal or hex */
- case '8': case '9':
- base = basefix[base];
- if (base <= 8)
- break; /* not legal here */
- flags &= ~(SIGNOK | PFXOK | NDIGITS);
- goto ok;
-
- /* letters ok iff hex */
- case 'A': case 'B': case 'C':
- case 'D': case 'E': case 'F':
- case 'a': case 'b': case 'c':
- case 'd': case 'e': case 'f':
- /* no need to fix base here */
- if (base <= 10)
- break; /* not legal here */
- flags &= ~(SIGNOK | PFXOK | NDIGITS);
- goto ok;
-
- /* sign ok only as first character */
- case '+': case '-':
- if (flags & SIGNOK) {
- flags &= ~SIGNOK;
- flags |= HAVESIGN;
- goto ok;
- }
- break;
-
- /*
- * x ok iff flag still set & 2nd char (or
- * 3rd char if we have a sign).
- */
- case 'x': case 'X':
- if (flags & PFXOK && p ==
- buf + 1 + !!(flags & HAVESIGN)) {
- base = 16; /* if %i */
- flags &= ~PFXOK;
- goto ok;
- }
- break;
- }
-
- /*
- * If we got here, c is not a legal character
- * for a number. Stop accumulating digits.
- */
- break;
- ok:
- /*
- * c is legal: store it and look at the next.
- */
- *p++ = c;
- if (--fp->_r > 0)
- fp->_p++;
- else if (__srefill(fp))
- break; /* EOF */
- }
- /*
- * If we had only a sign, it is no good; push
- * back the sign. If the number ends in `x',
- * it was [sign] '0' 'x', so push back the x
- * and treat it as [sign] '0'.
- */
- if (flags & NDIGITS) {
- if (p > buf)
- (void) __ungetc(*(u_char *)--p, fp);
+ nr = parseint(fp, buf, width, base, flags);
+ if (nr == 0)
goto match_failure;
- }
- c = ((u_char *)p)[-1];
- if (c == 'x' || c == 'X') {
- --p;
- (void) __ungetc(c, fp);
- }
if ((flags & SUPPRESS) == 0) {
uintmax_t res;
- *p = 0;
+ buf[nr] = '\0';
if ((flags & UNSIGNED) == 0)
res = strtoimax_l(buf, (char **)NULL, base, locale);
else
@@ -772,10 +769,7 @@
*va_arg(ap, size_t *) = res;
else
*va_arg(ap, int *) = res;
- nassigned++;
}
- nread += p - buf;
- nconversions++;
break;
#ifndef NO_FLOATING_POINT
@@ -783,26 +777,30 @@
/* scan a floating point number as if by strtod */
if (width == 0 || width > sizeof(buf) - 1)
width = sizeof(buf) - 1;
- if ((width = parsefloat(fp, buf, buf + width, locale)) == 0)
+ nr = parsefloat(fp, buf, buf + width, locale);
+ if (nr == 0)
goto match_failure;
if ((flags & SUPPRESS) == 0) {
if (flags & LONGDBL) {
- long double res = strtold_l(buf, &p, locale);
+ long double res = strtold_l(buf, NULL,
+ locale);
*va_arg(ap, long double *) = res;
} else if (flags & LONG) {
- double res = strtod_l(buf, &p, locale);
+ double res = strtod_l(buf, NULL,
+ locale);
*va_arg(ap, double *) = res;
} else {
- float res = strtof_l(buf, &p, locale);
+ float res = strtof_l(buf, NULL, locale);
*va_arg(ap, float *) = res;
}
- nassigned++;
}
- nread += width;
- nconversions++;
break;
#endif /* !NO_FLOATING_POINT */
}
+ if (!(flags & SUPPRESS))
+ nassigned++;
+ nread += nr;
+ nconversions++;
}
input_failure:
return (nconversions != 0 ? nassigned : EOF);
@@ -817,9 +815,7 @@
* considered part of the scanset.
*/
static const u_char *
-__sccl(tab, fmt)
- char *tab;
- const u_char *fmt;
+__sccl(char *tab, const u_char *fmt)
{
int c, n, v, i;
struct xlocale_collate *table =
@@ -878,7 +874,7 @@
n = *fmt;
if (n == ']'
|| (table->__collate_load_error ? n < c :
- __collate_range_cmp (table, n, c) < 0
+ __collate_range_cmp(n, c) < 0
)
) {
c = '-';
@@ -892,8 +888,8 @@
} while (c < n);
} else {
for (i = 0; i < 256; i ++)
- if ( __collate_range_cmp (table, c, i) < 0
- && __collate_range_cmp (table, i, n) <= 0
+ if (__collate_range_cmp(c, i) <= 0 &&
+ __collate_range_cmp(i, n) <= 0
)
tab[i] = v;
}
Modified: trunk/lib/libc/stdio/vfwprintf.c
===================================================================
--- trunk/lib/libc/stdio/vfwprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vfwprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -41,7 +42,7 @@
#endif /* LIBC_SCCS and not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vfwprintf.c 321074 2017-07-17 14:09:34Z kib $");
/*
* Actual wprintf innards.
@@ -54,6 +55,7 @@
#include <sys/types.h>
#include <ctype.h>
+#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <stdarg.h>
@@ -355,7 +357,7 @@
{
int ret;
FIX_LOCALE(locale);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
fp->_file >= 0)
@@ -362,7 +364,7 @@
ret = __sbprintf(fp, locale, fmt0, ap);
else
ret = __vfwprintf(fp, locale, fmt0, ap);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
int
@@ -443,6 +445,7 @@
int nextarg; /* 1-based argument index */
va_list orgap; /* original argument pointer */
wchar_t *convbuf; /* multibyte to wide conversion result */
+ int savserr;
static const char xdigs_lower[16] = "0123456789abcdef";
static const char xdigs_upper[16] = "0123456789ABCDEF";
@@ -530,9 +533,14 @@
/* sorry, fwprintf(read_only_file, L"") returns WEOF, not 0 */
- if (prepwrite(fp) != 0)
+ if (prepwrite(fp) != 0) {
+ errno = EBADF;
return (EOF);
+ }
+ savserr = fp->_flags & __SERR;
+ fp->_flags &= ~__SERR;
+
convbuf = NULL;
fmt = (wchar_t *)fmt0;
argtable = NULL;
@@ -553,6 +561,7 @@
if ((n = fmt - cp) != 0) {
if ((unsigned)ret + n > INT_MAX) {
ret = EOF;
+ errno = EOVERFLOW;
goto error;
}
PRINT(cp, n);
@@ -1003,6 +1012,7 @@
prsize = width > realsz ? width : realsz;
if ((unsigned)ret + prsize > INT_MAX) {
ret = EOF;
+ errno = EOVERFLOW;
goto error;
}
@@ -1091,6 +1101,8 @@
free(convbuf);
if (__sferror(fp))
ret = EOF;
+ else
+ fp->_flags |= savserr;
if ((argtable != NULL) && (argtable != statargtable))
free (argtable);
return (ret);
Modified: trunk/lib/libc/stdio/vfwscanf.c
===================================================================
--- trunk/lib/libc/stdio/vfwscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vfwscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -41,7 +42,7 @@
#endif /* LIBC_SCCS and not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vfwscanf.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <ctype.h>
@@ -101,13 +102,324 @@
static int parsefloat(FILE *, wchar_t *, wchar_t *, locale_t);
#endif
-#define INCCL(_c) \
- (cclcompl ? (wmemchr(ccls, (_c), ccle - ccls) == NULL) : \
- (wmemchr(ccls, (_c), ccle - ccls) != NULL))
+struct ccl {
+ const wchar_t *start; /* character class start */
+ const wchar_t *end; /* character class end */
+ int compl; /* ccl is complemented? */
+};
+static __inline int
+inccl(const struct ccl *ccl, wint_t wi)
+{
+
+ if (ccl->compl) {
+ return (wmemchr(ccl->start, wi, ccl->end - ccl->start)
+ == NULL);
+ } else {
+ return (wmemchr(ccl->start, wi, ccl->end - ccl->start) != NULL);
+ }
+}
+
+/*
+ * Conversion functions are passed a pointer to this object instead of
+ * a real parameter to indicate that the assignment-suppression (*)
+ * flag was specified. We could use a NULL pointer to indicate this,
+ * but that would mask bugs in applications that call scanf() with a
+ * NULL pointer.
+ */
+static const int suppress;
+#define SUPPRESS_PTR ((void *)&suppress)
+
static const mbstate_t initial_mbs;
/*
+ * The following conversion functions return the number of characters consumed,
+ * or -1 on input failure. Character class conversion returns 0 on match
+ * failure.
+ */
+
+static __inline int
+convert_char(FILE *fp, char * mbp, int width, locale_t locale)
+{
+ mbstate_t mbs;
+ size_t nconv;
+ wint_t wi;
+ int n;
+
+ n = 0;
+ mbs = initial_mbs;
+ while (width-- != 0 && (wi = __fgetwc(fp, locale)) != WEOF) {
+ if (mbp != SUPPRESS_PTR) {
+ nconv = wcrtomb(mbp, wi, &mbs);
+ if (nconv == (size_t)-1)
+ return (-1);
+ mbp += nconv;
+ }
+ n++;
+ }
+ if (n == 0)
+ return (-1);
+ return (n);
+}
+
+static __inline int
+convert_wchar(FILE *fp, wchar_t *wcp, int width, locale_t locale)
+{
+ wint_t wi;
+ int n;
+
+ n = 0;
+ while (width-- != 0 && (wi = __fgetwc(fp, locale)) != WEOF) {
+ if (wcp != SUPPRESS_PTR)
+ *wcp++ = (wchar_t)wi;
+ n++;
+ }
+ if (n == 0)
+ return (-1);
+ return (n);
+}
+
+static __inline int
+convert_ccl(FILE *fp, char * mbp, int width, const struct ccl *ccl,
+ locale_t locale)
+{
+ mbstate_t mbs;
+ size_t nconv;
+ wint_t wi;
+ int n;
+
+ n = 0;
+ mbs = initial_mbs;
+ while ((wi = __fgetwc(fp, locale)) != WEOF &&
+ width-- != 0 && inccl(ccl, wi)) {
+ if (mbp != SUPPRESS_PTR) {
+ nconv = wcrtomb(mbp, wi, &mbs);
+ if (nconv == (size_t)-1)
+ return (-1);
+ mbp += nconv;
+ }
+ n++;
+ }
+ if (wi != WEOF)
+ __ungetwc(wi, fp, locale);
+ if (mbp != SUPPRESS_PTR)
+ *mbp = 0;
+ return (n);
+}
+
+static __inline int
+convert_wccl(FILE *fp, wchar_t *wcp, int width, const struct ccl *ccl,
+ locale_t locale)
+{
+ wchar_t *wcp0;
+ wint_t wi;
+ int n;
+
+ if (wcp == SUPPRESS_PTR) {
+ n = 0;
+ while ((wi = __fgetwc(fp, locale)) != WEOF &&
+ width-- != 0 && inccl(ccl, wi))
+ n++;
+ if (wi != WEOF)
+ __ungetwc(wi, fp, locale);
+ } else {
+ wcp0 = wcp;
+ while ((wi = __fgetwc(fp, locale)) != WEOF &&
+ width-- != 0 && inccl(ccl, wi))
+ *wcp++ = (wchar_t)wi;
+ if (wi != WEOF)
+ __ungetwc(wi, fp, locale);
+ n = wcp - wcp0;
+ if (n == 0)
+ return (0);
+ *wcp = 0;
+ }
+ return (n);
+}
+
+static __inline int
+convert_string(FILE *fp, char * mbp, int width, locale_t locale)
+{
+ mbstate_t mbs;
+ size_t nconv;
+ wint_t wi;
+ int nread;
+
+ mbs = initial_mbs;
+ nread = 0;
+ while ((wi = __fgetwc(fp, locale)) != WEOF && width-- != 0 &&
+ !iswspace(wi)) {
+ if (mbp != SUPPRESS_PTR) {
+ nconv = wcrtomb(mbp, wi, &mbs);
+ if (nconv == (size_t)-1)
+ return (-1);
+ mbp += nconv;
+ }
+ nread++;
+ }
+ if (wi != WEOF)
+ __ungetwc(wi, fp, locale);
+ if (mbp != SUPPRESS_PTR)
+ *mbp = 0;
+ return (nread);
+}
+
+static __inline int
+convert_wstring(FILE *fp, wchar_t *wcp, int width, locale_t locale)
+{
+ wchar_t *wcp0;
+ wint_t wi;
+ int nread;
+
+ nread = 0;
+ if (wcp == SUPPRESS_PTR) {
+ while ((wi = __fgetwc(fp, locale)) != WEOF &&
+ width-- != 0 && !iswspace(wi))
+ nread++;
+ if (wi != WEOF)
+ __ungetwc(wi, fp, locale);
+ } else {
+ wcp0 = wcp;
+ while ((wi = __fgetwc(fp, locale)) != WEOF &&
+ width-- != 0 && !iswspace(wi)) {
+ *wcp++ = (wchar_t)wi;
+ nread++;
+ }
+ if (wi != WEOF)
+ __ungetwc(wi, fp, locale);
+ *wcp = '\0';
+ }
+ return (nread);
+}
+
+/*
+ * Read an integer, storing it in buf. The only relevant bit in the
+ * flags argument is PFXOK.
+ *
+ * Return 0 on a match failure, and the number of characters read
+ * otherwise.
+ */
+static __inline int
+parseint(FILE *fp, wchar_t *buf, int width, int base, int flags,
+ locale_t locale)
+{
+ /* `basefix' is used to avoid `if' tests */
+ static const short basefix[17] =
+ { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+ wchar_t *wcp;
+ int c;
+
+ flags |= SIGNOK | NDIGITS | NZDIGITS;
+ for (wcp = buf; width; width--) {
+ c = __fgetwc(fp, locale);
+ /*
+ * Switch on the character; `goto ok' if we accept it
+ * as a part of number.
+ */
+ switch (c) {
+
+ /*
+ * The digit 0 is always legal, but is special. For
+ * %i conversions, if no digits (zero or nonzero) have
+ * been scanned (only signs), we will have base==0.
+ * In that case, we should set it to 8 and enable 0x
+ * prefixing. Also, if we have not scanned zero
+ * digits before this, do not turn off prefixing
+ * (someone else will turn it off if we have scanned
+ * any nonzero digits).
+ */
+ case '0':
+ if (base == 0) {
+ base = 8;
+ flags |= PFXOK;
+ }
+ if (flags & NZDIGITS)
+ flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
+ else
+ flags &= ~(SIGNOK|PFXOK|NDIGITS);
+ goto ok;
+
+ /* 1 through 7 always legal */
+ case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ base = basefix[base];
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* digits 8 and 9 ok iff decimal or hex */
+ case '8': case '9':
+ base = basefix[base];
+ if (base <= 8)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* letters ok iff hex */
+ case 'A': case 'B': case 'C':
+ case 'D': case 'E': case 'F':
+ case 'a': case 'b': case 'c':
+ case 'd': case 'e': case 'f':
+ /* no need to fix base here */
+ if (base <= 10)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* sign ok only as first character */
+ case '+': case '-':
+ if (flags & SIGNOK) {
+ flags &= ~SIGNOK;
+ flags |= HAVESIGN;
+ goto ok;
+ }
+ break;
+
+ /*
+ * x ok iff flag still set & 2nd char (or 3rd char if
+ * we have a sign).
+ */
+ case 'x': case 'X':
+ if (flags & PFXOK && wcp ==
+ buf + 1 + !!(flags & HAVESIGN)) {
+ base = 16; /* if %i */
+ flags &= ~PFXOK;
+ goto ok;
+ }
+ break;
+ }
+
+ /*
+ * If we got here, c is not a legal character for a
+ * number. Stop accumulating digits.
+ */
+ if (c != WEOF)
+ __ungetwc(c, fp, locale);
+ break;
+ ok:
+ /*
+ * c is legal: store it and look at the next.
+ */
+ *wcp++ = (wchar_t)c;
+ }
+ /*
+ * If we had only a sign, it is no good; push back the sign.
+ * If the number ends in `x', it was [sign] '0' 'x', so push
+ * back the x and treat it as [sign] '0'.
+ */
+ if (flags & NDIGITS) {
+ if (wcp > buf)
+ __ungetwc(*--wcp, fp, locale);
+ return (0);
+ }
+ c = wcp[-1];
+ if (c == 'x' || c == 'X') {
+ --wcp;
+ __ungetwc(c, fp, locale);
+ }
+ return (wcp - buf);
+}
+
+/*
* MT-safe version.
*/
int
@@ -117,10 +429,10 @@
int ret;
FIX_LOCALE(locale);
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, 1);
ret = __vfwscanf(fp, locale, fmt, ap);
- FUNLOCKFILE(fp);
+ FUNLOCKFILE_CANCELSAFE();
return (ret);
}
int
@@ -136,34 +448,23 @@
__vfwscanf(FILE * __restrict fp, locale_t locale,
const wchar_t * __restrict fmt, va_list ap)
{
+#define GETARG(type) ((flags & SUPPRESS) ? SUPPRESS_PTR : va_arg(ap, type))
wint_t c; /* character from format, or conversion */
size_t width; /* field width, or 0 */
- wchar_t *p; /* points into all kinds of strings */
- int n; /* handy integer */
int flags; /* flags as defined above */
- wchar_t *p0; /* saves original value of p when necessary */
int nassigned; /* number of fields assigned */
int nconversions; /* number of conversions */
+ int nr; /* characters read by the current conversion */
int nread; /* number of characters consumed from fp */
int base; /* base argument to conversion function */
+ struct ccl ccl; /* character class info */
wchar_t buf[BUF]; /* buffer for numeric conversions */
- const wchar_t *ccls; /* character class start */
- const wchar_t *ccle; /* character class end */
- int cclcompl; /* ccl is complemented? */
wint_t wi; /* handy wint_t */
- char *mbp; /* multibyte string pointer for %c %s %[ */
- size_t nconv; /* number of bytes in mb. conversion */
- char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */
- mbstate_t mbs;
- /* `basefix' is used to avoid `if' tests in the integer scanner */
- static short basefix[17] =
- { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
-
nassigned = 0;
nconversions = 0;
nread = 0;
- ccls = ccle = NULL;
+ ccl.start = ccl.end = NULL;
for (;;) {
c = *fmt++;
if (c == 0)
@@ -171,7 +472,7 @@
if (iswspace(c)) {
while ((c = __fgetwc(fp, locale)) != WEOF &&
iswspace_l(c, locale))
- ;
+ nread++;
if (c != WEOF)
__ungetwc(c, fp, locale);
continue;
@@ -283,17 +584,17 @@
break;
case '[':
- ccls = fmt;
+ ccl.start = fmt;
if (*fmt == '^') {
- cclcompl = 1;
+ ccl.compl = 1;
fmt++;
} else
- cclcompl = 0;
+ ccl.compl = 0;
if (*fmt == ']')
fmt++;
while (*fmt != '\0' && *fmt != ']')
fmt++;
- ccle = fmt;
+ ccl.end = fmt;
fmt++;
flags |= NOSKIP;
c = CT_CCL;
@@ -315,7 +616,6 @@
break;
case 'n':
- nconversions++;
if (flags & SUPPRESS) /* ??? */
continue;
if (flags & SHORTSHORT)
@@ -368,57 +668,14 @@
if (width == 0)
width = 1;
if (flags & LONG) {
- if (!(flags & SUPPRESS))
- p = va_arg(ap, wchar_t *);
- n = 0;
- while (width-- != 0 &&
- (wi = __fgetwc(fp, locale)) != WEOF) {
- if (!(flags & SUPPRESS))
- *p++ = (wchar_t)wi;
- n++;
- }
- if (n == 0)
- goto input_failure;
- nread += n;
- if (!(flags & SUPPRESS))
- nassigned++;
+ nr = convert_wchar(fp, GETARG(wchar_t *), width,
+ locale);
} else {
- if (!(flags & SUPPRESS))
- mbp = va_arg(ap, char *);
- n = 0;
- mbs = initial_mbs;
- while (width != 0 &&
- (wi = __fgetwc(fp, locale)) != WEOF) {
- if (width >= MB_CUR_MAX &&
- !(flags & SUPPRESS)) {
- nconv = wcrtomb(mbp, wi, &mbs);
- if (nconv == (size_t)-1)
- goto input_failure;
- } else {
- nconv = wcrtomb(mbbuf, wi,
- &mbs);
- if (nconv == (size_t)-1)
- goto input_failure;
- if (nconv > width) {
- __ungetwc(wi, fp, locale);
- break;
- }
- if (!(flags & SUPPRESS))
- memcpy(mbp, mbbuf,
- nconv);
- }
- if (!(flags & SUPPRESS))
- mbp += nconv;
- width -= nconv;
- n++;
- }
- if (n == 0)
- goto input_failure;
- nread += n;
- if (!(flags & SUPPRESS))
- nassigned++;
+ nr = convert_char(fp, GETARG(char *), width,
+ locale);
}
- nconversions++;
+ if (nr < 0)
+ goto input_failure;
break;
case CT_CCL:
@@ -426,64 +683,19 @@
if (width == 0)
width = (size_t)~0; /* `infinity' */
/* take only those things in the class */
- if ((flags & SUPPRESS) && (flags & LONG)) {
- n = 0;
- while ((wi = __fgetwc(fp, locale)) != WEOF &&
- width-- != 0 && INCCL(wi))
- n++;
- if (wi != WEOF)
- __ungetwc(wi, fp, locale);
- if (n == 0)
- goto match_failure;
- } else if (flags & LONG) {
- p0 = p = va_arg(ap, wchar_t *);
- while ((wi = __fgetwc(fp, locale)) != WEOF &&
- width-- != 0 && INCCL(wi))
- *p++ = (wchar_t)wi;
- if (wi != WEOF)
- __ungetwc(wi, fp, locale);
- n = p - p0;
- if (n == 0)
- goto match_failure;
- *p = 0;
- nassigned++;
+ if (flags & LONG) {
+ nr = convert_wccl(fp, GETARG(wchar_t *), width,
+ &ccl, locale);
} else {
- if (!(flags & SUPPRESS))
- mbp = va_arg(ap, char *);
- n = 0;
- mbs = initial_mbs;
- while ((wi = __fgetwc(fp, locale)) != WEOF &&
- width != 0 && INCCL(wi)) {
- if (width >= MB_CUR_MAX &&
- !(flags & SUPPRESS)) {
- nconv = wcrtomb(mbp, wi, &mbs);
- if (nconv == (size_t)-1)
- goto input_failure;
- } else {
- nconv = wcrtomb(mbbuf, wi,
- &mbs);
- if (nconv == (size_t)-1)
- goto input_failure;
- if (nconv > width)
- break;
- if (!(flags & SUPPRESS))
- memcpy(mbp, mbbuf,
- nconv);
- }
- if (!(flags & SUPPRESS))
- mbp += nconv;
- width -= nconv;
- n++;
- }
- if (wi != WEOF)
- __ungetwc(wi, fp, locale);
- if (!(flags & SUPPRESS)) {
- *mbp = 0;
- nassigned++;
- }
+ nr = convert_ccl(fp, GETARG(char *), width,
+ &ccl, locale);
}
- nread += n;
- nconversions++;
+ if (nr <= 0) {
+ if (nr < 0)
+ goto input_failure;
+ else /* nr == 0 */
+ goto match_failure;
+ }
break;
case CT_STRING:
@@ -490,62 +702,16 @@
/* like CCL, but zero-length string OK, & no NOSKIP */
if (width == 0)
width = (size_t)~0;
- if ((flags & SUPPRESS) && (flags & LONG)) {
- while ((wi = __fgetwc(fp, locale)) != WEOF &&
- width-- != 0 &&
- !iswspace(wi))
- nread++;
- if (wi != WEOF)
- __ungetwc(wi, fp, locale);
- } else if (flags & LONG) {
- p0 = p = va_arg(ap, wchar_t *);
- while ((wi = __fgetwc(fp, locale)) != WEOF &&
- width-- != 0 &&
- !iswspace(wi)) {
- *p++ = (wchar_t)wi;
- nread++;
- }
- if (wi != WEOF)
- __ungetwc(wi, fp, locale);
- *p = '\0';
- nassigned++;
+ if (flags & LONG) {
+ nr = convert_wstring(fp, GETARG(wchar_t *),
+ width, locale);
} else {
- if (!(flags & SUPPRESS))
- mbp = va_arg(ap, char *);
- mbs = initial_mbs;
- while ((wi = __fgetwc(fp, locale)) != WEOF &&
- width != 0 &&
- !iswspace(wi)) {
- if (width >= MB_CUR_MAX &&
- !(flags & SUPPRESS)) {
- nconv = wcrtomb(mbp, wi, &mbs);
- if (nconv == (size_t)-1)
- goto input_failure;
- } else {
- nconv = wcrtomb(mbbuf, wi,
- &mbs);
- if (nconv == (size_t)-1)
- goto input_failure;
- if (nconv > width)
- break;
- if (!(flags & SUPPRESS))
- memcpy(mbp, mbbuf,
- nconv);
- }
- if (!(flags & SUPPRESS))
- mbp += nconv;
- width -= nconv;
- nread++;
- }
- if (wi != WEOF)
- __ungetwc(wi, fp, locale);
- if (!(flags & SUPPRESS)) {
- *mbp = 0;
- nassigned++;
- }
+ nr = convert_string(fp, GETARG(char *), width,
+ locale);
}
- nconversions++;
- continue;
+ if (nr < 0)
+ goto input_failure;
+ break;
case CT_INT:
/* scan an integer as if by the conversion function */
@@ -552,120 +718,14 @@
if (width == 0 || width > sizeof(buf) /
sizeof(*buf) - 1)
width = sizeof(buf) / sizeof(*buf) - 1;
- flags |= SIGNOK | NDIGITS | NZDIGITS;
- for (p = buf; width; width--) {
- c = __fgetwc(fp, locale);
- /*
- * Switch on the character; `goto ok'
- * if we accept it as a part of number.
- */
- switch (c) {
- /*
- * The digit 0 is always legal, but is
- * special. For %i conversions, if no
- * digits (zero or nonzero) have been
- * scanned (only signs), we will have
- * base==0. In that case, we should set
- * it to 8 and enable 0x prefixing.
- * Also, if we have not scanned zero digits
- * before this, do not turn off prefixing
- * (someone else will turn it off if we
- * have scanned any nonzero digits).
- */
- case '0':
- if (base == 0) {
- base = 8;
- flags |= PFXOK;
- }
- if (flags & NZDIGITS)
- flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
- else
- flags &= ~(SIGNOK|PFXOK|NDIGITS);
- goto ok;
-
- /* 1 through 7 always legal */
- case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- base = basefix[base];
- flags &= ~(SIGNOK | PFXOK | NDIGITS);
- goto ok;
-
- /* digits 8 and 9 ok iff decimal or hex */
- case '8': case '9':
- base = basefix[base];
- if (base <= 8)
- break; /* not legal here */
- flags &= ~(SIGNOK | PFXOK | NDIGITS);
- goto ok;
-
- /* letters ok iff hex */
- case 'A': case 'B': case 'C':
- case 'D': case 'E': case 'F':
- case 'a': case 'b': case 'c':
- case 'd': case 'e': case 'f':
- /* no need to fix base here */
- if (base <= 10)
- break; /* not legal here */
- flags &= ~(SIGNOK | PFXOK | NDIGITS);
- goto ok;
-
- /* sign ok only as first character */
- case '+': case '-':
- if (flags & SIGNOK) {
- flags &= ~SIGNOK;
- flags |= HAVESIGN;
- goto ok;
- }
- break;
-
- /*
- * x ok iff flag still set & 2nd char (or
- * 3rd char if we have a sign).
- */
- case 'x': case 'X':
- if (flags & PFXOK && p ==
- buf + 1 + !!(flags & HAVESIGN)) {
- base = 16; /* if %i */
- flags &= ~PFXOK;
- goto ok;
- }
- break;
- }
-
- /*
- * If we got here, c is not a legal character
- * for a number. Stop accumulating digits.
- */
- if (c != WEOF)
- __ungetwc(c, fp, locale);
- break;
- ok:
- /*
- * c is legal: store it and look at the next.
- */
- *p++ = (wchar_t)c;
- }
- /*
- * If we had only a sign, it is no good; push
- * back the sign. If the number ends in `x',
- * it was [sign] '0' 'x', so push back the x
- * and treat it as [sign] '0'.
- */
- if (flags & NDIGITS) {
- if (p > buf)
- __ungetwc(*--p, fp, locale);
+ nr = parseint(fp, buf, width, base, flags, locale);
+ if (nr == 0)
goto match_failure;
- }
- c = p[-1];
- if (c == 'x' || c == 'X') {
- --p;
- __ungetwc(c, fp, locale);
- }
if ((flags & SUPPRESS) == 0) {
uintmax_t res;
- *p = 0;
+ buf[nr] = L'\0';
if ((flags & UNSIGNED) == 0)
res = wcstoimax(buf, NULL, base);
else
@@ -689,10 +749,7 @@
*va_arg(ap, size_t *) = res;
else
*va_arg(ap, int *) = res;
- nassigned++;
}
- nread += p - buf;
- nconversions++;
break;
#ifndef NO_FLOATING_POINT
@@ -701,26 +758,28 @@
if (width == 0 || width > sizeof(buf) /
sizeof(*buf) - 1)
width = sizeof(buf) / sizeof(*buf) - 1;
- if ((width = parsefloat(fp, buf, buf + width, locale)) == 0)
+ nr = parsefloat(fp, buf, buf + width, locale);
+ if (nr == 0)
goto match_failure;
if ((flags & SUPPRESS) == 0) {
if (flags & LONGDBL) {
- long double res = wcstold(buf, &p);
+ long double res = wcstold(buf, NULL);
*va_arg(ap, long double *) = res;
} else if (flags & LONG) {
- double res = wcstod(buf, &p);
+ double res = wcstod(buf, NULL);
*va_arg(ap, double *) = res;
} else {
- float res = wcstof(buf, &p);
+ float res = wcstof(buf, NULL);
*va_arg(ap, float *) = res;
}
- nassigned++;
}
- nread += width;
- nconversions++;
break;
#endif /* !NO_FLOATING_POINT */
}
+ if (!(flags & SUPPRESS))
+ nassigned++;
+ nread += nr;
+ nconversions++;
}
input_failure:
return (nconversions != 0 ? nassigned : EOF);
Modified: trunk/lib/libc/stdio/vprintf.c
===================================================================
--- trunk/lib/libc/stdio/vprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)vprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vprintf.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include <xlocale.h>
Modified: trunk/lib/libc/stdio/vscanf.c
===================================================================
--- trunk/lib/libc/stdio/vscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)vscanf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vscanf.c 321074 2017-07-17 14:09:34Z kib $");
#include "namespace.h"
#include <stdio.h>
@@ -49,23 +50,18 @@
#include "xlocale_private.h"
int
-vscanf_l(locale, fmt, ap)
- locale_t locale;
- const char * __restrict fmt;
- __va_list ap;
+vscanf_l(locale_t locale, const char * __restrict fmt, __va_list ap)
{
int retval;
FIX_LOCALE(locale);
- FLOCKFILE(stdin);
+ FLOCKFILE_CANCELSAFE(stdin);
retval = __svfscanf(stdin, locale, fmt, ap);
- FUNLOCKFILE(stdin);
+ FUNLOCKFILE_CANCELSAFE();
return (retval);
}
int
-vscanf(fmt, ap)
- const char * __restrict fmt;
- __va_list ap;
+vscanf(const char * __restrict fmt, __va_list ap)
{
return vscanf_l(__get_locale(), fmt, ap);
}
Modified: trunk/lib/libc/stdio/vsnprintf.c
===================================================================
--- trunk/lib/libc/stdio/vsnprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vsnprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,8 +40,9 @@
static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vsnprintf.c 249808 2013-04-23 13:33:13Z emaste $");
+#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include "local.h"
@@ -59,8 +61,11 @@
on = n;
if (n != 0)
n--;
- if (n > INT_MAX)
- n = INT_MAX;
+ if (n > INT_MAX) {
+ errno = EOVERFLOW;
+ *str = '\0';
+ return (EOF);
+ }
/* Stdio internals do not deal correctly with zero length buffer */
if (n == 0) {
if (on > 0)
Modified: trunk/lib/libc/stdio/vsprintf.c
===================================================================
--- trunk/lib/libc/stdio/vsprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vsprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)vsprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vsprintf.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include <limits.h>
Modified: trunk/lib/libc/stdio/vsscanf.c
===================================================================
--- trunk/lib/libc/stdio/vsscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vsscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,7 +40,7 @@
static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vsscanf.c 249808 2013-04-23 13:33:13Z emaste $");
#include <stdio.h>
#include <string.h>
Modified: trunk/lib/libc/stdio/vswprintf.c
===================================================================
--- trunk/lib/libc/stdio/vswprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vswprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: vasprintf.c,v 1.4 1998/06/21 22:13:47 millert Exp $ */
/*
@@ -36,9 +37,10 @@
#if 0
__FBSDID("FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.16 2002/08/21 16:19:57 mike Exp ");
#endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vswprintf.c 234531 2012-04-21 06:10:18Z das $");
#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
@@ -61,6 +63,11 @@
errno = EINVAL;
return (-1);
}
+ if (n - 1 > INT_MAX) {
+ errno = EOVERFLOW;
+ *s = L'\0';
+ return (-1);
+ }
f._flags = __SWR | __SSTR | __SALC;
f._bf._base = f._p = (unsigned char *)malloc(128);
Modified: trunk/lib/libc/stdio/vswscanf.c
===================================================================
--- trunk/lib/libc/stdio/vswscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vswscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -18,7 +19,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -42,7 +43,7 @@
#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
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vswscanf.c 249808 2013-04-23 13:33:13Z emaste $");
#include <limits.h>
#include <stdarg.h>
Modified: trunk/lib/libc/stdio/vwprintf.c
===================================================================
--- trunk/lib/libc/stdio/vwprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vwprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vwprintf.c 227753 2011-11-20 14:45:42Z theraven $");
#include <stdarg.h>
#include <stdio.h>
Modified: trunk/lib/libc/stdio/vwscanf.c
===================================================================
--- trunk/lib/libc/stdio/vwscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/vwscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/vwscanf.c 227753 2011-11-20 14:45:42Z theraven $");
#include <stdarg.h>
#include <stdio.h>
Modified: trunk/lib/libc/stdio/wbuf.c
===================================================================
--- trunk/lib/libc/stdio/wbuf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/wbuf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,8 +35,9 @@
static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/wbuf.c 269482 2014-08-03 18:28:10Z pfg $");
+#include <errno.h>
#include <stdio.h>
#include "local.h"
@@ -47,9 +49,7 @@
* Non-MT-safe
*/
int
-__swbuf(c, fp)
- int c;
- FILE *fp;
+__swbuf(int c, FILE *fp)
{
int n;
@@ -61,8 +61,10 @@
* calls might wrap _w from negative to positive.
*/
fp->_w = fp->_lbfsize;
- if (prepwrite(fp) != 0)
+ if (prepwrite(fp) != 0) {
+ errno = EBADF;
return (EOF);
+ }
c = (unsigned char)c;
ORIENT(fp, -1);
Modified: trunk/lib/libc/stdio/wprintf.3
===================================================================
--- trunk/lib/libc/stdio/wprintf.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/wprintf.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -31,7 +32,7 @@
.\"
.\" @(#)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
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/wprintf.3 208027 2010-05-13 12:07:55Z uqs $
.\"
.Dd July 5, 2003
.Dt WPRINTF 3
Property changes on: trunk/lib/libc/stdio/wprintf.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/wprintf.c
===================================================================
--- trunk/lib/libc/stdio/wprintf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/wprintf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/wprintf.c 227753 2011-11-20 14:45:42Z theraven $");
#include <stdarg.h>
#include <stdio.h>
Modified: trunk/lib/libc/stdio/wscanf.3
===================================================================
--- trunk/lib/libc/stdio/wscanf.3 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/wscanf.3 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -31,7 +32,7 @@
.\"
.\" @(#)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
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdio/wscanf.3 235363 2012-05-12 20:27:13Z joel $
.\"
.Dd July 5, 2003
.Dt WSCANF 3
@@ -365,10 +366,10 @@
(or not in)
a particular set;
the set is defined by the characters between the open bracket
-.Cm [
+.Cm \&[
character
and a close bracket
-.Cm ]
+.Cm \&]
character.
The set
.Em excludes
Property changes on: trunk/lib/libc/stdio/wscanf.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdio/wscanf.c
===================================================================
--- trunk/lib/libc/stdio/wscanf.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/wscanf.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/wscanf.c 227753 2011-11-20 14:45:42Z theraven $");
#include <stdarg.h>
#include <stdio.h>
Modified: trunk/lib/libc/stdio/wsetup.c
===================================================================
--- trunk/lib/libc/stdio/wsetup.c 2018-06-08 00:56:56 UTC (rev 10558)
+++ trunk/lib/libc/stdio/wsetup.c 2018-06-08 00:59:17 UTC (rev 10559)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -34,7 +35,7 @@
static char sccsid[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdio/wsetup.c 249810 2013-04-23 14:36:44Z emaste $");
#include <errno.h>
#include <stdio.h>
@@ -47,8 +48,7 @@
* _wsetup returns 0 if OK to write; otherwise, it returns EOF and sets errno.
*/
int
-__swsetup(fp)
- FILE *fp;
+__swsetup(FILE *fp)
{
/* make sure stdio is set up */
if (!__sdidinit)
More information about the Midnightbsd-cvs
mailing list