summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/Makefile.inc4
-rw-r--r--lib/libc/gen/directory.363
-rw-r--r--lib/libc/sys/Makefile.inc21
-rw-r--r--lib/libc/sys/access.284
-rw-r--r--lib/libc/sys/chmod.298
-rw-r--r--lib/libc/sys/chown.287
-rw-r--r--lib/libc/sys/link.293
-rw-r--r--lib/libc/sys/mkdir.261
-rw-r--r--lib/libc/sys/mkfifo.261
-rw-r--r--lib/libc/sys/mknod.254
-rw-r--r--lib/libc/sys/open.264
-rw-r--r--lib/libc/sys/readlink.264
-rw-r--r--lib/libc/sys/rename.277
-rw-r--r--lib/libc/sys/stat.289
-rw-r--r--lib/libc/sys/symlink.256
-rw-r--r--lib/libc/sys/unlink.2101
-rw-r--r--lib/libc/sys/utimes.2109
17 files changed, 1094 insertions, 92 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 2025fe6742f..c476a614ca3 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.53 2011/07/08 22:58:54 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.54 2011/07/18 23:04:40 matthew Exp $
# gen sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen ${LIBCSRCDIR}/gen
@@ -81,7 +81,7 @@ MLINKS+=authenticate.3 auth_approval.3 authenticate.3 auth_cat.3 \
authenticate.3 auth_verify.3
MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \
directory.3 readdir.3 directory.3 rewinddir.3 directory.3 seekdir.3 \
- directory.3 telldir.3 directory.3 readdir_r.3
+ directory.3 telldir.3 directory.3 readdir_r.3 directory.3 fdopendir.3
MLINKS+=err.3 verr.3 err.3 errx.3 err.3 verrx.3 err.3 warn.3 err.3 vwarn.3 \
err.3 warnx.3 err.3 vwarnx.3
MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 execv.3 \
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3
index 204df4137d4..887d88a24c5 100644
--- a/lib/libc/gen/directory.3
+++ b/lib/libc/gen/directory.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: directory.3,v 1.20 2010/01/19 17:43:39 millert Exp $
+.\" $OpenBSD: directory.3,v 1.21 2011/07/18 23:04:40 matthew Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,11 +27,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: January 19 2010 $
+.Dd $Mdocdate: July 18 2011 $
.Dt DIRECTORY 3
.Os
.Sh NAME
.Nm opendir ,
+.Nm fdopendir ,
.Nm readdir ,
.Nm readdir_r ,
.Nm telldir ,
@@ -45,6 +46,8 @@
.Fd #include <dirent.h>
.Ft DIR *
.Fn opendir "const char *filename"
+.Ft DIR *
+.Fn fdopendir "int fd"
.Ft struct dirent *
.Fn readdir "DIR *dirp"
.Ft int
@@ -73,6 +76,30 @@ is returned and
is set to indicate the error.
.Pp
The
+.Fn fdopendir
+function is equivalent to
+.Fn opendir
+except that the directory is specified by file descriptor rather than by name.
+The file offset associated with the file descriptor at the time of the call
+determines which entries are returned.
+.Pp
+Upon successful return from
+.Fn fdopendir ,
+the file descriptor is under the control of the system,
+and if any attempt is made to close the file descriptor
+or to modify the state of the associated directory,
+other than by means of
+.Fn closedir ,
+.Fn readdir ,
+.Fn readdir_r ,
+or
+.Fn rewinddir ,
+the behavior is undefined.
+Upon calling
+.Fn closedir
+the file descriptor shall be closed.
+.Pp
+The
.Fn readdir
function returns a pointer to the next directory entry in the named
directory stream
@@ -203,6 +230,20 @@ and
.Xr malloc 3 .
.Pp
The
+.Fn fdopendir
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EBADF
+The
+.Fa fd
+argument is not a valid file descriptor open for reading.
+.It Bq Er ENOTDIR
+The descriptor
+.Fa fd
+is not associated with a directory.
+.El
+.Pp
+The
.Fn readdir
and
.Fn readdir_r
@@ -230,6 +271,20 @@ for any of the errors specified for the routine
.Xr lseek 2 ,
.Xr open 2 ,
.Xr dir 5
+.Sh STANDARDS
+The
+.Fn opendir ,
+.Fn fdopendir ,
+.Fn readdir ,
+.Fn readdir_r ,
+.Fn telldir ,
+.Fn seekdir ,
+.Fn rewinddir ,
+.Fn closedir ,
+and
+.Fn dirfd
+functions conform to
+.St -p1003.1-2008 .
.Sh HISTORY
The
.Fn opendir ,
@@ -242,3 +297,7 @@ and
.Fn dirfd
functions appeared in
.Bx 4.2 .
+The
+.Fn fdopendir
+function appeared in
+.Ox 5.0 .
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index 9763500dac8..4dfab7d3b9c 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.93 2011/07/18 17:29:49 matthew Exp $
+# $OpenBSD: Makefile.inc,v 1.94 2011/07/18 23:04:40 matthew Exp $
# $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $
# @(#)Makefile.inc 8.1 (Berkeley) 6/17/93
@@ -241,13 +241,13 @@ MAN+= accept.2 access.2 acct.2 adjfreq.2 adjtime.2 bind.2 brk.2 chdir.2 \
MAN+= msgctl.2 shmctl.2 shmat.2 semop.2 semget.2 semctl.2 msgsnd.2 msgrcv.2 \
msgget.2 shmget.2
+MLINKS+=access.2 faccessat.2
MLINKS+=brk.2 sbrk.2
MLINKS+=dup.2 dup2.2
MLINKS+=chdir.2 fchdir.2
MLINKS+=chflags.2 fchflags.2
-MLINKS+=chmod.2 fchmod.2
-MLINKS+=chown.2 fchown.2
-MLINKS+=chown.2 lchown.2
+MLINKS+=chmod.2 fchmod.2 chmod.2 fchmodat.2
+MLINKS+=chown.2 fchown.2 chown.2 fchownat.2 chown.2 lchown.2
MLINKS+=clock_gettime.2 clock_settime.2
MLINKS+=clock_gettime.2 clock_getres.2
MLINKS+=execve.2 exect.2
@@ -269,13 +269,20 @@ MLINKS+=getrtable.2 setrtable.2
MLINKS+=gettimeofday.2 settimeofday.2
MLINKS+=getuid.2 geteuid.2
MLINKS+=kqueue.2 kevent.2 kqueue.2 EV_SET.2
+MLINKS+=link.2 linkat.2
MLINKS+=intro.2 errno.2
MLINKS+=madvise.2 posix_madvise.2
+MLINKS+=mkdir.2 mkdirat.2
+MLINKS+=mkfifo.2 mkfifoat.2
+MLINKS+=mknod.2 mknodat.2
MLINKS+=mlock.2 munlock.2
MLINKS+=mlockall.2 munlockall.2
MLINKS+=mount.2 unmount.2
+MLINKS+=open.2 openat.2
MLINKS+=pathconf.2 fpathconf.2
MLINKS+=read.2 readv.2 read.2 pread.2 read.2 preadv.2
+MLINKS+=readlink.2 readlinkat.2
+MLINKS+=rename.2 renameat.2
MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2
MLINKS+=send.2 sendmsg.2 send.2 sendto.2
MLINKS+=setpgid.2 setpgrp.2
@@ -283,13 +290,15 @@ MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2
MLINKS+=setresuid.2 getresgid.2 setresuid.2 getresuid.2
MLINKS+=setresuid.2 setresgid.2
MLINKS+=shmat.2 shmdt.2
-MLINKS+=stat.2 fstat.2 stat.2 lstat.2
+MLINKS+=stat.2 fstat.2 stat.2 fstatat.2 stat.2 lstat.2
MLINKS+=stat.2 S_ISBLK.2 stat.2 S_ISCHR.2 stat.2 S_ISDIR.2
MLINKS+=stat.2 S_ISFIFO.2 stat.2 S_ISLNK.2 stat.2 S_ISREG.2 stat.2 S_ISSOCK.2
MLINKS+=statfs.2 fstatfs.2
+MLINKS+=symlink.2 symlinkat.2
MLINKS+=syscall.2 __syscall.2
MLINKS+=truncate.2 ftruncate.2
-MLINKS+=utimes.2 futimes.2
+MLINKS+=unlink.2 unlinkat.2
+MLINKS+=utimes.2 futimens.2 utimes.2 futimes.2 utimes.2 utimensat.2
MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2
MLINKS+=write.2 writev.2 write.2 pwrite.2 write.2 pwritev.2
MLINKS+=select.2 FD_SET.3 select.2 FD_CLR.3
diff --git a/lib/libc/sys/access.2 b/lib/libc/sys/access.2
index 213b40b146e..8a0fbd320c9 100644
--- a/lib/libc/sys/access.2
+++ b/lib/libc/sys/access.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: access.2,v 1.15 2008/06/10 16:37:57 otto Exp $
+.\" $OpenBSD: access.2,v 1.16 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: access.2,v 1.7 1995/02/27 12:31:44 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@@ -30,25 +30,29 @@
.\"
.\" @(#)access.2 8.2 (Berkeley) 4/1/94
.\"
-.Dd $Mdocdate: June 10 2008 $
+.Dd $Mdocdate: July 18 2011 $
.Dt ACCESS 2
.Os
.Sh NAME
-.Nm access
+.Nm access ,
+.Nm faccessat
.Nd check access permissions of a file or pathname
.Sh SYNOPSIS
+.Fd #include <fcntl.h>
.Fd #include <unistd.h>
.Ft int
-.Fn access "const char *path" "int mode"
+.Fn access "const char *path" "int amode"
+.Ft int
+.Fn faccessat "int fd" "const char *path" "int amode" "int flag"
.Sh DESCRIPTION
The
.Fn access
function checks the accessibility of the file named by
.Fa path
for the access permissions indicated by
-.Fa mode .
+.Fa amode .
The value of
-.Fa mode
+.Fa amode
is the bitwise inclusive
.Tn OR
of the access permissions to be checked
@@ -83,6 +87,45 @@ if the file has any of the execute bits set and
is not a directory,
.Fn access
will indicate success.
+.Pp
+The
+.Fn faccessat
+function is equivalent to
+.Fn access
+except that where
+.Fa path
+specifies a relative path,
+the file whose accessibility is checked is determined relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn faccessat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used.
+If also
+.Fa flag
+is zero, the behavior is identical to a call to
+.Fn access .
+.Pp
+Values for
+.Fa flag
+are constructed by bitwise-inclusive
+.Tn OR Ns 'ing
+of flags from the following list defined in
+.In fcntl.h :
+.Pp
+.Bl -tag -width AT_EACCESS -offset indent -compact
+.It Dv AT_EACCESS
+The checks for accessibility are performed using the effective user
+and group IDs instead of the real user and group IDs.
+.El
.Sh RETURN VALUES
If
.Fa path
@@ -130,7 +173,21 @@ points outside the process's allocated address space.
An I/O error occurred while reading from or writing to the file system.
.It Bq Er EINVAL
An invalid value was specified for
-.Ar mode .
+.Ar amode .
+.El
+.Pp
+Additionally,
+.Fn faccessat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
.El
.Sh SEE ALSO
.Xr chmod 2 ,
@@ -138,9 +195,18 @@ An invalid value was specified for
.Sh STANDARDS
The
.Fn access
-function conforms to
-.St -p1003.1-90 .
+and
+.Fn faccessat
+functions conform to
+.St -p1003.1-2008 .
+.Sh HISTORY
+The
+.Fn faccessat
+function appeared in
+.Ox 5.0 .
.Sh CAVEATS
.Fn access
+and
+.Fn faccessat
should never be used for actual access control.
Doing so can result in a time of check vs. time of use security hole.
diff --git a/lib/libc/sys/chmod.2 b/lib/libc/sys/chmod.2
index 47454747149..6e81521c90e 100644
--- a/lib/libc/sys/chmod.2
+++ b/lib/libc/sys/chmod.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: chmod.2,v 1.14 2007/05/31 19:19:32 jmc Exp $
+.\" $OpenBSD: chmod.2,v 1.15 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: chmod.2,v 1.7 1995/02/27 12:32:06 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@@ -30,40 +30,41 @@
.\"
.\" @(#)chmod.2 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: July 18 2011 $
.Dt CHMOD 2
.Os
.Sh NAME
.Nm chmod ,
+.Nm fchmodat ,
.Nm fchmod
.Nd change mode of file
.Sh SYNOPSIS
.Fd #include <sys/types.h>
.Fd #include <sys/stat.h>
+.Fd #include <fcntl.h>
.Ft int
.Fn chmod "const char *path" "mode_t mode"
.Ft int
+.Fn fchmodat "int fd" "const char *path" "mode_t mode" "int flag"
+.Ft int
.Fn fchmod "int fd" "mode_t mode"
.Sh DESCRIPTION
-The function
+The
.Fn chmod
-sets the file permission bits of the file specified by the pathname
+function sets the file permission bits of the file specified by the pathname
.Fa path
to
.Fa mode .
-.Fn fchmod
-sets the permission bits of the specified file descriptor
-.Fa fd .
.Fn chmod
-verifies that the process owner (user) either owns the file specified by
-.Fa path
-(or
-.Fa fd ) ,
+verifies that the process owner (user) either owns the specified file
or is the superuser.
-A mode is created from
-.Em or'd
-permission bit masks defined in
-.Aq Pa sys/stat.h :
+.Pp
+Values for
+.Fa mode
+are constructed by bitwise-inclusive
+.Tn OR Ns 'ing
+of permission bit masks from the following list defined in
+.In sys/stat.h :
.Bd -literal -offset indent
#define S_IRWXU 0000700 /* RWX mask for owner */
#define S_IRUSR 0000400 /* R for owner */
@@ -107,14 +108,65 @@ set-group-ID bits unless the user is the superuser.
This makes the system somewhat more secure by protecting
set-user-ID (set-group-ID) files from remaining set-user-ID (set-group-ID)
if they are modified, at the expense of a degree of compatibility.
+.Pp
+The
+.Fn fchmodat
+function is equivalent to
+.Fn chmod
+except in the case where
+.Fa path
+specifies a relative path.
+In this case the file to be changed is determined relative to the directory
+associated with the file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn fchmodat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used.
+If also
+.Fa flag
+is zero, the behavior is identical to a call to
+.Fn chmod .
+.Pp
+Values for
+.Fa flag
+are constructed by bitwise-inclusive
+.Tn OR Ns 'ing
+of flags from the following list defined in
+.In fcntl.h :
+.Pp
+.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact
+.It Dv AT_SYMLINK_NOFOLLOW
+If
+.Fa path
+names a symbolic link, then the mode of the symbolic link is changed.
+.El
+.Pp
+The
+.Fn fchmod
+function is equivalent to
+.Fn chmod
+except that the file whose permissions are changed is specified
+by the file descriptor
+.Fa fd .
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of \-1 is returned and
.Va errno
is set to indicate the error.
.Sh ERRORS
+The
.Fn chmod
-will fail and the file mode will be unchanged if:
+and
+.Fn fchmodat
+functions will fail and the file mode will be unchanged if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
@@ -145,6 +197,20 @@ points outside the process's allocated address space.
An I/O error occurred while reading from or writing to the file system.
.El
.Pp
+Additionally, the
+.Fn fchmodat
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
+.El
+.Pp
.Fn fchmod
will fail and the file mode will be unchanged if:
.Bl -tag -width Er
diff --git a/lib/libc/sys/chown.2 b/lib/libc/sys/chown.2
index ee341d019b2..bb4ba52788c 100644
--- a/lib/libc/sys/chown.2
+++ b/lib/libc/sys/chown.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: chown.2,v 1.15 2007/05/31 19:19:32 jmc Exp $
+.\" $OpenBSD: chown.2,v 1.16 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: chown.2,v 1.10 1995/10/12 15:40:47 jtc Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993, 1994
@@ -30,22 +30,26 @@
.\"
.\" @(#)chown.2 8.4 (Berkeley) 4/19/94
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: July 18 2011 $
.Dt CHOWN 2
.Os
.Sh NAME
.Nm chown ,
.Nm lchown ,
+.Nm fchownat ,
.Nm fchown
.Nd change owner and group of a file or link
.Sh SYNOPSIS
.Fd #include <sys/types.h>
+.Fd #include <fcntl.h>
.Fd #include <unistd.h>
.Ft int
.Fn chown "const char *path" "uid_t owner" "gid_t group"
.Ft int
.Fn lchown "const char *path" "uid_t owner" "gid_t group"
.Ft int
+.Fn fchownat "int fd" "const char *path" "uid_t owner" "gid_t group" "int flag"
+.Ft int
.Fn fchown "int fd" "uid_t owner" "gid_t group"
.Sh DESCRIPTION
The owner ID and group ID of the file (or link) named by
@@ -79,6 +83,54 @@ operates similarly to how
operated on older systems, and does not follow symbolic links.
It allows the owner and group of a symbolic link to be set.
.Pp
+The
+.Fn fchownat
+function is equivalent to either the
+.Fn chown
+or
+.Fn lchown
+function depending on the value of
+.Fa flag
+(see below), except that where
+.Fa path
+specifies a relative path,
+the file whose ownership is changed is determined relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn fchownat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used
+and the behavior is identical to a call to
+.Fn chown
+or
+.Fn lchown ,
+depending on whether or not the
+.Dv AT_SYMLINK_NOFOLLOW
+bit is set in
+.Fa flag .
+.Pp
+Values for
+.Fa flag
+are constructed by bitwise-inclusive
+.Tn OR Ns 'ing
+of flags from the following list defined in
+.In fcntl.h :
+.Pp
+.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact
+.It Dv AT_SYMLINK_NOFOLLOW
+If
+.Fa path
+names a symbolic link, then the ownership of the symbolic link is changed.
+.El
+.Pp
.Fn fchown
is particularly useful when used in conjunction
with the file locking primitives (see
@@ -92,9 +144,10 @@ Zero is returned if the operation was successful;
error code being placed in the global variable
.Va errno .
.Sh ERRORS
-.Fn chown
-or
-.Fn lchown
+.Fn chown ,
+.Fn lchown ,
+and
+.Fn fchownat
will fail and the file or link will be unchanged if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
@@ -122,6 +175,20 @@ points outside the process's allocated address space.
An I/O error occurred while reading from or writing to the file system.
.El
.Pp
+Additionally,
+.Fn fchownat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
+.El
+.Pp
.Fn fchown
will fail if:
.Bl -tag -width Er
@@ -146,8 +213,10 @@ An I/O error occurred while reading from or writing to the file system.
.Sh STANDARDS
The
.Fn chown
-function is expected to conform to
-.St -p1003.1-88 .
+and
+.Fn fchownat
+functions are expected to conform to
+.St -p1003.1-2008 .
.Sh HISTORY
The
.Fn fchown
@@ -166,3 +235,7 @@ The
function was added to
.Ox
due to the above.
+The
+.Fn fchownat
+function appeared in
+.Ox 5.0 .
diff --git a/lib/libc/sys/link.2 b/lib/libc/sys/link.2
index 386093de547..ce0402b425c 100644
--- a/lib/libc/sys/link.2
+++ b/lib/libc/sys/link.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: link.2,v 1.18 2008/11/21 15:52:55 jasper Exp $
+.\" $OpenBSD: link.2,v 1.19 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: link.2,v 1.7 1995/02/27 12:34:01 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@@ -30,16 +30,19 @@
.\"
.\" @(#)link.2 8.3 (Berkeley) 1/12/94
.\"
-.Dd $Mdocdate: November 21 2008 $
+.Dd $Mdocdate: July 18 2011 $
.Dt LINK 2
.Os
.Sh NAME
.Nm link
.Nd make hard link to a file
.Sh SYNOPSIS
+.Fd #include <fcntl.h>
.Fd #include <unistd.h>
.Ft int
.Fn link "const char *name1" "const char *name2"
+.Ft int
+.Fn linkat "int fd1" "const char *name1" "int fd2" "const char *name2"
.Sh DESCRIPTION
The
.Fn link
@@ -69,6 +72,61 @@ must be in the same file system.
As mandated by POSIX.1
.Fa name1
may not be a directory.
+.Pp
+The
+.Fn linkat
+function is equivalent to
+.Fn link
+except that where
+.Fa name1
+or
+.Fa name2
+specifies a relative path,
+the directory entries linked are resolved relative to
+the directories associated with file descriptors
+.Fa fd1
+or
+.Fa fd2
+(respectively) instead of the current working directory.
+.Pp
+If
+.Fn linkat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd1
+or
+.Fa fd2
+parameter, the current working directory is used for resolving the respective
+.Fa name1
+or
+.Fa name2
+argument.
+.Pp
+Values for
+.Fa flag
+are constructed by bitwise-inclusive
+.Tn OR Ns 'ing
+of flags from the following list defined in
+.In fcntl.h :
+.Pp
+.Bl -tag -width AT_SYMLINK_FOLLOW -offset indent -compact
+.It Dv AT_SYMLINK_FOLLOW
+If
+.Fa name1
+names a symbolic link,
+a new link for the target of the symbolic link is created.
+.El
+.Pp
+If the
+.Dv AT_SYMLINK_FOLLOW
+flag is clear and
+.Fa name1
+names a symbolic link, a new link is created for the symbolic link
+.Fa name1
+and not its target.
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of \-1 is returned and
@@ -76,6 +134,8 @@ Otherwise, a value of \-1 is returned and
is set to indicate the error.
.Sh ERRORS
.Fn link
+and
+.Fn linkat
will fail and no link will be created if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
@@ -149,6 +209,24 @@ system.
One of the pathnames specified
is outside the process's allocated address space.
.El
+.Pp
+Additionally,
+.Fn linkat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EBADF
+The
+.Fa name1
+or
+.Fa name2
+argument does not specify an absolute path and
+.Fa fd1
+or
+.Fa fd2 ,
+respectively, is neither
+.Dv AT_FDCWD
+nor a valid file descriptor open for reading.
+.El
.Sh SEE ALSO
.Xr ln 1 ,
.Xr readlink 2 ,
@@ -157,5 +235,12 @@ is outside the process's allocated address space.
.Sh STANDARDS
The
.Fn link
-function is expected to conform to
-.St -p1003.1-88 .
+and
+.Fn linkat
+functions are expected to conform to
+.St -p1003.1-2008 .
+.Sh HISTORY
+The
+.Fn linkat
+function appeared in
+.Ox 5.0 .
diff --git a/lib/libc/sys/mkdir.2 b/lib/libc/sys/mkdir.2
index 478a7512990..177621d40dd 100644
--- a/lib/libc/sys/mkdir.2
+++ b/lib/libc/sys/mkdir.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mkdir.2,v 1.9 2007/05/31 19:19:33 jmc Exp $
+.\" $OpenBSD: mkdir.2,v 1.10 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: mkdir.2,v 1.8 1995/02/27 12:34:22 cgd Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -30,17 +30,21 @@
.\"
.\" @(#)mkdir.2 8.2 (Berkeley) 12/11/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: July 18 2011 $
.Dt MKDIR 2
.Os
.Sh NAME
-.Nm mkdir
+.Nm mkdir ,
+.Nm mkdirat
.Nd make a directory file
.Sh SYNOPSIS
.Fd #include <sys/types.h>
.Fd #include <sys/stat.h>
+.Fd #include <fcntl.h>
.Ft int
.Fn mkdir "const char *path" "mode_t mode"
+.Ft int
+.Fn mkdirat "int fd" "const char *path" "mode_t mode"
.Sh DESCRIPTION
The directory
.Fa path
@@ -53,12 +57,38 @@ of the calling process.
The directory's owner ID is set to the process's effective user ID.
The directory's group ID is set to that of the parent directory in
which it is created.
+.Pp
+The
+.Fn mkdirat
+function is equivalent to
+.Fn mkdir
+except that where
+.Fa path
+specifies a relative path,
+the newly created directory is created relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn mkdirat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used
+and the behavior is identical to a call to
+.Fn mkdir .
.Sh RETURN VALUES
A 0 return value indicates success.
A \-1 return value indicates an error, and an error code is stored in
.Va errno .
.Sh ERRORS
.Fn mkdir
+and
+.Fn mkdirat
will fail and no directory will be created if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
@@ -100,6 +130,20 @@ An I/O error occurred while reading from or writing to the file system.
.Fa path
points outside the process's allocated address space.
.El
+.Pp
+Additionally,
+.Fn mkdirat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
+.El
.Sh SEE ALSO
.Xr chmod 2 ,
.Xr stat 2 ,
@@ -107,5 +151,12 @@ points outside the process's allocated address space.
.Sh STANDARDS
The
.Fn mkdir
-function conforms to
-.St -p1003.1-88 .
+and
+.Fn mkdirat
+functions conform to
+.St -p1003.1-2008 .
+.Sh HISTORY
+The
+.Fn mkdirat
+function appeared in
+.Ox 5.0 .
diff --git a/lib/libc/sys/mkfifo.2 b/lib/libc/sys/mkfifo.2
index 852d14d14df..f696dd762d1 100644
--- a/lib/libc/sys/mkfifo.2
+++ b/lib/libc/sys/mkfifo.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mkfifo.2,v 1.8 2007/05/31 19:19:33 jmc Exp $
+.\" $OpenBSD: mkfifo.2,v 1.9 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: mkfifo.2,v 1.8 1995/02/27 12:34:27 cgd Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
@@ -30,17 +30,21 @@
.\"
.\" @(#)mkfifo.2 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: July 18 2011 $
.Dt MKFIFO 2
.Os
.Sh NAME
-.Nm mkfifo
+.Nm mkfifo ,
+.Nm mkfifoat
.Nd make a FIFO file
.Sh SYNOPSIS
.Fd #include <sys/types.h>
.Fd #include <sys/stat.h>
+.Fd #include <fcntl.h>
.Ft int
.Fn mkfifo "const char *path" "mode_t mode"
+.Ft int
+.Fn mkfifoat "int fd" "const char *path" "mode_t mode"
.Sh DESCRIPTION
.Fn mkfifo
creates a new FIFO file with name
@@ -55,12 +59,38 @@ of the calling process.
The FIFO's owner ID is set to the process's effective user ID.
The FIFO's group ID is set to that of the parent directory in
which it is created.
+.Pp
+The
+.Fn mkfifoat
+function is equivalent to
+.Fn mkfifo
+except that where
+.Fa path
+specifies a relative path,
+the newly created FIFO is created relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn mkfifoat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used
+and the behavior is identical to a call to
+.Fn mkfifo .
.Sh RETURN VALUES
A 0 return value indicates success.
A \-1 return value indicates an error, and an error code is stored in
.Va errno .
.Sh ERRORS
.Fn mkfifo
+and
+.Fn mkfifoat
will fail and no FIFO will be created if:
.Bl -tag -width Er
.It Bq Er EOPNOTSUPP
@@ -110,6 +140,20 @@ error occurred while reading from or writing to the file system.
.Fa path
points outside the process's allocated address space.
.El
+.Pp
+Additionally,
+.Fn mkfifoat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
+.El
.Sh SEE ALSO
.Xr chmod 2 ,
.Xr stat 2 ,
@@ -117,5 +161,12 @@ points outside the process's allocated address space.
.Sh STANDARDS
The
.Nm mkfifo
-function call conforms to
-.St -p1003.1-88 .
+and
+.Nm mkfifoat
+functions conform to
+.St -p1003.1-2008 .
+.Sh HISTORY
+The
+.Nm mkfifoat
+function appeared in
+.Ox 5.0 .
diff --git a/lib/libc/sys/mknod.2 b/lib/libc/sys/mknod.2
index 2ae76c5b63e..dca64d12ee0 100644
--- a/lib/libc/sys/mknod.2
+++ b/lib/libc/sys/mknod.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mknod.2,v 1.12 2007/05/31 19:19:33 jmc Exp $
+.\" $OpenBSD: mknod.2,v 1.13 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: mknod.2,v 1.6 1995/02/27 12:34:33 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@@ -30,16 +30,20 @@
.\"
.\" @(#)mknod.2 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: July 18 2011 $
.Dt MKNOD 2
.Os
.Sh NAME
-.Nm mknod
+.Nm mknod ,
+.Nm mknodat
.Nd make a special file node
.Sh SYNOPSIS
.Fd #include <sys/stat.h>
+.Fd #include <fcntl.h>
.Ft int
.Fn mknod "const char *path" "mode_t mode" "dev_t dev"
+.Ft int
+.Fn mknodat "int fd" "const char *path" "mode_t mode" "dev_t dev"
.Sh DESCRIPTION
The device special file
.Fa path
@@ -66,6 +70,30 @@ is ignored.
.Pp
.Fn mknod
requires superuser privileges.
+.Pp
+The
+.Fn mknodat
+function is equivalent to
+.Fn mknod
+except that where
+.Fa path
+specifies a relative path,
+the newly created device special file is created relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn mknodat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used
+and the behavior is identical to a call to
+.Fn mknod .
.Sh RETURN VALUES
Upon successful completion a value of 0 is returned.
Otherwise, a value of \-1 is returned and
@@ -73,6 +101,8 @@ Otherwise, a value of \-1 is returned and
is set to indicate the error.
.Sh ERRORS
.Fn mknod
+and
+.Fn mknodat
will fail and the file will be not created if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
@@ -120,6 +150,20 @@ The process is running within an alternate root directory, as
created by
.Xr chroot 2 .
.El
+Additionally,
+.Fn mknodat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
+.El
+.Pp
.Sh SEE ALSO
.Xr chmod 2 ,
.Xr chroot 2 ,
@@ -130,3 +174,7 @@ A
.Fn mknod
function call appeared in
.At v6 .
+The
+.Fn mknodat
+function appeared in
+.Ox 5.0 .
diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2
index 7e9ea5dfb50..45b4ee28d8f 100644
--- a/lib/libc/sys/open.2
+++ b/lib/libc/sys/open.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: open.2,v 1.38 2011/07/12 18:41:38 matthew Exp $
+.\" $OpenBSD: open.2,v 1.39 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: open.2,v 1.8 1995/02/27 12:35:14 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@@ -30,16 +30,19 @@
.\"
.\" @(#)open.2 8.2 (Berkeley) 11/16/93
.\"
-.Dd $Mdocdate: July 12 2011 $
+.Dd $Mdocdate: July 18 2011 $
.Dt OPEN 2
.Os
.Sh NAME
-.Nm open
+.Nm open ,
+.Nm openat
.Nd open or create a file for reading or writing
.Sh SYNOPSIS
.Fd #include <fcntl.h>
.Ft int
.Fn open "const char *path" "int flags" "mode_t mode"
+.Ft int
+.Fn openat "int fd" "const char *path" "int flags" "mode_t mode"
.Sh DESCRIPTION
The file name specified by
.Fa path
@@ -62,7 +65,8 @@ and modified by the process' umask value (see
.Pp
The flags specified are formed by bitwise-inclusive
.Tn OR Ns 'ing
-the following values.
+the following values defined in
+.In fcntl.h .
Exactly one of the first three values (file access modes) must be specified:
.Pp
.Bl -tag -width O_DIRECTORY -offset indent -compact
@@ -185,6 +189,30 @@ The system imposes a limit on the number of file descriptors
open simultaneously by one process.
.Xr getdtablesize 3
returns the current system limit.
+.Pp
+The
+.Fn openat
+function is equivalent to
+.Fn open
+except that where
+.Fa path
+specifies a relative path,
+the file to be opened is determined relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn openat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used
+and the behavior is identical to a call to
+.Fn open .
.Sh RETURN VALUES
If successful,
.Fn open
@@ -193,7 +221,11 @@ Otherwise, a value of \-1 is returned and
.Va errno
is set to indicate the error.
.Sh ERRORS
-The named file is opened unless:
+The
+.Fn open
+and
+.Fn openat
+functions will fail if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
@@ -324,6 +356,20 @@ An attempt was made to open a socket (not currently implemented).
An attempt was made to open a terminal device that requires exclusive
access and the specified device has already be opened.
.El
+.Pp
+Additionally, the
+.Fn openat
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
+.El
.Sh SEE ALSO
.Xr chflags 2 ,
.Xr chmod 2 ,
@@ -338,7 +384,9 @@ access and the specified device has already be opened.
.Sh STANDARDS
The
.Fn open
-function conforms to
+and
+.Fn openat
+functions conform to
.St -p1003.1-2008 .
.Pp
.Dv POSIX
@@ -362,6 +410,10 @@ An
.Fn open
function call appeared in
.At v2 .
+The
+.Fn openat
+function call appeared in
+.Ox 5.0 .
.Sh CAVEATS
The
.Dv O_TRUNC
diff --git a/lib/libc/sys/readlink.2 b/lib/libc/sys/readlink.2
index 0666c56a0d5..96973aa7d5e 100644
--- a/lib/libc/sys/readlink.2
+++ b/lib/libc/sys/readlink.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: readlink.2,v 1.12 2007/05/31 19:19:33 jmc Exp $
+.\" $OpenBSD: readlink.2,v 1.13 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: readlink.2,v 1.7 1995/02/27 12:35:54 cgd Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -30,19 +30,24 @@
.\"
.\" @(#)readlink.2 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: July 18 2011 $
.Dt READLINK 2
.Os
.Sh NAME
-.Nm readlink
+.Nm readlink ,
+.Nm readlinkat
.Nd read value of a symbolic link
.Sh SYNOPSIS
+.Fd #include <fcntl.h>
.Fd #include <unistd.h>
.Ft int
.Fn readlink "const char *path" "char *buf" "size_t bufsiz"
+.Ft ssize_t
+.Fn readlinkat "int fd" "const char *path" "char *buf" "size_t bufsiz"
.Sh DESCRIPTION
+The
.Fn readlink
-places the contents of the symbolic link
+function places the contents of the symbolic link
.Fa path
in the buffer
.Fa buf ,
@@ -53,6 +58,30 @@ does not append a
.Dv NUL
character to
.Fa buf .
+.Pp
+The
+.Fn readlinkat
+function is equivalent to
+.Fn readlink
+except that where
+.Fa path
+specifies a relative path,
+the symbolic link whose contents are read is determined relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn readlinkat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used
+and the behavior is identical to a call to
+.Fn readlink .
.Sh RETURN VALUES
The call returns the count of characters placed in the buffer
if it succeeds, or a \-1 if an error occurs, placing the error
@@ -60,6 +89,8 @@ code in the global variable
.Va errno .
.Sh ERRORS
.Fn readlink
+and
+.Fn readlinkat
will fail if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
@@ -86,13 +117,38 @@ or
.Fa path
extends outside the process's allocated address space.
.El
+.Pp
+Additionally,
+.Fn readlinkat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
+.El
.Sh SEE ALSO
.Xr lstat 2 ,
.Xr stat 2 ,
.Xr symlink 2 ,
.Xr symlink 7
+.Sh STANDARDS
+The
+.Fn readlink
+and
+.Fn readlinkat
+functions conform to
+.St -p1003.1-2008 .
.Sh HISTORY
The
.Fn readlink
function call appeared in
.Bx 4.2 .
+The
+.Fn readlinkat
+function call appeared in
+.Ox 5.0 .
diff --git a/lib/libc/sys/rename.2 b/lib/libc/sys/rename.2
index 6113f4acb2c..5c5e515aced 100644
--- a/lib/libc/sys/rename.2
+++ b/lib/libc/sys/rename.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: rename.2,v 1.14 2008/10/24 14:34:39 jmc Exp $
+.\" $OpenBSD: rename.2,v 1.15 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: rename.2,v 1.7 1995/02/27 12:36:15 cgd Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -30,19 +30,24 @@
.\"
.\" @(#)rename.2 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: October 24 2008 $
+.Dd $Mdocdate: July 18 2011 $
.Dt RENAME 2
.Os
.Sh NAME
-.Nm rename
+.Nm rename ,
+.Nm renameat
.Nd change the name of a file
.Sh SYNOPSIS
+.Fd #include <fcntl.h>
.Fd #include <stdio.h>
.Ft int
.Fn rename "const char *from" "const char *to"
+.Ft int
+.Fn renameat "int fromfd" "const char *from" "int tofd" "const char *to"
.Sh DESCRIPTION
+The
.Fn rename
-causes the link named
+function causes the link named
.Fa from
to be renamed as
.Fa to .
@@ -69,6 +74,38 @@ If the final component of
is a symbolic link,
the symbolic link is renamed,
not the file or directory to which it points.
+.Pp
+The
+.Fn renameat
+function is equivalent to
+.Fn rename
+except that where
+.Fa from
+or
+.Fa to
+specifies a relative path,
+the directory entry names used are resolved relative to
+the directories associated with file descriptors
+.Fa fromfd
+or
+.Fa tofd
+(respectively) instead of the current working directory.
+.Pp
+If
+.Fn renameat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fromfd
+or
+.Fa tofd
+parameter, the current working directory is used for resolving the respective
+.Fa from
+or
+.Fa to
+argument.
.Sh RETURN VALUES
A 0 value is returned if the operation succeeds, otherwise
.Fn rename
@@ -77,6 +114,8 @@ returns \-1 and the global variable
indicates the reason for the failure.
.Sh ERRORS
.Fn rename
+and
+.Fn renameat
will fail and neither of the argument files will be
affected if:
.Bl -tag -width Er
@@ -171,6 +210,25 @@ or
.Fa to
is a directory and is not empty.
.El
+.Pp
+Additionally,
+.Fn renameat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EBADF
+The
+.Fa from
+or
+.Fa to
+argument does not specify an absolute path and
+.Fa fromfd
+or
+.Fa tofd ,
+respectively, is neither
+.Dv AT_FDCWD
+nor a valid file descriptor open for reading.
+.El
+.Pp
.Sh SEE ALSO
.Xr mv 1 ,
.Xr open 2 ,
@@ -178,8 +236,15 @@ is a directory and is not empty.
.Sh STANDARDS
The
.Fn rename
-function conforms to
-.St -p1003.1-88 .
+and
+.Fn renameat
+functions conform to
+.St -p1003.1-2008 .
+.Sh HISTORY
+The
+.Fn renameat
+function appeared in
+.Ox 5.0 .
.Sh CAVEATS
The system can deadlock if a loop in the file system graph is present.
This loop takes the form of an entry in directory
diff --git a/lib/libc/sys/stat.2 b/lib/libc/sys/stat.2
index c4ca2480d19..f639f34b420 100644
--- a/lib/libc/sys/stat.2
+++ b/lib/libc/sys/stat.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: stat.2,v 1.28 2009/11/10 07:25:32 jmc Exp $
+.\" $OpenBSD: stat.2,v 1.29 2011/07/18 23:04:40 matthew Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -29,22 +29,26 @@
.\"
.\" @(#)stat.2 8.3 (Berkeley) 4/19/94
.\"
-.Dd $Mdocdate: November 10 2009 $
+.Dd $Mdocdate: July 18 2011 $
.Dt STAT 2
.Os
.Sh NAME
.Nm stat ,
.Nm lstat ,
+.Nm fstatat ,
.Nm fstat
.Nd get file status
.Sh SYNOPSIS
.Fd #include <sys/types.h>
.Fd #include <sys/stat.h>
+.Fd #include <fcntl.h>
.Ft int
.Fn stat "const char *path" "struct stat *sb"
.Ft int
.Fn lstat "const char *path" "struct stat *sb"
.Ft int
+.Fn fstatat "int fd" "const char *path" "struct stat *sb" "int flag"
+.Ft int
.Fn fstat "int fd" "struct stat *sb"
.Sh DESCRIPTION
The
@@ -71,7 +75,55 @@ The only attributes returned from an
.Fn lstat
that refer to the symbolic link itself are the file type
.Pq Dv S_IFLNK ,
-size, blocks, and link count (always 1).
+size, blocks, and link count.
+.Pp
+The
+.Fn fstatat
+function is equivalent to either the
+.Fn stat
+or
+.Fn lstat
+function depending on the value of
+.Fa flag
+(see below), except that where
+.Fa path
+specifies a relative path,
+the file whose information is returned is determined relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn fstatat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used
+and the behavior is identical to a call to
+.Fn stat
+or
+.Fn lstat ,
+depending on whether or not the
+.Dv AT_SYMLINK_NOFOLLOW
+bit is set in
+.Fa flag .
+.Pp
+Values for
+.Fa flag
+are constructed by bitwise-inclusive
+.Tn OR Ns 'ing
+of flags from the following list defined in
+.In fcntl.h :
+.Pp
+.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact
+.It Dv AT_SYMLINK_NOFOLLOW
+If
+.Fa path
+names a symbolic link, then the status of the symbolic link is returned.
+.El
.Pp
The
.Fn fstat
@@ -85,7 +137,7 @@ argument is a pointer to a
.Fn stat
structure
as defined by
-.Aq Pa sys/stat.h
+.In sys/stat.h
(shown below)
and into which information is placed concerning the file.
.Bd -literal
@@ -238,7 +290,7 @@ S_ISSOCK(st_mode m) /* socket */
.Ed
.Pp
For a list of access modes, see
-.Aq Pa sys/stat.h ,
+.In sys/stat.h ,
.Xr access 2 ,
and
.Xr chmod 2 .
@@ -248,9 +300,10 @@ Otherwise, a value of \-1 is returned and
.Va errno
is set to indicate the error.
.Sh ERRORS
-.Fn stat
+.Fn stat ,
+.Fn lstat ,
and
-.Fn lstat
+.Fn fstatat
will fail if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
@@ -276,6 +329,20 @@ points to an invalid address.
An I/O error occurred while reading from or writing to the file system.
.El
.Pp
+Additionally,
+.Fn fstatat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
+.El
+.Pp
.Fn fstat
will fail if:
.Bl -tag -width Er
@@ -306,7 +373,9 @@ and
fields.
.Pp
The
-.Fn stat
+.Fn stat ,
+.Fn lstat ,
+.Fn fstatat ,
and
.Fn fstat
function calls are expected to conform to
@@ -320,6 +389,10 @@ An
.Fn lstat
function call appeared in
.Bx 4.2 .
+The
+.Fn fstatat
+function appeared in
+.Ox 5.0 .
.Sh CAVEATS
The file generation number,
.Fa st_gen ,
diff --git a/lib/libc/sys/symlink.2 b/lib/libc/sys/symlink.2
index 36666418bb5..1b6293f4917 100644
--- a/lib/libc/sys/symlink.2
+++ b/lib/libc/sys/symlink.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: symlink.2,v 1.12 2007/05/31 19:19:34 jmc Exp $
+.\" $OpenBSD: symlink.2,v 1.13 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: symlink.2,v 1.7 1995/02/27 12:38:34 cgd Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -30,16 +30,19 @@
.\"
.\" @(#)symlink.2 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: July 18 2011 $
.Dt SYMLINK 2
.Os
.Sh NAME
.Nm symlink
.Nd make symbolic link to a file
.Sh SYNOPSIS
+.Fd #include <fcntl.h>
.Fd #include <unistd.h>
.Ft int
.Fn symlink "const char *name1" "const char *name2"
+.Ft int
+.Fn symlinkat "const char *name1" "int fd" "const char *name2"
.Sh DESCRIPTION
A symbolic link
.Fa name2
@@ -55,6 +58,30 @@ Either name may be an arbitrary path name; the files need not
be on the same file system, and the file specified by
.Fa name1
need not exist at all.
+.Pp
+The
+.Fn symlinkat
+function is equivalent to
+.Fn symlink
+except that where
+.Fa name2
+specifies a relative path,
+the newly created symbolic link is created relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn symlinkat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used
+and the behavior is identical to a call to
+.Fn symlink .
.Sh RETURN VALUES
Upon successful completion, a zero value is returned.
If an error occurs, the error code is stored in
@@ -126,14 +153,39 @@ or
.Fa name2
points outside the process's allocated address space.
.El
+.Pp
+Additionally,
+.Fn symlinkat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EBADF
+The
+.Fa name2
+argument does not specify an absolute path and the
+.Fa fd
+argument is neither
+.Dv AT_FDCWD
+nor a valid file descriptor open for reading.
+.El
.Sh SEE ALSO
.Xr ln 1 ,
.Xr link 2 ,
.Xr readlink 2 ,
.Xr unlink 2 ,
.Xr symlink 7
+.Sh STANDARDS
+The
+.Fn symlink
+and
+.Fn symlinkat
+functions conform to
+.St -p1003.1-2008 .
.Sh HISTORY
The
.Fn symlink
function call appeared in
.Bx 4.2 .
+The
+.Fn symlinkat
+function call appeared in
+.Ox 5.0 .
diff --git a/lib/libc/sys/unlink.2 b/lib/libc/sys/unlink.2
index edba0d6c624..424078aaa9e 100644
--- a/lib/libc/sys/unlink.2
+++ b/lib/libc/sys/unlink.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: unlink.2,v 1.16 2008/10/24 14:34:39 jmc Exp $
+.\" $OpenBSD: unlink.2,v 1.17 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: unlink.2,v 1.7 1995/02/27 12:39:13 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@@ -30,16 +30,20 @@
.\"
.\" @(#)unlink.2 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: October 24 2008 $
+.Dd $Mdocdate: July 18 2011 $
.Dt UNLINK 2
.Os
.Sh NAME
-.Nm unlink
+.Nm unlink ,
+.Nm unlinkat
.Nd remove directory entry
.Sh SYNOPSIS
+.Fd #include <fcntl.h>
.Fd #include <unistd.h>
.Ft int
.Fn unlink "const char *path"
+.Ft int
+.Fn unlinkat "int fd" "const char *path" "int flag"
.Sh DESCRIPTION
The
.Fn unlink
@@ -54,6 +58,54 @@ all resources associated with the file are reclaimed.
If one or more processes have the file open when the last link is removed,
the link is removed, but the removal of the file is delayed until
all references to it have been closed.
+.Pp
+The
+.Fn unlinkat
+function is equivalent to either the
+.Fn unlink
+or
+.Xr rmdir 2
+function depending on the value of
+.Fa flag
+(see below), except that where
+.Fa path
+specifies a relative path,
+the directory entry to be removed is determined relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn unlinkat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used
+and the behavior is identical to a call to
+.Fn unlink
+or
+.Fn rmdir ,
+depending on whether or not the
+.Dv AT_REMOVEDIR
+bit is set in
+.Fa flag .
+.Pp
+Values for
+.Fa flag
+are constructed by bitwise-inclusive
+.Tn OR Ns 'ing
+of flags from the following list defined in
+.In fcntl.h :
+.Pp
+.Bl -tag -width AT_REMOVEDIR -offset indent -compact
+.It Dv AT_REMOVEDIR
+Remove the directory entry specified by
+.Fa path
+as a directory, not a normal file.
+.El
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of \-1 is returned and
@@ -62,7 +114,9 @@ is set to indicate the error.
.Sh ERRORS
The
.Fn unlink
-succeeds unless:
+and
+.Fn unlinkat
+functions will fail if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
@@ -106,14 +160,53 @@ The named file resides on a read-only file system.
.Fa path
points outside the process's allocated address space.
.El
+.Pp
+Additionally,
+.Fn unlinkat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
+.It Bq Er ENOTDIR
+The
+.Dv AT_REMOVEDIR
+flag bit is set and
+.Fa path
+does not name a directory.
+.It Bq Er ENOTEMPTY
+The
+.Dv AT_REMOVEDIR
+flag bit is set and the named directory contains files other than
+.Ql \&.
+and
+.Ql \&..
+in it.
+.El
.Sh SEE ALSO
.Xr rm 1 ,
.Xr close 2 ,
.Xr link 2 ,
.Xr rmdir 2 ,
.Xr symlink 7
+.Sh STANDARDS
+The
+.Fn unlink
+and
+.Fn unlinkat
+functions conform to
+.St -p1003.1-2008 .
.Sh HISTORY
An
.Fn unlink
function call appeared in
.At v2 .
+The
+.Fn unlinkat
+function appeared in
+.Ox 5.0 .
diff --git a/lib/libc/sys/utimes.2 b/lib/libc/sys/utimes.2
index 7d79f17d791..d33961ada79 100644
--- a/lib/libc/sys/utimes.2
+++ b/lib/libc/sys/utimes.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: utimes.2,v 1.10 2009/12/29 16:12:28 sobrado Exp $
+.\" $OpenBSD: utimes.2,v 1.11 2011/07/18 23:04:40 matthew Exp $
.\" $NetBSD: utimes.2,v 1.9 1996/04/23 10:34:16 mycroft Exp $
.\"
.\" Copyright (c) 1990, 1993
@@ -30,11 +30,14 @@
.\"
.\" @(#)utimes.2 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: December 29 2009 $
+.Dd $Mdocdate: July 18 2011 $
.Dt UTIMES 2
.Os
.Sh NAME
-.Nm utimes
+.Nm utimes ,
+.Nm futimens ,
+.Nm utimensat ,
+.Nm futimens
.Nd set file access and modification times
.Sh SYNOPSIS
.Fd #include <sys/time.h>
@@ -42,6 +45,12 @@
.Fn utimes "const char *file" "const struct timeval *times"
.Ft int
.Fn futimes "int fd" "const struct timeval *times"
+.Fd #include <sys/stat.h>
+.Fd #include <fcntl.h>
+.Ft int
+.Fn utimensat "int fd" "const char *file" "const struct timespec times[2]" "int flag"
+.Ft int
+.Fn futimes "int fd" "const struct timespec times[2]"
.Sh DESCRIPTION
The access and modification times of the file named by
.Fa path
@@ -68,6 +77,68 @@ The caller must be the owner of the file or be the superuser.
.Pp
In either case, the inode-change-time of the file is set to the current
time.
+.Pp
+The
+.Fn utimensat
+and
+.Fn futimens
+are equivalent to
+.Fn utimes
+and
+.Fn futimes ,
+respectively, with the following differences.
+.Pp
+Both
+.Fn utimensat
+and
+.Fn futimens
+take two timespec values instead of two timeval values.
+Further, either of the
+.Fa tv_nsec
+fields can be set to one of the following special values defined in
+.In sys/stat.h :
+.Pp
+.Bl -tag -width UTIME_OMIT -offset indent -compact
+.It Dv UTIME_NOW
+Set the respective timestamp to the greatest value supported
+that is not greater than the current time.
+.It Dv UTIME_OMIT
+Do change the respective timestamp.
+.El
+.Pp
+Additionally, if the
+.Fa path
+argument to
+.Fn utimensat
+specifies a relative path,
+the file whose timestamps are changed is determined relative to
+the directory associated with file descriptor
+.Fa fd
+instead of the current working directory.
+.Pp
+If
+.Fn utimensat
+is passed the special value
+.Dv AT_FDCWD
+(defined in
+.In fcntl.h )
+in the
+.Fa fd
+parameter, the current working directory is used.
+.Pp
+Values for
+.Fa flag
+are constructed by bitwise-inclusive
+.Tn OR Ns 'ing
+of flags from the following list defined in
+.In fcntl.h :
+.Pp
+.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact
+.It Dv AT_SYMLINK_NOFOLLOW
+If
+.Fa path
+names a symbolic link, then the timestamps of the symbolic link are changed.
+.El
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of \-1 is returned and
@@ -75,6 +146,8 @@ Otherwise, a value of \-1 is returned and
is set to indicate the error.
.Sh ERRORS
.Fn utimes
+and
+.Fn utimensat
will fail if:
.Bl -tag -width Er
.It Bq Er EACCES
@@ -116,7 +189,23 @@ does not match the owner of the file and is not the superuser.
The file system containing the file is mounted read-only.
.El
.Pp
+Additionally,
+.Fn utimensat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er 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 reading.
+.El
+.Pp
.Fn futimes
+and
+.Fn futimens
will fail if:
.Bl -tag -width Er
.It Bq Er EBADF
@@ -148,6 +237,14 @@ The file system containing the file is mounted read-only.
.Sh SEE ALSO
.Xr stat 2 ,
.Xr utime 3
+.Sh STANDARDS
+The
+.Fn utimes ,
+.Fn utimensat ,
+and
+.Fn futimens
+functions conform to
+.St -p1003.1-2008 .
.Sh HISTORY
The
.Fn utimes
@@ -157,3 +254,9 @@ The
.Fn futimes
function call appeared in
.Nx 1.2 .
+The
+.Fn utimensat
+and
+.Fn futimens
+function calls appeared in
+.Ox 5.0 .