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