summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
authorKeith M Wesolowski <wesolows@foobazco.org>2013-04-17 22:34:47 +0000
committerKeith M Wesolowski <wesolows@foobazco.org>2013-04-17 22:34:53 +0000
commit5be643a01102f085b0651abffcc0da87fd1f238e (patch)
tree966e61c63fb08029cc94033f5e3ea6cb666c4aa1 /usr/src
parentd74e1c52fb42c9e48fc33574a1cc964b27954bc6 (diff)
parentb89a2c3e86acf555d0e45c283052876d244d9e6b (diff)
downloadillumos-joyent-5be643a01102f085b0651abffcc0da87fd1f238e.tar.gz
[illumos-gate merge]
commit b89a2c3e86acf555d0e45c283052876d244d9e6b 3687 fopen() O_CLOEXEC support via the "e" flag
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/lib/libc/port/stdio/_endopen.c31
-rw-r--r--usr/src/man/man3c/fopen.3c27
2 files changed, 43 insertions, 15 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;
}
diff --git a/usr/src/man/man3c/fopen.3c b/usr/src/man/man3c/fopen.3c
index ef177a4264..648cd185ac 100644
--- a/usr/src/man/man3c/fopen.3c
+++ b/usr/src/man/man3c/fopen.3c
@@ -2,6 +2,7 @@
.\" Copyright 1989 AT&T.
.\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
+.\" Portions Copyright (c) 2013, OmniTI Computer Consulting, Inc. All Rights Reserved.
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
@@ -28,11 +29,11 @@ to by \fIfilename\fR, and associates a stream with it.
.sp
.LP
The argument \fImode\fR points to a string beginning with one of the following
-sequences:
+base sequences:
.sp
.ne 2
.na
-\fB\fBr\fR or \fBrb\fR\fR
+\fB\fBr\fR\fR
.ad
.RS 20n
Open file for reading.
@@ -41,7 +42,7 @@ Open file for reading.
.sp
.ne 2
.na
-\fB\fBw\fR or \fBwb\fR\fR
+\fB\fBw\fR\fR
.ad
.RS 20n
Truncate to zero length or create file for writing.
@@ -50,7 +51,7 @@ Truncate to zero length or create file for writing.
.sp
.ne 2
.na
-\fB\fBa\fR or \fBab\fR\fR
+\fB\fBa\fR\fR
.ad
.RS 20n
Append; open or create file for writing at end-of-file.
@@ -59,7 +60,7 @@ Append; open or create file for writing at end-of-file.
.sp
.ne 2
.na
-\fB\fBr+\fR or \fBrb+\fR or \fBr+b\fR\fR
+\fB\fBr+\fR\fR
.ad
.RS 20n
Open file for update (reading and writing).
@@ -68,7 +69,7 @@ Open file for update (reading and writing).
.sp
.ne 2
.na
-\fB\fBw+\fR or \fBwb+\fR or \fBw+b\fR\fR
+\fB\fBw+\fR\fR
.ad
.RS 20n
Truncate to zero length or create file for update.
@@ -77,7 +78,7 @@ Truncate to zero length or create file for update.
.sp
.ne 2
.na
-\fB\fBa+\fR or \fBab+\fR or \fBa+b\fR\fR
+\fB\fBa+\fR\fR
.ad
.RS 20n
Append; open or create file for update, writing at end-of-file.
@@ -85,12 +86,22 @@ Append; open or create file for update, writing at end-of-file.
.sp
.LP
+In addition to the base sequences for the \fImode\fR argument above, two
+additional flags are supported via the \fBb\fR character and the \fBe\fR
+character. Order of these additional flags (including the \fB+\fR) does
+not matter.
+.sp
+.LP
The character \fBb\fR has no effect, but is allowed for ISO C standard
conformance (see \fBstandards\fR(5)). Opening a file with read mode (\fBr\fR as
the first character in the \fImode\fR argument) fails if the file does not
exist or cannot be read.
.sp
.LP
+The character \fBe\fR will cause the underlying file descriptor to be
+opened with the O_CLOEXEC flag as described in \fBopen\fR(2).
+.sp
+.LP
Opening a file with append mode (\fBa\fR as the first character in the
\fImode\fR argument) causes all subsequent writes to the file to be forced to
the then current end-of-file, regardless of intervening calls to
@@ -392,4 +403,4 @@ respects this function is Standard.
.LP
\fBenable_extended_FILE_stdio\fR(3C), \fBfclose\fR(3C), \fBfdopen\fR(3C),
\fBfflush\fR(3C), \fBfreopen\fR(3C), \fBfsetpos\fR(3C), \fBrewind\fR(3C),
-\fBattributes\fR(5), \fBlf64\fR(5), \fBstandards\fR(5)
+\fBopen\fR(2), \fBattributes\fR(5), \fBlf64\fR(5), \fBstandards\fR(5)