xref: /freebsd/lib/libsys/open.2 (revision 32cd3ee5901ea33d41ff550e5f40ce743c8d4165)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd May 17, 2025
29.Dt OPEN 2
30.Os
31.Sh NAME
32.Nm open , openat
33.Nd open or create a file for reading, writing or executing
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In fcntl.h
38.Ft int
39.Fn open "const char *path" "int flags" "..."
40.Ft int
41.Fn openat "int fd" "const char *path" "int flags" "..."
42.Sh DESCRIPTION
43The file name specified by
44.Fa path
45is opened
46for either execution or reading and/or writing as specified by the
47argument
48.Fa flags
49and the file descriptor returned to the calling process.
50The
51.Fa flags
52argument may indicate the file is to be
53created if it does not exist (by specifying the
54.Dv O_CREAT
55flag).
56In this case
57.Fn open
58and
59.Fn openat
60require an additional argument
61.Fa "mode_t mode" ,
62and the file is created with mode
63.Fa mode
64as described in
65.Xr chmod 2
66and modified by the process' umask value (see
67.Xr umask 2 ) .
68.Pp
69The
70.Fn openat
71function is equivalent to the
72.Fn open
73function except in the case where the
74.Fa path
75specifies a relative path or the
76.Va O_EMPTY_PATH
77flag is specified.
78For
79.Fn openat
80and relative
81.Fa path ,
82when
83.Fa fd
84references a directory, and the
85.Va O_EMPTY_PATH
86flag is not specified,
87the file to be opened is determined relative to the directory
88associated with the file descriptor
89.Fa fd
90instead of the current working directory.
91The
92.Fa flag
93parameter and the optional fourth parameter correspond exactly to
94the parameters of
95.Fn open .
96If
97.Fn openat
98is passed the special value
99.Dv AT_FDCWD
100in the
101.Fa fd
102parameter, the current working directory is used
103and the behavior is identical to a call to
104.Fn open .
105.Pp
106When
107.Fn openat
108is called with an absolute
109.Fa path ,
110it ignores the
111.Fa fd
112argument.
113.Pp
114When
115.Fn openat
116is called with the
117.Fa fd
118argument that does not reference a directory, the call fails unless
119.Va O_EMPTY_PATH
120flag is specified, see below.
121.Pp
122In
123.Xr capsicum 4
124capability mode,
125.Fn open
126is not permitted.
127The
128.Fa path
129argument to
130.Fn openat
131must be strictly relative to a file descriptor
132.Fa fd ;
133that is,
134.Fa path
135must not be an absolute path and must not contain ".." components
136which cause the path resolution to escape the directory hierarchy
137starting at
138.Fa fd .
139Additionally, no symbolic link in
140.Fa path
141may target absolute path or contain escaping ".." components.
142.Fa fd
143must not be
144.Dv AT_FDCWD .
145.Pp
146If the
147.Dv vfs.lookup_cap_dotdot
148.Xr sysctl 3
149MIB is set to zero, ".." components in the paths,
150used in capability mode,
151are completely disabled.
152If the
153.Dv vfs.lookup_cap_dotdot_nonlocal
154MIB is set to zero, ".." is not allowed if found on non-local filesystem.
155.Pp
156The
157.Fa flags
158are formed by
159.Em or Ns 'ing
160the following values:
161.Pp
162.Bl -tag -width O_RESOLVE_BENEATH
163.It Dv O_RDONLY
164open for reading only
165.It Dv O_WRONLY
166open for writing only
167.It Dv O_RDWR
168open for reading and writing
169.It Dv O_EXEC
170open for execute only
171.It Dv O_SEARCH
172open for search only
173(an alias for
174.Dv O_EXEC
175typically used with
176.Dv O_DIRECTORY )
177.It Dv O_NONBLOCK
178do not block on open
179.It Dv O_APPEND
180set file pointer to the end of the file before each write
181.It Dv O_CREAT
182create file if it does not exist
183.It Dv O_TRUNC
184truncate size to 0
185.It Dv O_EXCL
186fail if
187.Dv O_CREAT
188is set and the file exists
189.It Dv O_SHLOCK
190atomically obtain a shared lock
191.It Dv O_EXLOCK
192atomically obtain an exclusive lock
193.It Dv O_DIRECT
194read and write directly from the backing store
195.It Dv O_FSYNC
196synchronous data and metadata writes
197.Pq historical synonym for Dv O_SYNC
198.It Dv O_SYNC
199synchronous data and metadata writes
200.It Dv O_DSYNC
201synchronous data writes
202.It Dv O_NOFOLLOW
203do not follow symlinks
204.It Dv O_NOCTTY
205ignored
206.It Dv O_TTY_INIT
207ignored
208.It Dv O_DIRECTORY
209error if file is not a directory
210.It Dv O_CLOEXEC
211automatically close file on
212.Xr execve 2
213.It Dv O_CLOFORK
214automatically close file on any child process created with
215.Fn fork 2
216.It Dv O_VERIFY
217verify the contents of the file with
218.Xr mac_veriexec 4
219.It Dv O_RESOLVE_BENEATH
220.Pq Xr openat 2 only
221path resolution must not cross the
222.Fa fd
223directory
224.It Dv O_PATH
225record only the target path in the opened descriptor
226.It Dv O_EMPTY_PATH
227.Pq Xr openat 2 only
228open file referenced by
229.Fa fd
230if path is empty
231.It Dv O_NAMEDATTR
232open a named attribute or named attribute directory
233.El
234.Pp
235Exactly one of the flags
236.Dv O_RDONLY ,
237.Dv O_WRONLY ,
238.Dv O_RDWR ,
239or
240.Dv O_EXEC
241must be provided.
242.Pp
243Opening a file with
244.Dv O_APPEND
245set causes each write on the resulting file descriptor
246to be appended to the end of the file.
247.Pp
248If
249.Dv O_TRUNC
250is specified and the
251file exists, the file is truncated to zero length.
252.Pp
253If
254.Dv O_CREAT
255is set, but file already exists,
256this flag has no effect except when
257.Dv O_EXCL
258is set too, in this case
259.Fn open
260fails with
261.Er EEXIST .
262This may be used to
263implement a simple exclusive access locking mechanism.
264In all other cases, the file is created
265and the access permission bits (see
266.Xr chmod 2)
267of the file mode
268are set to the value of the third argument taken as
269.Fa "mode_t mode"
270and passed through the
271.Xr umask 2 .
272This argument does not affect whether the file is opened
273for reading, writing, or for both.
274The open' request for a lock on the file, created with
275.Dv O_CREAT ,
276will never fail
277provided that the underlying file system supports locking;
278see also
279.Dv O_SHLOCK
280and
281.Dv O_EXLOCK
282below.
283.Pp
284If
285.Dv O_EXCL
286is set and the last component of the pathname is
287a symbolic link,
288.Fn open
289will fail even if the symbolic
290link points to a non-existent name.
291.Pp
292If
293.Dv O_NONBLOCK
294is specified and the
295.Fn open
296system call would
297block for some reason (for example, waiting for
298carrier on a dialup line),
299.Fn open
300returns immediately.
301The descriptor remains in non-blocking mode for subsequent operations.
302.Pp
303If
304.Dv O_SYNC
305is used in the mask, all writes will
306immediately and synchronously be written to disk.
307.Dv O_FSYNC
308is an historical synonym for
309.Dv O_SYNC .
310.Pp
311If
312.Dv O_DSYNC
313is used in the mask, all data and metadata required to read the data will be
314synchronously written to disk, but changes to metadata such as file access and
315modification timestamps may be written later.
316.Pp
317If
318.Dv O_NOFOLLOW
319is used in the mask and the target file passed to
320.Fn open
321is a symbolic link then the
322.Fn open
323will fail.
324.Pp
325When opening a file, a lock with
326.Xr flock 2
327semantics can be obtained by setting
328.Dv O_SHLOCK
329for a shared lock, or
330.Dv O_EXLOCK
331for an exclusive lock.
332.Pp
333.Dv O_DIRECT
334may be used to minimize or eliminate the cache effects of reading and writing.
335The system will attempt to avoid caching the data you read or write.
336If it cannot avoid caching the data,
337it will minimize the impact the data has on the cache.
338Use of this flag can drastically reduce performance if not used with care.
339The semantics of this flag are filesystem dependent,
340and some filesystems may ignore it entirely.
341.Pp
342.Dv O_NOCTTY
343may be used to ensure the OS does not assign this file as the
344controlling terminal when it opens a tty device.
345This is the default on
346.Fx ,
347but is present for
348POSIX
349compatibility.
350The
351.Fn open
352system call will not assign controlling terminals on
353.Fx .
354.Pp
355.Dv O_TTY_INIT
356may be used to ensure the OS restores the terminal attributes when
357initially opening a TTY.
358This is the default on
359.Fx ,
360but is present for
361POSIX
362compatibility.
363The initial call to
364.Fn open
365on a TTY will always restore default terminal attributes on
366.Fx .
367.Pp
368.Dv O_DIRECTORY
369may be used to ensure the resulting file descriptor refers to a
370directory.
371This flag can be used to prevent applications with elevated privileges
372from opening files which are even unsafe to open with
373.Dv O_RDONLY ,
374such as device nodes.
375.Pp
376.Dv O_CLOEXEC
377may be used to set
378.Dv FD_CLOEXEC
379flag for the newly returned file descriptor.
380.Pp
381.Dv O_CLOFORK
382may be used to set
383.Dv FD_CLOFORK
384flag for the newly returned file descriptor.
385The file will be closed on any child process created with
386.Fn fork 2 ,
387.Fn vfork 2
388or
389.Fn rfork 2
390with the
391.Dv RFFDG
392flag, remaining open in the parent.
393Both the
394.Dv O_CLOEXEC
395and
396.Dv O_CLOFORK
397flags can be modified with the
398.Dv F_SETFD
399.Fn fcntl 2
400command.
401.Pp
402.Dv O_VERIFY
403may be used to indicate to the kernel that the contents of the file should
404be verified before allowing the open to proceed.
405The details of what
406.Dq verified
407means is implementation specific.
408The run-time linker (rtld) uses this flag to ensure shared objects have
409been verified before operating on them.
410.Pp
411.Dv O_RESOLVE_BENEATH
412returns
413.Er ENOTCAPABLE
414if any intermediate component of the specified relative path does not
415reside in the directory hierarchy beneath the starting directory.
416Absolute paths or even the temporal escape from beneath of the starting
417directory is not allowed.
418.Pp
419When a directory
420is opened with
421.Dv O_SEARCH ,
422execute permissions are checked at open time.
423The returned file descriptor
424may not be used for any read operations like
425.Xr getdirentries 2 .
426The primary use of this descriptor is as the lookup descriptor for the
427.Fn *at
428family of functions.
429If
430.Dv O_SEARCH
431was not requested at open time, then the
432.Fn *at
433functions use the current directory permissions for the directory referenced
434by the descriptor at the time of the
435.Fn *at
436call.
437.Pp
438.Dv O_PATH
439returns a file descriptor that can be used as the first argument for
440.Fn openat
441and other filesystem-related system calls collectively named
442.Fn *at
443taking a file descriptor argument, like
444.Xr fstatat 2
445and others.
446The other functionality of the returned file descriptor is limited to
447the following descriptor-level operations:
448.Pp
449.Bl -tag -width __acl_aclcheck_fd -offset indent -compact
450.It Xr fcntl 2
451but advisory locking is not allowed
452.It Xr dup 2
453.It Xr close 2
454.It Xr fstat 2
455.It Xr fstatfs 2
456.It Xr fchdir 2
457.It Xr fchroot 2
458.It Xr fexecve 2
459.It Xr funlinkat 2
460can be passed as the third argument
461.It Dv SCM_RIGHTS
462can be passed over a
463.Xr unix 4
464socket using a
465.Dv SCM_RIGHTS
466message
467.It Xr kqueue 2
468only with
469.Dv EVFILT_VNODE
470.It Xr __acl_get_fd 2
471.It Xr __acl_aclcheck_fd 2
472.It Xr extattr 2
473.It Xr capsicum 4
474can be passed to
475.Fn cap_*_limit
476and
477.Fn cap_*_get
478system calls (such as
479.Xr cap_rights_limit 2 ) .
480.El
481.Pp
482Other operations like
483.Xr read 2 ,
484.Xr ftruncate 2 ,
485and any other that operate on file and not on file descriptor (except
486.Xr fstat 2 ) ,
487are not allowed.
488.Pp
489A file descriptor created with the
490.Dv O_PATH
491flag can be opened as a normal (operable) file descriptor by
492specifying it as the
493.Fa fd
494argument to
495.Fn openat
496with an empty
497.Fa path
498and the
499.Dv O_EMPTY_PATH
500flag.
501Such an open behaves as if the current path of the file referenced by
502.Fa fd
503is passed, except that path walk permissions are not checked.
504See also the description of
505.Dv AT_EMPTY_PATH
506flag for
507.Xr fstatat 2
508and related syscalls.
509.Pp
510Conversely, a file descriptor
511.Dv fd
512referencing a filesystem file can be converted to the
513.Dv O_PATH
514type of descriptor by using the following call
515.Dl opath_fd = openat(fd, \[dq]\[dq], O_EMPTY_PATH | O_PATH);
516.Pp
517If successful,
518.Fn open
519returns a non-negative integer, termed a file descriptor.
520It returns \-1 on failure.
521The file descriptor value returned is the lowest numbered descriptor
522currently not in use by the process.
523The file pointer used to mark the current position within the
524file is set to the beginning of the file.
525.Pp
526If a sleeping open of a device node from
527.Xr devfs 4
528is interrupted by a signal, the call always fails with
529.Er EINTR ,
530even if the
531.Dv SA_RESTART
532flag is set for the signal.
533A sleeping open of a fifo (see
534.Xr mkfifo 2 )
535is restarted as normal.
536.Pp
537When a new file is created, it is assigned the group of the directory
538which contains it.
539.Pp
540Unless
541.Dv O_CLOEXEC
542flag was specified,
543the new descriptor is set to remain open across
544.Xr execve 2
545system calls; see
546.Xr close 2 ,
547.Xr fcntl 2
548and the description of the
549.Dv O_CLOEXEC
550flag.
551.Pp
552When the
553.Dv O_NAMEDATTR
554flag is specified for an
555.Fn openat
556where the
557.Fa fd
558argument is for a file object,
559a named attribute for the file object
560is opened and not the file object itself.
561If the
562.Dv O_CREAT
563flag has been specified as well, the named attribute will be
564created if it does not exist.
565When the
566.Dv O_NAMEDATTR
567flag is specified for a
568.Fn open ,
569a named attribute for the current working directory is opened and
570not the current working directory.
571The
572.Fa path
573argument for this
574.Fn openat
575or
576.Fn open
577must be a single component name with no embedded
578.Ql / .
579If the
580.Fa path
581argument is
582.Ql .\&
583then the named attribute directory for the file object is opened.
584(See
585.Xr named_attribute 7
586for more information.)
587.Pp
588The system imposes a limit on the number of file descriptors
589open simultaneously by one process.
590The
591.Xr getdtablesize 2
592system call returns the current system limit.
593.Sh RETURN VALUES
594If successful,
595.Fn open
596and
597.Fn openat
598return a non-negative integer, termed a file descriptor.
599They return \-1 on failure, and set
600.Va errno
601to indicate the error.
602.Sh ERRORS
603The named file is opened unless:
604.Bl -tag -width Er
605.It Bq Er ENOTDIR
606A component of the path prefix is not a directory.
607.It Bq Er ENAMETOOLONG
608A component of a pathname exceeded 255 characters,
609or an entire path name exceeded 1023 characters.
610.It Bq Er ENOENT
611.Dv O_CREAT
612is not set and the named file does not exist.
613.It Bq Er ENOENT
614A component of the path name that must exist does not exist.
615.It Bq Er EACCES
616Search permission is denied for a component of the path prefix.
617.It Bq Er EACCES
618The required permissions (for reading and/or writing)
619are denied for the given flags.
620.It Bq Er EACCES
621.Dv O_TRUNC
622is specified and write permission is denied.
623.It Bq Er EACCES
624.Dv O_CREAT
625is specified,
626the file does not exist,
627and the directory in which it is to be created
628does not permit writing.
629.It Bq Er EPERM
630.Dv O_CREAT
631is specified, the file does not exist, and the directory in which it is to be
632created has its immutable flag set, see the
633.Xr chflags 2
634manual page for more information.
635.It Bq Er EPERM
636The named file has its immutable flag set and the file is to be modified.
637.It Bq Er EPERM
638The named file has its append-only flag set, the file is to be modified, and
639.Dv O_TRUNC
640is specified or
641.Dv O_APPEND
642is not specified.
643.It Bq Er ELOOP
644Too many symbolic links were encountered in translating the pathname.
645.It Bq Er EISDIR
646The named file is a directory, and the arguments specify
647it is to be modified.
648.It Bq Er EISDIR
649The named file is a directory, and the flags specified
650.Dv O_CREAT
651without
652.Dv O_DIRECTORY .
653.It Bq Er EROFS
654The named file resides on a read-only file system,
655and the file is to be modified.
656.It Bq Er EROFS
657.Dv O_CREAT
658is specified and the named file would reside on a read-only file system.
659.It Bq Er EMFILE
660The process has already reached its limit for open file descriptors.
661.It Bq Er ENFILE
662The system file table is full.
663.It Bq Er EMLINK
664.Dv O_NOFOLLOW
665was specified and the target is a symbolic link.
666POSIX
667specifies a different error for this case; see the note in
668.Sx STANDARDS
669below.
670.It Bq Er ENXIO
671The named file is a character special or block
672special file, and the device associated with this special file
673does not exist.
674.It Bq Er ENXIO
675.Dv O_NONBLOCK
676is set, the named file is a fifo,
677.Dv O_WRONLY
678is set, and no process has the file open for reading.
679.It Bq Er EINTR
680The
681.Fn open
682operation was interrupted by a signal.
683.It Bq Er EOPNOTSUPP
684.Dv O_SHLOCK
685or
686.Dv O_EXLOCK
687is specified but the underlying file system does not support locking.
688.It Bq Er EOPNOTSUPP
689The named file is a special file mounted through a file system that
690does not support access to it (for example, NFS).
691.It Bq Er EWOULDBLOCK
692.Dv O_NONBLOCK
693and one of
694.Dv O_SHLOCK
695or
696.Dv O_EXLOCK
697is specified and the file is locked.
698.It Bq Er ENOSPC
699.Dv O_CREAT
700is specified,
701the file does not exist,
702and the directory in which the entry for the new file is being placed
703cannot be extended because there is no space left on the file
704system containing the directory.
705.It Bq Er ENOSPC
706.Dv O_CREAT
707is specified,
708the file does not exist,
709and there are no free inodes on the file system on which the
710file is being created.
711.It Bq Er EDQUOT
712.Dv O_CREAT
713is specified,
714the file does not exist,
715and the directory in which the entry for the new file
716is being placed cannot be extended because the
717user's quota of disk blocks on the file system
718containing the directory has been exhausted.
719.It Bq Er EDQUOT
720.Dv O_CREAT
721is specified,
722the file does not exist,
723and the user's quota of inodes on the file system on
724which the file is being created has been exhausted.
725.It Bq Er EIO
726An I/O error occurred while making the directory entry or
727allocating the inode for
728.Dv O_CREAT .
729.It Bq Er EINTEGRITY
730Corrupted data was detected while reading from the file system.
731.It Bq Er ETXTBSY
732The file is a pure procedure (shared text) file that is being
733executed and the
734.Fn open
735system call requests write access.
736.It Bq Er EFAULT
737The
738.Fa path
739argument
740points outside the process's allocated address space.
741.It Bq Er EEXIST
742.Dv O_CREAT
743and
744.Dv O_EXCL
745were specified and the file exists.
746.It Bq Er EOPNOTSUPP
747An attempt was made to open a socket (not currently implemented).
748.It Bq Er EINVAL
749An attempt was made to open a descriptor with an illegal combination
750of
751.Dv O_RDONLY ,
752.Dv O_WRONLY ,
753or
754.Dv O_RDWR ,
755and
756.Dv O_EXEC
757or
758.Dv O_SEARCH .
759.It Bq Er EINVAL
760.Dv O_CREAT
761is specified,
762and the last component of the
763.Fa path
764argument is invalid on the file system on which the file is being created.
765.It Bq Er EBADF
766The
767.Fa path
768argument does not specify an absolute path and the
769.Fa fd
770argument is
771neither
772.Dv AT_FDCWD
773nor a valid file descriptor open for searching.
774.It Bq Er ENOTDIR
775The
776.Fa path
777argument is not an absolute path and
778.Fa fd
779is neither
780.Dv AT_FDCWD
781nor a file descriptor associated with a directory.
782.It Bq Er ENOTDIR
783.Dv O_DIRECTORY
784is specified and the file is not a directory.
785.It Bq Er ECAPMODE
786.Dv AT_FDCWD
787is specified and the process is in capability mode.
788.It Bq Er ECAPMODE
789.Fn open
790was called and the process is in capability mode.
791.It Bq Er ENOTCAPABLE
792.Fa path
793is an absolute path and the process is in capability mode.
794.It Bq Er ENOTCAPABLE
795.Fa path
796is an absolute path and
797.Dv O_RESOLVE_BENEATH
798is specified.
799.It Bq Er ENOTCAPABLE
800.Fa path
801contains a ".." component leading to a directory outside
802of the directory hierarchy specified by
803.Fa fd
804and the process is in capability mode.
805.It Bq Er ENOTCAPABLE
806.Fa path
807contains a ".." component leading to a directory outside
808of the directory hierarchy specified by
809.Fa fd
810and
811.Dv O_RESOLVE_BENEATH
812is specified.
813.It Bq Er ENOTCAPABLE
814.Fa path
815contains a ".." component, the
816.Dv vfs.lookup_cap_dotdot
817.Xr sysctl 3
818is set, and the process is in capability mode.
819.It Bq Er ENOATTR
820.Dv O_NAMEDATTR
821has been specified and the file object is not a named attribute
822directory or named attribute.
823.El
824.Sh SEE ALSO
825.Xr chmod 2 ,
826.Xr close 2 ,
827.Xr dup 2 ,
828.Xr fexecve 2 ,
829.Xr fhopen 2 ,
830.Xr getdtablesize 2 ,
831.Xr getfh 2 ,
832.Xr lgetfh 2 ,
833.Xr lseek 2 ,
834.Xr read 2 ,
835.Xr umask 2 ,
836.Xr write 2 ,
837.Xr fopen 3 ,
838.Xr capsicum 4 ,
839.Xr named_attribute 7
840.Sh STANDARDS
841These functions are specified by
842.St -p1003.1-2008 .
843.Pp
844.Fx
845sets
846.Va errno
847to
848.Er EMLINK instead of
849.Er ELOOP
850as specified by
851POSIX
852when
853.Dv O_NOFOLLOW
854is set in flags and the final component of pathname is a symbolic link
855to distinguish it from the case of too many symbolic link traversals
856in one of its non-final components.
857.Pp
858The Open Group Extended API Set 2 specification, that introduced the
859.Fn *at
860API, required that the test for whether
861.Fa fd
862is searchable is based on whether
863.Fa fd
864is open for searching, not whether the underlying directory currently
865permits searches.
866The present implementation of the
867.Fa openat
868system call is believed to be compatible with
869.\" .St -p1003.1-2017 ,
870.\" XXX: This should be replaced in the future when an appropriate argument to
871.\" the St macro is available: -p1003.1-2017
872.No IEEE Std 1003.1-2008, 2017 Edition ("POSIX.1") ,
873which specifies that behavior for
874.Dv O_SEARCH ,
875in the absence of the flag the implementation checks the current
876permissions of a directory.
877.Sh HISTORY
878The
879.Fn open
880function appeared in
881.At v1 .
882The
883.Fn openat
884function was introduced in
885.Fx 8.0 .
886.Dv O_DSYNC
887appeared in 13.0.
888.Dv O_NAMEDATTR
889appeared in 15.0.
890.Dv O_CLOFORK
891appeared in
892.Fx 15.0 .
893.Sh BUGS
894The
895.Fa mode
896argument is variadic and may result in different calling conventions
897than might otherwise be expected.
898