am d986f2e4
: Merge "Sync with upstream OpenBSD stdio."
* commit 'd986f2e4642a0571754cb1349101acf8ac10b484': Sync with upstream OpenBSD stdio.
This commit is contained in:
commit
5bff8a2337
7 changed files with 23 additions and 30 deletions
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: fgetln.c,v 1.12 2013/11/12 07:04:06 deraadt Exp $ */
|
||||
/* $OpenBSD: fgetln.c,v 1.13 2015/01/05 21:58:52 millert Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
@ -38,19 +38,12 @@
|
|||
|
||||
/*
|
||||
* Expand the line buffer. Return -1 on error.
|
||||
#ifdef notdef
|
||||
* The `new size' does not account for a terminating '\0',
|
||||
* so we add 1 here.
|
||||
#endif
|
||||
*/
|
||||
static int
|
||||
__slbexpand(FILE *fp, size_t newsize)
|
||||
{
|
||||
void *p;
|
||||
|
||||
#ifdef notdef
|
||||
++newsize;
|
||||
#endif
|
||||
if (fp->_lb._size >= newsize)
|
||||
return (0);
|
||||
if ((p = realloc(fp->_lb._base, newsize)) == NULL)
|
||||
|
@ -141,14 +134,11 @@ fgetln(FILE *fp, size_t *lenp)
|
|||
}
|
||||
*lenp = len;
|
||||
ret = (char *)fp->_lb._base;
|
||||
#ifdef notdef
|
||||
ret[len] = '\0';
|
||||
#endif
|
||||
FUNLOCKFILE(fp);
|
||||
return (ret);
|
||||
|
||||
error:
|
||||
*lenp = 0; /* ??? */
|
||||
FUNLOCKFILE(fp);
|
||||
return (NULL); /* ??? */
|
||||
*lenp = 0;
|
||||
return (NULL);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: getdelim.c,v 1.1 2012/03/21 23:44:35 fgsch Exp $ */
|
||||
/* $OpenBSD: getdelim.c,v 1.2 2014/10/16 17:31:51 millert Exp $ */
|
||||
/* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -78,13 +78,12 @@ getdelim(char **__restrict buf, size_t *__restrict buflen,
|
|||
else
|
||||
len = (p - fp->_p) + 1;
|
||||
|
||||
newlen = off + len;
|
||||
/* Ensure we can handle it */
|
||||
if (newlen < off || newlen > SSIZE_MAX) {
|
||||
if (off > SSIZE_MAX || len + 1 > SSIZE_MAX - off) {
|
||||
errno = EOVERFLOW;
|
||||
goto error;
|
||||
}
|
||||
newlen++; /* reserve space for the NULL terminator */
|
||||
newlen = off + len + 1; /* reserve space for NUL terminator */
|
||||
if (newlen > *buflen) {
|
||||
if (newlen < MINBUF)
|
||||
newlen = MINBUF;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: makebuf.c,v 1.8 2005/12/28 18:50:22 millert Exp $ */
|
||||
/* $OpenBSD: makebuf.c,v 1.9 2015/01/13 07:18:21 guenther Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
@ -65,7 +65,6 @@ __smakebuf(FILE *fp)
|
|||
fp->_bf._size = 1;
|
||||
return;
|
||||
}
|
||||
__atexit_register_cleanup(_cleanup);
|
||||
flags |= __SMBF;
|
||||
fp->_bf._base = fp->_p = p;
|
||||
fp->_bf._size = size;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: mktemp.c,v 1.34 2014/08/31 02:21:18 guenther Exp $ */
|
||||
/* $OpenBSD: mktemp.c,v 1.35 2014/10/31 15:54:14 millert Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1996-1998, 2008 Theo de Raadt
|
||||
* Copyright (c) 1997, 2008-2009 Todd C. Miller
|
||||
|
@ -45,7 +45,7 @@ static int
|
|||
mktemp_internal(char *path, int slen, int mode, int flags)
|
||||
{
|
||||
char *start, *cp, *ep;
|
||||
const char *tempchars = TEMPCHARS;
|
||||
const char tempchars[] = TEMPCHARS;
|
||||
unsigned int tries;
|
||||
struct stat sb;
|
||||
size_t len;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: open_wmemstream.c,v 1.3 2014/03/06 07:28:21 gerhard Exp $ */
|
||||
/* $OpenBSD: open_wmemstream.c,v 1.4 2014/10/08 05:28:19 deraadt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org>
|
||||
|
@ -52,7 +52,7 @@ wmemstream_write(void *v, const char *b, int l)
|
|||
|
||||
if (sz < end + 1)
|
||||
sz = end + 1;
|
||||
p = realloc(st->string, sz * sizeof(wchar_t));
|
||||
p = reallocarray(st->string, sz, sizeof(wchar_t));
|
||||
if (!p)
|
||||
return (-1);
|
||||
bzero(p + st->size, (sz - st->size) * sizeof(wchar_t));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: setvbuf.c,v 1.11 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/* $OpenBSD: setvbuf.c,v 1.12 2015/01/13 07:18:21 guenther Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
@ -114,6 +114,13 @@ nbf:
|
|||
flags |= __SMBF;
|
||||
}
|
||||
|
||||
/*
|
||||
* We're committed to buffering from here, so make sure we've
|
||||
* registered to flush buffers on exit.
|
||||
*/
|
||||
if (!__sdidinit)
|
||||
__sinit();
|
||||
|
||||
/*
|
||||
* Kill any seek optimization if the buffer is not the
|
||||
* right size.
|
||||
|
@ -124,8 +131,7 @@ nbf:
|
|||
flags |= __SNPT;
|
||||
|
||||
/*
|
||||
* Fix up the FILE fields, and set __cleanup for output flush on
|
||||
* exit (since we are buffered in some way).
|
||||
* Fix up the FILE fields.
|
||||
*/
|
||||
if (mode == _IOLBF)
|
||||
flags |= __SLBF;
|
||||
|
@ -148,7 +154,6 @@ nbf:
|
|||
fp->_w = 0;
|
||||
}
|
||||
FUNLOCKFILE(fp);
|
||||
__atexit_register_cleanup(_cleanup);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: ungetc.c,v 1.12 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/* $OpenBSD: ungetc.c,v 1.13 2014/10/11 04:05:10 deraadt Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
@ -64,14 +64,14 @@ __submore(FILE *fp)
|
|||
return (0);
|
||||
}
|
||||
i = _UB(fp)._size;
|
||||
p = realloc(_UB(fp)._base, i << 1);
|
||||
p = reallocarray(_UB(fp)._base, i, 2);
|
||||
if (p == NULL)
|
||||
return (EOF);
|
||||
/* no overlap (hence can use memcpy) because we doubled the size */
|
||||
(void)memcpy((void *)(p + i), (void *)p, (size_t)i);
|
||||
fp->_p = p + i;
|
||||
_UB(fp)._base = p;
|
||||
_UB(fp)._size = i << 1;
|
||||
_UB(fp)._size = i * 2;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue