Merge "More stdio cleanup."

This commit is contained in:
Elliott Hughes 2014-03-11 22:31:00 +00:00 committed by Gerrit Code Review
commit 76b4f1a33c
6 changed files with 88 additions and 72 deletions

View 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/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/fpurge.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/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/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/putc.c \
upstream-openbsd/lib/libc/stdio/vsprintf.c \
upstream-openbsd/lib/libc/stdio/rget.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/scanf.c \
upstream-openbsd/lib/libc/stdio/puts.c \
upstream-openbsd/lib/libc/stdio/getchar.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/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/freopen.c \
upstream-openbsd/lib/libc/stdio/fscanf.c \
upstream-openbsd/lib/libc/stdio/fseek.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/gets.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/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/scanf.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/atol.c \
upstream-openbsd/lib/libc/stdlib/atoll.c \
upstream-openbsd/lib/libc/stdlib/strtoimax.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/atoi.c \
upstream-openbsd/lib/libc/stdlib/atoll.c \
upstream-openbsd/lib/libc/stdlib/atol.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/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 \

View 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

View 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>
@ -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);

View 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, ...)
{

View 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.
@ -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;

View File

@ -18,5 +18,6 @@
#define _BIONIC_OPENBSD_COMPAT_H_included
#define _GNU_SOURCE
#define __USE_BSD
#endif