xref: /illumos-gate/usr/src/man/man2/open.2 (revision ca783257c986cddcc674ae22916a6766b98a2d36)
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 7M
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 7I
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 5 for special considerations when opening files owned by user ID
722.Sy 0
723for writing.
724The
725.Brq Dv PRIV_FILE_DAC_READ
726privilege allows
727processes to open files for reading regardless of permission bits.
728.It Er EAGAIN
729A mandatory share reservation could not be obtained because the desired access
730conflicts with an existing
731.Fa f_deny
732share reservation
733.Po
734see
735.Xr fcntl 2
736.Pc .
737.It Er EDQUOT
738The file does not exist,
739.Dv O_CREAT
740is specified, and either the directory where the new file entry is being placed
741cannot be extended because the user's quota of disk blocks on that file system
742has been exhausted, or the user's quota of inodes on the file system where the
743file is being created has been exhausted.
744.It Er EEXIST
745The
746.Dv O_CREAT
747and
748.Dv O_EXCL
749flags are set and the named file already exists.
750.It Er EILSEQ
751The
752.Fa path
753argument includes bytes that are not valid UTF-8 characters, and the file
754system accepts only file names where all characters are part of the UTF-8
755character codeset.
756.It Er EINTR
757A signal was caught during
758.Fn open .
759.It Er EFAULT
760The
761.Fa path
762argument points to an illegal address.
763.It Er EINVAL
764Either the system does not support synchronized or direct I/O for this file, or
765the
766.Dv O_XATTR
767flag was supplied and the underlying file system does not support extended file
768attributes.
769.It Er EIO
770The
771.Fa path
772argument names a STREAMS file and a hangup or error occurred during the
773.Fn open .
774.It Er EISDIR
775The named file is a directory and
776.Fa oflag
777includes
778.Dv O_WRONLY
779or
780.Dv O_RDWR .
781.It Er ELOOP
782Too many symbolic links were encountered in resolving
783.Fa path .
784.Pp
785A loop exists in symbolic links encountered during resolution of the
786.Fa path
787argument.
788.Pp
789The
790.Dv O_NOFOLLOW
791flag is set and the final component of path is a symbolic link.
792.It Er EMFILE
793There are currently
794.Brq Dv OPEN_MAX
795file descriptors open in the calling process.
796.It Er EMLINK
797The
798.Dv O_NOLINKS
799flag is set and the named file has a link count greater than
800.Sy 1 .
801.It Er EMULTIHOP
802Components of
803.Fa path
804require hopping to multiple remote machines and the file system does not allow
805it.
806.It Er ENAMETOOLONG
807The length of the
808.Fa path
809argument exceeds
810.Brq Dv PATH_MAX
811or a pathname component is longer than
812.Brq Dv NAME_MAX .
813.It Er ENFILE
814The maximum allowable number of files is currently open in the system.
815.It Er ENOENT
816The
817.Dv O_CREAT
818flag is not set and the named file does not exist; or the
819.Dv O_CREAT
820flag is set and either the path prefix does not exist or the
821.Fa path
822argument points to an empty string.
823.Pp
824The
825.Dv O_CREAT
826and
827.Dv O_DIRECTORY
828flags were both set and
829.Fa path
830did not point to a file.
831.It Er ENOEXEC
832The
833.Dv O_EXEC
834flag is set and
835.Fa path
836does not point to a regular file.
837.It Er ENOLINK
838The
839.Fa path
840argument points to a remote machine, and the link to that machine is no longer
841active.
842.It Er ENOSR
843Th
844.Fa path
845argument names a STREAMS-based file and the system is unable to allocate a
846STREAM.
847.It Er ENOSPC
848The directory or file system that would contain the new file cannot be
849expanded, the file does not exist, and
850.Dv O_CREAT
851is specified.
852.It Er ENOSYS
853The device specified by
854.Fa path
855does not support the open operation.
856.It Er ENOTDIR
857A component of the path prefix is not a directory or a relative path was
858supplied to
859.Fn openat ,
860the
861.Dv O_XATTR
862flag was not supplied, and the file descriptor does not refer to a directory.
863The
864.Dv O_SEARCH
865flag was passed and
866.Fa path
867does not refer to a directory.
868.Pp
869The
870.Dv O_DIRECTORY
871flag was set and the file was not a directory.
872.It Er ENXIO
873The
874.Dv O_NONBLOCK
875flag is set, the named file is a FIFO, the
876.Dv O_WRONLY
877flag is set, and no process has the file open for reading; or the named file is
878a character special or block special file and the device associated with this
879special file does not exist or has been retired by the fault management
880framework.
881.It Er EOPNOTSUPP
882An attempt was made to open a path that corresponds to an
883.Dv AF_UNIX
884socket.
885.It Er EOVERFLOW
886The named file is a regular file and either
887.Dv O_LARGEFILE
888is not set and the size of the file cannot be represented correctly in an
889object of type
890.Vt off_t
891or
892.Dv O_LARGEFILE
893is set and the size of the file cannot be represented correctly in an object of
894type
895.Vt off64_t .
896.It Er EROFS
897The named file resides on a read-only file system and either
898.Dv O_WRONLY ,
899.Dv O_RDWR ,
900.Dv O_CREAT
901(if file does not exist), or
902.Dv O_TRUNC
903is set in the
904.Fa oflag
905argument.
906.El
907.Pp
908The
909.Fn openat
910function will fail if:
911.Bl -tag -width Er
912.It Er EBADF
913The
914.Fa fildes
915argument is not a valid open file descriptor or is not
916.Dv AT_FTCWD .
917.El
918.Pp
919The
920.Fn open
921function may fail if:
922.Bl -tag -width Er
923.It Er EAGAIN
924The
925.Fa path
926argument names the subsidiary side of a pseudo-terminal device that is locked.
927.It Er EINVAL
928The value of the
929.Fa oflag
930argument is not valid.
931.It Er ENAMETOOLONG
932Pathname resolution of a symbolic link produced an intermediate result whose
933length exceeds
934.Brq Dv PATH_MAX .
935.It Er ENOMEM
936The
937.Fa path
938argument names a STREAMS file and the system is unable to allocate resources.
939.It Er ETXTBSY
940The file is a pure procedure (shared text) file that is being executed and
941.Fa oflag
942is
943.Dv O_WRONLY
944or
945.Dv O_RDWR .
946.El
947.Sh USAGE
948The
949.Fn open
950function has a transitional interface for 64-bit file offsets.
951See
952.Xr lf64 5 .
953Note that using
954.Fn open64
955is equivalent to using
956.Fn open with
957.Dv O_LARGEFILE
958set in
959.Fa oflag .
960.Sh INTERFACE STABILITY
961.Sy Committed
962.Sh MT LEVEL
963.Sy Async-Signal-Safe
964.Sh SEE ALSO
965.Xr chmod 2 ,
966.Xr close 2 ,
967.Xr creat 2 ,
968.Xr dup 2 ,
969.Xr exec 2 ,
970.Xr fcntl 2 ,
971.Xr getmsg 2 ,
972.Xr getrlimit 2 ,
973.Xr Intro 2 ,
974.Xr lseek 2 ,
975.Xr putmsg 2 ,
976.Xr read 2 ,
977.Xr stat 2 ,
978.Xr umask 2 ,
979.Xr write 2 ,
980.Xr attropen 3C ,
981.Xr directio 3C ,
982.Xr unlockpt 3C ,
983.Xr fcntl.h 3HEAD ,
984.Xr stat.h 3HEAD ,
985.Xr attributes 5 ,
986.Xr lf64 5 ,
987.Xr privileges 5 ,
988.Xr standards 5 ,
989.Xr streamio 7I ,
990.Xr connld 7M
991.Sh NOTES
992Hierarchical Storage Management
993.Pq HSM
994file systems can sometimes cause long delays when opening a file, since HSM
995files must be recalled from secondary storage.
996