Print this page
3665 Implement O_CLOEXEC as an open() flag
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
   1 '\" te
   2 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
   3 .\" Copyright 1989 AT&T
   4 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.

   5 .\" 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
   6 .\" http://www.opengroup.org/bookstore/.
   7 .\" 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.
   8 .\"  This notice shall appear on any product containing this material.
   9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
  10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
  11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  12 .TH OPEN 2 "Jun 16, 2008"
  13 .SH NAME
  14 open, openat \- open a file
  15 .SH SYNOPSIS
  16 .LP
  17 .nf
  18 #include <sys/types.h>
  19 #include <sys/stat.h>
  20 #include <fcntl.h>
  21 
  22 \fBint\fR \fBopen\fR(\fBconst char *\fR\fIpath\fR, \fBint\fR \fIoflag\fR, \fB/* mode_t\fR \fImode\fR */);
  23 .fi
  24 


 194 .na
 195 \fB\fBO_NOFOLLOW\fR\fR
 196 .ad
 197 .sp .6
 198 .RS 4n
 199 If the path names a symbolic link, \fBopen()\fR fails and sets \fBerrno\fR to
 200 \fBELOOP\fR.
 201 .RE
 202 
 203 .sp
 204 .ne 2
 205 .na
 206 \fB\fBO_NOLINKS\fR\fR
 207 .ad
 208 .sp .6
 209 .RS 4n
 210 If the link count of the named file is greater than 1, \fBopen()\fR fails and
 211 sets \fBerrno\fR to \fBEMLINK\fR.
 212 .RE
 213 











 214 .sp
 215 .ne 2
 216 .na
 217 \fB\fBO_NONBLOCK\fR or \fBO_NDELAY\fR\fR
 218 .ad
 219 .sp .6
 220 .RS 4n
 221 These flags can affect subsequent reads and writes (see \fBread\fR(2) and
 222 \fBwrite\fR(2)). If both \fBO_NDELAY\fR and \fBO_NONBLOCK\fR are set,
 223 \fBO_NONBLOCK\fR takes precedence.
 224 .sp
 225 When opening a \fBFIFO\fR with \fBO_RDONLY\fR or \fBO_WRONLY\fR set:
 226 .RS +4
 227 .TP
 228 .ie t \(bu
 229 .el o
 230 If \fBO_NONBLOCK\fR or \fBO_NDELAY\fR is set, an \fBopen()\fR for reading only
 231 returns without delay.  An \fBopen()\fR for writing only returns an error if no
 232 process currently has the file open for reading.
 233 .RE


   1 '\" te
   2 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
   3 .\" Copyright 1989 AT&T
   4 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
   5 .\" Portions Copyright (c) 2013, OmniTI Computer Consulting, Inc.  All Rights Reserved.
   6 .\" 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
   7 .\" http://www.opengroup.org/bookstore/.
   8 .\" 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.
   9 .\"  This notice shall appear on any product containing this material.
  10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
  11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
  12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  13 .TH OPEN 2 "Jun 16, 2008"
  14 .SH NAME
  15 open, openat \- open a file
  16 .SH SYNOPSIS
  17 .LP
  18 .nf
  19 #include <sys/types.h>
  20 #include <sys/stat.h>
  21 #include <fcntl.h>
  22 
  23 \fBint\fR \fBopen\fR(\fBconst char *\fR\fIpath\fR, \fBint\fR \fIoflag\fR, \fB/* mode_t\fR \fImode\fR */);
  24 .fi
  25 


 195 .na
 196 \fB\fBO_NOFOLLOW\fR\fR
 197 .ad
 198 .sp .6
 199 .RS 4n
 200 If the path names a symbolic link, \fBopen()\fR fails and sets \fBerrno\fR to
 201 \fBELOOP\fR.
 202 .RE
 203 
 204 .sp
 205 .ne 2
 206 .na
 207 \fB\fBO_NOLINKS\fR\fR
 208 .ad
 209 .sp .6
 210 .RS 4n
 211 If the link count of the named file is greater than 1, \fBopen()\fR fails and
 212 sets \fBerrno\fR to \fBEMLINK\fR.
 213 .RE
 214 
 215 .sp
 216 .ne 2
 217 .na
 218 \fB\fBO_CLOEXEC\fR\fR
 219 .ad
 220 .sp .6
 221 .RS 4n
 222 If set, the filedescriptor returned will be closed prior to any future
 223 \fBexec()\fR calls.
 224 .RE
 225 
 226 .sp
 227 .ne 2
 228 .na
 229 \fB\fBO_NONBLOCK\fR or \fBO_NDELAY\fR\fR
 230 .ad
 231 .sp .6
 232 .RS 4n
 233 These flags can affect subsequent reads and writes (see \fBread\fR(2) and
 234 \fBwrite\fR(2)). If both \fBO_NDELAY\fR and \fBO_NONBLOCK\fR are set,
 235 \fBO_NONBLOCK\fR takes precedence.
 236 .sp
 237 When opening a \fBFIFO\fR with \fBO_RDONLY\fR or \fBO_WRONLY\fR set:
 238 .RS +4
 239 .TP
 240 .ie t \(bu
 241 .el o
 242 If \fBO_NONBLOCK\fR or \fBO_NDELAY\fR is set, an \fBopen()\fR for reading only
 243 returns without delay.  An \fBopen()\fR for writing only returns an error if no
 244 process currently has the file open for reading.
 245 .RE