summaryrefslogtreecommitdiffstats
path: root/libc/upstream-openbsd
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-01-13 17:19:21 -0800
committerElliott Hughes <enh@google.com>2015-01-13 17:19:21 -0800
commit01abeacded873dd835d2115d7c9a9b0b47e75254 (patch)
treecbf005f1da99bbb023c3d28ee010fe70f4de53bd /libc/upstream-openbsd
parentd7f935a05b25d003a721565ba64a015b3a341fbe (diff)
downloadbionic-01abeacded873dd835d2115d7c9a9b0b47e75254.zip
bionic-01abeacded873dd835d2115d7c9a9b0b47e75254.tar.gz
bionic-01abeacded873dd835d2115d7c9a9b0b47e75254.tar.bz2
Sync with upstream OpenBSD stdio.
Mainly to get the __atexit_register_cleanup removals we suggested. Change-Id: I58d40b8c5b8401bfb6bfffe8f3430ac0718af917
Diffstat (limited to 'libc/upstream-openbsd')
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/fgetln.c16
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/getdelim.c7
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/makebuf.c3
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/mktemp.c4
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/open_wmemstream.c4
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/setvbuf.c13
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/ungetc.c6
7 files changed, 23 insertions, 30 deletions
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetln.c b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c
index d0c0809..1109cf2 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/fgetln.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c
@@ -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);
}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getdelim.c b/libc/upstream-openbsd/lib/libc/stdio/getdelim.c
index dcde0c3..5e583cb 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/getdelim.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/getdelim.c
@@ -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;
diff --git a/libc/upstream-openbsd/lib/libc/stdio/makebuf.c b/libc/upstream-openbsd/lib/libc/stdio/makebuf.c
index d47e27c..56e5f21 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/makebuf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/makebuf.c
@@ -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;
diff --git a/libc/upstream-openbsd/lib/libc/stdio/mktemp.c b/libc/upstream-openbsd/lib/libc/stdio/mktemp.c
index 2a17e52..956608c 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/mktemp.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/mktemp.c
@@ -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;
diff --git a/libc/upstream-openbsd/lib/libc/stdio/open_wmemstream.c b/libc/upstream-openbsd/lib/libc/stdio/open_wmemstream.c
index 9414187..391a944 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/open_wmemstream.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/open_wmemstream.c
@@ -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));
diff --git a/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c b/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c
index 6c49f7a..9b2ab57 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c
@@ -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.
@@ -115,6 +115,13 @@ nbf:
}
/*
+ * 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);
}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/ungetc.c b/libc/upstream-openbsd/lib/libc/stdio/ungetc.c
index 675733a..ec98f26 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/ungetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/ungetc.c
@@ -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);
}