xref: /illumos-gate/usr/src/man/man2/open.2 (revision aaceae985c2e78cadef76bf0b7b50ed887ccb3a6)
1.\"
2.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3.\" permission to reproduce portions of its copyrighted documentation.
4.\" Original documentation from The Open Group can be obtained online at
5.\" http://www.opengroup.org/bookstore/.
6.\"
7.\" The Institute of Electrical and Electronics Engineers and The Open
8.\" Group, have given us permission to reprint portions of their
9.\" documentation.
10.\"
11.\" In the following statement, the phrase ``this text'' refers to portions
12.\" of the system documentation.
13.\"
14.\" Portions of this text are reprinted and reproduced in electronic form
15.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16.\" Standard for Information Technology -- Portable Operating System
17.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20.\" between these versions and the original IEEE and The Open Group
21.\" Standard, the original IEEE and The Open Group Standard is the referee
22.\" document.  The original Standard can be obtained online at
23.\" http://www.opengroup.org/unix/online.html.
24.\"
25.\" This notice shall appear on any product containing this material.
26.\"
27.\" The contents of this file are subject to the terms of the
28.\" Common Development and Distribution License (the "License").
29.\" You may not use this file except in compliance with the License.
30.\"
31.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32.\" or http://www.opensolaris.org/os/licensing.
33.\" See the License for the specific language governing permissions
34.\" and limitations under the License.
35.\"
36.\" When distributing Covered Code, include this CDDL HEADER in each
37.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38.\" If applicable, add the following below this CDDL HEADER, with the
39.\" fields enclosed by brackets "[]" replaced with your own identifying
40.\" information: Portions Copyright [yyyy] [name of copyright owner]
41.\"
42.\"
43.\" Copyright 1989 AT&T
44.\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
45.\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
46.\" Portions Copyright (c) 2013, OmniTI Computer Consulting, Inc.
47.\" All Rights Reserved.
48.\" Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
49.\" Copyright 2020 Joyent, Inc.
50.\" Copyright 2024 Oxide Computer Company
51.\"
52.Dd February 5, 2024
53.Dt OPEN 2
54.Os
55.Sh NAME
56.Nm open ,
57.Nm openat
58.Nd open a file
59.Sh SYNOPSIS
60.In sys/types.h
61.In sys/stat.h
62.In fcntl.h
63.Ft int
64.Fo open
65.Fa "const char *path"
66.Fa "int oflag"
67.Op , Fa "mode_t mode"
68.Fc
69.Ft int
70.Fo openat
71.Fa "int fildes"
72.Fa "const char *path"
73.Fa "int oflag"
74.Op , Fa "mode_t mode"
75.Fc
76.Sh DESCRIPTION
77The
78.Fn open
79function establishes the connection between a file and a file descriptor.
80It creates an open file description that refers to a file and a file descriptor
81that refers to that open file description.
82The file descriptor is used by other I/O functions to refer to that file.
83The
84.Fa path
85argument points to a pathname naming the file.
86.Pp
87The
88.Fn openat
89function is identical to the
90.Fn open
91function except
92that the
93.Fa path
94argument is interpreted relative to the starting point
95implied by the
96.Fa fildes
97argument.
98If the
99.Fa fildes
100argument has the special value
101.Dv AT_FDCWD ,
102a relative path argument will be resolved relative to the current working
103directory.
104If the
105.Fa path
106argument is absolute, the
107.Fa fildes
108argument is ignored.
109.Pp
110The
111.Fn open
112function returns a file descriptor for the named file that is the lowest file
113descriptor not currently open for that process.
114The open file description is new, and therefore the file descriptor does not
115share it with any other process in the system.
116.Pp
117The file offset used to mark the current position within the file is set to the
118beginning of the file.
119.Pp
120The file status flags and file access modes of the open file description are
121set according to the value of
122.Fa oflag .
123The
124.Fa mode
125argument is used only
126when
127.Dv O_CREAT
128is specified
129.Pq "see below" .
130.Pp
131Values for
132.Fa oflag
133are constructed by a bitwise-inclusive-OR of flags from
134the following list, defined in
135.Xr fcntl.h 3HEAD .
136Applications must specify exactly one of the first three values (file access
137modes) below in the value of
138.Fa oflag :
139.Bl -tag -width Ds
140.It Dv O_RDONLY
141Open for reading only.
142.It Dv O_WRONLY
143Open for writing only.
144.It Dv O_RDWR
145Open for reading and writing.
146The result is undefined if this flag is applied to a FIFO.
147.El
148.Pp
149Any combination of the following may be used:
150.Bl -tag -width Ds
151.It Dv O_APPEND
152If set, the file offset is set to the end of the file prior to each write.
153.It Dv O_CREAT
154Create the file if it does not exist.
155This flag requires that the
156.Fa mode
157argument be specified.
158.Pp
159If the file exists, this flag has no effect except as noted under
160.Dv O_EXCL
161below.
162Otherwise, the file is created with the user ID of the file set to the
163effective user ID of the process.
164The group ID of the file is set to the effective group IDs of the process, or
165if the
166.Dv S_ISGID
167bit is set in the directory in which the file is being created, the file's
168group ID is set to the group ID of its parent directory.
169If the group ID of the new file does not match the effective group
170ID or one of the supplementary groups IDs, the
171.Dv S_ISGID bit is cleared.
172.Pp
173The access permission bits
174.Po
175see
176.Xr stat.h 3HEAD
177.Pc
178of the file mode are set to the value of
179.Fa mode ,
180modified as follows
181.Po
182see
183.Xr creat 2
184.Pc :
185a bitwise-AND is performed on the file-mode bits and the corresponding bits in
186the complement of the process's file mode creation mask.
187Thus, all bits set in the process's file mode creation mask
188.Po
189see
190.Xr umask 2
191.Pc
192are correspondingly cleared in the file's permission mask.
193The
194.Dq save text image after execution bit
195of the mode is cleared
196.Po
197see
198.Xr chmod 2
199.Pc .
200When bits other than the file permission bits are set, the effect is
201unspecified.
202The
203.Fa mode
204argument does not affect whether the file is open for reading, writing or for
205both.
206.It Dv O_DIRECT
207Indicates that the file data is not going to be reused in the near future.
208When possible, data is read or written directly between the application's
209memory and the device when the data is accessed with
210.Xr read 2
211and
212.Xr write 2
213operations.
214See
215.Xr directio 3C
216for more details.
217.It Dv O_DIRECTORY
218Indicates that attempts to open
219.Fa path
220should fail unless
221.Fa path
222is a directory.
223If both
224.Dv O_CREAT
225and
226.Dv O_DIRECTORY
227are specified then the call will fail if it would result in a file being
228created.
229If a directory already exists at
230.Fa path
231then it will behave as if the
232.Dv O_DIRECTORY
233flag had not been present.
234If the
235.Dv O_EXCL
236and
237.Dv O_CREAT
238flags are specified, then the call will always fail as they imply a file should
239always be created.
240.It Dv O_DSYNC
241Write I/O operations on the file descriptor complete as defined by synchronized
242I/O data integrity completion.
243.It Dv O_EXCL
244If
245.Dv O_CREAT
246and
247.Dv O_EXCL
248are set,
249.Fn open
250fails if the file exists.
251The check for the existence of the file and the creation of the file if
252it does not exist is atomic with respect to other threads executing
253.Fn open
254naming the same filename in the same directory with
255.Dv O_EXCL
256and
257.Dv O_CREAT
258set.
259If
260.Dv O_EXCL
261and
262.Dv O_CREAT
263are set, and
264.Fa path
265names a symbolic link,
266.Fn open
267fails and sets
268.Va errno
269to
270.Er EEXIST ,
271regardless of the contents of the symbolic link.
272If
273.Dv O_EXCL
274is set and
275.Dv O_CREAT
276is not set, the result is undefined.
277.It Dv O_EXEC
278If set, indicates that the file should be opened for execute permission.
279This option is only valid for regular files; an error will be returned if the
280target is not a regular file.
281.It Dv O_LARGEFILE
282If set, the offset maximum in the open file description is the largest value
283that can be represented correctly in an object of type
284.Vt off64_t .
285.It Dv O_NOCTTY
286If set and
287.Fa path
288identifies a terminal device,
289.Fn open
290does not cause the terminal device to become the controlling terminal for the
291process.
292.It Dv O_NOFOLLOW
293If the path names a symbolic link,
294.Fn open
295fails and sets
296.Va errno
297to
298.Er ELOOP .
299.It Dv O_NOLINKS
300If the link count of the named file is greater than
301.Sy 1 ,
302.Fn open
303fails and sets
304.Va errno
305to
306.Er EMLINK .
307.It Dv O_CLOEXEC
308If set, the file descriptor returned will be closed prior to any future
309.Xr exec 2
310calls.
311This sets the
312.Dv FD_CLOEXEC
313flag on the file descriptor.
314If not performed at open time, this can later be set with the
315.Dv F_SETFD
316.Xr fcntl 2
317command.
318.It Dv O_CLOFORK
319If set, the file descriptor returned will be closed in any child processses
320created with the
321.Xr fork 2
322family of functions.
323The file descriptor will remain open in the parent.
324This sets the
325.Dv FD_CLOFORK
326flag on the file descriptor.
327If not performed at open time, this can later be set with the
328.Dv F_SETFD
329.Xr fcntl 2
330command.
331.It Dv O_NONBLOCK O_NDELAY
332These flags can affect subsequent reads and writes
333.Po
334see
335.Xr read 2
336and
337.Xr write 2
338.Pc .
339If both
340.Dv O_NDELAY
341and
342.Dv O_NONBLOCK
343are set,
344.Dv O_NONBLOCK
345takes precedence.
346.Pp
347When opening a FIFO with
348.Dv O_RDONLY
349or
350.Dv O_WRONLY
351set:
352.Bl -bullet
353.It
354If
355.Dv O_NONBLOCK
356or
357.Dv O_NDELAY
358is set, an
359.Fn open
360for reading only returns without delay.
361An
362.Fn open
363for writing only returns an error if no process currently has the file open for
364reading.
365.It
366If
367.Dv O_NONBLOCK
368and
369.Dv O_NDELAY
370are clear, an
371.Fn open
372for reading only blocks until a thread opens the file for writing.
373An
374.Fn open
375for writing only blocks the calling thread until a thread opens the file for
376reading.
377.El
378.Pp
379After both ends of a FIFO have been opened once, there is no guarantee that
380further calls to
381.Fn open
382.Dv O_RDONLY
383.Pq Dv O_WRONLY
384will synchronize with later calls to
385.Fn open
386.Dv O_WRONLY
387.Pq Dv O_RDONLY
388until both ends of the FIFO have been closed by all readers and writers.
389Any data written into a FIFO will be lost if both ends of the FIFO are closed
390before the data is read.
391.Pp
392When opening a block special or character special file that supports
393non-blocking opens:
394.Bl -bullet
395.It
396If
397.Dv O_NONBLOCK
398or
399.Dv O_NDELAY
400is set, the
401.Fn open
402function returns without blocking for the device to be ready or available.
403Subsequent behavior of the device is device-specific.
404.It
405If
406.Dv O_NONBLOCK
407and
408.Dv O_NDELAY
409are clear, the
410.Fn open
411function blocks the calling thread until the device is ready or available
412before returning.
413.El
414.Pp
415Otherwise, the behavior of
416.Dv O_NONBLOCK
417and
418.Dv O_NDELAY
419is unspecified.
420.It Dv O_RSYNC
421Read I/O operations on the file descriptor complete at the same level of
422integrity as specified by the
423.Dv O_DSYNC
424and
425.Dv O_SYNC
426flags.
427If both
428.Dv O_DSYNC
429and
430.Dv O_RSYNC
431are set in
432.Fa oflag ,
433all I/O operations on the file descriptor complete as defined by synchronized
434I/O data integrity completion.
435If both
436.Dv O_SYNC
437and
438.Dv O_RSYNC
439are set in
440.Fa oflag ,
441all I/O operations on the file descriptor complete as defined by synchronized
442I/O file integrity completion.
443.It Dv O_SEARCH
444If set, indicates that the directory should be opened for searching.
445This option is only valid for a directory; an error will be returned if the
446target is not a directory.
447.It Dv O_SYNC
448Write I/O operations on the file descriptor complete as defined by synchronized
449I/O file integrity completion
450.Po
451see
452.Xr fcntl.h 3HEAD
453.Pc
454definition of
455.Dv O_SYNC .
456.It Dv O_TRUNC
457If the file exists and is a regular file, and the file is successfully opened
458.Dv O_RDWR
459or
460.Dv O_WRONLY ,
461its length is truncated to
462.Sy 0
463and the mode and owner are unchanged.
464It has no effect on FIFO special files or terminal device files.
465Its effect on other file types is implementation-dependent.
466The result of using
467.Dv O_TRUNC
468with
469.Dv O_RDONLY
470is undefined.
471.It Dv O_XATTR
472If set in
473.Fn openat ,
474a relative path argument is interpreted as a reference to an extended attribute
475of the file associated with the supplied file descriptor.
476This flag therefore requires the presence of a legal
477.Fa fildes
478argument.
479If set in
480.Fn open ,
481the implied file descriptor is that for the current working directory.
482Extended attributes must be referenced with a relative path; providing an
483absolute path results in a normal file reference.
484.El
485.Pp
486If
487.Dv O_CREAT
488is set and the file did not previously exist, upon successful completion,
489.Fn open
490marks for update the
491.Fa st_atime ,
492.Fa st_ctime ,
493and
494.Fa st_mtime
495fields of the file and the
496.Fa st_ctime
497and
498.Fa st_mtime
499fields of the parent directory.
500.Pp
501If
502.Dv O_TRUNC
503is set and the file did previously exist, upon successful completion,
504.Fn open
505marks for update the
506.Fa st_ctime
507and
508.Fa st_mtime
509fields of the file.
510.Pp
511If both the
512.Dv O_SYNC
513and
514.Dv O_DSYNC
515flags are set, the effect is as if only the
516.Dv O_SYNC
517flag was set.
518.Pp
519If
520.Fa path
521refers to a STREAMS file,
522.Fa oflag
523may be constructed from
524.Dv O_NONBLOCK
525or
526.Dv O_NODELAY
527OR-ed with either
528.Dv O_RDONLY ,
529.Dv O_WRONLY ,
530or
531.Dv O_RDWR .
532Other flag values are not applicable to STREAMS devices and have no effect on
533them.
534The values
535.Dv O_NONBLOCK
536and
537.Dv O_NODELAY
538affect the operation of STREAMS drivers and certain functions
539.Po
540see
541.Xr read 2 ,
542.Xr getmsg 2 ,
543.Xr putmsg 2 ,
544and
545.Xr write 2
546.Pc
547applied to file descriptors associated with STREAMS files.
548For STREAMS drivers, the implementation of
549.Dv O_NONBLOCK
550and
551.Dv O_NODELAY
552is device-specific.
553.Pp
554When
555.Fn open
556is invoked to open a named stream, and the
557.Xr connld 4M
558module has been pushed on the pipe,
559.Fn open
560blocks until the server process has issued an
561.Dv I_RECVFD
562.Xr ioctl 2
563.Po
564see
565.Xr streamio 4I
566.Pc
567to receive the file descriptor.
568.Pp
569If
570.Fa path
571names the manager side of a pseudo-terminal device, then it is unspecified
572whether
573.Fn open
574locks the subsidiary side so that it cannot be opened.
575Portable applications must call
576.Xr unlockpt 3C
577before opening the subsidiary side.
578.Pp
579If the file is a regular file and the local file system is mounted with the
580.Cm nbmand
581mount option, then a mandatory share reservation is automatically obtained on
582the file.
583The share reservation is obtained as if
584.Xr fcntl 2
585were called with
586.Fa cmd
587.Dv F_SHARE_NBMAND
588and the
589.Vt fshare_t
590values set as follows:
591.Bl -tag -width Ds -offset Ds
592.It Fa f_access
593Set to the type of read/write access for which the file is opened.
594.It Fa f_deny
595.Dv F_NODNY
596.It Fa f_id
597The file descriptor value returned from
598.Fn open .
599.El
600.Pp
601If
602.Fa path
603is a symbolic link and
604.Dv O_CREAT
605and
606.Dv O_EXCL
607are set, the link is not followed.
608.Pp
609Certain flag values can be set following
610.Fn open
611as described in
612.Xr fcntl 2 .
613.Pp
614The largest value that can be represented correctly in an object of type
615.Vt off_t
616is established as the offset maximum in the open file description.
617.Sh RETURN VALUES
618The
619.Fn open
620and
621.Fn openat
622functions open the file and, if successful, return a non-negative integer
623representing the lowest numbered unused file descriptor; otherwise the
624value
625.Sy -1
626is returned and the global variable
627.Va errno
628is set to indicate the error and no files are created or modified.
629.Sh EXAMPLES
630.Sy Example 1
631Open a file for writing by the owner.
632.Pp
633The following example opens the file
634.Pa /tmp/file ,
635either by creating it if it does not already exist, or by truncating its length
636to
637.Sy 0
638if it does exist.
639If the call creates a new file, the access permission bits in the file mode of
640the file are set to permit reading and writing by the owner, and to permit
641reading only by group members and others.
642.Pp
643If the call to
644.Fn open
645is successful, the file is opened for writing.
646.Bd -literal -offset Ds
647#include <fcntl.h>
648\&...
649int fd;
650mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
651char *filename = "/tmp/file";
652\&...
653fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, mode);
654\&...
655.Ed
656.Pp
657.Sy Example 2
658Open a file using an existence check.
659.Pp
660The following example uses the
661.Fn open
662function to try to create the
663.Dv LOCKFILE
664file and open it for writing.
665Since the
666.Fn open
667function specifies the
668.Dv O_EXCL
669flag, the call fails if the file already exists.
670In that case, the application assumes that someone else is updating the
671password file and exits.
672.Bd -literal -offset Ds
673#include <fcntl.h>
674#include <stdio.h>
675#include <stdlib.h>
676#include <err.h>
677\&...
678#define LOCKFILE "/etc/ptmp"
679\&...
680int pfd; /* Integer for file descriptor returned by open() call. */
681\&...
682if ((pfd = open(LOCKFILE, O_WRONLY | O_CREAT | O_EXCL,
683    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
684        err(1, "Cannot open %s. Try again later.", LOCKFILE);
685}
686\&...
687.Ed
688.Pp
689.Sy Example 3
690Open a file for writing.
691.Pp
692The following example opens a file for writing, creating the file if it does
693not already exist.
694If the file does exist, the system truncates the file to zero bytes.
695.Bd -literal -offset Ds
696#include <fcntl.h>
697#include <stdio.h>
698#include <stdlib.h>
699#include <err.h>
700\&...
701int pfd;
702char filename[PATH_MAX+1];
703\&...
704if ((pfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC,
705    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
706        err(1, "Cannot open output file");
707}
708\&...
709.Ed
710.Sh ERRORS
711The
712.Fn open
713and
714.Fn openat
715functions will fail if:
716.Bl -tag -width Er
717.It Er EACCES
718Search permission is denied on a component of the path prefix.
719.Pp
720The file exists and the permissions specified by
721.Fa oflag
722are denied.
723.Pp
724The file does not exist and write permission is denied for the parent directory
725of the file to be created.
726.Pp
727.Dv O_TRUNC
728is specified and write permission is denied.
729.Pp
730The
731.Brq Dv PRIV_FILE_DAC_SEARCH
732privilege allows processes to search directories regardless of permission bits.
733The
734.Brq Dv PRIV_FILE_DAC_WRITE
735privilege allows processes to open files for writing regardless of permission
736bits.
737See
738.Xr privileges 7
739for special considerations when opening files owned by user ID
740.Sy 0
741for writing.
742The
743.Brq Dv PRIV_FILE_DAC_READ
744privilege allows
745processes to open files for reading regardless of permission bits.
746.It Er EAGAIN
747A mandatory share reservation could not be obtained because the desired access
748conflicts with an existing
749.Fa f_deny
750share reservation
751.Po
752see
753.Xr fcntl 2
754.Pc .
755.It Er EDQUOT
756The file does not exist,
757.Dv O_CREAT
758is specified, and either the directory where the new file entry is being placed
759cannot be extended because the user's quota of disk blocks on that file system
760has been exhausted, or the user's quota of inodes on the file system where the
761file is being created has been exhausted.
762.It Er EEXIST
763The
764.Dv O_CREAT
765and
766.Dv O_EXCL
767flags are set and the named file already exists.
768.It Er EILSEQ
769The
770.Fa path
771argument includes bytes that are not valid UTF-8 characters, and the file
772system accepts only file names where all characters are part of the UTF-8
773character codeset.
774.It Er EINTR
775A signal was caught during
776.Fn open .
777.It Er EFAULT
778The
779.Fa path
780argument points to an illegal address.
781.It Er EINVAL
782Either the system does not support synchronized or direct I/O for this file, or
783the
784.Dv O_XATTR
785flag was supplied and the underlying file system does not support extended file
786attributes.
787.It Er EIO
788The
789.Fa path
790argument names a STREAMS file and a hangup or error occurred during the
791.Fn open .
792.It Er EISDIR
793The named file is a directory and
794.Fa oflag
795includes
796.Dv O_WRONLY
797or
798.Dv O_RDWR .
799.It Er ELOOP
800Too many symbolic links were encountered in resolving
801.Fa path .
802.Pp
803A loop exists in symbolic links encountered during resolution of the
804.Fa path
805argument.
806.Pp
807The
808.Dv O_NOFOLLOW
809flag is set and the final component of path is a symbolic link.
810.It Er EMFILE
811There are currently
812.Brq Dv OPEN_MAX
813file descriptors open in the calling process.
814.It Er EMLINK
815The
816.Dv O_NOLINKS
817flag is set and the named file has a link count greater than
818.Sy 1 .
819.It Er EMULTIHOP
820Components of
821.Fa path
822require hopping to multiple remote machines and the file system does not allow
823it.
824.It Er ENAMETOOLONG
825The length of the
826.Fa path
827argument exceeds
828.Brq Dv PATH_MAX
829or a pathname component is longer than
830.Brq Dv NAME_MAX .
831.It Er ENFILE
832The maximum allowable number of files is currently open in the system.
833.It Er ENOENT
834The
835.Dv O_CREAT
836flag is not set and the named file does not exist; or the
837.Dv O_CREAT
838flag is set and either the path prefix does not exist or the
839.Fa path
840argument points to an empty string.
841.Pp
842The
843.Dv O_CREAT
844and
845.Dv O_DIRECTORY
846flags were both set and
847.Fa path
848did not point to a file.
849.It Er ENOEXEC
850The
851.Dv O_EXEC
852flag is set and
853.Fa path
854does not point to a regular file.
855.It Er ENOLINK
856The
857.Fa path
858argument points to a remote machine, and the link to that machine is no longer
859active.
860.It Er ENOSR
861Th
862.Fa path
863argument names a STREAMS-based file and the system is unable to allocate a
864STREAM.
865.It Er ENOSPC
866The directory or file system that would contain the new file cannot be
867expanded, the file does not exist, and
868.Dv O_CREAT
869is specified.
870.It Er ENOSYS
871The device specified by
872.Fa path
873does not support the open operation.
874.It Er ENOTDIR
875A component of the path prefix is not a directory or a relative path was
876supplied to
877.Fn openat ,
878the
879.Dv O_XATTR
880flag was not supplied, and the file descriptor does not refer to a directory.
881The
882.Dv O_SEARCH
883flag was passed and
884.Fa path
885does not refer to a directory.
886.Pp
887The
888.Dv O_DIRECTORY
889flag was set and the file was not a directory.
890.It Er ENXIO
891The
892.Dv O_NONBLOCK
893flag is set, the named file is a FIFO, the
894.Dv O_WRONLY
895flag is set, and no process has the file open for reading; or the named file is
896a character special or block special file and the device associated with this
897special file does not exist or has been retired by the fault management
898framework.
899.It Er EOPNOTSUPP
900An attempt was made to open a path that corresponds to an
901.Dv AF_UNIX
902socket.
903.It Er EOVERFLOW
904The named file is a regular file and either
905.Dv O_LARGEFILE
906is not set and the size of the file cannot be represented correctly in an
907object of type
908.Vt off_t
909or
910.Dv O_LARGEFILE
911is set and the size of the file cannot be represented correctly in an object of
912type
913.Vt off64_t .
914.It Er EROFS
915The named file resides on a read-only file system and either
916.Dv O_WRONLY ,
917.Dv O_RDWR ,
918.Dv O_CREAT
919(if file does not exist), or
920.Dv O_TRUNC
921is set in the
922.Fa oflag
923argument.
924.El
925.Pp
926The
927.Fn openat
928function will fail if:
929.Bl -tag -width Er
930.It Er EBADF
931The
932.Fa fildes
933argument is not a valid open file descriptor or is not
934.Dv AT_FTCWD .
935.El
936.Pp
937The
938.Fn open
939function may fail if:
940.Bl -tag -width Er
941.It Er EAGAIN
942The
943.Fa path
944argument names the subsidiary side of a pseudo-terminal device that is locked.
945.It Er EINVAL
946The value of the
947.Fa oflag
948argument is not valid.
949.It Er ENAMETOOLONG
950Pathname resolution of a symbolic link produced an intermediate result whose
951length exceeds
952.Brq Dv PATH_MAX .
953.It Er ENOMEM
954The
955.Fa path
956argument names a STREAMS file and the system is unable to allocate resources.
957.It Er ETXTBSY
958The file is a pure procedure (shared text) file that is being executed and
959.Fa oflag
960is
961.Dv O_WRONLY
962or
963.Dv O_RDWR .
964.El
965.Sh USAGE
966The
967.Fn open
968function has a transitional interface for 64-bit file offsets.
969See
970.Xr lf64 7 .
971Note that using
972.Fn open64
973is equivalent to using
974.Fn open with
975.Dv O_LARGEFILE
976set in
977.Fa oflag .
978.Sh INTERFACE STABILITY
979.Sy Committed
980.Sh MT LEVEL
981.Sy Async-Signal-Safe
982.Sh SEE ALSO
983.Xr chmod 2 ,
984.Xr close 2 ,
985.Xr creat 2 ,
986.Xr dup 2 ,
987.Xr exec 2 ,
988.Xr fcntl 2 ,
989.Xr getmsg 2 ,
990.Xr getrlimit 2 ,
991.Xr Intro 2 ,
992.Xr lseek 2 ,
993.Xr putmsg 2 ,
994.Xr read 2 ,
995.Xr stat 2 ,
996.Xr umask 2 ,
997.Xr write 2 ,
998.Xr attropen 3C ,
999.Xr directio 3C ,
1000.Xr unlockpt 3C ,
1001.Xr fcntl.h 3HEAD ,
1002.Xr stat.h 3HEAD ,
1003.Xr streamio 4I ,
1004.Xr connld 4M ,
1005.Xr attributes 7 ,
1006.Xr lf64 7 ,
1007.Xr privileges 7 ,
1008.Xr standards 7
1009.Sh NOTES
1010Hierarchical Storage Management
1011.Pq HSM
1012file systems can sometimes cause long delays when opening a file, since HSM
1013files must be recalled from secondary storage.
1014