131 lines
6.1 KiB
HTML
131 lines
6.1 KiB
HTML
|
|
<head>
|
||
|
|
<title>open(3) - Plan 9 from User Space</title>
|
||
|
|
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
|
||
|
|
</head>
|
||
|
|
<body bgcolor=#ffffff>
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0 width=100%>
|
||
|
|
<tr height=10><td>
|
||
|
|
<tr><td width=20><td>
|
||
|
|
<tr><td width=20><td><b>OPEN(3)</b><td align=right><b>OPEN(3)</b>
|
||
|
|
<tr><td width=20><td colspan=2>
|
||
|
|
<br>
|
||
|
|
<p><font size=+1><b>NAME </b></font><br>
|
||
|
|
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
||
|
|
|
||
|
|
open, create, close – open a file for reading or writing, create
|
||
|
|
file<br>
|
||
|
|
|
||
|
|
</table>
|
||
|
|
<p><font size=+1><b>SYNOPSIS </b></font><br>
|
||
|
|
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
||
|
|
|
||
|
|
<tt><font size=+1>#include <u.h><br>
|
||
|
|
#include <libc.h>
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>int open(char *file, int omode)
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>int create(char *file, int omode, ulong perm)
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>int close(int fd)<br>
|
||
|
|
</font></tt>
|
||
|
|
</table>
|
||
|
|
<p><font size=+1><b>DESCRIPTION </b></font><br>
|
||
|
|
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
||
|
|
|
||
|
|
<i>Open</i> opens the <i>file</i> for I/O and returns an associated file descriptor.
|
||
|
|
<i>Omode</i> is one of <tt><font size=+1>OREAD</font></tt>, <tt><font size=+1>OWRITE</font></tt>, <tt><font size=+1>ORDWR</font></tt>, or <tt><font size=+1>OEXEC</font></tt>, asking for permission
|
||
|
|
to read, write, read and write, or execute, respectively. In addition,
|
||
|
|
there are three values that can be ORed with the <i>omode</i>: <tt><font size=+1>OTRUNC</font></tt>
|
||
|
|
says to truncate the file to zero length
|
||
|
|
before opening it; <tt><font size=+1>OCEXEC</font></tt> says to close the file when an <a href="../man3/exec.html"><i>exec</i>(3)</a>
|
||
|
|
or <i>execl</i> system call is made; and <tt><font size=+1>ORCLOSE</font></tt> says to remove the file
|
||
|
|
when it is closed (by everyone who has a copy of the file descriptor).
|
||
|
|
<i>Open</i> fails if the file does not exist or the user does not have
|
||
|
|
permission to open it for the requested purpose (see
|
||
|
|
<a href="../man3/stat.html"><i>stat</i>(3)</a> for a description of permissions). The user must have
|
||
|
|
write permission on the <i>file</i> if the <tt><font size=+1>OTRUNC</font></tt> bit is set. For the
|
||
|
|
<i>open</i> system call (unlike the implicit <i>open</i> in <a href="../man3/exec.html"><i>exec</i>(3)</a>), <tt><font size=+1>OEXEC</font></tt>
|
||
|
|
is actually identical to <tt><font size=+1>OREAD</font></tt>.
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
|
||
|
|
<i>Create</i> creates a new <i>file</i> or prepares to rewrite an existing <i>file</i>,
|
||
|
|
opens it according to <i>omode</i> (as described for <i>open</i>), and returns
|
||
|
|
an associated file descriptor. If the file is new, the owner is
|
||
|
|
set to the userid of the creating process group; the group to
|
||
|
|
that of the containing directory; the permissions to <i>perm</i> ANDed
|
||
|
|
with
|
||
|
|
the permissions of the containing directory. If the file already
|
||
|
|
exists, it is truncated to 0 length, and the permissions, owner,
|
||
|
|
and group remain unchanged. The created file is a directory if
|
||
|
|
the <tt><font size=+1>DMDIR</font></tt> bit is set in <i>perm</i>, an exclusive-use file if the <tt><font size=+1>DMEXCL</font></tt>
|
||
|
|
bit is set, and an append-only file if the <tt><font size=+1>DMAPPEND</font></tt> bit is set.
|
||
|
|
Exclusive-use files may be open for I/O by only one client at
|
||
|
|
a time, but the file descriptor may become invalid if no I/O is
|
||
|
|
done for an extended period; see <i>open</i>(9p).
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
|
||
|
|
<i>Create</i> fails if the path up to the last element of <i>file</i> cannot
|
||
|
|
be evaluated, if the user doesn’t have write permission in the
|
||
|
|
final directory, if the file already exists and does not permit
|
||
|
|
the access defined by <i>omode</i>, of if there there are no free file
|
||
|
|
descriptors. In the last case, the file may be created even when
|
||
|
|
an error is
|
||
|
|
returned.
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
|
||
|
|
Since <i>create</i> may succeed even if the file exists, a special mechanism
|
||
|
|
is necessary for those applications that require an atomic create
|
||
|
|
operation. If the <tt><font size=+1>OEXCL</font></tt> (<tt><font size=+1>0x1000</font></tt>) bit is set in the <i>mode</i> for a
|
||
|
|
<i>create,</i> the call succeeds only if the file does not already exist;
|
||
|
|
see <i>open</i>(9p) for details.
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
|
||
|
|
<i>Close</i> closes the file associated with a file descriptor. Provided
|
||
|
|
the file descriptor is a valid open descriptor, <i>close</i> is guaranteed
|
||
|
|
to close it; there will be no error. Files are closed automatically
|
||
|
|
upon termination of a process; <i>close</i> allows the file descriptor
|
||
|
|
to be reused.<br>
|
||
|
|
|
||
|
|
</table>
|
||
|
|
<p><font size=+1><b>SOURCE </b></font><br>
|
||
|
|
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
||
|
|
|
||
|
|
<tt><font size=+1>/usr/local/plan9/src/lib9<br>
|
||
|
|
</font></tt>
|
||
|
|
</table>
|
||
|
|
<p><font size=+1><b>SEE ALSO </b></font><br>
|
||
|
|
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
||
|
|
|
||
|
|
<a href="../man3/intro.html"><i>intro</i>(3)</a>, <a href="../man3/stat.html"><i>stat</i>(3)</a><br>
|
||
|
|
|
||
|
|
</table>
|
||
|
|
<p><font size=+1><b>DIAGNOSTICS </b></font><br>
|
||
|
|
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
||
|
|
|
||
|
|
These functions set <i>errstr</i>.<br>
|
||
|
|
|
||
|
|
</table>
|
||
|
|
|
||
|
|
<td width=20>
|
||
|
|
<tr height=20><td>
|
||
|
|
</table>
|
||
|
|
<!-- TRAILER -->
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0 width=100%>
|
||
|
|
<tr height=15><td width=10><td><td width=10>
|
||
|
|
<tr><td><td>
|
||
|
|
<center>
|
||
|
|
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
|
||
|
|
</center>
|
||
|
|
</table>
|
||
|
|
<!-- TRAILER -->
|
||
|
|
</body></html>
|