summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-09-23 20:02:42 -0700
committerElliott Hughes <enh@google.com>2014-09-23 20:02:42 -0700
commita71b4c3f144a516826e8ac5b262099b920c49ce0 (patch)
treee08cf9b42a597024264767fb9588bc0d8d3c4d4c
parentc57e5c828914714a283dd41f0a4adb064f6b8763 (diff)
downloadbionic-a71b4c3f144a516826e8ac5b262099b920c49ce0.tar.gz
bionic-a71b4c3f144a516826e8ac5b262099b920c49ce0.tar.bz2
bionic-a71b4c3f144a516826e8ac5b262099b920c49ce0.zip
Switch to OpenBSD flags.c.
Change-Id: I0a35e5bd9f8edba27e0c73e5c8150636346d6a81
-rw-r--r--libc/Android.mk2
-rw-r--r--libc/upstream-openbsd/lib/libc/stdio/flags.c (renamed from libc/upstream-freebsd/lib/libc/stdio/flags.c)59
2 files changed, 27 insertions, 34 deletions
diff --git a/libc/Android.mk b/libc/Android.mk
index dae254f38..0670930a2 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -241,7 +241,6 @@ libc_upstream_freebsd_src_files := \
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/flags.c \
upstream-freebsd/lib/libc/stdio/fopen.c \
upstream-freebsd/lib/libc/stdlib/abs.c \
upstream-freebsd/lib/libc/stdlib/getopt_long.c \
@@ -399,6 +398,7 @@ libc_upstream_openbsd_src_files := \
upstream-openbsd/lib/libc/stdio/fgetws.c \
upstream-openbsd/lib/libc/stdio/fileno.c \
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/fprintf.c \
upstream-openbsd/lib/libc/stdio/fpurge.c \
diff --git a/libc/upstream-freebsd/lib/libc/stdio/flags.c b/libc/upstream-openbsd/lib/libc/stdio/flags.c
index 1878c2f4e..d6df6daab 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/flags.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/flags.c
@@ -1,3 +1,4 @@
+/* $OpenBSD: flags.c,v 1.8 2014/08/31 02:21:18 guenther Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,22 +31,15 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)flags.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/file.h>
#include <stdio.h>
#include <errno.h>
-
#include "local.h"
/*
* Return the (stdio) flags for a given mode. Store the flags
- * to be passed to an _open() syscall through *optr.
+ * to be passed to an open() syscall through *optr.
* Return 0 on error.
*/
int
@@ -78,34 +72,33 @@ __sflags(const char *mode, int *optr)
return (0);
}
- /* 'b' (binary) is ignored */
- if (*mode == 'b')
- mode++;
-
- /* [rwa][b]\+ means read and write */
- if (*mode == '+') {
- mode++;
- ret = __SRW;
- m = O_RDWR;
- }
-
- /* 'b' (binary) can appear here, too -- and is ignored again */
- if (*mode == 'b')
- mode++;
-
- /* 'x' means exclusive (fail if the file exists) */
- if (*mode == 'x') {
- mode++;
- if (m == O_RDONLY) {
+ while (*mode != '\0')
+ switch (*mode++) {
+ case 'b':
+ break;
+ case '+':
+ ret = __SRW;
+ m = O_RDWR;
+ break;
+ case 'e':
+ o |= O_CLOEXEC;
+ break;
+ case 'x':
+ if (o & O_CREAT)
+ o |= O_EXCL;
+ break;
+ default:
+ /*
+ * Lots of software passes other extension mode
+ * letters, like Window's 't'
+ */
+#if 0
errno = EINVAL;
return (0);
+#else
+ break;
+#endif
}
- o |= O_EXCL;
- }
-
- /* set close-on-exec */
- if (*mode == 'e')
- o |= O_CLOEXEC;
*optr = m | o;
return (ret);