summaryrefslogtreecommitdiffstats
path: root/libc/upstream-freebsd
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-09-24 11:14:36 -0700
committerElliott Hughes <enh@google.com>2014-09-24 11:14:36 -0700
commit5a69da8d7af6a388a4ad5b3dd619017b0030031a (patch)
tree0d5e4cbbb4c74d7714f49a7b5de28c563ee9561b /libc/upstream-freebsd
parentf05410edc634040f96643b8f378320faddfef423 (diff)
downloadbionic-5a69da8d7af6a388a4ad5b3dd619017b0030031a.zip
bionic-5a69da8d7af6a388a4ad5b3dd619017b0030031a.tar.gz
bionic-5a69da8d7af6a388a4ad5b3dd619017b0030031a.tar.bz2
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
Diffstat (limited to 'libc/upstream-freebsd')
-rw-r--r--libc/upstream-freebsd/android/include/freebsd-compat.h11
-rw-r--r--libc/upstream-freebsd/lib/libc/stdio/fclose.c85
-rw-r--r--libc/upstream-freebsd/lib/libc/stdio/fopen.c97
3 files changed, 0 insertions, 193 deletions
diff --git a/libc/upstream-freebsd/android/include/freebsd-compat.h b/libc/upstream-freebsd/android/include/freebsd-compat.h
index b44b94a..7acdf7c 100644
--- a/libc/upstream-freebsd/android/include/freebsd-compat.h
+++ b/libc/upstream-freebsd/android/include/freebsd-compat.h
@@ -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
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fclose.c b/libc/upstream-freebsd/lib/libc/stdio/fclose.c
deleted file mode 100644
index 5ed8b2c..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fclose.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * 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
-fclose(FILE *fp)
-{
- int r;
-
- if (fp->_flags == 0) { /* not open! */
- errno = EBADF;
- return (EOF);
- }
- FLOCKFILE(fp);
- r = fp->_flags & __SWR ? __sflush(fp) : 0;
- if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0)
- r = EOF;
- if (fp->_flags & __SMBF)
- free((char *)fp->_bf._base);
- if (HASUB(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);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fopen.c b/libc/upstream-freebsd/lib/libc/stdio/fopen.c
deleted file mode 100644
index b08e336..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fopen.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * 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 <stdio.h>
-#include <errno.h>
-#include <limits.h>
-#include "un-namespace.h"
-
-#include "local.h"
-
-FILE *
-fopen(const char * __restrict file, const char * __restrict mode)
-{
- FILE *fp;
- int f;
- int flags, oflags;
-
- if ((flags = __sflags(mode, &oflags)) == 0)
- return (NULL);
- if ((fp = __sfp()) == NULL)
- return (NULL);
- 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.
- */
- if (f > SHRT_MAX) {
- fp->_flags = 0; /* release */
- _close(f);
- errno = EMFILE;
- return (NULL);
- }
- fp->_file = f;
- fp->_flags = flags;
- fp->_cookie = fp;
- fp->_read = __sread;
- 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
- * answer. If the user then alters the seek pointer, or
- * the file extends, this will fail, but there is not much
- * we can do about this. (We could set __SAPP and check in
- * fseek and ftell.)
- */
- if (oflags & O_APPEND)
- (void)_sseek(fp, (fpos_t)0, SEEK_END);
- return (fp);
-}