xref: /minix3/lib/libc/sys/open.2 (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc.\"	$NetBSD: open.2,v 1.56 2013/07/29 18:37:16 njoly Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 1980, 1991, 1993
42fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
72fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
82fe8fb19SBen Gras.\" are met:
92fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
102fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
112fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
122fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
132fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
142fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
152fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
162fe8fb19SBen Gras.\"    without specific prior written permission.
172fe8fb19SBen Gras.\"
182fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
192fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
202fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
212fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
222fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
232fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
242fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
252fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
262fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
272fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
282fe8fb19SBen Gras.\" SUCH DAMAGE.
292fe8fb19SBen Gras.\"
302fe8fb19SBen Gras.\"     @(#)open.2	8.2 (Berkeley) 11/16/93
312fe8fb19SBen Gras.\"
32*84d9c625SLionel Sambuc.Dd July 29, 2013
332fe8fb19SBen Gras.Dt OPEN 2
342fe8fb19SBen Gras.Os
352fe8fb19SBen Gras.Sh NAME
36*84d9c625SLionel Sambuc.Nm open ,
37*84d9c625SLionel Sambuc.Nm openat
382fe8fb19SBen Gras.Nd open or create a file for reading or writing
392fe8fb19SBen Gras.Sh LIBRARY
402fe8fb19SBen Gras.Lb libc
412fe8fb19SBen Gras.Sh SYNOPSIS
422fe8fb19SBen Gras.In fcntl.h
432fe8fb19SBen Gras.Ft int
44f14fb602SLionel Sambuc.Fn open "const char *path" "int flags" "..."
45*84d9c625SLionel Sambuc.Ft int
46*84d9c625SLionel Sambuc.Fn openat "int fd" "const char *path" "int flags" "..."
472fe8fb19SBen Gras.Sh DESCRIPTION
482fe8fb19SBen GrasThe file name specified by
492fe8fb19SBen Gras.Fa path
502fe8fb19SBen Grasis opened
512fe8fb19SBen Grasfor reading and/or writing as specified by the
522fe8fb19SBen Grasargument
532fe8fb19SBen Gras.Fa flags
542fe8fb19SBen Grasand the file descriptor returned to the calling process.
55*84d9c625SLionel Sambuc.Pp
56*84d9c625SLionel Sambuc.Fn openat
57*84d9c625SLionel Sambucworks the same way as
58*84d9c625SLionel Sambuc.Fn open
59*84d9c625SLionel Sambucexcept if
60*84d9c625SLionel Sambuc.Fa path
61*84d9c625SLionel Sambucis relative.
62*84d9c625SLionel SambucIn that case, it is looked up from a directory whose file
63*84d9c625SLionel Sambucdescriptor was passed as
64*84d9c625SLionel Sambuc.Fa fd .
65*84d9c625SLionel SambucSearch permission is required on this directory.
66*84d9c625SLionel Sambuc.\"    (These alternatives await a decision about the semantics of O_SEARCH)
67*84d9c625SLionel Sambuc.\" Search permission is required on this directory
68*84d9c625SLionel Sambuc.\" except if
69*84d9c625SLionel Sambuc.\" .Fa fd
70*84d9c625SLionel Sambuc.\" was opened with the
71*84d9c625SLionel Sambuc.\" .Dv O_SEARCH
72*84d9c625SLionel Sambuc.\" flag.
73*84d9c625SLionel Sambuc.\"    - or -
74*84d9c625SLionel Sambuc.\" This file descriptor must have been opened with the
75*84d9c625SLionel Sambuc.\" .Dv O_SEARCH
76*84d9c625SLionel Sambuc.\" flag.
77*84d9c625SLionel Sambuc.Fa fd
78*84d9c625SLionel Sambuccan be set to
79*84d9c625SLionel Sambuc.Dv AT_FDCWD
80*84d9c625SLionel Sambucin order to specify the current directory.
81*84d9c625SLionel Sambuc.Pp
822fe8fb19SBen GrasThe
832fe8fb19SBen Gras.Fa flags
842fe8fb19SBen Grasare specified by
852fe8fb19SBen Gras.Em or Ns 'ing
862fe8fb19SBen Grasthe values listed below.
872fe8fb19SBen GrasApplications must specify exactly one of the first three values
882fe8fb19SBen Gras(file access methods):
89f14fb602SLionel Sambuc.Bl -tag -offset indent -width O_DIRECTORY
902fe8fb19SBen Gras.It Dv O_RDONLY
912fe8fb19SBen GrasOpen for reading only.
922fe8fb19SBen Gras.It Dv O_WRONLY
932fe8fb19SBen GrasOpen for writing only.
942fe8fb19SBen Gras.It Dv O_RDWR
952fe8fb19SBen GrasOpen for reading and writing.
962fe8fb19SBen Gras.El
972fe8fb19SBen Gras.Pp
982fe8fb19SBen GrasAny combination of the following may be used:
99f14fb602SLionel Sambuc.Bl -tag -offset indent -width O_DIRECTORY
1002fe8fb19SBen Gras.It Dv O_NONBLOCK
1012fe8fb19SBen GrasDo not block on open or for data to become available.
1022fe8fb19SBen Gras.It Dv O_APPEND
1032fe8fb19SBen GrasAppend to the file on each write.
1042fe8fb19SBen Gras.It Dv O_CREAT
105f14fb602SLionel SambucCreate the file if it does not exist.
106f14fb602SLionel SambucThe third argument of type
107f14fb602SLionel Sambuc.Ft mode_t
108f14fb602SLionel Sambucis used to compute the mode bits of the file as described in
1092fe8fb19SBen Gras.Xr chmod 2
1102fe8fb19SBen Grasand modified by the process' umask value (see
1112fe8fb19SBen Gras.Xr umask 2 ) .
1122fe8fb19SBen Gras.It Dv O_TRUNC
1132fe8fb19SBen GrasTruncate size to 0.
1142fe8fb19SBen Gras.It Dv O_EXCL
1152fe8fb19SBen GrasError if
1162fe8fb19SBen Gras.Dv O_CREAT
1172fe8fb19SBen Grasand the file already exists.
1182fe8fb19SBen Gras.It Dv O_SHLOCK
1192fe8fb19SBen GrasAtomically obtain a shared lock.
1202fe8fb19SBen Gras.It Dv O_EXLOCK
1212fe8fb19SBen GrasAtomically obtain an exclusive lock.
1222fe8fb19SBen Gras.It Dv O_NOFOLLOW
1232fe8fb19SBen GrasIf last path element is a symlink, don't follow it.
1242fe8fb19SBen GrasThis option is provided for compatibility with other operating
1252fe8fb19SBen Grassystems, but its security value is questionable.
126f14fb602SLionel Sambuc.It Dv O_CLOEXEC
127f14fb602SLionel SambucSet the
128f14fb602SLionel Sambuc.Xr close 2
129f14fb602SLionel Sambucon
130f14fb602SLionel Sambuc.Xr exec 3
131f14fb602SLionel Sambucflag.
132f14fb602SLionel Sambuc.It Dv O_NOSIGPIPE
133f14fb602SLionel SambucReturn
134f14fb602SLionel Sambuc.Er EPIPE
135f14fb602SLionel Sambucinstead of raising
136f14fb602SLionel Sambuc.Dv SIGPIPE .
1372fe8fb19SBen Gras.It Dv O_DSYNC
1382fe8fb19SBen GrasIf set, write operations will be performed according to synchronized
1392fe8fb19SBen GrasI/O data integrity completion:
1402fe8fb19SBen Graseach write will wait for the file data to be committed to stable
1412fe8fb19SBen Grasstorage.
1422fe8fb19SBen Gras.It Dv O_SYNC
1432fe8fb19SBen GrasIf set, write operations will be performed according to synchronized
1442fe8fb19SBen GrasI/O file integrity completion:
1452fe8fb19SBen Graseach write will wait for both the file data and file status to be
1462fe8fb19SBen Grascommitted to stable storage.
1472fe8fb19SBen Gras.It Dv O_RSYNC
1482fe8fb19SBen GrasIf set, read operations will complete at the same level of
1492fe8fb19SBen Grasintegrity which is in effect for write operations:
1502fe8fb19SBen Grasif specified together with
1512fe8fb19SBen Gras.Dv O_SYNC ,
1522fe8fb19SBen Graseach read will wait for the file status to be committed to stable
1532fe8fb19SBen Grasstorage.
1542fe8fb19SBen Gras.Pp
1552fe8fb19SBen GrasCombining
1562fe8fb19SBen Gras.Dv O_RSYNC
1572fe8fb19SBen Graswith
1582fe8fb19SBen Gras.Dv O_DSYNC
1592fe8fb19SBen Grasonly, or specifying it without any other synchronized I/O integrity
1602fe8fb19SBen Grascompletion flag set, has no further effect.
1612fe8fb19SBen Gras.It Dv O_ALT_IO
1622fe8fb19SBen GrasAlternate I/O semantics will be used for read and write operations
1632fe8fb19SBen Grason the file descriptor.
1642fe8fb19SBen GrasAlternate semantics are defined by the underlying layers and will not
1652fe8fb19SBen Grashave any alternate effect in most cases.
1662fe8fb19SBen Gras.It Dv O_NOCTTY
1672fe8fb19SBen GrasIf the file is a terminal device, the opened device is not
1682fe8fb19SBen Grasmade the controlling terminal for the session.
1692fe8fb19SBen GrasThis flag has no effect on
1702fe8fb19SBen Gras.Nx ,
1712fe8fb19SBen Grassince the system defaults to the abovementioned behaviour.
1722fe8fb19SBen GrasThe flag is present only for standards conformance.
1732fe8fb19SBen Gras.It Dv O_DIRECT
1742fe8fb19SBen GrasIf set on a regular file, data I/O operations will not buffer the data
1752fe8fb19SBen Grasbeing transferred in the kernel's cache, but rather transfer the data
1762fe8fb19SBen Grasdirectly between user memory and the underlying device driver if possible.
1772fe8fb19SBen GrasThis flag is advisory; the request may be performed in the normal
1782fe8fb19SBen Grasbuffered fashion if certain conditions are not met, e.g. if the request
1792fe8fb19SBen Grasis not sufficiently aligned or if the file is mapped.
1802fe8fb19SBen Gras.Pp
1812fe8fb19SBen GrasTo meet the alignment requirements for direct I/O, the file offset,
1822fe8fb19SBen Grasthe length of the I/O and the address of the buffer in memory must all
1832fe8fb19SBen Grasbe multiples of
1842fe8fb19SBen Gras.Dv DEV_BSIZE
1852fe8fb19SBen Gras(512 bytes).
1862fe8fb19SBen GrasIf the I/O request is made
1872fe8fb19SBen Grasusing an interface that supports scatter/gather via struct iovec, each
1882fe8fb19SBen Graselement of the request must meet the above alignment constraints.
1892fe8fb19SBen Gras.It Dv O_DIRECTORY
1902fe8fb19SBen GrasFail if the file is not a directory.
191f14fb602SLionel Sambuc.It Dv O_ASYNC
192f14fb602SLionel SambucEnable the
193f14fb602SLionel Sambuc.Dv SIGIO
194f14fb602SLionel Sambucsignal to be sent to the process group
195f14fb602SLionel Sambucwhen I/O is possible, e.g.,
196f14fb602SLionel Sambucupon availability of data to be read.
197*84d9c625SLionel Sambuc.\"    (This block awaits a decision about the semantics of O_SEARCH)
198*84d9c625SLionel Sambuc.\" .It Dv O_SEARCH
199*84d9c625SLionel Sambuc.\" If opening a directory, search permission checks will not be performed on
200*84d9c625SLionel Sambuc.\" subsequent usage of the file descriptor for looking up relative paths by
201*84d9c625SLionel Sambuc.\" .Xr faccessat 2 ,
202*84d9c625SLionel Sambuc.\" .Xr fchmodat 2 ,
203*84d9c625SLionel Sambuc.\" .Xr fchownat 2 ,
204*84d9c625SLionel Sambuc.\" .Xr fstatat 2 ,
205*84d9c625SLionel Sambuc.\" .Xr linkat 2 ,
206*84d9c625SLionel Sambuc.\" .Xr mkdirat 2 ,
207*84d9c625SLionel Sambuc.\" .Xr mkfifoat 2 ,
208*84d9c625SLionel Sambuc.\" .Xr mknodat 2 ,
209*84d9c625SLionel Sambuc.\" .Xr openat 2 ,
210*84d9c625SLionel Sambuc.\" .Xr readlinkat 2 ,
211*84d9c625SLionel Sambuc.\" .Xr symlinkat 2 ,
212*84d9c625SLionel Sambuc.\" .Xr unlinkat 2 ,
213*84d9c625SLionel Sambuc.\" and
214*84d9c625SLionel Sambuc.\" .Xr utimensat 2 .
2152fe8fb19SBen Gras.El
2162fe8fb19SBen Gras.Pp
2172fe8fb19SBen GrasOpening a file with
2182fe8fb19SBen Gras.Dv O_APPEND
2192fe8fb19SBen Grasset causes each write on the file
2202fe8fb19SBen Grasto be appended to the end.
2212fe8fb19SBen GrasIf
2222fe8fb19SBen Gras.Dv O_TRUNC
2232fe8fb19SBen Grasis specified and the
2242fe8fb19SBen Grasfile exists, the file is truncated to zero length.
2252fe8fb19SBen Gras.Pp
2262fe8fb19SBen GrasIf
2272fe8fb19SBen Gras.Dv O_EXCL
2282fe8fb19SBen Grasis set with
2292fe8fb19SBen Gras.Dv O_CREAT
2302fe8fb19SBen Grasand the file already
2312fe8fb19SBen Grasexists,
2322fe8fb19SBen Gras.Fn open
2332fe8fb19SBen Grasreturns an error.
2342fe8fb19SBen GrasThis may be used to implement a simple exclusive access locking mechanism.
2352fe8fb19SBen GrasIf
2362fe8fb19SBen Gras.Dv O_EXCL
2372fe8fb19SBen Grasis set and the last component of the pathname is
2382fe8fb19SBen Grasa symbolic link,
2392fe8fb19SBen Gras.Fn open
2402fe8fb19SBen Graswill fail even if the symbolic
2412fe8fb19SBen Graslink points to a non-existent name.
2422fe8fb19SBen Gras.Pp
2432fe8fb19SBen GrasIf the
2442fe8fb19SBen Gras.Dv O_NONBLOCK
2452fe8fb19SBen Grasflag is specified, do not wait for the device or file to be ready or
2462fe8fb19SBen Grasavailable.
2472fe8fb19SBen GrasIf the
2482fe8fb19SBen Gras.Fn open
2492fe8fb19SBen Grascall would result
2502fe8fb19SBen Grasin the process being blocked for some reason (e.g., waiting for
2512fe8fb19SBen Grascarrier on a dialup line),
2522fe8fb19SBen Gras.Fn open
2532fe8fb19SBen Grasreturns immediately.
2542fe8fb19SBen GrasThis flag also has the effect of making all subsequent I/O on the open file non-blocking.
2552fe8fb19SBen Gras.Pp
2562fe8fb19SBen GrasWhen opening a file, a lock with
2572fe8fb19SBen Gras.Xr flock 2
2582fe8fb19SBen Grassemantics can be obtained by setting
2592fe8fb19SBen Gras.Dv O_SHLOCK
2602fe8fb19SBen Grasfor a shared lock, or
2612fe8fb19SBen Gras.Dv O_EXLOCK
2622fe8fb19SBen Grasfor an exclusive lock.
2632fe8fb19SBen GrasIf creating a file with
2642fe8fb19SBen Gras.Dv O_CREAT ,
2652fe8fb19SBen Grasthe request for the lock will never fail
2662fe8fb19SBen Gras(provided that the underlying filesystem supports locking).
2672fe8fb19SBen Gras.Pp
2682fe8fb19SBen GrasIf
2692fe8fb19SBen Gras.Fn open
2702fe8fb19SBen Grasis successful, the file pointer used to mark the current position within
2712fe8fb19SBen Grasthe file is set to the beginning of the file.
2722fe8fb19SBen Gras.Pp
2732fe8fb19SBen GrasWhen a new file is created it is given the group of the directory
2742fe8fb19SBen Graswhich contains it.
2752fe8fb19SBen Gras.Pp
2762fe8fb19SBen GrasThe new descriptor is set to remain open across
2772fe8fb19SBen Gras.Xr execve 2
2782fe8fb19SBen Grassystem calls; see
2792fe8fb19SBen Gras.Xr close 2
2802fe8fb19SBen Grasand
2812fe8fb19SBen Gras.Xr fcntl 2 .
2822fe8fb19SBen Gras.Pp
2832fe8fb19SBen GrasThe system imposes a limit on the number of file descriptors
2842fe8fb19SBen Grasopen simultaneously by one process.
2852fe8fb19SBen GrasCalling
2862fe8fb19SBen Gras.Xr getdtablesize 3
2872fe8fb19SBen Grasreturns the current system limit.
2882fe8fb19SBen Gras.Sh RETURN VALUES
2892fe8fb19SBen GrasIf successful,
2902fe8fb19SBen Gras.Fn open
291*84d9c625SLionel Sambucand
292*84d9c625SLionel Sambuc.Fn openat
2932fe8fb19SBen Grasreturns a non-negative integer, termed a file descriptor.
2942fe8fb19SBen GrasOtherwise, a value of \-1 is returned and
2952fe8fb19SBen Gras.Va errno
2962fe8fb19SBen Grasis set to indicate the error.
2972fe8fb19SBen Gras.Sh ERRORS
2982fe8fb19SBen GrasThe named file is opened unless:
2992fe8fb19SBen Gras.Bl -tag -width Er
3002fe8fb19SBen Gras.It Bq Er EACCES
3012fe8fb19SBen GrasSearch permission is denied for a component of the path prefix,
3022fe8fb19SBen Grasthe required permissions (for reading and/or writing)
3032fe8fb19SBen Grasare denied for the given flags, or
3042fe8fb19SBen Gras.Dv O_CREAT
3052fe8fb19SBen Grasis specified,
3062fe8fb19SBen Grasthe file does not exist,
3072fe8fb19SBen Grasand the directory in which it is to be created
3082fe8fb19SBen Grasdoes not permit writing.
3092fe8fb19SBen Gras.It Bq Er EDQUOT
3102fe8fb19SBen Gras.Dv O_CREAT
3112fe8fb19SBen Grasis specified,
3122fe8fb19SBen Grasthe file does not exist,
3132fe8fb19SBen Grasand the directory in which the entry for the new file
3142fe8fb19SBen Grasis being placed cannot be extended because the
3152fe8fb19SBen Grasuser's quota of disk blocks on the file system
3162fe8fb19SBen Grascontaining the directory has been exhausted; or
3172fe8fb19SBen Gras.Dv O_CREAT
3182fe8fb19SBen Grasis specified,
3192fe8fb19SBen Grasthe file does not exist,
3202fe8fb19SBen Grasand the user's quota of inodes on the file system on
3212fe8fb19SBen Graswhich the file is being created has been exhausted.
3222fe8fb19SBen Gras.It Bq Er EEXIST
3232fe8fb19SBen Gras.Dv O_CREAT
3242fe8fb19SBen Grasand
3252fe8fb19SBen Gras.Dv O_EXCL
3262fe8fb19SBen Graswere specified and the file exists.
3272fe8fb19SBen Gras.It Bq Er EFAULT
3282fe8fb19SBen Gras.Fa path
3292fe8fb19SBen Graspoints outside the process's allocated address space.
3302fe8fb19SBen Gras.It Bq Er EFTYPE
3312fe8fb19SBen Gras.Dv O_NOFOLLOW
3322fe8fb19SBen Graswas specified, but the last path component is a symlink.
3332fe8fb19SBen Gras.Em Note :
3342fe8fb19SBen Gras.St -p1003.1-2008
3352fe8fb19SBen Grasspecifies returning
3362fe8fb19SBen Gras.Bq Er ELOOP
3372fe8fb19SBen Grasfor this case.
3382fe8fb19SBen Gras.It Bq Er EINTR
3392fe8fb19SBen GrasThe
3402fe8fb19SBen Gras.Fn open
3412fe8fb19SBen Grasoperation was interrupted by a signal.
3422fe8fb19SBen Gras.It Bq Er EIO
3432fe8fb19SBen GrasAn I/O error occurred while making the directory entry or
3442fe8fb19SBen Grasallocating the inode for
3452fe8fb19SBen Gras.Dv O_CREAT .
3462fe8fb19SBen Gras.It Bq Er EISDIR
3472fe8fb19SBen GrasThe named file is a directory, and the arguments specify
3482fe8fb19SBen Grasit is to be opened for writing.
3492fe8fb19SBen Gras.It Bq Er ELOOP
3502fe8fb19SBen GrasToo many symbolic links were encountered in translating the pathname.
3512fe8fb19SBen Gras.It Bq Er EMFILE
3522fe8fb19SBen GrasThe process has already reached its limit for open file descriptors.
3532fe8fb19SBen Gras.It Bq Er ENAMETOOLONG
3542fe8fb19SBen GrasA component of a pathname exceeded
3552fe8fb19SBen Gras.Brq Dv NAME_MAX
3562fe8fb19SBen Grascharacters, or an entire path name exceeded
3572fe8fb19SBen Gras.Brq Dv PATH_MAX
3582fe8fb19SBen Grascharacters.
3592fe8fb19SBen Gras.It Bq Er ENFILE
3602fe8fb19SBen GrasThe system file table is full.
3612fe8fb19SBen Gras.It Bq Er ENOENT
3622fe8fb19SBen Gras.Dv O_CREAT
3632fe8fb19SBen Grasis not set and the named file does not exist, or
3642fe8fb19SBen Grasa component of the path name that must exist does not exist.
3652fe8fb19SBen Gras.It Bq Er ENOSPC
3662fe8fb19SBen Gras.Dv O_CREAT
3672fe8fb19SBen Grasis specified,
3682fe8fb19SBen Grasthe file does not exist,
3692fe8fb19SBen Grasand the directory in which the entry for the new file is being placed
3702fe8fb19SBen Grascannot be extended because there is no space left on the file
3712fe8fb19SBen Grassystem containing the directory; or
3722fe8fb19SBen Gras.Dv O_CREAT
3732fe8fb19SBen Grasis specified,
3742fe8fb19SBen Grasthe file does not exist,
3752fe8fb19SBen Grasand there are no free inodes on the file system on which the
3762fe8fb19SBen Grasfile is being created.
3772fe8fb19SBen Gras.It Bq Er ENOTDIR
3782fe8fb19SBen GrasA component of the path prefix is not a directory; or
3792fe8fb19SBen Gras.Dv O_DIRECTORY
3802fe8fb19SBen Grasis specified and the last path component is not a directory.
3812fe8fb19SBen Gras.It Bq Er ENXIO
3822fe8fb19SBen GrasThe named file is a character special or block
3832fe8fb19SBen Grasspecial file, and the device associated with this special file
3842fe8fb19SBen Grasdoes not exist, or
3852fe8fb19SBen Grasthe named file is a
3862fe8fb19SBen Gras.Tn FIFO ,
3872fe8fb19SBen Gras.Dv O_NONBLOCK
3882fe8fb19SBen Grasand
3892fe8fb19SBen Gras.Dv O_WRONLY
3902fe8fb19SBen Grasis set and no process has the file open for reading.
3912fe8fb19SBen Gras.It Bq Er EOPNOTSUPP
3922fe8fb19SBen Gras.Dv O_SHLOCK
3932fe8fb19SBen Grasor
3942fe8fb19SBen Gras.Dv O_EXLOCK
3952fe8fb19SBen Grasis specified but the underlying filesystem does not support locking; or
3962fe8fb19SBen Grasan attempt was made to open a socket (not currently implemented).
3972fe8fb19SBen Gras.It Bq Er EPERM
3982fe8fb19SBen GrasThe file's flags (see
3992fe8fb19SBen Gras.Xr chflags 2 )
4002fe8fb19SBen Grasdon't allow the file to be opened.
4012fe8fb19SBen Gras.It Bq Er EROFS
4022fe8fb19SBen GrasThe named file resides on a read-only file system,
4032fe8fb19SBen Grasand the file is to be modified.
4042fe8fb19SBen Gras.It Bq Er ETXTBSY
4052fe8fb19SBen GrasThe file is a pure procedure (shared text) file that is being
4062fe8fb19SBen Grasexecuted and the
4072fe8fb19SBen Gras.Fn open
4082fe8fb19SBen Grascall requests write access.
4092fe8fb19SBen Gras.El
410*84d9c625SLionel Sambuc.Pp
411*84d9c625SLionel SambucIn addition,
412*84d9c625SLionel Sambuc.Fn openat
413*84d9c625SLionel Sambucwill fail if:
414*84d9c625SLionel Sambuc.Bl -tag -width Er
415*84d9c625SLionel Sambuc.It Bq Er EBADF
416*84d9c625SLionel Sambuc.Fa path
417*84d9c625SLionel Sambucdoes not specify an absolute path and
418*84d9c625SLionel Sambuc.Fa fd
419*84d9c625SLionel Sambucis neither
420*84d9c625SLionel Sambuc.Dv AT_FDCWD
421*84d9c625SLionel Sambucnor a valid file descriptor open for reading or searching.
422*84d9c625SLionel Sambuc.It Bq Er ENOTDIR
423*84d9c625SLionel Sambuc.Fa path
424*84d9c625SLionel Sambucis not an absolute path and
425*84d9c625SLionel Sambuc.Fa fd
426*84d9c625SLionel Sambucis a file descriptor associated with a non-directory file.
427*84d9c625SLionel Sambuc.El
4282fe8fb19SBen Gras.Sh SEE ALSO
4292fe8fb19SBen Gras.Xr chmod 2 ,
4302fe8fb19SBen Gras.Xr close 2 ,
4312fe8fb19SBen Gras.Xr dup 2 ,
432*84d9c625SLionel Sambuc.Xr faccessat 2 ,
433*84d9c625SLionel Sambuc.Xr fchmodat 2 ,
434*84d9c625SLionel Sambuc.Xr fchownat 2 ,
435*84d9c625SLionel Sambuc.Xr fstatat 2 ,
436*84d9c625SLionel Sambuc.Xr linkat 2 ,
4372fe8fb19SBen Gras.Xr lseek 2 ,
438*84d9c625SLionel Sambuc.Xr mkdirat 2 ,
439*84d9c625SLionel Sambuc.Xr mkfifoat 2 ,
440*84d9c625SLionel Sambuc.Xr mknodat 2 ,
4412fe8fb19SBen Gras.Xr read 2 ,
442*84d9c625SLionel Sambuc.Xr readlinkat 2 ,
443*84d9c625SLionel Sambuc.Xr symlinkat 2 ,
4442fe8fb19SBen Gras.Xr umask 2 ,
445*84d9c625SLionel Sambuc.Xr unlinkat 2 ,
446*84d9c625SLionel Sambuc.Xr utimensat 2 ,
4472fe8fb19SBen Gras.Xr write 2 ,
4482fe8fb19SBen Gras.Xr getdtablesize 3
4492fe8fb19SBen Gras.Sh STANDARDS
4502fe8fb19SBen GrasThe
4512fe8fb19SBen Gras.Fn open
4522fe8fb19SBen Grasfunction conforms to
4532fe8fb19SBen Gras.St -p1003.1-90 .
454*84d9c625SLionel Sambuc.Fn openat
455*84d9c625SLionel Sambucconforms to
456*84d9c625SLionel Sambuc.St -p1003.1-2008 .
457*84d9c625SLionel Sambuc.Pp
4582fe8fb19SBen GrasThe
4592fe8fb19SBen Gras.Fa flags
4602fe8fb19SBen Grasvalues
4612fe8fb19SBen Gras.Dv O_DSYNC ,
4622fe8fb19SBen Gras.Dv O_SYNC
4632fe8fb19SBen Grasand
4642fe8fb19SBen Gras.Dv O_RSYNC
4652fe8fb19SBen Grasare extensions defined in
4662fe8fb19SBen Gras.St -p1003.1b-93 .
467*84d9c625SLionel Sambuc.\"    (This block awaits a decision about the semantics of O_SEARCH)
468*84d9c625SLionel Sambuc.\" .Dv O_SEARCH
469*84d9c625SLionel Sambuc.\" is defined in
470*84d9c625SLionel Sambuc.\" .St -p1003.1-2008 .
4712fe8fb19SBen Gras.Pp
4722fe8fb19SBen GrasThe
4732fe8fb19SBen Gras.Dv O_SHLOCK
4742fe8fb19SBen Grasand
4752fe8fb19SBen Gras.Dv O_EXLOCK
4762fe8fb19SBen Grasflags are non-standard extensions and should not be used if portability
4772fe8fb19SBen Grasis of concern.
4782fe8fb19SBen Gras.Sh HISTORY
4792fe8fb19SBen GrasAn
4802fe8fb19SBen Gras.Fn open
4812fe8fb19SBen Grasfunction call appeared in
4822fe8fb19SBen Gras.At v2 .
483