diff options
author | Theo Schlossnagle <jesus@omniti.com> | 2013-04-17 10:28:26 -0400 |
---|---|---|
committer | Dan McDonald <danmcd@nexenta.com> | 2013-04-17 10:29:08 -0400 |
commit | b89a2c3e86acf555d0e45c283052876d244d9e6b (patch) | |
tree | 2cd42e4379926821bc7ec763f3e024c9dbe7e172 /usr/src/lib/libc | |
parent | 8c430e5901323dc4ac1bd69a6bbf0bc356f02ae5 (diff) | |
download | illumos-joyent-b89a2c3e86acf555d0e45c283052876d244d9e6b.tar.gz |
3687 fopen() O_CLOEXEC support via the "e" flag
Reviewed by Robert Mustacchi <rm@joyent.com>
Reviewed by Richard Lowe <richlowe@richlowe.net>
Approved by Dan McDonald <danmcd@nexenta.com>
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r-- | usr/src/lib/libc/port/stdio/_endopen.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/usr/src/lib/libc/port/stdio/_endopen.c b/usr/src/lib/libc/port/stdio/_endopen.c index 8e9ef792ac..b1f6d12912 100644 --- a/usr/src/lib/libc/port/stdio/_endopen.c +++ b/usr/src/lib/libc/port/stdio/_endopen.c @@ -27,7 +27,7 @@ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ -#pragma ident "%Z%%M% %I% %E% SMI" +/* Copyright (c) 2013 OmniTI Computer Consulting, Inc. All rights reserved. */ /* * This routine is a special case, in that it is aware of @@ -55,8 +55,8 @@ FILE * _endopen(const char *name, const char *type, FILE *iop, int largefile) { - int oflag, fd, fflag; - char plus; + int oflag, fd, fflag, eflag, plusflag; + const char *echr; if (iop == NULL) return (NULL); @@ -77,10 +77,27 @@ _endopen(const char *name, const char *type, FILE *iop, int largefile) fflag = _IOWRT; break; } - /* UNIX ignores 'b' and treats text and binary the same */ - if ((plus = type[1]) == 'b') - plus = type[2]; - if (plus == '+') { + + plusflag = 0; + eflag = 0; + for (echr = type + 1; *echr != '\0'; echr++) { + switch (*echr) { + /* UNIX ignores 'b' and treats text and binary the same */ + default: + break; + case '+': + plusflag = 1; + break; + case 'e': + eflag = 1; + break; + } + } + if (eflag) { + /* Subsequent to a mode flag, 'e' indicates O_CLOEXEC */ + oflag = oflag | O_CLOEXEC; + } + if (plusflag) { oflag = (oflag & ~(O_RDONLY | O_WRONLY)) | O_RDWR; fflag = _IORW; } |