diff options
author | Elliott Hughes <enh@google.com> | 2014-09-24 04:50:44 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-09-24 04:50:45 +0000 |
commit | ebf37e38861e376ae47c72d45ab8de6703dd18f0 (patch) | |
tree | a6437bfad6ddc9fa7814b9bc4ee4706281384496 | |
parent | 04643c181c3256348a6fd78e54c8bc5527ad0b0a (diff) | |
parent | a71b4c3f144a516826e8ac5b262099b920c49ce0 (diff) | |
download | bionic-ebf37e38861e376ae47c72d45ab8de6703dd18f0.zip bionic-ebf37e38861e376ae47c72d45ab8de6703dd18f0.tar.gz bionic-ebf37e38861e376ae47c72d45ab8de6703dd18f0.tar.bz2 |
Merge "Switch to OpenBSD flags.c."
-rw-r--r-- | libc/Android.mk | 2 | ||||
-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 dae254f..0670930 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 1878c2f..d6df6da 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); |