Switch to OpenBSD fopen/fclose.
This means all our stdio implementation is now the OpenBSD implementation. The only thing we lose is the STDIO_THREAD_LOCK calls but they were no-ops anyway. We should probably talk to upstream about this. Either fix the locking or, preferably, encourage them to move away from this pooling (especially since there's no eviction policy). Bug: 17154680 Change-Id: Ie2523e444a7d0965b8d141d57e3e11f6432d5b9a
This commit is contained in:
parent
f05410edc6
commit
5a69da8d7a
|
@ -242,8 +242,6 @@ libc_upstream_freebsd_src_files := \
|
|||
upstream-freebsd/lib/libc/gen/ldexp.c \
|
||||
upstream-freebsd/lib/libc/gen/sleep.c \
|
||||
upstream-freebsd/lib/libc/gen/usleep.c \
|
||||
upstream-freebsd/lib/libc/stdio/fclose.c \
|
||||
upstream-freebsd/lib/libc/stdio/fopen.c \
|
||||
upstream-freebsd/lib/libc/stdlib/abs.c \
|
||||
upstream-freebsd/lib/libc/stdlib/getopt_long.c \
|
||||
upstream-freebsd/lib/libc/stdlib/imaxabs.c \
|
||||
|
@ -388,6 +386,7 @@ libc_upstream_openbsd_src_files := \
|
|||
upstream-openbsd/lib/libc/stdio/asprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/clrerr.c \
|
||||
upstream-openbsd/lib/libc/stdio/dprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/fclose.c \
|
||||
upstream-openbsd/lib/libc/stdio/fdopen.c \
|
||||
upstream-openbsd/lib/libc/stdio/feof.c \
|
||||
upstream-openbsd/lib/libc/stdio/ferror.c \
|
||||
|
@ -402,6 +401,7 @@ libc_upstream_openbsd_src_files := \
|
|||
upstream-openbsd/lib/libc/stdio/findfp.c \
|
||||
upstream-openbsd/lib/libc/stdio/flags.c \
|
||||
upstream-openbsd/lib/libc/stdio/fmemopen.c \
|
||||
upstream-openbsd/lib/libc/stdio/fopen.c \
|
||||
upstream-openbsd/lib/libc/stdio/fprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/fpurge.c \
|
||||
upstream-openbsd/lib/libc/stdio/fputc.c \
|
||||
|
|
|
@ -38,17 +38,6 @@
|
|||
#define __usleep usleep
|
||||
|
||||
/* Redirect internal C library calls to the public function. */
|
||||
#define _close close
|
||||
#define _fcntl fcntl
|
||||
#define _fstat fstat
|
||||
#define _nanosleep nanosleep
|
||||
#define _open open
|
||||
|
||||
/* This one is only needed as long as we have a mix of OpenBSD and FreeBSD stdio. */
|
||||
#define _sseek __sseek
|
||||
|
||||
/* This is in BSD's <stdlib.h>. */
|
||||
#include <stdint.h>
|
||||
extern uint32_t arc4random_uniform(uint32_t upper_bound);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* $OpenBSD: fclose.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
@ -30,19 +31,9 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "un-namespace.h"
|
||||
#include <spinlock.h>
|
||||
#include "libc_private.h"
|
||||
#include "local.h"
|
||||
|
||||
int
|
||||
|
@ -55,6 +46,7 @@ fclose(FILE *fp)
|
|||
return (EOF);
|
||||
}
|
||||
FLOCKFILE(fp);
|
||||
WCIO_FREE(fp);
|
||||
r = fp->_flags & __SWR ? __sflush(fp) : 0;
|
||||
if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0)
|
||||
r = EOF;
|
||||
|
@ -64,22 +56,8 @@ fclose(FILE *fp)
|
|||
FREEUB(fp);
|
||||
if (HASLB(fp))
|
||||
FREELB(fp);
|
||||
fp->_file = -1;
|
||||
fp->_r = fp->_w = 0; /* Mess up if reaccessed. */
|
||||
|
||||
/*
|
||||
* Lock the spinlock used to protect __sglue list walk in
|
||||
* __sfp(). The __sfp() uses fp->_flags == 0 test as an
|
||||
* indication of the unused FILE.
|
||||
*
|
||||
* Taking the lock prevents possible compiler or processor
|
||||
* reordering of the writes performed before the final _flags
|
||||
* cleanup, making sure that we are done with the FILE before
|
||||
* it is considered available.
|
||||
*/
|
||||
STDIO_THREAD_LOCK();
|
||||
fp->_flags = 0; /* Release this FILE for reuse. */
|
||||
STDIO_THREAD_UNLOCK();
|
||||
FUNLOCKFILE(fp);
|
||||
return (r);
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
/* $OpenBSD: fopen.c,v 1.7 2008/05/03 18:46:41 chl Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
@ -30,26 +31,17 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include "local.h"
|
||||
|
||||
FILE *
|
||||
fopen(const char * __restrict file, const char * __restrict mode)
|
||||
fopen(const char *file, const char *mode)
|
||||
{
|
||||
FILE *fp;
|
||||
int f;
|
||||
|
@ -59,23 +51,19 @@ fopen(const char * __restrict file, const char * __restrict mode)
|
|||
return (NULL);
|
||||
if ((fp = __sfp()) == NULL)
|
||||
return (NULL);
|
||||
if ((f = _open(file, oflags, DEFFILEMODE)) < 0) {
|
||||
if ((f = open(file, oflags, DEFFILEMODE)) < 0) {
|
||||
fp->_flags = 0; /* release */
|
||||
return (NULL);
|
||||
}
|
||||
/*
|
||||
* File descriptors are a full int, but _file is only a short.
|
||||
* If we get a valid file descriptor that is greater than
|
||||
* SHRT_MAX, then the fd will get sign-extended into an
|
||||
* invalid file descriptor. Handle this case by failing the
|
||||
* open.
|
||||
*/
|
||||
|
||||
/* _file is only a short */
|
||||
if (f > SHRT_MAX) {
|
||||
fp->_flags = 0; /* release */
|
||||
_close(f);
|
||||
close(f);
|
||||
errno = EMFILE;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
fp->_file = f;
|
||||
fp->_flags = flags;
|
||||
fp->_cookie = fp;
|
||||
|
@ -83,6 +71,7 @@ fopen(const char * __restrict file, const char * __restrict mode)
|
|||
fp->_write = __swrite;
|
||||
fp->_seek = __sseek;
|
||||
fp->_close = __sclose;
|
||||
|
||||
/*
|
||||
* When opening in append mode, even though we use O_APPEND,
|
||||
* we need to seek to the end so that ftell() gets the right
|
||||
|
@ -92,6 +81,6 @@ fopen(const char * __restrict file, const char * __restrict mode)
|
|||
* fseek and ftell.)
|
||||
*/
|
||||
if (oflags & O_APPEND)
|
||||
(void)_sseek(fp, (fpos_t)0, SEEK_END);
|
||||
(void) __sseek((void *)fp, (fpos_t)0, SEEK_END);
|
||||
return (fp);
|
||||
}
|
Loading…
Reference in New Issue