OSDN Git Service

More stdio cleanup.
authorElliott Hughes <enh@google.com>
Tue, 11 Mar 2014 22:05:50 +0000 (15:05 -0700)
committerElliott Hughes <enh@google.com>
Tue, 11 Mar 2014 22:05:50 +0000 (15:05 -0700)
Change-Id: Idc909cd3dc7b072f1edd2ae4980932d6550e8568

libc/Android.mk
libc/upstream-netbsd/netbsd-compat.h
libc/upstream-openbsd/lib/libc/stdio/asprintf.c [moved from libc/stdio/asprintf.c with 87% similarity]
libc/upstream-openbsd/lib/libc/stdio/fprintf.c [moved from libc/stdio/fprintf.c with 95% similarity]
libc/upstream-openbsd/lib/libc/stdio/freopen.c [moved from libc/stdio/freopen.c with 95% similarity]
libc/upstream-openbsd/openbsd-compat.h

index eb9433f..472241f 100644 (file)
@@ -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 \
index f830f38..84be931 100644 (file)
@@ -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
similarity index 87%
rename from libc/stdio/asprintf.c
rename to libc/upstream-openbsd/lib/libc/stdio/asprintf.c
index c3d8d61..5424c90 100644 (file)
@@ -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>
 #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);
similarity index 95%
rename from libc/stdio/fprintf.c
rename to libc/upstream-openbsd/lib/libc/stdio/fprintf.c
index 7415b2f..a391142 100644 (file)
@@ -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, ...)
 {
similarity index 95%
rename from libc/stdio/freopen.c
rename to libc/upstream-openbsd/lib/libc/stdio/freopen.c
index f0386e9..3158fb1 100644 (file)
@@ -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.
  * 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;
index 428156f..2c3fe56 100644 (file)
@@ -18,5 +18,6 @@
 #define _BIONIC_OPENBSD_COMPAT_H_included
 
 #define _GNU_SOURCE
+#define __USE_BSD
 
 #endif