Print this page
4330 open(2) manual describes O_SYNC twice
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/man/man2/open.2
+++ new/usr/src/man/man2/open.2
1 1 '\" te
2 2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
|
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
3 3 .\" Copyright 1989 AT&T
4 4 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
5 5 .\" Portions Copyright (c) 2013, OmniTI Computer Consulting, Inc. All Rights Reserved.
6 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 7 .\" http://www.opengroup.org/bookstore/.
8 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 9 .\" This notice shall appear on any product containing this material.
10 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 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 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"
13 +.TH OPEN 2 "Nov 16, 2013"
14 14 .SH NAME
15 15 open, openat \- open a file
16 16 .SH SYNOPSIS
17 17 .LP
18 18 .nf
19 19 #include <sys/types.h>
20 20 #include <sys/stat.h>
21 21 #include <fcntl.h>
22 22
23 23 \fBint\fR \fBopen\fR(\fBconst char *\fR\fIpath\fR, \fBint\fR \fIoflag\fR, \fB/* mode_t\fR \fImode\fR */);
24 24 .fi
25 25
26 26 .LP
27 27 .nf
28 28 \fBint\fR \fBopenat\fR(\fBint\fR \fIfildes\fR, \fBconst char *\fR\fIpath\fR, \fBint\fR \fIoflag\fR,
29 29 \fB/* mode_t\fR \fImode\fR */);
30 30 .fi
31 31
32 32 .SH DESCRIPTION
33 33 .sp
34 34 .LP
35 35 The \fBopen()\fR function establishes the connection between a file and a file
36 36 descriptor. It creates an open file description that refers to a file and a
37 37 file descriptor that refers to that open file description. The file descriptor
38 38 is used by other I/O functions to refer to that file. The \fIpath\fR argument
39 39 points to a pathname naming the file.
40 40 .sp
41 41 .LP
42 42 The \fBopenat()\fR function is identical to the \fBopen()\fR function except
43 43 that the \fIpath\fR argument is interpreted relative to the starting point
44 44 implied by the \fIfildes\fR argument. If the \fIfildes\fR argument has the
45 45 special value \fBAT_FDCWD\fR, a relative path argument will be resolved
46 46 relative to the current working directory. If the \fIpath\fR argument is
47 47 absolute, the \fIfildes\fR argument is ignored.
48 48 .sp
49 49 .LP
50 50 The \fBopen()\fR function returns a file descriptor for the named file that is
51 51 the lowest file descriptor not currently open for that process. The open file
52 52 description is new, and therefore the file descriptor does not share it with
53 53 any other process in the system. The \fBFD_CLOEXEC\fR file descriptor flag
54 54 associated with the new file descriptor is cleared.
55 55 .sp
56 56 .LP
57 57 The file offset used to mark the current position within the file is set to the
58 58 beginning of the file.
59 59 .sp
60 60 .LP
61 61 The file status flags and file access modes of the open file description are
62 62 set according to the value of \fIoflag\fR. The \fImode\fR argument is used only
63 63 when \fBO_CREAT\fR is specified (see below.)
64 64 .sp
65 65 .LP
66 66 Values for \fIoflag\fR are constructed by a bitwise-inclusive-OR of flags from
67 67 the following list, defined in <\fBfcntl.h\fR>. Applications must specify
68 68 exactly one of the first three values (file access modes) below in the value of
69 69 \fIoflag\fR:
70 70 .sp
71 71 .ne 2
72 72 .na
73 73 \fB\fBO_RDONLY\fR\fR
74 74 .ad
75 75 .RS 12n
76 76 Open for reading only.
77 77 .RE
78 78
79 79 .sp
80 80 .ne 2
81 81 .na
82 82 \fB\fBO_WRONLY\fR\fR
83 83 .ad
84 84 .RS 12n
85 85 Open for writing only.
86 86 .RE
87 87
88 88 .sp
89 89 .ne 2
90 90 .na
91 91 \fB\fBO_RDWR\fR\fR
92 92 .ad
93 93 .RS 12n
94 94 Open for reading and writing. The result is undefined if this flag is applied
95 95 to a FIFO.
96 96 .RE
97 97
98 98 .sp
99 99 .LP
100 100 Any combination of the following may be used:
101 101 .sp
102 102 .ne 2
103 103 .na
104 104 \fB\fBO_APPEND\fR\fR
105 105 .ad
106 106 .sp .6
107 107 .RS 4n
108 108 If set, the file offset is set to the end of the file prior to each write.
109 109 .RE
110 110
111 111 .sp
112 112 .ne 2
113 113 .na
114 114 \fB\fBO_CREAT\fR\fR
115 115 .ad
116 116 .sp .6
117 117 .RS 4n
118 118 Create the file if it does not exist. This flag requires that the \fImode\fR
119 119 argument be specified.
120 120 .sp
121 121 If the file exists, this flag has no effect except as noted under \fBO_EXCL\fR
122 122 below. Otherwise, the file is created with the user \fBID\fR of the file set
123 123 to the effective user \fBID\fR of the process. The group \fBID\fR of the file
124 124 is set to the effective group \fBIDs\fR of the process, or if the \fBS_ISGID\fR
|
↓ open down ↓ |
101 lines elided |
↑ open up ↑ |
125 125 bit is set in the directory in which the file is being created, the file's
126 126 group \fBID\fR is set to the group \fBID\fR of its parent directory. If the
127 127 group \fBID\fR of the new file does not match the effective group \fBID\fR or
128 128 one of the supplementary groups IDs, the \fBS_ISGID\fR bit is cleared. The
129 129 access permission bits (see \fB<sys/stat.h>\fR) of the file mode are set to the
130 130 value of \fImode\fR, modified as follows (see \fBcreat\fR(2)): a bitwise-AND is
131 131 performed on the file-mode bits and the corresponding bits in the complement of
132 132 the process's file mode creation mask. Thus, all bits set in the process's file
133 133 mode creation mask (see \fBumask\fR(2)) are correspondingly cleared in the
134 134 file's permission mask. The "save text image after execution bit" of the mode
135 -is cleared (see \fBchmod\fR(2)). \fBO_SYNC\fR Write I/O operations on the file
136 -descriptor complete as defined by synchronized I/O file integrity completion
137 -(see \fBfcntl.h\fR(3HEAD) definition of \fBO_SYNC\fR.) When bits other than the
138 -file permission bits are set, the effect is unspecified. The \fImode\fR
139 -argument does not affect whether the file is open for reading, writing or for
140 -both.
135 +is cleared (see \fBchmod\fR(2)). When bits other than the file permission bits
136 +are set, the effect is unspecified. The \fImode\fR argument does not affect
137 +whether the file is open for reading, writing or for both.
141 138 .RE
142 139
143 140 .sp
144 141 .ne 2
145 142 .na
146 143 \fB\fBO_DSYNC\fR\fR
147 144 .ad
148 145 .sp .6
149 146 .RS 4n
150 147 Write I/O operations on the file descriptor complete as defined by synchronized
151 148 I/O data integrity completion.
152 149 .RE
153 150
154 151 .sp
155 152 .ne 2
156 153 .na
157 154 \fB\fBO_EXCL\fR\fR
158 155 .ad
159 156 .sp .6
160 157 .RS 4n
161 158 If \fBO_CREAT\fR and \fBO_EXCL\fR are set, \fBopen()\fR fails if the file
162 159 exists. The check for the existence of the file and the creation of the file if
163 160 it does not exist is atomic with respect to other threads executing
164 161 \fBopen()\fR naming the same filename in the same directory with \fBO_EXCL\fR
165 162 and \fBO_CREAT\fR set. If \fBO_EXCL\fR and \fBO_CREAT\fR are set, and path
166 163 names a symbolic link, \fBopen()\fR fails and sets \fBerrno\fR to \fBEEXIST\fR,
167 164 regardless of the contents of the symbolic link. If \fBO_EXCL\fR is set and
168 165 \fBO_CREAT\fR is not set, the result is undefined.
169 166 .RE
170 167
171 168 .sp
172 169 .ne 2
173 170 .na
174 171 \fB\fBO_LARGEFILE\fR\fR
175 172 .ad
176 173 .sp .6
177 174 .RS 4n
178 175 If set, the offset maximum in the open file description is the largest value
179 176 that can be represented correctly in an object of type \fBoff64_t\fR.
180 177 .RE
181 178
182 179 .sp
183 180 .ne 2
184 181 .na
185 182 \fB\fBO_NOCTTY\fR\fR
186 183 .ad
187 184 .sp .6
188 185 .RS 4n
189 186 If set and \fIpath\fR identifies a terminal device, \fBopen()\fR does not cause
190 187 the terminal device to become the controlling terminal for the process.
191 188 .RE
192 189
193 190 .sp
194 191 .ne 2
195 192 .na
196 193 \fB\fBO_NOFOLLOW\fR\fR
197 194 .ad
198 195 .sp .6
199 196 .RS 4n
200 197 If the path names a symbolic link, \fBopen()\fR fails and sets \fBerrno\fR to
201 198 \fBELOOP\fR.
202 199 .RE
203 200
204 201 .sp
205 202 .ne 2
206 203 .na
207 204 \fB\fBO_NOLINKS\fR\fR
208 205 .ad
209 206 .sp .6
210 207 .RS 4n
211 208 If the link count of the named file is greater than 1, \fBopen()\fR fails and
212 209 sets \fBerrno\fR to \fBEMLINK\fR.
213 210 .RE
214 211
215 212 .sp
216 213 .ne 2
217 214 .na
218 215 \fB\fBO_CLOEXEC\fR\fR
219 216 .ad
220 217 .sp .6
221 218 .RS 4n
222 219 If set, the file descriptor returned will be closed prior to any future
223 220 \fBexec()\fR calls.
224 221 .RE
225 222
226 223 .sp
227 224 .ne 2
228 225 .na
229 226 \fB\fBO_NONBLOCK\fR or \fBO_NDELAY\fR\fR
230 227 .ad
231 228 .sp .6
232 229 .RS 4n
233 230 These flags can affect subsequent reads and writes (see \fBread\fR(2) and
234 231 \fBwrite\fR(2)). If both \fBO_NDELAY\fR and \fBO_NONBLOCK\fR are set,
235 232 \fBO_NONBLOCK\fR takes precedence.
236 233 .sp
237 234 When opening a \fBFIFO\fR with \fBO_RDONLY\fR or \fBO_WRONLY\fR set:
238 235 .RS +4
239 236 .TP
240 237 .ie t \(bu
241 238 .el o
242 239 If \fBO_NONBLOCK\fR or \fBO_NDELAY\fR is set, an \fBopen()\fR for reading only
243 240 returns without delay. An \fBopen()\fR for writing only returns an error if no
244 241 process currently has the file open for reading.
245 242 .RE
246 243 .RS +4
247 244 .TP
248 245 .ie t \(bu
249 246 .el o
250 247 If \fBO_NONBLOCK\fR and \fBO_NDELAY\fR are clear, an \fBopen()\fR for reading
251 248 only blocks until a thread opens the file for writing. An \fBopen()\fR for
252 249 writing only blocks the calling thread until a thread opens the file for
253 250 reading.
254 251 .RE
255 252 After both ends of a \fBFIFO\fR have been opened, there is no guarantee that
256 253 further calls to \fBopen()\fR \fBO_RDONLY\fR (\fBO_WRONLY\fR) will synchronize
257 254 with later calls to \fBopen()\fR \fBO_WRONLY\fR (\fBO_RDONLY\fR) until both
258 255 ends of the \fBFIFO\fR have been closed by all readers and writers. Any data
259 256 written into a \fBFIFO\fR will be lost if both ends of the \fBFIFO\fR are
260 257 closed before the data is read.
261 258 .sp
262 259 When opening a block special or character special file that supports
263 260 non-blocking opens:
264 261 .RS +4
265 262 .TP
266 263 .ie t \(bu
267 264 .el o
268 265 If \fBO_NONBLOCK\fR or \fBO_NDELAY\fR is set, the \fBopen()\fR function returns
269 266 without blocking for the device to be ready or available. Subsequent behavior
270 267 of the device is device-specific.
271 268 .RE
272 269 .RS +4
273 270 .TP
274 271 .ie t \(bu
275 272 .el o
276 273 If \fBO_NONBLOCK\fR and \fBO_NDELAY\fR are clear, the \fBopen()\fR function
277 274 blocks the calling thread until the device is ready or available before
278 275 returning.
279 276 .RE
280 277 Otherwise, the behavior of \fBO_NONBLOCK\fR and \fBO_NDELAY\fR is unspecified.
281 278 .RE
282 279
283 280 .sp
284 281 .ne 2
285 282 .na
286 283 \fB\fBO_RSYNC\fR\fR
287 284 .ad
288 285 .sp .6
289 286 .RS 4n
290 287 Read I/O operations on the file descriptor complete at the same level of
291 288 integrity as specified by the \fBO_DSYNC\fR and \fBO_SYNC\fR flags. If both
292 289 \fBO_DSYNC\fR and \fBO_RSYNC\fR are set in \fIoflag\fR, all I/O operations on
293 290 the file descriptor complete as defined by synchronized I/O data integrity
294 291 completion. If both \fBO_SYNC\fR and \fBO_RSYNC\fR are set in \fIoflag\fR, all
295 292 I/O operations on the file descriptor complete as defined by synchronized I/O
296 293 file integrity completion.
|
↓ open down ↓ |
146 lines elided |
↑ open up ↑ |
297 294 .RE
298 295
299 296 .sp
300 297 .ne 2
301 298 .na
302 299 \fB\fBO_SYNC\fR\fR
303 300 .ad
304 301 .sp .6
305 302 .RS 4n
306 303 Write I/O operations on the file descriptor complete as defined by synchronized
307 -I/O file integrity completion.
304 +I/O file integrity completion (see \fBfcntl.h\fR(3HEAD) definition of
305 +\fBO_SYNC\fR.)
308 306 .RE
309 307
310 308 .sp
311 309 .ne 2
312 310 .na
313 311 \fB\fBO_TRUNC\fR\fR
314 312 .ad
315 313 .sp .6
316 314 .RS 4n
317 315 If the file exists and is a regular file, and the file is successfully opened
318 316 \fBO_RDWR\fR or \fBO_WRONLY\fR, its length is truncated to 0 and the mode and
319 317 owner are unchanged. It has no effect on \fBFIFO\fR special files or terminal
320 318 device files. Its effect on other file types is implementation-dependent. The
321 319 result of using \fBO_TRUNC\fR with \fBO_RDONLY\fR is undefined.
322 320 .RE
323 321
324 322 .sp
325 323 .ne 2
326 324 .na
327 325 \fB\fBO_XATTR\fR\fR
328 326 .ad
329 327 .sp .6
330 328 .RS 4n
331 329 If set in \fBopenat()\fR, a relative path argument is interpreted as a
332 330 reference to an extended attribute of the file associated with the supplied
333 331 file descriptor. This flag therefore requires the presence of a legal
334 332 \fIfildes\fR argument. If set in \fBopen()\fR, the implied file descriptor is
335 333 that for the current working directory. Extended attributes must be referenced
336 334 with a relative path; providing an absolute path results in a normal file
337 335 reference.
338 336 .RE
339 337
340 338 .sp
341 339 .LP
342 340 If \fBO_CREAT\fR is set and the file did not previously exist, upon successful
343 341 completion, \fBopen()\fR marks for update the \fBst_atime\fR, \fBst_ctime\fR,
344 342 and \fBst_mtime\fR fields of the file and the \fBst_ctime\fR and \fBst_mtime\fR
345 343 fields of the parent directory.
346 344 .sp
347 345 .LP
348 346 If \fBO_TRUNC\fR is set and the file did previously exist, upon successful
349 347 completion, \fBopen()\fR marks for update the \fBst_ctime\fR and \fBst_mtime\fR
350 348 fields of the file.
351 349 .sp
352 350 .LP
353 351 If both the \fBO_SYNC\fR and \fBO_DSYNC\fR flags are set, the effect is as if
354 352 only the \fBO_SYNC\fR flag was set.
355 353 .sp
356 354 .LP
357 355 If \fIpath\fR refers to a \fBSTREAMS\fR file, \fIoflag\fR may be constructed
358 356 from \fBO_NONBLOCK\fR or \fBO_NODELAY\fR OR-ed with either \fBO_RDONLY\fR,
359 357 \fBO_WRONLY\fR, or \fBO_RDWR\fR. Other flag values are not applicable to
360 358 \fBSTREAMS\fR devices and have no effect on them. The values \fBO_NONBLOCK\fR
361 359 and \fBO_NODELAY\fR affect the operation of \fBSTREAMS\fR drivers and certain
362 360 functions (see \fBread\fR(2), \fBgetmsg\fR(2), \fBputmsg\fR(2), and
363 361 \fBwrite\fR(2)) applied to file descriptors associated with \fBSTREAMS\fR
364 362 files. For \fBSTREAMS\fR drivers, the implementation of \fBO_NONBLOCK\fR and
365 363 \fBO_NODELAY\fR is device-specific.
366 364 .sp
367 365 .LP
368 366 When \fBopen()\fR is invoked to open a named stream, and the \fBconnld\fR
369 367 module (see \fBconnld\fR(7M)) has been pushed on the pipe, \fBopen()\fR blocks
370 368 until the server process has issued an \fBI_RECVFD\fR \fBioctl()\fR (see
371 369 \fBstreamio\fR(7I)) to receive the file descriptor.
372 370 .sp
373 371 .LP
374 372 If \fIpath\fR names the master side of a pseudo-terminal device, then it is
375 373 unspecified whether \fBopen()\fR locks the slave side so that it cannot be
376 374 opened. Portable applications must call \fBunlockpt\fR(3C) before opening the
377 375 slave side.
378 376 .sp
379 377 .LP
380 378 If the file is a regular file and the local file system is mounted with the
381 379 \fBnbmand\fR mount option, then a mandatory share reservation is automatically
382 380 obtained on the file. The share reservation is obtained as if \fBfcntl\fR(2)
383 381 were called with \fIcmd\fR \fBF_SHARE_NBMAND\fR and the \fBfshare_t\fR values
384 382 set as follows:
385 383 .sp
386 384 .ne 2
387 385 .na
388 386 \fB\fBf_access\fR\fR
389 387 .ad
390 388 .RS 12n
391 389 Set to the type of read/write access for which the file is opened.
392 390 .RE
393 391
394 392 .sp
395 393 .ne 2
396 394 .na
397 395 \fB\fBf_deny\fR\fR
398 396 .ad
399 397 .RS 12n
400 398 \fBF_NODNY\fR
401 399 .RE
402 400
403 401 .sp
404 402 .ne 2
405 403 .na
406 404 \fB\fBf_id\fR\fR
407 405 .ad
408 406 .RS 12n
409 407 The file descriptor value returned from \fBopen()\fR.
410 408 .RE
411 409
412 410 .sp
413 411 .LP
414 412 If \fIpath\fR is a symbolic link and \fBO_CREAT\fR and \fBO_EXCL\fR are set,
415 413 the link is not followed.
416 414 .sp
417 415 .LP
418 416 Certain flag values can be set following \fBopen()\fR as described in
419 417 \fBfcntl\fR(2).
420 418 .sp
421 419 .LP
422 420 The largest value that can be represented correctly in an object of type
423 421 \fBoff_t\fR is established as the offset maximum in the open file description.
424 422 .SH RETURN VALUES
425 423 .sp
426 424 .LP
427 425 Upon successful completion, the \fBopen()\fR function opens the file and return
428 426 a non-negative integer representing the lowest numbered unused file descriptor.
429 427 Otherwise, \fB\(mi1\fR is returned, \fBerrno\fR is set to indicate the error,
430 428 and no files are created or modified.
431 429 .SH ERRORS
432 430 .sp
433 431 .LP
434 432 The \fBopen()\fR and \fBopenat()\fR functions will fail if:
435 433 .sp
436 434 .ne 2
437 435 .na
438 436 \fB\fBEACCES\fR\fR
439 437 .ad
440 438 .RS 16n
441 439 Search permission is denied on a component of the path prefix.
442 440 .sp
443 441 The file exists and the permissions specified by \fIoflag\fR are denied.
444 442 .sp
445 443 The file does not exist and write permission is denied for the parent directory
446 444 of the file to be created.
447 445 .sp
448 446 \fBO_TRUNC\fR is specified and write permission is denied.
449 447 .sp
450 448 The {\fBPRIV_FILE_DAC_SEARCH\fR} privilege allows processes to search
451 449 directories regardless of permission bits. The {\fBPRIV_FILE_DAC_WRITE\fR}
452 450 privilege allows processes to open files for writing regardless of permission
453 451 bits. See \fBprivileges\fR(5) for special considerations when opening files
454 452 owned by UID 0 for writing. The {\fBPRIV_FILE_DAC_READ\fR} privilege allows
455 453 processes to open files for reading regardless of permission bits.
456 454 .RE
457 455
458 456 .sp
459 457 .ne 2
460 458 .na
461 459 \fB\fBEAGAIN\fR\fR
462 460 .ad
463 461 .RS 16n
464 462 A mandatory share reservation could not be obtained because the desired access
465 463 conflicts with an existing \fBf_deny\fR share reservation.
466 464 .RE
467 465
468 466 .sp
469 467 .ne 2
470 468 .na
471 469 \fB\fBEBADF\fR\fR
472 470 .ad
473 471 .RS 16n
474 472 The file descriptor provided to \fBopenat()\fR is invalid.
475 473 .RE
476 474
477 475 .sp
478 476 .ne 2
479 477 .na
480 478 \fB\fBEDQUOT\fR\fR
481 479 .ad
482 480 .RS 16n
483 481 The file does not exist, \fBO_CREAT\fR is specified, and either the directory
484 482 where the new file entry is being placed cannot be extended because the user's
485 483 quota of disk blocks on that file system has been exhausted, or the user's
486 484 quota of inodes on the file system where the file is being created has been
487 485 exhausted.
488 486 .RE
489 487
490 488 .sp
491 489 .ne 2
492 490 .na
493 491 \fB\fBEEXIST\fR\fR
494 492 .ad
495 493 .RS 16n
496 494 The \fBO_CREAT\fR and \fBO_EXCL\fR flags are set and the named file exists.
497 495 .RE
498 496
499 497 .sp
500 498 .ne 2
501 499 .na
502 500 \fB\fBEILSEQ\fR\fR
503 501 .ad
504 502 .RS 16n
505 503 The \fIpath\fR argument includes non-UTF8 characters and the file system
506 504 accepts only file names where all characters are part of the UTF-8 character
507 505 codeset.
508 506 .RE
509 507
510 508 .sp
511 509 .ne 2
512 510 .na
513 511 \fB\fBEINTR\fR\fR
514 512 .ad
515 513 .RS 16n
516 514 A signal was caught during \fBopen()\fR.
517 515 .RE
518 516
519 517 .sp
520 518 .ne 2
521 519 .na
522 520 \fB\fBEFAULT\fR\fR
523 521 .ad
524 522 .RS 16n
525 523 The \fIpath\fR argument points to an illegal address.
526 524 .RE
527 525
528 526 .sp
529 527 .ne 2
530 528 .na
531 529 \fB\fBEINVAL\fR\fR
532 530 .ad
533 531 .RS 16n
534 532 The system does not support synchronized I/O for this file, or the
535 533 \fBO_XATTR\fR flag was supplied and the underlying file system does not support
536 534 extended file attributes.
537 535 .RE
538 536
539 537 .sp
540 538 .ne 2
541 539 .na
542 540 \fB\fBEIO\fR\fR
543 541 .ad
544 542 .RS 16n
545 543 The \fIpath\fR argument names a \fBSTREAMS\fR file and a hangup or error
546 544 occurred during the \fBopen()\fR.
547 545 .RE
548 546
549 547 .sp
550 548 .ne 2
551 549 .na
552 550 \fB\fBEISDIR\fR\fR
553 551 .ad
554 552 .RS 16n
555 553 The named file is a directory and \fIoflag\fR includes \fBO_WRONLY\fR or
556 554 \fBO_RDWR\fR.
557 555 .RE
558 556
559 557 .sp
560 558 .ne 2
561 559 .na
562 560 \fB\fBELOOP\fR\fR
563 561 .ad
564 562 .RS 16n
565 563 Too many symbolic links were encountered in resolving \fIpath\fR.
566 564 .sp
567 565 A loop exists in symbolic links encountered during resolution of the \fIpath\fR
568 566 argument.
569 567 .sp
570 568 The \fBO_NOFOLLOW\fR flag is set and the final component of path is a symbolic
571 569 link.
572 570 .RE
573 571
574 572 .sp
575 573 .ne 2
576 574 .na
577 575 \fB\fBEMFILE\fR\fR
578 576 .ad
579 577 .RS 16n
580 578 There are currently {\fBOPEN_MAX\fR} file descriptors open in the calling
581 579 process.
582 580 .RE
583 581
584 582 .sp
585 583 .ne 2
586 584 .na
587 585 \fB\fBEMLINK\fR\fR
588 586 .ad
589 587 .RS 16n
590 588 The \fBO_NOLINKS\fR flag is set and the named file has a link count greater
591 589 than 1.
592 590 .RE
593 591
594 592 .sp
595 593 .ne 2
596 594 .na
597 595 \fB\fBEMULTIHOP\fR\fR
598 596 .ad
599 597 .RS 16n
600 598 Components of \fIpath\fR require hopping to multiple remote machines and the
601 599 file system does not allow it.
602 600 .RE
603 601
604 602 .sp
605 603 .ne 2
606 604 .na
607 605 \fB\fBENAMETOOLONG\fR\fR
608 606 .ad
609 607 .RS 16n
610 608 The length of the \fIpath\fR argument exceeds {\fBPATH_MAX\fR} or a pathname
611 609 component is longer than {\fBNAME_MAX\fR}.
612 610 .RE
613 611
614 612 .sp
615 613 .ne 2
616 614 .na
617 615 \fB\fBENFILE\fR\fR
618 616 .ad
619 617 .RS 16n
620 618 The maximum allowable number of files is currently open in the system.
621 619 .RE
622 620
623 621 .sp
624 622 .ne 2
625 623 .na
626 624 \fB\fBENOENT\fR\fR
627 625 .ad
628 626 .RS 16n
629 627 The \fBO_CREAT\fR flag is not set and the named file does not exist; or the
630 628 \fBO_CREAT\fR flag is set and either the path prefix does not exist or the
631 629 \fIpath\fR argument points to an empty string.
632 630 .RE
633 631
634 632 .sp
635 633 .ne 2
636 634 .na
637 635 \fB\fBENOLINK\fR\fR
638 636 .ad
639 637 .RS 16n
640 638 The \fIpath\fR argument points to a remote machine, and the link to that
641 639 machine is no longer active.
642 640 .RE
643 641
644 642 .sp
645 643 .ne 2
646 644 .na
647 645 \fB\fBENOSR\fR\fR
648 646 .ad
649 647 .RS 16n
650 648 The \fIpath\fR argument names a STREAMS-based file and the system is unable to
651 649 allocate a STREAM.
652 650 .RE
653 651
654 652 .sp
655 653 .ne 2
656 654 .na
657 655 \fB\fBENOSPC\fR\fR
658 656 .ad
659 657 .RS 16n
660 658 The directory or file system that would contain the new file cannot be
661 659 expanded, the file does not exist, and \fBO_CREAT\fR is specified.
662 660 .RE
663 661
664 662 .sp
665 663 .ne 2
666 664 .na
667 665 \fB\fBENOSYS\fR\fR
668 666 .ad
669 667 .RS 16n
670 668 The device specified by \fIpath\fR does not support the open operation.
671 669 .RE
672 670
673 671 .sp
674 672 .ne 2
675 673 .na
676 674 \fB\fBENOTDIR\fR\fR
677 675 .ad
678 676 .RS 16n
679 677 A component of the path prefix is not a directory or a relative path was
680 678 supplied to \fBopenat()\fR, the \fBO_XATTR\fR flag was not supplied, and the
681 679 file descriptor does not refer to a directory.
682 680 .RE
683 681
684 682 .sp
685 683 .ne 2
686 684 .na
687 685 \fB\fBENXIO\fR\fR
688 686 .ad
689 687 .RS 16n
690 688 The \fBO_NONBLOCK\fR flag is set, the named file is a FIFO, the \fBO_WRONLY\fR
691 689 flag is set, and no process has the file open for reading; or the named file is
692 690 a character special or block special file and the device associated with this
693 691 special file does not exist or has been retired by the fault management
694 692 framework .
695 693 .RE
696 694
697 695 .sp
698 696 .ne 2
699 697 .na
700 698 \fB\fBEOPNOTSUPP\fR\fR
701 699 .ad
702 700 .RS 16n
703 701 An attempt was made to open a path that corresponds to a \fBAF_UNIX\fR socket.
704 702 .RE
705 703
706 704 .sp
707 705 .ne 2
708 706 .na
709 707 \fB\fBEOVERFLOW\fR\fR
710 708 .ad
711 709 .RS 16n
712 710 The named file is a regular file and either \fBO_LARGEFILE\fR is not set and
713 711 the size of the file cannot be represented correctly in an object of type
714 712 \fBoff_t\fR or \fBO_LARGEFILE\fR is set and the size of the file cannot be
715 713 represented correctly in an object of type \fBoff64_t\fR.
716 714 .RE
717 715
718 716 .sp
719 717 .ne 2
720 718 .na
721 719 \fB\fBEROFS\fR\fR
722 720 .ad
723 721 .RS 16n
724 722 The named file resides on a read-only file system and either \fBO_WRONLY\fR,
725 723 \fBO_RDWR\fR, \fBO_CREAT\fR (if file does not exist), or \fBO_TRUNC\fR is set
726 724 in the \fIoflag\fR argument.
727 725 .RE
728 726
729 727 .sp
730 728 .LP
731 729 The \fBopenat()\fR function will fail if:
732 730 .sp
733 731 .ne 2
734 732 .na
735 733 \fB\fBEBADF\fR\fR
736 734 .ad
737 735 .RS 9n
738 736 The \fIfildes\fR argument is not a valid open file descriptor or is not
739 737 \fBAT_FTCWD\fR.
740 738 .RE
741 739
742 740 .sp
743 741 .LP
744 742 The \fBopen()\fR function may fail if:
745 743 .sp
746 744 .ne 2
747 745 .na
748 746 \fB\fBEAGAIN\fR\fR
749 747 .ad
750 748 .RS 16n
751 749 The \fIpath\fR argument names the slave side of a pseudo-terminal device that
752 750 is locked.
753 751 .RE
754 752
755 753 .sp
756 754 .ne 2
757 755 .na
758 756 \fB\fBEINVAL\fR\fR
759 757 .ad
760 758 .RS 16n
761 759 The value of the \fIoflag\fR argument is not valid.
762 760 .RE
763 761
764 762 .sp
765 763 .ne 2
766 764 .na
767 765 \fB\fBENAMETOOLONG\fR\fR
768 766 .ad
769 767 .RS 16n
770 768 Pathname resolution of a symbolic link produced an intermediate result whose
771 769 length exceeds {\fBPATH_MAX\fR}.
772 770 .RE
773 771
774 772 .sp
775 773 .ne 2
776 774 .na
777 775 \fB\fBENOMEM\fR\fR
778 776 .ad
779 777 .RS 16n
780 778 The \fIpath\fR argument names a \fBSTREAMS\fR file and the system is unable to
781 779 allocate resources.
782 780 .RE
783 781
784 782 .sp
785 783 .ne 2
786 784 .na
787 785 \fB\fBETXTBSY\fR\fR
788 786 .ad
789 787 .RS 16n
790 788 The file is a pure procedure (shared text) file that is being executed and
791 789 \fIoflag\fR is \fBO_WRONLY\fR or \fBO_RDWR\fR.
792 790 .RE
793 791
794 792 .SH EXAMPLES
795 793 .LP
796 794 \fBExample 1 \fROpen a file for writing by the owner.
797 795 .sp
798 796 .LP
799 797 The following example opens the file \fB/tmp/file\fR, either by creating it if
800 798 it does not already exist, or by truncating its length to 0 if it does exist.
801 799 If the call creates a new file, the access permission bits in the file mode of
802 800 the file are set to permit reading and writing by the owner, and to permit
803 801 reading only by group members and others.
804 802
805 803 .sp
806 804 .LP
807 805 If the call to \fBopen()\fR is successful, the file is opened for writing.
808 806
809 807 .sp
810 808 .in +2
811 809 .nf
812 810 #include <fcntl.h>
813 811 \&...
814 812 int fd;
815 813 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
816 814 char *filename = "/tmp/file";
817 815 \&...
818 816 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, mode);
819 817 \&...
820 818 .fi
821 819 .in -2
822 820
823 821 .LP
824 822 \fBExample 2 \fROpen a file using an existence check.
825 823 .sp
826 824 .LP
827 825 The following example uses the \fBopen()\fR function to try to create the
828 826 \fBLOCKFILE\fR file and open it for writing. Since the \fBopen()\fR function
829 827 specifies the \fBO_EXCL\fR flag, the call fails if the file already exists. In
830 828 that case, the application assumes that someone else is updating the password
831 829 file and exits.
832 830
833 831 .sp
834 832 .in +2
835 833 .nf
836 834 #include <fcntl.h>
837 835 #include <stdio.h>
838 836 #include <stdlib.h>
839 837 #define LOCKFILE "/etc/ptmp"
840 838 \&...
841 839 int pfd; /* Integer for file descriptor returned by open() call. */
842 840 \&...
843 841 if ((pfd = open(LOCKFILE, O_WRONLY | O_CREAT | O_EXCL,
844 842 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
845 843 {
846 844 fprintf(stderr, "Cannot open /etc/ptmp. Try again later.\en");
847 845 exit(1);
848 846 }
849 847 \&...
850 848 .fi
851 849 .in -2
852 850
853 851 .LP
854 852 \fBExample 3 \fROpen a file for writing.
855 853 .sp
856 854 .LP
857 855 The following example opens a file for writing, creating the file if it does
858 856 not already exist. If the file does exist, the system truncates the file to
859 857 zero bytes.
860 858
861 859 .sp
862 860 .in +2
863 861 .nf
864 862 #include <fcntl.h>
865 863 #include <stdio.h>
866 864 #include <stdlib.h>
867 865 #define LOCKFILE "/etc/ptmp"
868 866 \&...
869 867 int pfd;
870 868 char filename[PATH_MAX+1];
871 869 \&...
872 870 if ((pfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC,
873 871 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
874 872 {
875 873 perror("Cannot open output file\en"); exit(1);
876 874 }
877 875 \&...
878 876 .fi
879 877 .in -2
880 878
881 879 .SH USAGE
882 880 .sp
883 881 .LP
884 882 The \fBopen()\fR function has a transitional interface for 64-bit file offsets.
885 883 See \fBlf64\fR(5). Note that using \fBopen64()\fR is equivalent to using
886 884 \fBopen()\fR with \fBO_LARGEFILE\fR set in \fIoflag\fR.
887 885 .SH ATTRIBUTES
888 886 .sp
889 887 .LP
890 888 See \fBattributes\fR(5) for descriptions of the following attributes:
891 889 .sp
892 890
893 891 .sp
894 892 .TS
895 893 box;
896 894 c | c
897 895 l | l .
898 896 ATTRIBUTE TYPE ATTRIBUTE VALUE
899 897 _
900 898 Interface Stability Committed
901 899 _
902 900 MT-Level Async-Signal-Safe
903 901 _
904 902 Standard For \fBopen()\fR, see \fBstandards\fR(5).
905 903 .TE
906 904
907 905 .SH SEE ALSO
908 906 .sp
909 907 .LP
910 908 \fBIntro\fR(2), \fBchmod\fR(2), \fBclose\fR(2), \fBcreat\fR(2), \fBdup\fR(2),
911 909 \fBexec\fR(2), \fBfcntl\fR(2), \fBgetmsg\fR(2), \fBgetrlimit\fR(2),
912 910 \fBlseek\fR(2), \fBputmsg\fR(2), \fBread\fR(2), \fBstat\fR(2), \fBumask\fR(2),
913 911 \fBwrite\fR(2), \fBattropen\fR(3C), \fBfcntl.h\fR(3HEAD), \fBstat.h\fR(3HEAD),
914 912 \fBunlockpt\fR(3C), \fBattributes\fR(5), \fBlf64\fR(5), \fBprivileges\fR(5),
915 913 \fBstandards\fR(5), \fBconnld\fR(7M), \fBstreamio\fR(7I)
916 914 .SH NOTES
917 915 .sp
918 916 .LP
919 917 Hierarchical Storage Management (HSM) file systems can sometimes cause long
920 918 delays when opening a file, since HSM files must be recalled from secondary
921 919 storage.
|
↓ open down ↓ |
604 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX