From 677ee5647721df22f13909375d5d0e770a1a80bf Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 12 Jun 2013 15:24:15 -0700 Subject: [PATCH] Switch to current upstream stdio makebuf.c and setvbuf.c. Change-Id: I4761b5e94459815520f01062eef39abf62af621f --- libc/Android.mk | 4 ++-- libc/upstream-freebsd/freebsd-compat.h | 1 + .../lib/libc}/stdio/makebuf.c | 20 ++++++++++++---- .../lib/libc}/stdio/setvbuf.c | 23 +++++++++++++------ 4 files changed, 34 insertions(+), 14 deletions(-) rename libc/{ => upstream-freebsd/lib/libc}/stdio/makebuf.c (86%) rename libc/{ => upstream-freebsd/lib/libc}/stdio/setvbuf.c (88%) diff --git a/libc/Android.mk b/libc/Android.mk index 49d93af4b..04741be89 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -26,13 +26,11 @@ libc_common_src_files := \ stdio/ftell.c \ stdio/fvwrite.c \ stdio/gets.c \ - stdio/makebuf.c \ stdio/mktemp.c \ stdio/printf.c \ stdio/refill.c \ stdio/rewind.c \ stdio/scanf.c \ - stdio/setvbuf.c \ stdio/snprintf.c\ stdio/sprintf.c \ stdio/sscanf.c \ @@ -268,6 +266,7 @@ libc_upstream_freebsd_src_files := \ upstream-freebsd/lib/libc/stdio/fwrite.c \ upstream-freebsd/lib/libc/stdio/getc.c \ upstream-freebsd/lib/libc/stdio/getchar.c \ + upstream-freebsd/lib/libc/stdio/makebuf.c \ upstream-freebsd/lib/libc/stdio/putc.c \ upstream-freebsd/lib/libc/stdio/putchar.c \ upstream-freebsd/lib/libc/stdio/puts.c \ @@ -276,6 +275,7 @@ libc_upstream_freebsd_src_files := \ upstream-freebsd/lib/libc/stdio/rget.c \ upstream-freebsd/lib/libc/stdio/setbuf.c \ upstream-freebsd/lib/libc/stdio/setbuffer.c \ + upstream-freebsd/lib/libc/stdio/setvbuf.c \ upstream-freebsd/lib/libc/stdio/tempnam.c \ upstream-freebsd/lib/libc/stdio/tmpnam.c \ upstream-freebsd/lib/libc/stdio/wsetup.c \ diff --git a/libc/upstream-freebsd/freebsd-compat.h b/libc/upstream-freebsd/freebsd-compat.h index 697ddcbcf..5298663b9 100644 --- a/libc/upstream-freebsd/freebsd-compat.h +++ b/libc/upstream-freebsd/freebsd-compat.h @@ -21,6 +21,7 @@ #define _close close #define _fcntl fcntl +#define _fstat fstat #define _open open #define _sseek __sseek /* Needed as long as we have a mix of OpenBSD and FreeBSD stdio. */ diff --git a/libc/stdio/makebuf.c b/libc/upstream-freebsd/lib/libc/stdio/makebuf.c similarity index 86% rename from libc/stdio/makebuf.c rename to libc/upstream-freebsd/lib/libc/stdio/makebuf.c index 362cf0577..a92087e0e 100644 --- a/libc/stdio/makebuf.c +++ b/libc/upstream-freebsd/lib/libc/stdio/makebuf.c @@ -1,4 +1,3 @@ -/* $OpenBSD: makebuf.c,v 1.8 2005/12/28 18:50:22 millert Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -31,11 +30,21 @@ * SUCH DAMAGE. */ +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)makebuf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD$"); + +#include "namespace.h" #include #include #include #include #include +#include "un-namespace.h" + +#include "libc_private.h" #include "local.h" /* @@ -43,7 +52,7 @@ * Per the ANSI C standard, ALL tty devices default to line buffered. * * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek - * optimisation) right after the fstat() that finds the buffer size. + * optimisation) right after the _fstat() that finds the buffer size. */ void __smakebuf(FILE *fp) @@ -65,6 +74,7 @@ __smakebuf(FILE *fp) fp->_bf._size = 1; return; } + __cleanup = _cleanup; flags |= __SMBF; fp->_bf._base = fp->_p = p; fp->_bf._size = size; @@ -81,15 +91,15 @@ __swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty) { struct stat st; - if (fp->_file < 0 || fstat(fp->_file, &st) < 0) { + if (fp->_file < 0 || _fstat(fp->_file, &st) < 0) { *couldbetty = 0; *bufsize = BUFSIZ; return (__SNPT); } /* could be a tty iff it is a character device */ - *couldbetty = S_ISCHR(st.st_mode); - if (st.st_blksize == 0) { + *couldbetty = (st.st_mode & S_IFMT) == S_IFCHR; + if (st.st_blksize <= 0) { *bufsize = BUFSIZ; return (__SNPT); } diff --git a/libc/stdio/setvbuf.c b/libc/upstream-freebsd/lib/libc/stdio/setvbuf.c similarity index 88% rename from libc/stdio/setvbuf.c rename to libc/upstream-freebsd/lib/libc/stdio/setvbuf.c index eb0ec683b..d39696058 100644 --- a/libc/stdio/setvbuf.c +++ b/libc/upstream-freebsd/lib/libc/stdio/setvbuf.c @@ -1,4 +1,3 @@ -/* $OpenBSD: setvbuf.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -31,16 +30,25 @@ * SUCH DAMAGE. */ +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)setvbuf.c 8.2 (Berkeley) 11/16/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD$"); + +#include "namespace.h" #include #include +#include "un-namespace.h" #include "local.h" +#include "libc_private.h" /* * Set one of the three kinds of buffering, optionally including * a buffer. */ int -setvbuf(FILE *fp, char *buf, int mode, size_t size) +setvbuf(FILE * __restrict fp, char * __restrict buf, int mode, size_t size) { int ret, flags; size_t iosize; @@ -55,23 +63,22 @@ setvbuf(FILE *fp, char *buf, int mode, size_t size) if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0) return (EOF); + FLOCKFILE(fp); /* * Write current buffer, if any. Discard unread input (including * ungetc data), cancel line buffering, and free old buffer if * malloc()ed. We also clear any eof condition, as if this were * a seek. */ - FLOCKFILE(fp); ret = 0; (void)__sflush(fp); if (HASUB(fp)) FREEUB(fp); - WCIO_FREE(fp); fp->_r = fp->_lbfsize = 0; flags = fp->_flags; if (flags & __SMBF) free((void *)fp->_bf._base); - flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SNPT | __SEOF); + flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SOFF | __SNPT | __SEOF); /* If setting unbuffered mode, skip all the hard work. */ if (mode == _IONBF) @@ -124,7 +131,8 @@ nbf: flags |= __SNPT; /* - * Fix up the FILE fields. + * Fix up the FILE fields, and set __cleanup for output flush on + * exit (since we are buffered in some way). */ if (mode == _IOLBF) flags |= __SLBF; @@ -146,7 +154,8 @@ nbf: /* begin/continue reading, or stay in intermediate state */ fp->_w = 0; } - FUNLOCKFILE(fp); + __cleanup = _cleanup; + FUNLOCKFILE(fp); return (ret); }