NetBSD re-synchronization of the source tree

This brings our tree to NetBSD 7.0, as found on -current on the
10-10-2015.

This updates:
 - LLVM to 3.6.1
 - GCC to GCC 5.1
 - Replace minix/commands/zdump with usr.bin/zdump
 - external/bsd/libelf has moved to /external/bsd/elftoolchain/
 - Import ctwm
 - Drop sprintf from libminc

Change-Id: I149836ac18e9326be9353958bab9b266efb056f0
This commit is contained in:
2016-01-13 20:32:14 +01:00
parent 8933525b85
commit 0a6a1f1d05
32425 changed files with 2998492 additions and 1342217 deletions
+9 -8
View File
@@ -1,5 +1,5 @@
# from: @(#)Makefile.inc 5.7 (Berkeley) 6/27/91
# $NetBSD: Makefile.inc,v 1.42 2013/04/19 15:22:25 joerg Exp $
# $NetBSD: Makefile.inc,v 1.46 2014/10/13 00:40:36 christos Exp $
# stdio sources
.PATH: ${.CURDIR}/stdio
@@ -13,27 +13,25 @@ SRCS+= clrerr.c dprintf.c fclose.c fdopen.c feof.c ferror.c \
fread.c freopen.c fscanf.c fseek.c fseeko.c fsetpos.c ftell.c ftello.c \
funopen.c fvwrite.c fwalk.c fwide.c fwprintf.c fwrite.c fwscanf.c \
getc.c getchar.c getdelim.c getline.c gettemp.c getw.c getwc.c \
getwchar.c makebuf.c mkdtemp.c mkstemp.c perror.c printf.c putc.c \
putchar.c puts.c putw.c putwc.c putwchar.c refill.c remove.c rewind.c \
getwchar.c makebuf.c mkdtemp.c mkstemp.c mkstemps.c mkostemp.c \
mkostemps.c perror.c printf.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 setvbuf.c snprintf_ss.c \
sscanf.c stdio.c swprintf.c swscanf.c tmpfile.c ungetc.c ungetwc.c \
vasprintf.c vdprintf.c vfprintf.c vfscanf.c vfwprintf.c vfwscanf.c \
vprintf.c vscanf.c vsnprintf.c vsnprintf_ss.c vsscanf.c vswprintf.c \
vswscanf.c vwprintf.c vwscanf.c wbuf.c wprintf.c wscanf.c wsetup.c
SRCS+= fmemopen.c
SRCS+= fmemopen.c open_memstream.c open_wmemstream.c
.if !defined(AUDIT)
SRCS+= gets.c vsprintf.c tempnam.c tmpnam.c mktemp.c
.endif
# namespace purity wrappers
SRCS+= _fileno.c _fseeko.c _ftello.c
MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetwln.3 fgetws.3 \
flockfile.3 fmemopen.3 fopen.3 fparseln.3 fputs.3 fputws.3 fread.3 \
fseek.3 funopen.3 fwide.3 getc.3 getdelim.3 getwc.3 mktemp.3 printf.3 \
putc.3 putwc.3 remove.3 scanf.3 setbuf.3 stdio.3 tmpnam.3 \
ungetc.3 ungetwc.3 wprintf.3 wscanf.3
ungetc.3 ungetwc.3 wprintf.3 wscanf.3 open_memstream.3
MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
MLINKS+=fflush.3 fpurge.3
@@ -50,6 +48,8 @@ MLINKS+=getc.3 fgetc.3 getc.3 getc_unlocked.3 getc.3 getchar.3 \
getc.3 getchar_unlocked.3 getc.3 getw.3
MLINKS+=getdelim.3 getline.3
MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3
MLINKS+=mktemp.3 mkostemp.3 mktemp.3 mkostemps.3
MLINKS+=mktemp.3 mkstemps.3
MLINKS+=printf.3 asprintf.3 printf.3 fprintf.3 printf.3 snprintf.3 \
printf.3 sprintf.3 printf.3 vasprintf.3 printf.3 vfprintf.3 \
printf.3 vprintf.3 printf.3 vsnprintf.3 printf.3 vsprintf.3 \
@@ -66,3 +66,4 @@ MLINKS+=wprintf.3 fwprintf.3 wprintf.3 swprintf.3
MLINKS+=wprintf.3 vwprintf.3 wprintf.3 vfwprintf.3 wprintf.3 vswprintf.3
MLINKS+=wscanf.3 fwscanf.3 wscanf.3 swscanf.3 wscanf.3 vwscanf.3
MLINKS+=wscanf.3 vswscanf.3 wscanf.3 vfwscanf.3
MLINKS+=open_memstream.3 open_wmemstream.3
-46
View File
@@ -1,46 +0,0 @@
/* $NetBSD: _fileno.c,v 1.5 2009/10/21 01:07:45 snj Exp $ */
/*
* Copyright (c) 1996 Christos Zoulas. 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 ``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 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>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _fileno.c,v 1.5 2009/10/21 01:07:45 snj Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(__indr_reference)
__indr_reference(_fileno, fileno)
#else
#include <stdio.h>
#undef fileno
int _fileno (FILE *);
int
fileno(FILE *stream)
{
return _fileno(stream);
}
#endif
-45
View File
@@ -1,45 +0,0 @@
/* $NetBSD: _fseeko.c,v 1.5 2009/10/21 01:07:45 snj Exp $ */
/*
* Copyright (c) 1996 Christos Zoulas. 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 ``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 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>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _fseeko.c,v 1.5 2009/10/21 01:07:45 snj Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(__indr_reference)
__indr_reference(_fseeko, fseeko)
#else
#include <stdio.h>
int _fseeko(FILE *, off_t, int);
int
fseeko(FILE *stream, off_t offset, int whence)
{
return _fseeko(stream, offset, whence);
}
#endif
-45
View File
@@ -1,45 +0,0 @@
/* $NetBSD: _ftello.c,v 1.5 2009/10/21 01:07:45 snj Exp $ */
/*
* Copyright (c) 1996 Christos Zoulas. 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 ``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 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>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _ftello.c,v 1.5 2009/10/21 01:07:45 snj Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(__indr_reference)
__indr_reference(_ftello, ftello)
#else
#include <stdio.h>
off_t _ftello(FILE *);
off_t
ftello(FILE *stream)
{
return _ftello(stream);
}
#endif
+7 -15
View File
@@ -1,4 +1,4 @@
.\" $NetBSD: fgetln.3,v 1.14 2004/05/10 17:15:28 drochner Exp $
.\" $NetBSD: fgetln.3,v 1.15 2014/06/19 14:27:50 christos Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94
.\"
.Dd April 21, 2004
.Dd June 19, 2014
.Dt FGETLN 3
.Os
.Sh NAME
@@ -134,22 +134,14 @@ temporary buffer:
char *buf, *lbuf;
size_t len;
lbuf = NULL;
while ((buf = fgetln(fp, &len))) {
if (buf[len - 1] == '\en')
while ((lbuf = buf = fgetln(fp, &len)) != NULL) {
if (len > 0 && buf[len - 1] == '\en')
buf[len - 1] = '\e0';
else {
if ((lbuf = (char *)malloc(len + 1)) == NULL)
else if ((lbuf = strndup(buf, len + 1)) == NULL)
err(1, NULL);
memcpy(lbuf, buf, len);
lbuf[len] = '\e0';
buf = lbuf;
}
printf("%s\en", buf);
printf("%s\en", lbuf);
if (lbuf != NULL) {
if (lbuf != buf)
free(lbuf);
lbuf = NULL;
}
}
.Ed
+5 -5
View File
@@ -110,12 +110,12 @@ int __sdidinit;
#endif /* !defined(_LIBMINC) && !defined(__kernel__) */
#if !defined(__kernel__)
#if !defined(__kernel__) && defined(__minix)
/* the usual - (stdin + stdout + stderr) */
static FILE usual[FOPEN_MAX - 3];
static struct __sfileext usualext[FOPEN_MAX - 3];
static struct glue uglue = { 0, FOPEN_MAX - 3, usual };
#endif /* !defined(__kernel__) */
#endif /* !defined(__kernel__) && defined(__minix) */
#if defined(_REENTRANT) && !defined(__lint__) /* XXX lint is busted */
#define STDEXT { ._lock = MUTEX_INITIALIZER, ._lockcond = COND_INITIALIZER }
@@ -230,7 +230,7 @@ f_prealloc(void)
continue;
if (n > 0)
g->next = moreglue(n);
#endif /* !defined(_LIBMINC) */
#endif /* !defined(_LIBMINC) && defined(__minix) */
}
/*
@@ -246,7 +246,7 @@ _cleanup(void)
#if !defined(_LIBMINC) && defined(__minix)
/* (void) _fwalk(fclose); */
(void) fflush(NULL); /* `cheating' */
#endif /* !defined(_LIBMINC) */
#endif /* !defined(_LIBMINC) && defined(__minix) */
}
/*
@@ -264,4 +264,4 @@ __sinit(void)
__cleanup = _cleanup; /* conservative */
__sdidinit = 1;
}
#endif /* !defined(__kernel__) */
#endif /* !defined(__kernel__) && defined(__minix) */
+4 -4
View File
@@ -1,4 +1,4 @@
.\" $NetBSD: fmemopen.3,v 1.7 2012/10/08 18:15:09 njoly Exp $
.\" $NetBSD: fmemopen.3,v 1.9 2015/09/06 03:10:50 pgoyette Exp $
.\"
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -30,12 +30,12 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd October 15, 2011
.Dd September 5, 2015
.Dt FMEMOPEN 3
.Os
.Sh NAME
.Nm fmemopen
.Nd open a stream that points to the given buffer
.Nd open a stream that points to a memory buffer
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -190,5 +190,5 @@ function conforms to
.Sh HISTORY
The
.Fn fmemopen
functions first appeared in
function first appeared in
.Nx 6.0 .
+10 -3
View File
@@ -1,4 +1,4 @@
.\" $NetBSD: fopen.3,v 1.29 2012/11/15 03:50:36 christos Exp $
.\" $NetBSD: fopen.3,v 1.31 2015/07/15 19:08:43 christos Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -120,8 +120,8 @@ extension.
.It Sq x
The letter
.Sq x
in the mode turns on exclusive open mode to the file (
.Dv O_EXCL )
in the mode turns on exclusive open mode to the file
.Pq Dv O_EXCL
which means that the file will not be created if it already exists.
.El
.Pp
@@ -196,6 +196,13 @@ standard text stream
.Em stdin ,
or
.Em stdout ) .
.Pp
Input and output against the opened stream will be fully buffered, unless
it refers to an interactive terminal device, or a different kind of buffering
is specified in the environment.
See
.Xr setvbuf 3
for additional details.
.Sh RETURN VALUES
Upon successful completion
.Fn fopen ,
+1 -2
View File
@@ -1,4 +1,4 @@
.\" $NetBSD: fparseln.3,v 1.4 2009/10/21 01:07:45 snj Exp $
.\" $NetBSD: fparseln.3,v 1.5 2014/01/07 13:34:11 njoly Exp $
.\"
.\" Copyright (c) 1997 Christos Zoulas. All rights reserved.
.\"
@@ -114,7 +114,6 @@ Remove escape preceding any other character.
.It Dv FPARSELN_UNESCALL
All of the above.
.El
.Pp
.El
.Sh RETURN VALUES
Upon successful completion a pointer to the parsed line is returned;
+5 -2
View File
@@ -1,4 +1,4 @@
/* $NetBSD: fseek.c,v 1.23 2008/04/29 06:53:01 martin Exp $ */
/* $NetBSD: fseek.c,v 1.24 2014/11/16 20:32:52 christos Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: fseek.c,v 1.23 2008/04/29 06:53:01 martin Exp $");
__RCSID("$NetBSD: fseek.c,v 1.24 2014/11/16 20:32:52 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -55,9 +55,12 @@ fseek(FILE *fp, long l_offset, int whence)
{
off_t offset;
#if 0
/* This is a bad idea because makes fseek(fp, -6, SEEK_SET) work... */
if (whence == SEEK_SET)
offset = (unsigned long)l_offset;
else
#endif
offset = l_offset;
return fseeko(fp, offset, whence);
}
+12 -2
View File
@@ -1,4 +1,4 @@
/* $NetBSD: fseeko.c,v 1.12 2012/03/27 15:05:42 christos Exp $ */
/* $NetBSD: fseeko.c,v 1.13 2014/10/19 11:17:43 justin Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: fseeko.c,v 1.12 2012/03/27 15:05:42 christos Exp $");
__RCSID("$NetBSD: fseeko.c,v 1.13 2014/10/19 11:17:43 justin Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -115,11 +115,21 @@ fseeko(FILE *fp, off_t offset, int whence)
curoff += fp->_p - fp->_bf._base;
offset += curoff;
if (offset < 0) {
errno = EINVAL;
FUNLOCKFILE(fp);
return -1;
}
whence = SEEK_SET;
havepos = 1;
break;
case SEEK_SET:
if (offset < 0) {
errno = EINVAL;
FUNLOCKFILE(fp);
return -1;
}
case SEEK_END:
curoff = 0; /* XXX just to keep gcc quiet */
havepos = 0;
+2 -1
View File
@@ -1,4 +1,4 @@
.\" $NetBSD: funopen.3,v 1.22 2012/10/08 18:15:09 njoly Exp $
.\" $NetBSD: funopen.3,v 1.23 2015/09/06 01:36:21 dholland Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -169,6 +169,7 @@ specified for the routine
.Xr fcntl 2 ,
.Xr open 2 ,
.Xr fclose 3 ,
.Xr fmemopen 3 ,
.Xr fopen 3 ,
.Xr fseek 3 ,
.Xr setbuf 3
+21 -6
View File
@@ -1,4 +1,4 @@
.\" $NetBSD: getdelim.3,v 1.9 2011/04/20 23:37:51 enami Exp $
.\" $NetBSD: getdelim.3,v 1.14 2014/09/16 08:52:02 wiz Exp $
.\"
.\" Copyright (c) 2009 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd June 30, 2010
.Dd September 15, 2014
.Dt GETDELIM 3
.Os
.Sh NAME
@@ -48,12 +48,14 @@ The
function reads from the
.Fa stream
until it encounters a character matching
.Fa delimiter ,
.Fa delimiter
or
.Dv EOF ,
storing the input in
.Fa *lineptr .
The buffer is
.Dv NUL Ns No -terminated
and includes the delimiter.
and includes the delimiter, if one was found.
The
.Fa delimiter
character must be representable as an unsigned char.
@@ -88,7 +90,8 @@ The
.Fn getdelim
and
.Fn getline
functions return the number of characters read, including the delimiter.
functions return the number of characters read, including the delimiter if
one was found.
If no characters were read and the stream is at end-of-file, the functions
return \-1.
If an error occurs, the functions return \-1 and the global variable
@@ -144,7 +147,8 @@ or
.Sh SEE ALSO
.Xr ferror 3 ,
.Xr fgets 3 ,
.Xr fopen 3
.Xr fopen 3 ,
.Xr strlen 3
.Sh STANDARDS
The
.Fn getdelim
@@ -152,3 +156,14 @@ and
.Fn getline
functions conform to
.St -p1003.1-2008 .
.Sh NOTES
The
.Fn getdelim
and
.Fn getline
functions can return results that include
.Dv NUL
characters, which can cause the apparent length reported by
.Xr strlen 3
to be less than the true length reported by the
return values of the functions.
+81 -89
View File
@@ -1,4 +1,4 @@
/* $NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $ */
/* $NetBSD: gettemp.c,v 1.20 2015/02/05 16:05:20 christos Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -29,9 +29,7 @@
* SUCH DAMAGE.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include "gettemp.h"
#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP || !HAVE_MKDTEMP
@@ -40,125 +38,119 @@
#if 0
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $");
__RCSID("$NetBSD: gettemp.c,v 1.20 2015/02/05 16:05:20 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <sys/param.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#if HAVE_NBTOOL_CONFIG_H
#define GETTEMP __nbcompat_gettemp
#else
#include "reentrant.h"
#include "local.h"
#define GETTEMP __gettemp
#endif
static const unsigned char padchar[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int
GETTEMP(char *path, int *doopen, int domkdir)
GETTEMP(char *path, int *doopen, int domkdir, int slen, int oflags)
{
char *start, *trv;
char *start, *trv, *suffp, *carryp;
char *pad;
struct stat sbuf;
u_int pid;
/* To guarantee multiple calls generate unique names even if
the file is not created. 676 different possibilities with 7
or more X's, 26 with 6 or less. */
static char xtra[2] = "aa";
int xcnt = 0;
int rval;
uint32_t r;
char carrybuf[MAXPATHLEN];
_DIAGASSERT(path != NULL);
/* doopen may be NULL */
pid = getpid();
/* Move to end of path and count trailing X's. */
for (trv = path; *trv; ++trv)
if (*trv == 'X')
xcnt++;
else
xcnt = 0;
/* Use at least one from xtra. Use 2 if more than 6 X's. */
if (*(trv - 1) == 'X')
*--trv = xtra[0];
if (xcnt > 6 && *(trv - 1) == 'X')
*--trv = xtra[1];
/* Set remaining X's to pid digits with 0's to the left. */
while (*--trv == 'X') {
*trv = (pid % 10) + '0';
pid /= 10;
if ((doopen != NULL && domkdir) || slen < 0 ||
(oflags & ~(O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC |
O_CLOEXEC)) != 0) {
errno = EINVAL;
return 0;
}
/* update xtra for next call. */
if (xtra[0] != 'z')
xtra[0]++;
else {
xtra[0] = 'a';
if (xtra[1] != 'z')
xtra[1]++;
else
xtra[1] = 'a';
for (trv = path; *trv != '\0'; ++trv)
continue;
if (trv - path >= MAXPATHLEN) {
errno = ENAMETOOLONG;
return 0;
}
trv -= slen;
suffp = trv;
--trv;
if (trv < path || NULL != strchr(suffp, '/')) {
errno = EINVAL;
return 0;
}
/* Fill space with random characters */
while (trv >= path && *trv == 'X') {
r = arc4random_uniform((unsigned int)(sizeof(padchar) - 1));
*trv-- = padchar[r];
}
start = trv + 1;
/* save first combination of random characters */
memcpy(carrybuf, start, (size_t)(suffp - start));
/*
* check the target directory; if you have six X's and it
* doesn't exist this runs for a *very* long time.
* check the target directory.
*/
for (start = trv + 1;; --trv) {
if (trv <= path)
break;
if (*trv == '/') {
int e;
*trv = '\0';
e = stat(path, &sbuf);
*trv = '/';
if (e == -1)
return doopen == NULL && !domkdir;
if (!S_ISDIR(sbuf.st_mode)) {
errno = ENOTDIR;
return doopen == NULL && !domkdir;
if (doopen != NULL || domkdir) {
for (; trv > path; --trv) {
if (*trv == '/') {
*trv = '\0';
rval = stat(path, &sbuf);
*trv = '/';
if (rval != 0)
return 0;
if (!S_ISDIR(sbuf.st_mode)) {
errno = ENOTDIR;
return 0;
}
break;
}
break;
}
}
for (;;) {
if (doopen) {
if ((*doopen =
open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0)
if ((*doopen = open(path, O_CREAT|O_EXCL|O_RDWR|oflags,
0600)) != -1)
return 1;
if (errno != EEXIST)
return 0;
} else if (domkdir) {
if (mkdir(path, 0700) >= 0)
if (mkdir(path, 0700) != -1)
return 1;
if (errno != EEXIST)
return 0;
} else if (lstat(path, &sbuf))
return errno == ENOENT ? 1 : 0;
return errno == ENOENT;
/* tricky little algorithm for backward compatibility */
for (trv = start;;) {
if (!*trv)
/*
* If we have a collision,
* cycle through the space of filenames
*/
for (trv = start, carryp = carrybuf;;) {
/* have we tried all possible permutations? */
if (trv == suffp)
return 0; /* yes - exit with EEXIST */
pad = strchr((const char *)padchar, *trv);
if (pad == NULL) {
/* this should never happen */
errno = EIO;
return 0;
if (*trv == 'z')
*trv++ = 'a';
else {
if (isdigit((unsigned char)*trv))
*trv = 'a';
else
++*trv;
}
/* increment character */
*trv = (*++pad == '\0') ? padchar[0] : *pad;
/* carry to next position? */
if (*trv == *carryp) {
/* increment position and loop */
++trv;
++carryp;
} else {
/* try with new name */
break;
}
}
+48
View File
@@ -0,0 +1,48 @@
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GETTEMP_H_
#define _GETTEMP_H_
#include "namespace.h"
#if HAVE_NBTOOL_CONFIG_H
# include "nbtool_config.h"
# define GETTEMP __nbcompat_gettemp
#else
# include <assert.h>
# include <errno.h>
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
# include "reentrant.h"
# define GETTEMP __gettemp
#endif
__BEGIN_DECLS
int GETTEMP(char *, int *, int, int, int);
__END_DECLS
#endif /* _GETTEMP_H_ */
+2 -4
View File
@@ -1,4 +1,4 @@
/* $NetBSD: local.h,v 1.37 2013/10/04 20:49:16 christos Exp $ */
/* $NetBSD: local.h,v 1.38 2014/06/18 17:47:58 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -60,7 +60,7 @@ extern void (*__cleanup)(void);
extern void __smakebuf(FILE *);
extern int __swhatbuf(FILE *, size_t *, int *);
extern int _fwalk(int (*)(FILE *));
extern char *_mktemp(char *);
extern char *_mktemp(char *);
extern int __swsetup(FILE *);
extern int __sflags(const char *, int *);
extern int __svfscanf(FILE * __restrict, const char * __restrict,
@@ -75,8 +75,6 @@ extern int __vfprintf_unlocked_l(FILE * __restrict, locale_t,
extern int __sdidinit;
extern int __gettemp(char *, int *, int);
extern wint_t __fgetwc_unlock(FILE *);
extern wint_t __fputwc_unlock(wchar_t, FILE *);
+74 -12
View File
@@ -1,4 +1,4 @@
/* $NetBSD: makebuf.c,v 1.17 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: makebuf.c,v 1.18 2015/07/15 19:08:43 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)makebuf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: makebuf.c,v 1.17 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: makebuf.c,v 1.18 2015/07/15 19:08:43 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -49,9 +49,63 @@ __RCSID("$NetBSD: makebuf.c,v 1.17 2012/03/15 18:22:30 christos Exp $");
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
#include <ctype.h>
#include "reentrant.h"
#include "local.h"
/*
* Override the file buffering based on the environment setting STDBUF%d
* (for the specific file descriptor) and STDBUF (for all descriptors).
* the setting is ULB<num> standing for "Unbuffered", "Linebuffered",
* and Fullybuffered", and <num> is a value from 0 to 1M.
*/
static int
__senvbuf(FILE *fp, size_t *size, int *couldbetty)
{
char evb[64], *evp;
int flags, e;
intmax_t s;
flags = 0;
if (snprintf(evb, sizeof(evb), "STDBUF%d", fp->_file) < 0)
return flags;
if ((evp = getenv(evb)) == NULL && (evp = getenv("STDBUF")) == NULL)
return flags;
switch (*evp) {
case 'u':
case 'U':
evp++;
flags |= __SNBF;
break;
case 'l':
case 'L':
evp++;
flags |= __SLBF;
break;
case 'f':
case 'F':
evp++;
*couldbetty = 0;
break;
}
if (!isdigit((unsigned char)*evp))
return flags;
s = strtoi(evp, NULL, 0, 0, 1024 * 1024, &e);
if (e != 0)
return flags;
*size = (size_t)s;
if (*size == 0)
return __SNBF;
return flags;
}
/*
* Allocate a file buffer, or switch to unbuffered I/O.
* Per the ANSI C standard, ALL tty devices default to line buffered.
@@ -69,18 +123,21 @@ __smakebuf(FILE *fp)
_DIAGASSERT(fp != NULL);
if (fp->_flags & __SNBF) {
fp->_bf._base = fp->_p = fp->_nbuf;
fp->_bf._size = 1;
return;
}
if (fp->_flags & __SNBF)
goto unbuf;
flags = __swhatbuf(fp, &size, &couldbetty);
if ((p = malloc(size)) == NULL) {
fp->_flags |= __SNBF;
fp->_bf._base = fp->_p = fp->_nbuf;
fp->_bf._size = 1;
return;
if ((fp->_flags & (__SLBF|__SNBF|__SMBF)) == 0
&& fp->_cookie == fp && fp->_file >= 0) {
flags |= __senvbuf(fp, &size, &couldbetty);
if (flags & __SNBF)
goto unbuf;
}
if ((p = malloc(size)) == NULL)
goto unbuf;
__cleanup = _cleanup;
flags |= __SMBF;
fp->_bf._base = fp->_p = p;
@@ -89,6 +146,11 @@ __smakebuf(FILE *fp)
if (couldbetty && isatty(__sfileno(fp)))
flags |= __SLBF;
fp->_flags |= flags;
return;
unbuf:
fp->_flags |= __SNBF;
fp->_bf._base = fp->_p = fp->_nbuf;
fp->_bf._size = 1;
}
/*
+4 -19
View File
@@ -1,4 +1,4 @@
/* $NetBSD: mkdtemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: mkdtemp.c,v 1.12 2014/06/18 17:47:58 christos Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -29,9 +29,7 @@
* SUCH DAMAGE.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include "gettemp.h"
#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKDTEMP
@@ -40,29 +38,16 @@
#if 0
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: mkdtemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: mkdtemp.c,v 1.12 2014/06/18 17:47:58 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#if HAVE_NBTOOL_CONFIG_H
#define GETTEMP __nbcompat_gettemp
#else
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "reentrant.h"
#include "local.h"
#define GETTEMP __gettemp
#endif
char *
mkdtemp(char *path)
{
_DIAGASSERT(path != NULL);
return GETTEMP(path, NULL, 1) ? path : NULL;
return GETTEMP(path, NULL, 1, 0, 0) ? path : NULL;
}
#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKDTEMP */
+36
View File
@@ -0,0 +1,36 @@
/* $NetBSD: mkostemp.c,v 1.1 2014/06/18 17:47:58 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "gettemp.h"
int
mkostemp(char *path, int oflags)
{
int fd;
return GETTEMP(path, &fd, 0, 0, oflags) ? fd : -1;
}
+36
View File
@@ -0,0 +1,36 @@
/* $NetBSD: mkostemps.c,v 1.1 2014/06/18 17:47:58 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "gettemp.h"
int
mkostemps(char *path, int slen, int oflags)
{
int fd;
return GETTEMP(path, &fd, 0, slen, oflags) ? fd : -1;
}
+4 -22
View File
@@ -1,4 +1,4 @@
/* $NetBSD: mkstemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: mkstemp.c,v 1.12 2014/06/18 17:47:58 christos Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -28,10 +28,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include "gettemp.h"
#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP
@@ -40,25 +37,10 @@
#if 0
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: mkstemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: mkstemp.c,v 1.12 2014/06/18 17:47:58 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#if HAVE_NBTOOL_CONFIG_H
#define GETTEMP __nbcompat_gettemp
#else
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "reentrant.h"
#include "local.h"
#define GETTEMP __gettemp
#endif
#ifdef __weak_alias
__weak_alias(mkstemp,_mkstemp)
#endif
@@ -70,7 +52,7 @@ mkstemp(char *path)
_DIAGASSERT(path != NULL);
return GETTEMP(path, &fd, 0) ? fd : -1;
return GETTEMP(path, &fd, 0, 0, 0) ? fd : -1;
}
#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP */
+36
View File
@@ -0,0 +1,36 @@
/* $NetBSD: mkstemps.c,v 1.1 2014/06/18 17:47:58 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "gettemp.h"
int
mkstemps(char *path, int slen)
{
int fd;
return GETTEMP(path, &fd, 0, slen, 0) ? fd : -1;
}
+74 -6
View File
@@ -1,4 +1,4 @@
.\" $NetBSD: mktemp.3,v 1.28 2010/05/14 03:22:49 joerg Exp $
.\" $NetBSD: mktemp.3,v 1.30 2014/06/19 09:30:33 wiz Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,12 +29,15 @@
.\"
.\" @(#)mktemp.3 8.1 (Berkeley) 6/4/93
.\"
.Dd April 29, 2010
.Dd June 18, 2014
.Dt MKTEMP 3
.Os
.Sh NAME
.Nm mktemp ,
.Nm mkstemp ,
.Nm mkstemps ,
.Nm mkostemp ,
.Nm mkostemps ,
.Nm mkdtemp
.Nd make unique temporary file or directory name
.Sh LIBRARY
@@ -45,8 +48,15 @@
.Fn mktemp "char *template"
.Ft int
.Fn mkstemp "char *template"
.Ft int
.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
@@ -92,6 +102,42 @@ makes the same replacement to the template and creates the template file,
mode 0600, returning a file descriptor opened for reading and writing.
This avoids the race between testing for a file's existence and opening it
for use.
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
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
are told the length of the suffix string.
.Pp
The
.Fn mkdtemp
@@ -115,8 +161,12 @@ return a pointer to the template on success and
.Dv NULL
on failure.
The
.Fn mkstemp
function
.Fn mkstemp ,
.Fn mkostemp ,
.Fn mkstemps
and
.Fn mkostemps
functions
returns \-1 if no suitable file could be created.
If either call fails an error code is placed in the global variable
.Va errno .
@@ -201,8 +251,10 @@ of
.Er EEXIST .
.Sh ERRORS
The
.Fn mktemp ,
.Fn mkstemp
.Fn mkstemp ,
.Fn mkostemp ,
.Fn mkstemps ,
.Fn mkostemps
and
.Fn mkdtemp
functions
@@ -281,6 +333,22 @@ The
.Fn mkdtemp
function appeared in
.Nx 1.4 .
The
.Fn mkstemps
function first appeared in
.Ox 2.4 ,
and later in
.Fx 3.4
and
.Nx 7.0 .
The
.Fn mkostemp
and
.Fn mkostemps
functions appeared in
.Fx 10.0
and
.Nx 7.0 .
.Sh BUGS
For
.Fn mktemp
+5 -10
View File
@@ -1,4 +1,4 @@
/* $NetBSD: mktemp.c,v 1.20 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: mktemp.c,v 1.21 2014/06/18 17:47:58 christos Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -28,22 +28,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "gettemp.h"
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: mktemp.c,v 1.20 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: mktemp.c,v 1.21 2014/06/18 17:47:58 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "reentrant.h"
#include "local.h"
char *
@@ -52,7 +47,7 @@ _mktemp(char *path)
_DIAGASSERT(path != NULL);
return __gettemp(path, NULL, 0) ? path : NULL;
return GETTEMP(path, NULL, 0, 0, 0) ? path : NULL;
}
__warn_references(mktemp,
@@ -64,5 +59,5 @@ mktemp(char *path)
_DIAGASSERT(path != NULL);
return __gettemp(path, NULL, 0) ? path : NULL;
return GETTEMP(path, NULL, 0, 0, 0) ? path : NULL;
}
+155
View File
@@ -0,0 +1,155 @@
.\" $NetBSD: open_memstream.3,v 1.3 2014/10/26 14:19:28 christos Exp $
.\" Copyright (c) 2013 Advanced Computing Technologies LLC
.\" Written by: John H. Baldwin <jhb@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: head/lib/libc/stdio/open_memstream.3 247415 2013-02-27 20:09:25Z joel $
.\"
.Dd October 12, 2014
.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 stdio 3
.Sh STANDARDS
The
.Fn open_memstream
and
.Fn open_wmemstream
functions conform to
.St -p1003.1-2008 .
+214
View File
@@ -0,0 +1,214 @@
/* $NetBSD: open_memstream.c,v 1.1 2014/10/13 00:40:36 christos Exp $ */
/*-
* Copyright (c) 2013 Advanced Computing Technologies LLC
* Written by: John H. Baldwin <jhb@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>
#if 0
__FBSDID("$FreeBSD: head/lib/libc/stdio/open_memstream.c 247411 2013-02-27 19:50:46Z jhb $");
#endif
__RCSID("$NetBSD: open_memstream.c,v 1.1 2014/10/13 00:40:36 christos Exp $");
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#define OFF_MAX LLONG_MAX
struct memstream {
char **bufp;
size_t *sizep;
size_t len;
size_t offset;
};
static int
memstream_grow(struct memstream *ms, off_t newoff)
{
char *buf;
size_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)
{
*ms->sizep = ms->len < ms->offset ? ms->len : ms->offset;
}
static ssize_t
memstream_write(void *cookie, const void *buf, size_t len)
{
struct memstream *ms;
size_t tocopy;
off_t more;
ms = cookie;
more = ms->offset;
more += len;
if (!memstream_grow(ms, more))
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, %zu) = %zu\n", ms, len, tocopy);
#endif
return (ssize_t)tocopy;
}
static off_t
memstream_seek(void *cookie, off_t pos, int whence)
{
struct memstream *ms;
#ifdef DEBUG
size_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 + (ssize_t)ms->len < 0) {
#ifdef DEBUG
fprintf(stderr,
"MS: bad SEEK_END: pos %jd, len %zu\n",
(intmax_t)pos, ms->len);
#endif
errno = EINVAL;
return (-1);
}
} else {
if (OFF_MAX - (ssize_t)ms->len < pos) {
#ifdef DEBUG
fprintf(stderr,
"MS: bad SEEK_END: pos %jd, len %zu\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) %zu -> %zu\n", ms,
(intmax_t)pos, whence, old, 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 = funopen2(ms, NULL, memstream_write, memstream_seek,
NULL, memstream_close);
if (fp == NULL) {
save_errno = errno;
free(ms);
free(*bufp);
*bufp = NULL;
errno = save_errno;
return (NULL);
}
fwide(fp, -1);
return (fp);
}
+273
View File
@@ -0,0 +1,273 @@
/* $NetBSD: open_wmemstream.c,v 1.1 2014/10/13 00:40:36 christos Exp $ */
/*-
* Copyright (c) 2013 Advanced Computing Technologies LLC
* Written by: John H. Baldwin <jhb@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>
#if 0
__FBSDID("$FreeBSD: head/lib/libc/stdio/open_wmemstream.c 247411 2013-02-27 19:50:46Z jhb $");
#endif
__RCSID("$NetBSD: open_wmemstream.c,v 1.1 2014/10/13 00:40:36 christos Exp $");
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#define OFF_MAX LLONG_MAX
struct wmemstream {
wchar_t **bufp;
size_t *sizep;
size_t len;
size_t offset;
mbstate_t mbstate;
};
static int
wmemstream_grow(struct wmemstream *ms, size_t newoff)
{
wchar_t *buf;
size_t newsize;
if (newoff >= (off_t)(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 %zu to %zu\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)
{
*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 ssize_t
wbuflen(const mbstate_t *state, const char *buf, size_t 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 ssize_t
wmemstream_write(void *cookie, const void *buf, size_t 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 = (const char *)buf + charlen;
len -= charlen;
ms->offset++;
}
}
wmemstream_update(ms);
#ifdef DEBUG
fprintf(stderr, "WMS: write(%p, %zu) = %zd\n", ms, len, consumed);
#endif
return (consumed);
}
static off_t
wmemstream_seek(void *cookie, off_t pos, int whence)
{
struct wmemstream *ms;
size_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 + (ssize_t)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 (OFF_MAX - ms->len < (size_t)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 = funopen2(ms, NULL, wmemstream_write, wmemstream_seek,
NULL, wmemstream_close);
if (fp == NULL) {
save_errno = errno;
free(ms);
free(*bufp);
*bufp = NULL;
errno = save_errno;
return (NULL);
}
fwide(fp, 1);
return (fp);
}
+9 -2
View File
@@ -1,4 +1,4 @@
.\" $NetBSD: printf.3,v 1.63 2013/05/04 19:17:38 wiz Exp $
.\" $NetBSD: printf.3,v 1.64 2014/09/29 14:58:33 christos Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -33,7 +33,7 @@
.\"
.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
.\"
.Dd May 4, 2013
.Dd September 29, 2014
.Dt PRINTF 3
.Os
.Sh NAME
@@ -799,6 +799,13 @@ family of functions may fail if:
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 ,
or the return value would be too large to be represented by an
.Vt int .
.El
.Sh SEE ALSO
.Xr printf 1 ,
+22 -1
View File
@@ -1,4 +1,4 @@
.\" $NetBSD: setbuf.3,v 1.13 2003/08/07 16:43:31 agc Exp $
.\" $NetBSD: setbuf.3,v 1.14 2015/07/15 19:08:43 christos Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -63,6 +63,27 @@ when it is block buffered many characters are saved up and written as a block;
when it is line buffered characters are saved up until a newline is
output or input is read from any stream attached to a terminal device
(typically stdin).
.Pp
The default buffer settings can be overwritten per descriptor
.Dv ( STDBUFn )
where
.Dv n
is the numeric value of the file descriptor represented by the stream, or
for all descriptors
.Dv ( STDBUF ) .
The environment variable value is a letter followed by an optional numeric
value indicating the size of the buffer.
Valid sizes range from 0B to 1MB.
Valid letters are:
.Bl -tag -width X -indent
.It Dv Li U
Unbuffered.
.It Dv Li L
Line-buffered.
.It Dv Li F
Fully-buffered.
.El
.Pp
The function
.Xr fflush 3
may be used to force the block out early.
+31 -2
View File
@@ -1,4 +1,4 @@
.\" $NetBSD: stdio.3,v 1.24 2010/05/05 04:13:16 jruoho Exp $
.\" $NetBSD: stdio.3,v 1.26 2015/09/06 04:20:50 mrg Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)stdio.3 8.7 (Berkeley) 4/19/94
.\"
.Dd May 5, 2010
.Dd September 6, 2015
.Dt STDIO 3
.Os
.Sh NAME
@@ -228,7 +228,11 @@ library conforms to
.Sh LIST OF FUNCTIONS
.Bl -column "putchar_unlocked" "Description"
.It Sy Function Description
.It asprintf formatted output conversion with allocation
.It asprintf_l formatted output conversion with allocation
.It clearerr check and reset stream status
.It dprintf formatted output conversion
.It dprintf_l formatted output conversion
.It fclose close a stream
.It fdopen stream open functions
.It feof check and reset stream status
@@ -241,8 +245,10 @@ library conforms to
.It fgetwc get next wide character from input stream
.It fileno check and reset stream status
.It flockfile lock a stream
.It fmemopen open a stream that points to a memory buffer
.It fopen stream open functions
.It fprintf formatted output conversion
.It fprintf_l formatted output conversion
.It fpurge flush a stream
.It fputc output a character or word to a stream
.It fputs output a line to a stream
@@ -251,12 +257,16 @@ library conforms to
.It freopen stream open functions
.It fropen open a stream
.It fscanf input format conversion
.It fscanf_l input format conversion
.It fseek reposition a stream
.It fseeko reposition a stream
.It fsetpos reposition a stream
.It ftell reposition a stream
.It ftello reposition a stream
.It ftrylockfile lock a stream (non-blocking)
.It funlockfile unlock a stream
.It funopen open a stream
.It funopen2 open a stream, with flush support
.It fwide set/get orientation of a stream
.It fwopen open a stream
.It fwrite binary stream input/output
@@ -274,8 +284,13 @@ library conforms to
.It getwchar get next wide character from input stream
.It mkstemp create unique temporary file
.It mktemp create unique temporary file
.It open_memstream open memory as a stream
.It popen open a program as a stream
.It popenve open a program as a stream
.It pclose close an opened program stream
.It perror system error messages
.It printf formatted output conversion
.It printf_l formatted output conversion
.It putc output a character or word to a stream
.It putc_unlocked output a character or word to a stream
.It Ta (no implicit locking)
@@ -289,13 +304,16 @@ library conforms to
.It remove remove directory entry
.It rewind reposition a stream
.It scanf input format conversion
.It scanf_l input format conversion
.It setbuf stream buffering operations
.It setbuffer stream buffering operations
.It setlinebuf stream buffering operations
.It setvbuf stream buffering operations
.It snprintf formatted output conversion
.It snprintf_l formatted output conversion
.It sprintf formatted output conversion
.It sscanf input format conversion
.It sscanf_l input format conversion
.It strerror system error messages
.It sys_errlist system error messages
.It sys_nerr system error messages
@@ -304,13 +322,24 @@ library conforms to
.It tmpnam temporary file routines
.It ungetc un-get character from input stream
.It ungetwc un-get wide character from input stream
.It vasprintf formatted output conversion with allocation
.It vasprintf_l formatted output conversion with allocation
.It vdprintf formatted output conversion
.It vdprintf_l formatted output conversion
.It vfprintf formatted output conversion
.It vfprintf_l formatted output conversion
.It vfscanf input format conversion
.It vfscanf_l input format conversion
.It vprintf formatted output conversion
.It vprintf_l formatted output conversion
.It vscanf input format conversion
.It vscanf_l input format conversion
.It vsnprintf formatted output conversion
.It vsnprintf_l formatted output conversion
.It vsprintf formatted output conversion
.It vsprintf_l formatted output conversion
.It vsscanf input format conversion
.It vsscanf_l input format conversion
.El
.Sh BUGS
The standard buffered functions do not interact well with certain other
+6 -3
View File
@@ -1,4 +1,4 @@
/* $NetBSD: vfwprintf.c,v 1.33 2013/09/23 12:41:37 pooka Exp $ */
/* $NetBSD: vfwprintf.c,v 1.34 2014/01/20 14:11:03 yamt Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.27 2007/01/09 00:28:08 imp Exp $");
#else
__RCSID("$NetBSD: vfwprintf.c,v 1.33 2013/09/23 12:41:37 pooka Exp $");
__RCSID("$NetBSD: vfwprintf.c,v 1.34 2014/01/20 14:11:03 yamt Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -712,7 +712,10 @@ WDECL(__vf,printf_unlocked_l)(FILE *fp, locale_t loc, const CHAR_T *fmt0, va_lis
#ifndef NARROW
#define PRINT(ptr, len) do { \
for (n3 = 0; n3 < (len); n3++) \
__xfputwc((ptr)[n3], fp, loc); \
if (__xfputwc((ptr)[n3], fp, loc) == END_OF_FILE) { \
fp->_flags |= __SERR; \
goto error; \
} \
} while (/*CONSTCOND*/0)
#define FLUSH()
#else
+3 -2
View File
@@ -1,4 +1,4 @@
/* $NetBSD: vfwscanf.c,v 1.11 2013/09/23 12:41:37 pooka Exp $ */
/* $NetBSD: vfwscanf.c,v 1.12 2014/06/12 22:21:20 justin Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -42,7 +42,7 @@
static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95";
__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp $");
#else
__RCSID("$NetBSD: vfwscanf.c,v 1.11 2013/09/23 12:41:37 pooka Exp $");
__RCSID("$NetBSD: vfwscanf.c,v 1.12 2014/06/12 22:21:20 justin Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -180,6 +180,7 @@ __vfwscanf_unlocked_l(FILE * __restrict fp, locale_t loc,
base = 0;
cclcompl = 0;
mbp = NULL;
p = NULL; /* XXXgcc */
for (;;) {
c = *fmt++;
if (c == 0)
+4 -4
View File
@@ -1,4 +1,4 @@
/* $NetBSD: vsnprintf.c,v 1.27 2013/05/17 12:55:57 joerg Exp $ */
/* $NetBSD: vsnprintf.c,v 1.28 2014/09/29 14:58:33 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: vsnprintf.c,v 1.27 2013/05/17 12:55:57 joerg Exp $");
__RCSID("$NetBSD: vsnprintf.c,v 1.28 2014/09/29 14:58:33 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -76,8 +76,8 @@ vsnprintf_l(char *str, size_t n, locale_t loc, const char *fmt, va_list ap)
_DIAGASSERT(n == 0 || str != NULL);
_DIAGASSERT(fmt != NULL);
if ((int)n < 0) {
errno = EINVAL;
if (n > INT_MAX) {
errno = EOVERFLOW;
return -1;
}
+4 -4
View File
@@ -1,4 +1,4 @@
/* $NetBSD: vsnprintf_ss.c,v 1.12 2012/03/15 18:22:31 christos Exp $ */
/* $NetBSD: vsnprintf_ss.c,v 1.13 2014/09/29 14:58:33 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: vsnprintf_ss.c,v 1.12 2012/03/15 18:22:31 christos Exp $");
__RCSID("$NetBSD: vsnprintf_ss.c,v 1.13 2014/09/29 14:58:33 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -144,8 +144,8 @@ vsnprintf_ss(char *sbuf, size_t slen, const char *fmt0, va_list ap)
_DIAGASSERT(slen == 0 || sbuf != NULL);
_DIAGASSERT(fmt0 != NULL);
if ((int)slen < 0) {
errno = EINVAL;
if (slen > INT_MAX) {
errno = EOVERFLOW;
return -1;
}