570 lines
25 KiB
HTML
570 lines
25 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>open</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="open"></a> <a name="tag_03_410"></a><!-- open -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_410_01"></a>NAME</h4>
|
|
|
|
<blockquote>open - open a file</blockquote>
|
|
|
|
<h4><a name="tag_03_410_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<div class="box"><code><tt><sup>[<a href="javascript:open_code('OH')">OH</a>]</sup> <img src="../images/opt-start.gif" alt=
|
|
"[Option Start]" border="0"> #include <sys/stat.h> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
|
|
|
|
<tt><br>
|
|
#include <<a href="../basedefs/fcntl.h.html">fcntl.h</a>><br>
|
|
<br>
|
|
int open(const char *</tt><i>path</i><tt>, int</tt> <i>oflag</i><tt>, ... );<br>
|
|
</tt></blockquote>
|
|
|
|
<h4><a name="tag_03_410_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>open</i>() function shall establish the connection between a file and a file descriptor. It shall create an open file
|
|
description that refers to a file and a file descriptor that refers to that open file description. The file descriptor is used by
|
|
other I/O functions to refer to that file. The <i>path</i> argument points to a pathname naming the file.</p>
|
|
|
|
<p>The <i>open</i>() function shall return a file descriptor for the named file that is the lowest file descriptor not currently
|
|
open for that process. The open file description is new, and therefore the file descriptor shall not share it with any other
|
|
process in the system. The FD_CLOEXEC file descriptor flag associated with the new file descriptor shall be cleared.</p>
|
|
|
|
<p>The file offset used to mark the current position within the file shall be set to the beginning of the file.</p>
|
|
|
|
<p>The file status flags and file access modes of the open file description shall be set according to the value of
|
|
<i>oflag</i>.</p>
|
|
|
|
<p>Values for <i>oflag</i> are constructed by a bitwise-inclusive OR of flags from the following list, defined in <a href=
|
|
"../basedefs/fcntl.h.html"><i><fcntl.h></i></a>. Applications shall specify exactly one of the first three values (file
|
|
access modes) below in the value of <i>oflag</i>:</p>
|
|
|
|
<dl compact>
|
|
<dt>O_RDONLY</dt>
|
|
|
|
<dd>Open for reading only.</dd>
|
|
|
|
<dt>O_WRONLY</dt>
|
|
|
|
<dd>Open for writing only.</dd>
|
|
|
|
<dt>O_RDWR</dt>
|
|
|
|
<dd>Open for reading and writing. The result is undefined if this flag is applied to a FIFO.</dd>
|
|
</dl>
|
|
|
|
<p>Any combination of the following may be used:</p>
|
|
|
|
<dl compact>
|
|
<dt>O_APPEND</dt>
|
|
|
|
<dd>If set, the file offset shall be set to the end of the file prior to each write.</dd>
|
|
|
|
<dt>O_CREAT</dt>
|
|
|
|
<dd>If the file exists, this flag has no effect except as noted under O_EXCL below. Otherwise, the file shall be created; the user
|
|
ID of the file shall be set to the effective user ID of the process; the group ID of the file shall be set to the group ID of the
|
|
file's parent directory or to the effective group ID of the process; and the access permission bits (see <a href=
|
|
"../basedefs/sys/stat.h.html"><i><sys/stat.h></i></a>) of the file mode shall be set to the value of the third argument taken
|
|
as type <b>mode_t</b> modified as follows: a bitwise AND is performed on the file-mode bits and the corresponding bits in the
|
|
complement of the process' file mode creation mask. Thus, all bits in the file mode whose corresponding bit in the file mode
|
|
creation mask is set are cleared. When bits other than the file permission bits are set, the effect is unspecified. The third
|
|
argument does not affect whether the file is open for reading, writing, or for both. Implementations shall provide a way to
|
|
initialize the file's group ID to the group ID of the parent directory. Implementations may, but need not, provide an
|
|
implementation-defined way to initialize the file's group ID to the effective group ID of the calling process.</dd>
|
|
|
|
<dt>O_DSYNC</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('SIO')">SIO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Write I/O operations on the file descriptor shall complete as defined by synchronized I/O data integrity completion. <img src=
|
|
"../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt>O_EXCL</dt>
|
|
|
|
<dd>If O_CREAT and O_EXCL are set, <i>open</i>() shall fail if the file exists. The check for the existence of the file and the
|
|
creation of the file if it does not exist shall be atomic with respect to other threads executing <i>open</i>() naming the same
|
|
filename in the same directory with O_EXCL and O_CREAT set. If O_EXCL and O_CREAT are set, and <i>path</i> names a symbolic link,
|
|
<i>open</i>() shall fail and set <i>errno</i> to [EEXIST], regardless of the contents of the symbolic link. If O_EXCL is set and
|
|
O_CREAT is not set, the result is undefined.</dd>
|
|
|
|
<dt>O_NOCTTY</dt>
|
|
|
|
<dd>If set and <i>path</i> identifies a terminal device, <i>open</i>() shall not cause the terminal device to become the
|
|
controlling terminal for the process.</dd>
|
|
|
|
<dt>O_NONBLOCK</dt>
|
|
|
|
<dd>When opening a FIFO with O_RDONLY or O_WRONLY set:
|
|
|
|
<ul>
|
|
<li>
|
|
<p>If O_NONBLOCK is set, an <i>open</i>() for reading-only shall return without delay. An <i>open</i>() for writing-only shall
|
|
return an error if no process currently has the file open for reading.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If O_NONBLOCK is clear, an <i>open</i>() for reading-only shall block the calling thread until a thread opens the file for
|
|
writing. An <i>open</i>() for writing-only shall block the calling thread until a thread opens the file for reading.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>When opening a block special or character special file that supports non-blocking opens:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>If O_NONBLOCK is set, the <i>open</i>() function shall return without blocking for the device to be ready or available.
|
|
Subsequent behavior of the device is device-specific.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If O_NONBLOCK is clear, the <i>open</i>() function shall block the calling thread until the device is ready or available before
|
|
returning.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>Otherwise, the behavior of O_NONBLOCK is unspecified.</p>
|
|
</dd>
|
|
|
|
<dt>O_RSYNC</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('SIO')">SIO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Read I/O operations on the file descriptor shall complete at the same level of integrity as specified by the O_DSYNC and O_SYNC
|
|
flags. If both O_DSYNC and O_RSYNC are set in <i>oflag</i>, all I/O operations on the file descriptor shall complete as defined by
|
|
synchronized I/O data integrity completion. If both O_SYNC and O_RSYNC are set in flags, all I/O operations on the file descriptor
|
|
shall complete as defined by synchronized I/O file integrity completion. <img src="../images/opt-end.gif" alt="[Option End]"
|
|
border="0"></dd>
|
|
|
|
<dt>O_SYNC</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('SIO')">SIO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Write I/O operations on the file descriptor shall complete as defined by synchronized I/O file integrity completion. <img src=
|
|
"../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt>O_TRUNC</dt>
|
|
|
|
<dd>If the file exists and is a regular file, and the file is successfully opened O_RDWR or O_WRONLY, its length shall be truncated
|
|
to 0, and the mode and owner shall be unchanged. It shall have no effect on FIFO special files or terminal device files. Its effect
|
|
on other file types is implementation-defined. The result of using O_TRUNC with O_RDONLY is undefined.</dd>
|
|
</dl>
|
|
|
|
<p>If O_CREAT is set and the file did not previously exist, upon successful completion, <i>open</i>() shall mark for update the
|
|
<i>st_atime,</i> <i>st_ctime</i>, and <i>st_mtime</i> fields of the file and the <i>st_ctime</i> and <i>st_mtime</i> fields of the
|
|
parent directory.</p>
|
|
|
|
<p>If O_TRUNC is set and the file did previously exist, upon successful completion, <i>open</i>() shall mark for update the
|
|
<i>st_ctime</i> and <i>st_mtime</i> fields of the file.</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('SIO')">SIO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
If both the O_SYNC and O_DSYNC flags are set, the effect is as if only the O_SYNC flag was set. <img src="../images/opt-end.gif"
|
|
alt="[Option End]" border="0"></p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('XSR')">XSR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
If <i>path</i> refers to a STREAMS file, <i>oflag</i> may be constructed from O_NONBLOCK OR'ed with either O_RDONLY, O_WRONLY, or
|
|
O_RDWR. Other flag values are not applicable to STREAMS devices and shall have no effect on them. The value O_NONBLOCK affects the
|
|
operation of STREAMS drivers and certain functions applied to file descriptors associated with STREAMS files. For STREAMS drivers,
|
|
the implementation of O_NONBLOCK is device-specific. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
If <i>path</i> names the master side of a pseudo-terminal device, then it is unspecified whether <i>open</i>() locks the slave side
|
|
so that it cannot be opened. Conforming applications shall call <a href="../functions/unlockpt.html"><i>unlockpt</i>()</a> before
|
|
opening the slave side. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
|
|
<p>The largest value that can be represented correctly in an object of type <b>off_t</b> shall be established as the offset maximum
|
|
in the open file description.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_410_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, the function shall open the file and return a non-negative integer representing the lowest numbered
|
|
unused file descriptor. Otherwise, -1 shall be returned and <i>errno</i> set to indicate the error. No files shall be created or
|
|
modified if the function returns -1.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_410_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>open</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EACCES]</dt>
|
|
|
|
<dd>Search permission is denied on a component of the path prefix, or the file exists and the permissions specified by <i>oflag</i>
|
|
are denied, or the file does not exist and write permission is denied for the parent directory of the file to be created, or
|
|
O_TRUNC is specified and write permission is denied.</dd>
|
|
|
|
<dt>[EEXIST]</dt>
|
|
|
|
<dd>O_CREAT and O_EXCL are set, and the named file exists.</dd>
|
|
|
|
<dt>[EINTR]</dt>
|
|
|
|
<dd>A signal was caught during <i>open</i>().</dd>
|
|
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('SIO')">SIO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The implementation does not support synchronized I/O for this file. <img src="../images/opt-end.gif" alt="[Option End]" border=
|
|
"0"></dd>
|
|
|
|
<dt>[EIO]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSR')">XSR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The <i>path</i> argument names a STREAMS file and a hangup or error occurred during the <i>open</i>(). <img src=
|
|
"../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt>[EISDIR]</dt>
|
|
|
|
<dd>The named file is a directory and <i>oflag</i> includes O_WRONLY or O_RDWR.</dd>
|
|
|
|
<dt>[ELOOP]</dt>
|
|
|
|
<dd>A loop exists in symbolic links encountered during resolution of the <i>path</i> argument.</dd>
|
|
|
|
<dt>[EMFILE]</dt>
|
|
|
|
<dd>{OPEN_MAX} file descriptors are currently open in the calling process.</dd>
|
|
|
|
<dt>[ENAMETOOLONG]</dt>
|
|
|
|
<dd>
|
|
The length of the <i>path</i> argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.</dd>
|
|
|
|
<dt>[ENFILE]</dt>
|
|
|
|
<dd>The maximum allowable number of files is currently open in the system.</dd>
|
|
|
|
<dt>[ENOENT]</dt>
|
|
|
|
<dd>O_CREAT is not set and the named file does not exist; or O_CREAT is set and either the path prefix does not exist or the
|
|
<i>path</i> argument points to an empty string.</dd>
|
|
|
|
<dt>[ENOSR]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSR')">XSR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The <i>path</i> argument names a STREAMS-based file and the system is unable to allocate a STREAM. <img src="../images/opt-end.gif"
|
|
alt="[Option End]" border="0"></dd>
|
|
|
|
<dt>[ENOSPC]</dt>
|
|
|
|
<dd>The directory or file system that would contain the new file cannot be expanded, the file does not exist, and O_CREAT is
|
|
specified.</dd>
|
|
|
|
<dt>[ENOTDIR]</dt>
|
|
|
|
<dd>A component of the path prefix is not a directory.</dd>
|
|
|
|
<dt>[ENXIO]</dt>
|
|
|
|
<dd>O_NONBLOCK is set, the named file is a FIFO, O_WRONLY is set, and no process has the file open for reading.</dd>
|
|
|
|
<dt>[ENXIO]</dt>
|
|
|
|
<dd>The named file is a character special or block special file, and the device associated with this special file does not
|
|
exist.</dd>
|
|
|
|
<dt>[EOVERFLOW]</dt>
|
|
|
|
<dd>The named file is a regular file and the size of the file cannot be represented correctly in an object of type
|
|
<b>off_t</b>.</dd>
|
|
|
|
<dt>[EROFS]</dt>
|
|
|
|
<dd>The named file resides on a read-only file system and either O_WRONLY, O_RDWR, O_CREAT (if the file does not exist), or O_TRUNC
|
|
is set in the <i>oflag</i> argument.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>open</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EAGAIN]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The <i>path</i> argument names the slave side of a pseudo-terminal device that is locked. <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></dd>
|
|
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>The value of the <i>oflag</i> argument is not valid.</dd>
|
|
|
|
<dt>[ELOOP]</dt>
|
|
|
|
<dd>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the <i>path</i> argument.</dd>
|
|
|
|
<dt>[ENAMETOOLONG]</dt>
|
|
|
|
<dd>
|
|
As a result of encountering a symbolic link in resolution of the <i>path</i> argument, the length of the substituted pathname
|
|
string exceeded {PATH_MAX}.</dd>
|
|
|
|
<dt>[ENOMEM]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSR')">XSR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The <i>path</i> argument names a STREAMS file and the system is unable to allocate resources. <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></dd>
|
|
|
|
<dt>[ETXTBSY]</dt>
|
|
|
|
<dd>The file is a pure procedure (shared text) file that is being executed and <i>oflag</i> is O_WRONLY or O_RDWR.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_410_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<h5><a name="tag_03_410_06_01"></a>Opening a File for Writing by the Owner</h5>
|
|
|
|
<p>The following example opens the file <b>/tmp/file</b>, either by creating it (if it does not already exist), or by truncating
|
|
its length to 0 (if it does exist). In the former case, if the call creates a new file, the access permission bits in the file mode
|
|
of the file are set to permit reading and writing by the owner, and to permit reading only by group members and others.</p>
|
|
|
|
<p>If the call to <i>open</i>() is successful, the file is opened for writing.</p>
|
|
|
|
<pre>
|
|
<tt>#include <fcntl.h>
|
|
...
|
|
int fd;
|
|
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
|
char *filename = "/tmp/file";
|
|
...
|
|
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
|
...
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_410_06_02"></a>Opening a File Using an Existence Check</h5>
|
|
|
|
<p>The following example uses the <i>open</i>() function to try to create the <b>LOCKFILE</b> file and open it for writing. Since
|
|
the <i>open</i>() function specifies the O_EXCL flag, the call fails if the file already exists. In that case, the program assumes
|
|
that someone else is updating the password file and exits.</p>
|
|
|
|
<pre>
|
|
<tt>#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
<br>
|
|
#define LOCKFILE "/etc/ptmp"
|
|
...
|
|
int pfd; /* Integer for file descriptor returned by open() call. */
|
|
...
|
|
if ((pfd = open(LOCKFILE, O_WRONLY | O_CREAT | O_EXCL,
|
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
|
|
{
|
|
fprintf(stderr, "Cannot open /etc/ptmp. Try again later.\n");
|
|
exit(1);
|
|
}
|
|
...
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_410_06_03"></a>Opening a File for Writing</h5>
|
|
|
|
<p>The following example opens a file for writing, creating the file if it does not already exist. If the file does exist, the
|
|
system truncates the file to zero bytes.</p>
|
|
|
|
<pre>
|
|
<tt>#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
<br>
|
|
#define LOCKFILE "/etc/ptmp"
|
|
...
|
|
int pfd;
|
|
char filename[PATH_MAX+1];
|
|
...
|
|
if ((pfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC,
|
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
|
|
{
|
|
perror("Cannot open output file\n"); exit(1);
|
|
}
|
|
...
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_410_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_410_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>Except as specified in this volume of IEEE Std 1003.1-2001, the flags allowed in <i>oflag</i> are not
|
|
mutually-exclusive and any number of them may be used simultaneously.</p>
|
|
|
|
<p>Some implementations permit opening FIFOs with O_RDWR. Since FIFOs could be implemented in other ways, and since two file
|
|
descriptors can be used to the same effect, this possibility is left as undefined.</p>
|
|
|
|
<p>See <a href="getgroups.html"><i>getgroups</i>()</a> about the group of a newly created file.</p>
|
|
|
|
<p>The use of <i>open</i>() to create a regular file is preferable to the use of <a href=
|
|
"../functions/creat.html"><i>creat</i>()</a>, because the latter is redundant and included only for historical reasons.</p>
|
|
|
|
<p>The use of the O_TRUNC flag on FIFOs and directories (pipes cannot be <i>open</i>()-ed) must be permissible without unexpected
|
|
side effects (for example, <a href="../functions/creat.html"><i>creat</i>()</a> on a FIFO must not remove data). Since terminal
|
|
special files might have type-ahead data stored in the buffer, O_TRUNC should not affect their content, particularly if a program
|
|
that normally opens a regular file should open the current controlling terminal instead. Other file types, particularly
|
|
implementation-defined ones, are left implementation-defined.</p>
|
|
|
|
<p>IEEE Std 1003.1-2001 permits [EACCES] to be returned for conditions other than those explicitly listed.</p>
|
|
|
|
<p>The O_NOCTTY flag was added to allow applications to avoid unintentionally acquiring a controlling terminal as a side effect of
|
|
opening a terminal file. This volume of IEEE Std 1003.1-2001 does not specify how a controlling terminal is acquired, but
|
|
it allows an implementation to provide this on <i>open</i>() if the O_NOCTTY flag is not set and other conditions specified in the
|
|
Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap11.html#tag_11">Chapter 11, General
|
|
Terminal Interface</a> are met. The O_NOCTTY flag is an effective no-op if the file being opened is not a terminal device.</p>
|
|
|
|
<p>In historical implementations the value of O_RDONLY is zero. Because of that, it is not possible to detect the presence of
|
|
O_RDONLY and another option. Future implementations should encode O_RDONLY and O_WRONLY as bit flags so that:</p>
|
|
|
|
<pre>
|
|
<tt>O_RDONLY | O_WRONLY == O_RDWR
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>In general, the <i>open</i>() function follows the symbolic link if <i>path</i> names a symbolic link. However, the
|
|
<i>open</i>() function, when called with O_CREAT and O_EXCL, is required to fail with [EEXIST] if <i>path</i> names an existing
|
|
symbolic link, even if the symbolic link refers to a nonexistent file. This behavior is required so that privileged applications
|
|
can create a new file in a known location without the possibility that a symbolic link might cause the file to be created in a
|
|
different location.</p>
|
|
|
|
<p>For example, a privileged application that must create a file with a predictable name in a user-writable directory, such as the
|
|
user's home directory, could be compromised if the user creates a symbolic link with that name that refers to a nonexistent file in
|
|
a system directory. If the user can influence the contents of a file, the user could compromise the system by creating a new system
|
|
configuration or spool file that would then be interpreted by the system. The test for a symbolic link which refers to a
|
|
nonexisting file must be atomic with the creation of a new file.</p>
|
|
|
|
<p>The POSIX.1-1990 standard required that the group ID of a newly created file be set to the group ID of its parent directory or
|
|
to the effective group ID of the creating process. FIPS 151-2 required that implementations provide a way to have the group ID be
|
|
set to the group ID of the containing directory, but did not prohibit implementations also supporting a way to set the group ID to
|
|
the effective group ID of the creating process. Conforming applications should not assume which group ID will be used. If it
|
|
matters, an application can use <a href="../functions/chown.html"><i>chown</i>()</a> to set the group ID after the file is created,
|
|
or determine under what conditions the implementation will set the desired group ID.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_410_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_410_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="chmod.html"><i>chmod</i>()</a> , <a href="close.html"><i>close</i>()</a> , <a href="creat.html"><i>creat</i>()</a> , <a
|
|
href="dup.html"><i>dup</i>()</a> , <a href="fcntl.html"><i>fcntl</i>()</a> , <a href="lseek.html"><i>lseek</i>()</a> , <a href=
|
|
"read.html"><i>read</i>()</a> , <a href="umask.html"><i>umask</i>()</a> , <a href="unlockpt.html"><i>unlockpt</i>()</a> , <a href=
|
|
"write.html"><i>write</i>()</a> , the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/fcntl.h.html"><i><fcntl.h></i></a>, <a href="../basedefs/sys/stat.h.html"><i><sys/stat.h></i></a>, <a
|
|
href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_410_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_410_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>The DESCRIPTION is updated for alignment with the POSIX Realtime Extension and the POSIX Threads Extension.</p>
|
|
|
|
<p>Large File Summit extensions are added.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_410_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>In the SYNOPSIS, the optional include of the <a href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> header is
|
|
removed.</p>
|
|
|
|
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The requirement to include <a href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> has been removed. Although <a
|
|
href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> was required for conforming implementations of previous POSIX
|
|
specifications, it was not required for UNIX applications.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>In the DESCRIPTION, O_CREAT is amended to state that the group ID of the file is set to the group ID of the file's parent
|
|
directory or to the effective group ID of the process. This is a FIPS requirement.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>In the DESCRIPTION, text is added to indicate setting of the offset maximum in the open file description. This change is to
|
|
support large files.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>In the ERRORS section, the [EOVERFLOW] condition is added. This change is to support large files.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [ENXIO] mandatory error condition is added.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [EINVAL], [ENAMETOOLONG], and [ETXTBSY] optional error conditions are added.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The DESCRIPTION and ERRORS sections are updated so that items related to the optional XSI STREAMS Option Group are marked.</p>
|
|
|
|
<p>The following changes were made to align with the IEEE P1003.1a draft standard:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>An explanation is added of the effect of the O_CREAT and O_EXCL flags when the path refers to a symbolic link.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [ELOOP] optional error condition is added.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The DESCRIPTION is updated to avoid use of the term "must" for application requirements.</p>
|
|
|
|
<p>The DESCRIPTION of O_EXCL is updated in response to IEEE PASC Interpretation 1003.1c #48.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|