summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys/open.2
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2008-04-16 13:03:12 +0000
committerkib <kib@FreeBSD.org>2008-04-16 13:03:12 +0000
commit2e4b86adc7ebc6a6f218f0ad58bf2e06954acd0d (patch)
tree03acdbf3f7e88a48d315dac76d504fadeac388b0 /lib/libc/sys/open.2
parent52243403eb48561abd7b33995f5a4be6a56fa1f0 (diff)
downloadFreeBSD-src-2e4b86adc7ebc6a6f218f0ad58bf2e06954acd0d.zip
FreeBSD-src-2e4b86adc7ebc6a6f218f0ad58bf2e06954acd0d.tar.gz
Man pages for the openat(2), fexecve(2) and related syscalls.
Reviewed by: ru
Diffstat (limited to 'lib/libc/sys/open.2')
-rw-r--r--lib/libc/sys/open.285
1 files changed, 76 insertions, 9 deletions
diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2
index 423cf8b..8fc6d76 100644
--- a/lib/libc/sys/open.2
+++ b/lib/libc/sys/open.2
@@ -28,23 +28,25 @@
.\" @(#)open.2 8.2 (Berkeley) 11/16/93
.\" $FreeBSD$
.\"
-.Dd January 7, 2007
+.Dd April 10, 2008
.Dt OPEN 2
.Os
.Sh NAME
-.Nm open
-.Nd open or create a file for reading or writing
+.Nm open , openat
+.Nd open or create a file for reading, writing or executing
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In fcntl.h
.Ft int
.Fn open "const char *path" "int flags" "..."
+.Ft int
+.Fn openat "int fd" "const char *path" "int flags" "..."
.Sh DESCRIPTION
The file name specified by
.Fa path
is opened
-for reading and/or writing as specified by the
+for either execution or reading and/or writing as specified by the
argument
.Fa flags
and the file descriptor returned to the calling process.
@@ -56,7 +58,9 @@ created if it does not exist (by specifying the
flag).
In this case
.Fn open
-requires a third argument
+and
+.Fn openat
+require an additional argument
.Fa "mode_t mode" ,
and the file is created with mode
.Fa mode
@@ -65,6 +69,32 @@ as described in
and modified by the process' umask value (see
.Xr umask 2 ) .
.Pp
+The
+.Fn openat
+function is equivalent to the
+.Fn open
+function except in the case where the
+.Fa path
+specifies a relative path.
+In this case the file to be opened is determined relative to the directory
+associated with the file descriptor
+.Fa fd
+instead of the current working directory.
+The
+.Fa flag
+parameter and the optional fourth parameter correspond exactly to
+the parameters of
+.Fn open .
+If
+.Fn openat
+is passed the special value
+.Dv AT_FDCWD
+in the
+.Fa fd
+parameter, the current working directory is used
+and the behavior is identical to a call to
+.Fn open .
+.Pp
The flags specified are formed by
.Em or Ns 'ing
the following values
@@ -73,6 +103,7 @@ the following values
O_RDONLY open for reading only
O_WRONLY open for writing only
O_RDWR open for reading and writing
+O_EXEC open for execute only
O_NONBLOCK do not block on open
O_APPEND append on each write
O_CREAT create file if it does not exist
@@ -180,7 +211,7 @@ system call will not assign controlling terminals on
If successful,
.Fn open
returns a non-negative integer, termed a file descriptor.
-It returns -1 on failure.
+It returns \-1 on failure.
The file pointer used to mark the current position within the
file is set to the beginning of the file.
.Pp
@@ -202,8 +233,10 @@ system call returns the current system limit.
.Sh RETURN VALUES
If successful,
.Fn open
-returns a non-negative integer, termed a file descriptor.
-It returns -1 on failure, and sets
+and
+.Fn openat
+return a non-negative integer, termed a file descriptor.
+They return \-1 on failure, and set
.Va errno
to indicate the error.
.Sh ERRORS
@@ -346,13 +379,32 @@ An attempt was made to open a descriptor with an illegal combination
of
.Dv O_RDONLY ,
.Dv O_WRONLY ,
+.Dv O_RDWR
and
-.Dv O_RDWR .
+.Dv O_EXEC.
+.It Bq Eq EBADF
+The
+.Fa path
+argument does not specify an absolute path and the
+.Fa fd
+argument is
+neither
+.Dv AT_FDCWD
+nor a valid file descriptor open for searching.
+.It Bq Eq ENOTDIR
+The
+.Fa path
+argument is not an absolute path and
+.Fa fd
+is neither
+.Dv AT_FDCWD
+nor a file descriptor associated with a directory.
.El
.Sh SEE ALSO
.Xr chmod 2 ,
.Xr close 2 ,
.Xr dup 2 ,
+.Xr fexecve 2 ,
.Xr fhopen 2 ,
.Xr getdtablesize 2 ,
.Xr getfh 2 ,
@@ -367,3 +419,18 @@ The
.Fn open
function appeared in
.At v6 .
+The
+.Fn openat
+function was introduced in
+.Fx 8.0 .
+.Sh BUGS
+The Open Group Extended API Set 2 specification requires that the test
+for whether
+.Fa fd
+is searchable is based on whether
+.Fa fd
+is open for searching, not whether the underlying directory currently
+permits searches.
+The present implementation of the
+.Fa openat
+checks the current permissions of directory instead.
OpenPOWER on IntegriCloud