summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-03-11 15:05:50 -0700
committerElliott Hughes <enh@google.com>2014-03-11 15:05:50 -0700
commitad41e9a4eb957ea318bbc93dd49dbe76b89df1e9 (patch)
tree8d95daa4b9d104c3b77467ae7eac651430cbe4f2
parent55f9710ac4843b4a5d2c8b03ade3d2bddd1fdf46 (diff)
downloadbionic-ad41e9a4eb957ea318bbc93dd49dbe76b89df1e9.zip
bionic-ad41e9a4eb957ea318bbc93dd49dbe76b89df1e9.tar.gz
bionic-ad41e9a4eb957ea318bbc93dd49dbe76b89df1e9.tar.bz2
More stdio cleanup.
Change-Id: Idc909cd3dc7b072f1edd2ae4980932d6550e8568
-rw-r--r--libc/Android.mk112
-rw-r--r--libc/upstream-netbsd/netbsd-compat.h1
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/asprintf.c (renamed from libc/stdio/asprintf.c)10
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/fprintf.c (renamed from libc/stdio/fprintf.c)3
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/freopen.c (renamed from libc/stdio/freopen.c)17
-rw-r--r--libc/upstream-openbsd/openbsd-compat.h1
6 files changed, 80 insertions, 64 deletions
diff --git a/libc/Android.mk b/libc/Android.mk
index eb9433f..472241f 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -77,11 +77,8 @@ libc_common_src_files := \
bionic/tcsetpgrp.c \
bionic/time64.c \
bionic/unlockpt.c \
- stdio/asprintf.c \
stdio/findfp.c \
- stdio/fprintf.c \
stdio/fread.c \
- stdio/freopen.c \
stdio/fvwrite.c \
stdio/snprintf.c\
stdio/sprintf.c \
@@ -323,74 +320,77 @@ libc_upstream_openbsd_src_files := \
upstream-openbsd/lib/libc/gen/tolower_.c \
upstream-openbsd/lib/libc/gen/toupper_.c \
upstream-openbsd/lib/libc/locale/wcscoll.c \
- upstream-openbsd/lib/libc/string/strstr.c \
- upstream-openbsd/lib/libc/string/strsep.c \
- upstream-openbsd/lib/libc/string/wcslcpy.c \
- upstream-openbsd/lib/libc/string/strcasecmp.c \
- upstream-openbsd/lib/libc/string/strdup.c \
- upstream-openbsd/lib/libc/string/strcspn.c \
- upstream-openbsd/lib/libc/string/strtok.c \
- upstream-openbsd/lib/libc/string/strpbrk.c \
- upstream-openbsd/lib/libc/string/strspn.c \
- upstream-openbsd/lib/libc/string/wcswidth.c \
- upstream-openbsd/lib/libc/string/strndup.c \
- upstream-openbsd/lib/libc/stdio/ungetc.c \
- upstream-openbsd/lib/libc/stdio/vsnprintf.c \
- upstream-openbsd/lib/libc/stdio/tmpnam.c \
- upstream-openbsd/lib/libc/stdio/setbuffer.c \
- upstream-openbsd/lib/libc/stdio/fsetpos.c \
- upstream-openbsd/lib/libc/stdio/setbuf.c \
- upstream-openbsd/lib/libc/stdio/vprintf.c \
- upstream-openbsd/lib/libc/stdio/perror.c \
- upstream-openbsd/lib/libc/stdio/remove.c \
- upstream-openbsd/lib/libc/stdio/getc.c \
- upstream-openbsd/lib/libc/stdio/funopen.c \
+ upstream-openbsd/lib/libc/locale/wcsxfrm.c \
+ upstream-openbsd/lib/libc/stdio/asprintf.c \
+ upstream-openbsd/lib/libc/stdio/clrerr.c \
+ upstream-openbsd/lib/libc/stdio/fdopen.c \
+ upstream-openbsd/lib/libc/stdio/feof.c \
upstream-openbsd/lib/libc/stdio/ferror.c \
- upstream-openbsd/lib/libc/stdio/putchar.c \
- upstream-openbsd/lib/libc/stdio/vscanf.c \
upstream-openbsd/lib/libc/stdio/fflush.c \
+ upstream-openbsd/lib/libc/stdio/fgetc.c \
+ upstream-openbsd/lib/libc/stdio/fgetln.c \
+ upstream-openbsd/lib/libc/stdio/fgetpos.c \
+ upstream-openbsd/lib/libc/stdio/fgets.c \
+ upstream-openbsd/lib/libc/stdio/fileno.c \
+ upstream-openbsd/lib/libc/stdio/fprintf.c \
upstream-openbsd/lib/libc/stdio/fpurge.c \
+ upstream-openbsd/lib/libc/stdio/fputc.c \
upstream-openbsd/lib/libc/stdio/fputs.c \
- upstream-openbsd/lib/libc/stdio/tempnam.c \
- upstream-openbsd/lib/libc/stdio/printf.c \
- upstream-openbsd/lib/libc/stdio/fileno.c \
- upstream-openbsd/lib/libc/stdio/stdio.c \
- upstream-openbsd/lib/libc/stdio/getdelim.c \
+ upstream-openbsd/lib/libc/stdio/freopen.c \
+ upstream-openbsd/lib/libc/stdio/fscanf.c \
upstream-openbsd/lib/libc/stdio/fseek.c \
- upstream-openbsd/lib/libc/stdio/fputc.c \
- upstream-openbsd/lib/libc/stdio/fgetln.c \
- upstream-openbsd/lib/libc/stdio/fdopen.c \
- upstream-openbsd/lib/libc/stdio/fgets.c \
- upstream-openbsd/lib/libc/stdio/fgetc.c \
- upstream-openbsd/lib/libc/stdio/feof.c \
- upstream-openbsd/lib/libc/stdio/vasprintf.c \
- upstream-openbsd/lib/libc/stdio/refill.c \
+ upstream-openbsd/lib/libc/stdio/fsetpos.c \
+ upstream-openbsd/lib/libc/stdio/ftell.c \
+ upstream-openbsd/lib/libc/stdio/funopen.c \
+ upstream-openbsd/lib/libc/stdio/fwalk.c \
+ upstream-openbsd/lib/libc/stdio/getc.c \
+ upstream-openbsd/lib/libc/stdio/getchar.c \
+ upstream-openbsd/lib/libc/stdio/getdelim.c \
upstream-openbsd/lib/libc/stdio/getline.c \
- upstream-openbsd/lib/libc/stdio/rewind.c \
- upstream-openbsd/lib/libc/stdio/wbuf.c \
upstream-openbsd/lib/libc/stdio/gets.c \
- upstream-openbsd/lib/libc/stdio/fgetpos.c \
- upstream-openbsd/lib/libc/stdio/fscanf.c \
+ upstream-openbsd/lib/libc/stdio/perror.c \
+ upstream-openbsd/lib/libc/stdio/printf.c \
upstream-openbsd/lib/libc/stdio/putc.c \
- upstream-openbsd/lib/libc/stdio/vsprintf.c \
+ upstream-openbsd/lib/libc/stdio/putchar.c \
+ upstream-openbsd/lib/libc/stdio/puts.c \
+ upstream-openbsd/lib/libc/stdio/refill.c \
+ upstream-openbsd/lib/libc/stdio/remove.c \
+ upstream-openbsd/lib/libc/stdio/rewind.c \
upstream-openbsd/lib/libc/stdio/rget.c \
- upstream-openbsd/lib/libc/stdio/clrerr.c \
upstream-openbsd/lib/libc/stdio/scanf.c \
- upstream-openbsd/lib/libc/stdio/puts.c \
- upstream-openbsd/lib/libc/stdio/getchar.c \
- upstream-openbsd/lib/libc/stdio/ftell.c \
- upstream-openbsd/lib/libc/stdio/fwalk.c \
- upstream-openbsd/lib/libc/stdlib/strtoul.c \
- upstream-openbsd/lib/libc/stdlib/strtoull.c \
+ upstream-openbsd/lib/libc/stdio/setbuf.c \
+ upstream-openbsd/lib/libc/stdio/setbuffer.c \
+ upstream-openbsd/lib/libc/stdio/stdio.c \
+ upstream-openbsd/lib/libc/stdio/tempnam.c \
+ upstream-openbsd/lib/libc/stdio/tmpnam.c \
+ upstream-openbsd/lib/libc/stdio/ungetc.c \
+ upstream-openbsd/lib/libc/stdio/vasprintf.c \
+ upstream-openbsd/lib/libc/stdio/vprintf.c \
+ upstream-openbsd/lib/libc/stdio/vscanf.c \
+ upstream-openbsd/lib/libc/stdio/vsnprintf.c \
+ upstream-openbsd/lib/libc/stdio/vsprintf.c \
+ upstream-openbsd/lib/libc/stdio/wbuf.c \
upstream-openbsd/lib/libc/stdlib/atoi.c \
- upstream-openbsd/lib/libc/stdlib/atoll.c \
upstream-openbsd/lib/libc/stdlib/atol.c \
+ upstream-openbsd/lib/libc/stdlib/atoll.c \
upstream-openbsd/lib/libc/stdlib/strtoimax.c \
- upstream-openbsd/lib/libc/stdlib/strtoumax.c \
- upstream-openbsd/lib/libc/stdlib/strtoll.c \
upstream-openbsd/lib/libc/stdlib/strtol.c \
+ upstream-openbsd/lib/libc/stdlib/strtoll.c \
+ upstream-openbsd/lib/libc/stdlib/strtoul.c \
+ upstream-openbsd/lib/libc/stdlib/strtoull.c \
+ upstream-openbsd/lib/libc/stdlib/strtoumax.c \
upstream-openbsd/lib/libc/stdlib/system.c \
- upstream-openbsd/lib/libc/locale/wcsxfrm.c \
+ upstream-openbsd/lib/libc/string/strcasecmp.c \
+ upstream-openbsd/lib/libc/string/strcspn.c \
+ upstream-openbsd/lib/libc/string/strdup.c \
+ upstream-openbsd/lib/libc/string/strndup.c \
+ upstream-openbsd/lib/libc/string/strpbrk.c \
+ upstream-openbsd/lib/libc/string/strsep.c \
+ upstream-openbsd/lib/libc/string/strspn.c \
+ upstream-openbsd/lib/libc/string/strstr.c \
+ upstream-openbsd/lib/libc/string/strtok.c \
+ upstream-openbsd/lib/libc/string/wcslcpy.c \
+ upstream-openbsd/lib/libc/string/wcswidth.c \
libc_arch_static_src_files := \
bionic/dl_iterate_phdr_static.cpp \
diff --git a/libc/upstream-netbsd/netbsd-compat.h b/libc/upstream-netbsd/netbsd-compat.h
index f830f38..84be931 100644
--- a/libc/upstream-netbsd/netbsd-compat.h
+++ b/libc/upstream-netbsd/netbsd-compat.h
@@ -25,6 +25,7 @@
#define __type_fit(t, a) (0 == 0)
#define _GNU_SOURCE
+#define __USE_BSD
// TODO: we don't yet have thread-safe environment variables.
#define __readlockenv() 0
diff --git a/libc/stdio/asprintf.c b/libc/upstream-openbsd/lib/libc/stdio/asprintf.c
index c3d8d61..5424c90 100644
--- a/libc/stdio/asprintf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/asprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asprintf.c,v 1.15 2005/10/10 12:00:52 espie Exp $ */
+/* $OpenBSD: asprintf.c,v 1.19 2011/05/30 18:48:33 martynas Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -23,14 +23,17 @@
#include <stdarg.h>
#include "local.h"
+/* PRINTFLIKE2 */
int
asprintf(char **str, const char *fmt, ...)
{
int ret;
va_list ap;
FILE f;
+ struct __sfileext fext;
unsigned char *_base;
+ _FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR | __SALC;
f._bf._base = f._p = (unsigned char *)malloc(128);
@@ -50,7 +53,10 @@ asprintf(char **str, const char *fmt, ...)
return (ret);
err:
- free(f._bf._base);
+ if (f._bf._base) {
+ free(f._bf._base);
+ f._bf._base = NULL;
+ }
*str = NULL;
errno = ENOMEM;
return (-1);
diff --git a/libc/stdio/fprintf.c b/libc/upstream-openbsd/lib/libc/stdio/fprintf.c
index 7415b2f..a391142 100644
--- a/libc/stdio/fprintf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fprintf.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
+/* $OpenBSD: fprintf.c,v 1.7 2011/05/30 18:48:33 martynas Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -34,6 +34,7 @@
#include <stdio.h>
#include <stdarg.h>
+/* PRINTFLIKE2 */
int
fprintf(FILE *fp, const char *fmt, ...)
{
diff --git a/libc/stdio/freopen.c b/libc/upstream-openbsd/lib/libc/stdio/freopen.c
index f0386e9..3158fb1 100644
--- a/libc/stdio/freopen.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/freopen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: freopen.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
+/* $OpenBSD: freopen.c,v 1.13 2009/11/09 00:18:27 kurt Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,19 +31,18 @@
* SUCH DAMAGE.
*/
-#define __USE_BSD
-
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
+#include <limits.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
-/*
- * Re-direct an existing, open (probably) file to some other file.
+/*
+ * Re-direct an existing, open (probably) file to some other file.
* ANSI is written such that the original file gets closed if at
* all possible, no matter what.
*/
@@ -141,6 +140,14 @@ freopen(const char *file, const char *mode, FILE *fp)
}
}
+ /* _file is only a short */
+ if (f > SHRT_MAX) {
+ fp->_flags = 0; /* set it free */
+ FUNLOCKFILE(fp);
+ errno = EMFILE;
+ return (NULL);
+ }
+
fp->_flags = flags;
fp->_file = f;
fp->_cookie = fp;
diff --git a/libc/upstream-openbsd/openbsd-compat.h b/libc/upstream-openbsd/openbsd-compat.h
index 428156f..2c3fe56 100644
--- a/libc/upstream-openbsd/openbsd-compat.h
+++ b/libc/upstream-openbsd/openbsd-compat.h
@@ -18,5 +18,6 @@
#define _BIONIC_OPENBSD_COMPAT_H_included
#define _GNU_SOURCE
+#define __USE_BSD
#endif