xref: /freebsd/lib/libsys/open.2 (revision 0c2d64ce3da9c042da133c8b6d7391abb177f2c9)
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 bindat 2
451for unix domain socket
452.Pq see Xr unix 4
453.It Xr connectat 2
454for unix domain socket
455.It Xr fcntl 2
456but advisory locking is not allowed
457.It Xr dup 2
458.It Xr close 2
459.It Xr fstat 2
460.It Xr fstatfs 2
461.It Xr fchdir 2
462.It Xr fchroot 2
463.It Xr fexecve 2
464.It Xr funlinkat 2
465can be passed as the third argument
466.It Dv SCM_RIGHTS
467can be passed over a
468.Xr unix 4
469socket using a
470.Dv SCM_RIGHTS
471message
472.It Xr kqueue 2
473only with
474.Dv EVFILT_VNODE
475.It Xr __acl_get_fd 2
476.It Xr __acl_aclcheck_fd 2
477.It Xr extattr 2
478.It Xr capsicum 4
479can be passed to
480.Fn cap_*_limit
481and
482.Fn cap_*_get
483system calls (such as
484.Xr cap_rights_limit 2 ) .
485.El
486.Pp
487Other operations like
488.Xr read 2 ,
489.Xr ftruncate 2 ,
490and any other that operate on file and not on file descriptor (except
491.Xr fstat 2 ) ,
492are not allowed.
493.Pp
494A file descriptor created with the
495.Dv O_PATH
496flag can be opened as a normal (operable) file descriptor by
497specifying it as the
498.Fa fd
499argument to
500.Fn openat
501with an empty
502.Fa path
503and the
504.Dv O_EMPTY_PATH
505flag.
506Such an open behaves as if the current path of the file referenced by
507.Fa fd
508is passed, except that path walk permissions are not checked.
509See also the description of
510.Dv AT_EMPTY_PATH
511flag for
512.Xr fstatat 2
513and related syscalls.
514.Pp
515Conversely, a file descriptor
516.Dv fd
517referencing a filesystem file can be converted to the
518.Dv O_PATH
519type of descriptor by using the following call
520.Dl opath_fd = openat(fd, \[dq]\[dq], O_EMPTY_PATH | O_PATH);
521.Pp
522If successful,
523.Fn open
524returns a non-negative integer, termed a file descriptor.
525It returns \-1 on failure.
526The file descriptor value returned is the lowest numbered descriptor
527currently not in use by the process.
528The file pointer used to mark the current position within the
529file is set to the beginning of the file.
530.Pp
531If a sleeping open of a device node from
532.Xr devfs 4
533is interrupted by a signal, the call always fails with
534.Er EINTR ,
535even if the
536.Dv SA_RESTART
537flag is set for the signal.
538A sleeping open of a fifo (see
539.Xr mkfifo 2 )
540is restarted as normal.
541.Pp
542When a new file is created, it is assigned the group of the directory
543which contains it.
544.Pp
545Unless
546.Dv O_CLOEXEC
547flag was specified,
548the new descriptor is set to remain open across
549.Xr execve 2
550system calls; see
551.Xr close 2 ,
552.Xr fcntl 2
553and the description of the
554.Dv O_CLOEXEC
555flag.
556.Pp
557When the
558.Dv O_NAMEDATTR
559flag is specified for an
560.Fn openat
561where the
562.Fa fd
563argument is for a file object,
564a named attribute for the file object
565is opened and not the file object itself.
566If the
567.Dv O_CREAT
568flag has been specified as well, the named attribute will be
569created if it does not exist.
570When the
571.Dv O_NAMEDATTR
572flag is specified for a
573.Fn open ,
574a named attribute for the current working directory is opened and
575not the current working directory.
576The
577.Fa path
578argument for this
579.Fn openat
580or
581.Fn open
582must be a single component name with no embedded
583.Ql / .
584If the
585.Fa path
586argument is
587.Ql .\&
588then the named attribute directory for the file object is opened.
589(See
590.Xr named_attribute 7
591for more information.)
592.Pp
593The system imposes a limit on the number of file descriptors
594open simultaneously by one process.
595The
596.Xr getdtablesize 2
597system call returns the current system limit.
598.Sh RETURN VALUES
599If successful,
600.Fn open
601and
602.Fn openat
603return a non-negative integer, termed a file descriptor.
604They return \-1 on failure, and set
605.Va errno
606to indicate the error.
607.Sh ERRORS
608The named file is opened unless:
609.Bl -tag -width Er
610.It Bq Er ENOTDIR
611A component of the path prefix is not a directory.
612.It Bq Er ENAMETOOLONG
613A component of a pathname exceeded 255 characters,
614or an entire path name exceeded 1023 characters.
615.It Bq Er ENOENT
616.Dv O_CREAT
617is not set and the named file does not exist.
618.It Bq Er ENOENT
619A component of the path name that must exist does not exist.
620.It Bq Er EACCES
621Search permission is denied for a component of the path prefix.
622.It Bq Er EACCES
623The required permissions (for reading and/or writing)
624are denied for the given flags.
625.It Bq Er EACCES
626.Dv O_TRUNC
627is specified and write permission is denied.
628.It Bq Er EACCES
629.Dv O_CREAT
630is specified,
631the file does not exist,
632and the directory in which it is to be created
633does not permit writing.
634.It Bq Er EPERM
635.Dv O_CREAT
636is specified, the file does not exist, and the directory in which it is to be
637created has its immutable flag set, see the
638.Xr chflags 2
639manual page for more information.
640.It Bq Er EPERM
641The named file has its immutable flag set and the file is to be modified.
642.It Bq Er EPERM
643The named file has its append-only flag set, the file is to be modified, and
644.Dv O_TRUNC
645is specified or
646.Dv O_APPEND
647is not specified.
648.It Bq Er ELOOP
649Too many symbolic links were encountered in translating the pathname.
650.It Bq Er EISDIR
651The named file is a directory, and the arguments specify
652it is to be modified.
653.It Bq Er EISDIR
654The named file is a directory, and the flags specified
655.Dv O_CREAT
656without
657.Dv O_DIRECTORY .
658.It Bq Er EROFS
659The named file resides on a read-only file system,
660and the file is to be modified.
661.It Bq Er EROFS
662.Dv O_CREAT
663is specified and the named file would reside on a read-only file system.
664.It Bq Er EMFILE
665The process has already reached its limit for open file descriptors.
666.It Bq Er ENFILE
667The system file table is full.
668.It Bq Er EMLINK
669.Dv O_NOFOLLOW
670was specified and the target is a symbolic link.
671POSIX
672specifies a different error for this case; see the note in
673.Sx STANDARDS
674below.
675.It Bq Er ENXIO
676The named file is a character special or block
677special file, and the device associated with this special file
678does not exist.
679.It Bq Er ENXIO
680.Dv O_NONBLOCK
681is set, the named file is a fifo,
682.Dv O_WRONLY
683is set, and no process has the file open for reading.
684.It Bq Er EINTR
685The
686.Fn open
687operation was interrupted by a signal.
688.It Bq Er EOPNOTSUPP
689.Dv O_SHLOCK
690or
691.Dv O_EXLOCK
692is specified but the underlying file system does not support locking.
693.It Bq Er EOPNOTSUPP
694The named file is a special file mounted through a file system that
695does not support access to it (for example, NFS).
696.It Bq Er EWOULDBLOCK
697.Dv O_NONBLOCK
698and one of
699.Dv O_SHLOCK
700or
701.Dv O_EXLOCK
702is specified and the file is locked.
703.It Bq Er ENOSPC
704.Dv O_CREAT
705is specified,
706the file does not exist,
707and the directory in which the entry for the new file is being placed
708cannot be extended because there is no space left on the file
709system containing the directory.
710.It Bq Er ENOSPC
711.Dv O_CREAT
712is specified,
713the file does not exist,
714and there are no free inodes on the file system on which the
715file is being created.
716.It Bq Er EDQUOT
717.Dv O_CREAT
718is specified,
719the file does not exist,
720and the directory in which the entry for the new file
721is being placed cannot be extended because the
722user's quota of disk blocks on the file system
723containing the directory has been exhausted.
724.It Bq Er EDQUOT
725.Dv O_CREAT
726is specified,
727the file does not exist,
728and the user's quota of inodes on the file system on
729which the file is being created has been exhausted.
730.It Bq Er EIO
731An I/O error occurred while making the directory entry or
732allocating the inode for
733.Dv O_CREAT .
734.It Bq Er EINTEGRITY
735Corrupted data was detected while reading from the file system.
736.It Bq Er ETXTBSY
737The file is a pure procedure (shared text) file that is being
738executed and the
739.Fn open
740system call requests write access.
741.It Bq Er EFAULT
742The
743.Fa path
744argument
745points outside the process's allocated address space.
746.It Bq Er EEXIST
747.Dv O_CREAT
748and
749.Dv O_EXCL
750were specified and the file exists.
751.It Bq Er EOPNOTSUPP
752An attempt was made to open a socket (not currently implemented).
753.It Bq Er EINVAL
754An attempt was made to open a descriptor with an illegal combination
755of
756.Dv O_RDONLY ,
757.Dv O_WRONLY ,
758or
759.Dv O_RDWR ,
760and
761.Dv O_EXEC
762or
763.Dv O_SEARCH .
764.It Bq Er EINVAL
765.Dv O_CREAT
766is specified,
767and the last component of the
768.Fa path
769argument is invalid on the file system on which the file is being created.
770.It Bq Er EBADF
771The
772.Fa path
773argument does not specify an absolute path and the
774.Fa fd
775argument is
776neither
777.Dv AT_FDCWD
778nor a valid file descriptor open for searching.
779.It Bq Er ENOTDIR
780The
781.Fa path
782argument is not an absolute path and
783.Fa fd
784is neither
785.Dv AT_FDCWD
786nor a file descriptor associated with a directory.
787.It Bq Er ENOTDIR
788.Dv O_DIRECTORY
789is specified and the file is not a directory.
790.It Bq Er ECAPMODE
791.Dv AT_FDCWD
792is specified and the process is in capability mode.
793.It Bq Er ECAPMODE
794.Fn open
795was called and the process is in capability mode.
796.It Bq Er ENOTCAPABLE
797.Fa path
798is an absolute path and the process is in capability mode.
799.It Bq Er ENOTCAPABLE
800.Fa path
801is an absolute path and
802.Dv O_RESOLVE_BENEATH
803is specified.
804.It Bq Er ENOTCAPABLE
805.Fa path
806contains a ".." component leading to a directory outside
807of the directory hierarchy specified by
808.Fa fd
809and the process is in capability mode.
810.It Bq Er ENOTCAPABLE
811.Fa path
812contains a ".." component leading to a directory outside
813of the directory hierarchy specified by
814.Fa fd
815and
816.Dv O_RESOLVE_BENEATH
817is specified.
818.It Bq Er ENOTCAPABLE
819.Fa path
820contains a ".." component, the
821.Dv vfs.lookup_cap_dotdot
822.Xr sysctl 3
823is set, and the process is in capability mode.
824.It Bq Er ENOATTR
825.Dv O_NAMEDATTR
826has been specified and the file object is not a named attribute
827directory or named attribute.
828.El
829.Sh SEE ALSO
830.Xr chmod 2 ,
831.Xr close 2 ,
832.Xr dup 2 ,
833.Xr fexecve 2 ,
834.Xr fhopen 2 ,
835.Xr getdtablesize 2 ,
836.Xr getfh 2 ,
837.Xr lgetfh 2 ,
838.Xr lseek 2 ,
839.Xr read 2 ,
840.Xr umask 2 ,
841.Xr write 2 ,
842.Xr fopen 3 ,
843.Xr capsicum 4 ,
844.Xr unix 4 ,
845.Xr named_attribute 7
846.Sh STANDARDS
847These functions are specified by
848.St -p1003.1-2008 .
849.Pp
850.Fx
851sets
852.Va errno
853to
854.Er EMLINK instead of
855.Er ELOOP
856as specified by
857POSIX
858when
859.Dv O_NOFOLLOW
860is set in flags and the final component of pathname is a symbolic link
861to distinguish it from the case of too many symbolic link traversals
862in one of its non-final components.
863.Pp
864The Open Group Extended API Set 2 specification, that introduced the
865.Fn *at
866API, required that the test for whether
867.Fa fd
868is searchable is based on whether
869.Fa fd
870is open for searching, not whether the underlying directory currently
871permits searches.
872The present implementation of the
873.Fa openat
874system call is believed to be compatible with
875.\" .St -p1003.1-2017 ,
876.\" XXX: This should be replaced in the future when an appropriate argument to
877.\" the St macro is available: -p1003.1-2017
878.No IEEE Std 1003.1-2008, 2017 Edition ("POSIX.1") ,
879which specifies that behavior for
880.Dv O_SEARCH ,
881in the absence of the flag the implementation checks the current
882permissions of a directory.
883.Sh HISTORY
884The
885.Fn open
886function appeared in
887.At v1 .
888The
889.Fn openat
890function was introduced in
891.Fx 8.0 .
892.Dv O_DSYNC
893appeared in 13.0.
894.Dv O_NAMEDATTR
895appeared in 15.0.
896.Dv O_CLOFORK
897appeared in
898.Fx 15.0 .
899.Sh BUGS
900The
901.Fa mode
902argument is variadic and may result in different calling conventions
903than might otherwise be expected.
904