xref: /386bsd/usr/share/man/cat2/open.0 (revision a2142627)
1OPEN(2)                   386BSD Programmer's Manual                   OPEN(2)
2
3NNAAMMEE
4     ooppeenn - open or create a file for reading or writing
5
6SSYYNNOOPPSSIISS
7     ##iinncclluuddee <<ssyyss//ffiillee..hh>>
8
9     _i_n_t
10     ooppeenn(_c_o_n_s_t _c_h_a_r *_p_a_t_h, _i_n_t _f_l_a_g_s, _m_o_d_e__t _m_o_d_e)
11
12DDEESSCCRRIIPPTTIIOONN
13     The file name specified by _p_a_t_h is opened for reading and/or writing as
14     specified by the argument _f_l_a_g_s and the file descriptor returned to the
15     calling process.  The _f_l_a_g_s argument may indicate the file is to be
16     created if it does not exist (by specifying the O_CREAT flag), in which
17     case the file is created with mode _m_o_d_e as described in chmod(2) and
18     modified by the process' umask value (see umask(2)).
19
20     The flags specified are formed by _o_r'ing the following values
21
22           O_RDONLY        open for reading only
23           O_WRONLY        open for writing only
24           O_RDWR          open for reading and writing
25           O_NONBLOCK      do not block on open
26           O_APPEND        append on each write
27           O_CREAT         create file if it does not exist
28           O_TRUNC         truncate size to 0
29           O_EXCL          error if create and file exists
30           O_SHLOCK        atomically obtain a shared lock
31           O_EXLOCK        atomically obtain an exclusive lock
32
33     Opening a file with O_APPEND set causes each write on the file to be
34     appended to the end.  If O_TRUNC is specified and the file exists, the
35     file is truncated to zero length.  If O_EXCL is set with O_CREAT and the
36     file already exists, ooppeenn() returns an error.  This may be used to
37     implement a simple exclusive access locking mechanism.  If O_EXCL is set
38     and the last component of the pathname is a symbolic link, ooppeenn() will
39     fail even if the symbolic link points to a non-existent name.  If the
40     O_NONBLOCK flag is specified and the ooppeenn() call would result in the
41     process being blocked for some reason (e.g., waiting for carrier on a
42     dialup line), ooppeenn() returns immediately.  The first time the process
43     attempts to perform I/O on the open file it will block (not currently
44     implemented).
45
46     When opening a file, a lock with flock(2) semantics can be obtained by
47     setting O_SHLOCK for a shared lock, or O_EXLOCK for an exclusive lock.
48     If creating a file with O_CREAT, the request for the lock will never fail
49     (provided that the underlying filesystem supports locking).
50
51     If successful, ooppeenn() returns a non-negative integer, termed a file
52     descriptor.  It returns -1 on failure.  The file pointer used to mark the
53     current position within the file is set to the beginning of the file.
54
55     The new descriptor is set to remain open across execve system calls; see
56     close(2) and fcntl(2).
57
58     The system imposes a limit on the number of file descriptors open
59     simultaneously by one process.  Getdtablesize(2) returns the current
60     system limit.
61
62EERRRROORRSS
63     The named file is opened unless:
64
65
66     [ENOTDIR]     A component of the path prefix is not a directory.
67
68     [ENAMETOOLONG]
69                   A component of a pathname exceeded 255 characters, or an
70                   entire path name exceeded 1023 characters.
71
72     [ENOENT]      O_CREAT is not set and the named file does not exist.
73
74     [ENOENT]      A component of the path name that must exist does not
75                   exist.
76
77     [EACCES]      Search permission is denied for a component of the path
78                   prefix.
79
80     [EACCES]      The required permissions (for reading and/or writing) are
81                   denied for the given flags.
82
83     [EACCES]      O_CREAT is specified, the file does not exist, and the
84                   directory in which it is to be created does not permit
85                   writing.
86
87     [ELOOP]       Too many symbolic links were encountered in translating the
88                   pathname.
89
90     [EISDIR]      The named file is a directory, and the arguments specify it
91                   is to be opened for writing.
92
93     [EROFS]       The named file resides on a read-only file system, and the
94                   file is to be modified.
95
96     [EMFILE]      The process has already reached its limit for open file
97                   descriptors.
98
99     [ENFILE]      The system file table is full.
100
101     [ENXIO]       The named file is a character special or block special
102                   file, and the device associated with this special file does
103                   not exist.
104
105     [EINTR]       The ooppeenn operation was interrupted by a signal.
106
107     [EOPNOTSUPP]  O_SHLOCK or O_EXLOCK is specified but the underlying
108                   filesystem does not support locking.
109
110     [ENOSPC]      O_CREAT is specified, the file does not exist, and the
111                   directory in which the entry for the new file is being
112                   placed cannot be extended because there is no space left on
113                   the file system containing the directory.
114
115     [ENOSPC]      O_CREAT is specified, the file does not exist, and there
116                   are no free inodes on the file system on which the file is
117                   being created.
118
119     [EDQUOT]      O_CREAT is specified, the file does not exist, and the
120                   directory in which the entry for the new file is being
121                   placed cannot be extended because the user's quota of disk
122                   blocks on the file system containing the directory has been
123                   exhausted.
124
125     [EDQUOT]      O_CREAT is specified, the file does not exist, and the
126                   user's quota of inodes on the file system on which the file
127                   is being created has been exhausted.
128
129     [EIO]         An I/O error occurred while making the directory entry or
130
131
132                   allocating the inode for O_CREAT.
133
134     [ETXTBSY]     The file is a pure procedure (shared text) file that is
135                   being executed and the ooppeenn() call requests write access.
136
137     [EFAULT]      _P_a_t_h points outside the process's allocated address space.
138
139     [EEXIST]      O_CREAT and O_EXCL were specified and the file exists.
140
141     [EOPNOTSUPP]  An attempt was made to open a socket (not currently
142                   implemented).
143
144SSEEEE AALLSSOO
145     chmod(2),  close(2),  dup(2),  getdtablesize(2),  lseek(2),  read(2),
146     write(2),  umask(2)
147
148HHIISSTTOORRYY
149     An ooppeenn function call appeared in Version 6 AT&T UNIX.
150
1514th Berkeley Distribution        May 27, 1991                                3
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199