diff options
author | Keith M Wesolowski <wesolows@foobazco.org> | 2013-04-17 22:34:47 +0000 |
---|---|---|
committer | Keith M Wesolowski <wesolows@foobazco.org> | 2013-04-17 22:34:53 +0000 |
commit | 5be643a01102f085b0651abffcc0da87fd1f238e (patch) | |
tree | 966e61c63fb08029cc94033f5e3ea6cb666c4aa1 /usr/src/lib/libc | |
parent | d74e1c52fb42c9e48fc33574a1cc964b27954bc6 (diff) | |
parent | b89a2c3e86acf555d0e45c283052876d244d9e6b (diff) | |
download | illumos-joyent-5be643a01102f085b0651abffcc0da87fd1f238e.tar.gz |
[illumos-gate merge]
commit b89a2c3e86acf555d0e45c283052876d244d9e6b
3687 fopen() O_CLOEXEC support via the "e" flag
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; } |