diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2000-04-20 06:34:38 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2000-04-20 06:34:38 +0000 |
commit | 4873302c0040da7d8abe078ba6970c4c2a7937a9 (patch) | |
tree | 95e15495ceb01ff81cd51e1c676d9c3c14bb6bb0 | |
parent | 1635e742b4148d262cf5ac2ca4b18ea21a176e82 (diff) |
p{read,write}{,v} man pages
-rw-r--r-- | lib/libc/sys/Makefile.inc | 8 | ||||
-rw-r--r-- | lib/libc/sys/pread.c | 65 | ||||
-rw-r--r-- | lib/libc/sys/preadv.c | 66 | ||||
-rw-r--r-- | lib/libc/sys/pwrite.c | 65 | ||||
-rw-r--r-- | lib/libc/sys/pwritev.c | 66 | ||||
-rw-r--r-- | lib/libc/sys/read.2 | 53 | ||||
-rw-r--r-- | lib/libc/sys/write.2 | 55 |
7 files changed, 358 insertions, 20 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index a912af19dc7..f393247ad42 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.33 2000/02/07 04:59:30 assar Exp $ +# $OpenBSD: Makefile.inc,v 1.34 2000/04/20 06:34:36 deraadt Exp $ # $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 @@ -28,7 +28,7 @@ DPSRCS+= Lint_Ovfork.c Lint_brk.c Lint_exect.c Lint_fork.c \ # with old syscall interfaces. SRCS+= ftruncate.c lseek.c mmap.c ptrace.c semctl.c truncate.c \ timer_create.c timer_delete.c timer_getoverrun.c timer_gettime.c \ - timer_settime.c + timer_settime.c pread.c preadv.c pwrite.c pwritev.c # modules with default implementations on all architectures: ASM= accept.o access.o acct.o adjtime.o bind.o chdir.o chflags.o chmod.o \ @@ -196,7 +196,7 @@ MLINKS+=intro.2 errno.2 MLINKS+=mlock.2 munlock.2 MLINKS+=mount.2 unmount.2 MLINKS+=pathconf.2 fpathconf.2 -MLINKS+=read.2 readv.2 +MLINKS+=read.2 readv.2 read.2 pread.2 read.2 preadv.2 MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 MLINKS+=send.2 sendmsg.2 send.2 sendto.2 MLINKS+=setpgid.2 setpgrp.2 @@ -208,4 +208,4 @@ MLINKS+=syscall.2 __syscall.2 MLINKS+=truncate.2 ftruncate.2 MLINKS+=utimes.2 futimes.2 MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2 -MLINKS+=write.2 writev.2 +MLINKS+=write.2 writev.2 write.2 pwrite.2 write.2 pwritev.2 diff --git a/lib/libc/sys/pread.c b/lib/libc/sys/pread.c new file mode 100644 index 00000000000..ba8f98afee7 --- /dev/null +++ b/lib/libc/sys/pread.c @@ -0,0 +1,65 @@ +/* $OpenBSD: pread.c,v 1.1 2000/04/20 06:34:37 deraadt Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(SYSLIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: pread.c,v 1.1 2000/04/20 06:34:37 deraadt Exp $"; +#endif /* SYSLIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/syscall.h> +#include <unistd.h> + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +ssize_t +pread(fd, buf, nbyte, offset) + int fd; + void *buf; + size_t nbyte; + off_t offset; +{ + quad_t q; + int rv; + + q = __syscall((quad_t)SYS_pread, fd, buf, nbyte, 0, offset); + if (/* LINTED constant */ sizeof (quad_t) == sizeof (register_t) || + /* LINTED constant */ BYTE_ORDER == LITTLE_ENDIAN) + rv = (int)q; + else + rv = (int)((u_quad_t)q >> 32); + return rv; +} diff --git a/lib/libc/sys/preadv.c b/lib/libc/sys/preadv.c new file mode 100644 index 00000000000..2608da327f5 --- /dev/null +++ b/lib/libc/sys/preadv.c @@ -0,0 +1,66 @@ +/* $OpenBSD: preadv.c,v 1.1 2000/04/20 06:34:37 deraadt Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(SYSLIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: preadv.c,v 1.1 2000/04/20 06:34:37 deraadt Exp $"; +#endif /* SYSLIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/syscall.h> +#include <sys/uio.h> +#include <unistd.h> + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +ssize_t +preadv(fd, iovp, iovcnt, offset) + int fd; + const struct iovec *iovp; + int iovcnt; + off_t offset; +{ + quad_t q; + int rv; + + q = __syscall((quad_t)SYS_preadv, fd, iovp, iovcnt, 0, offset); + if (/* LINTED constant */ sizeof (quad_t) == sizeof (register_t) || + /* LINTED constant */ BYTE_ORDER == LITTLE_ENDIAN) + rv = (int)q; + else + rv = (int)((u_quad_t)q >> 32); + return rv; +} diff --git a/lib/libc/sys/pwrite.c b/lib/libc/sys/pwrite.c new file mode 100644 index 00000000000..5915d9f6cf6 --- /dev/null +++ b/lib/libc/sys/pwrite.c @@ -0,0 +1,65 @@ +/* $OpenBSD: pwrite.c,v 1.1 2000/04/20 06:34:37 deraadt Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(SYSLIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: pwrite.c,v 1.1 2000/04/20 06:34:37 deraadt Exp $"; +#endif /* SYSLIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/syscall.h> +#include <unistd.h> + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +ssize_t +pwrite(fd, buf, nbyte, offset) + int fd; + const void *buf; + size_t nbyte; + off_t offset; +{ + quad_t q; + int rv; + + q = __syscall((quad_t)SYS_pwrite, fd, buf, nbyte, 0, offset); + if (/* LINTED constant */ sizeof (quad_t) == sizeof (register_t) || + /* LINTED constant */ BYTE_ORDER == LITTLE_ENDIAN) + rv = (int)q; + else + rv = (int)((u_quad_t)q >> 32); + return rv; +} diff --git a/lib/libc/sys/pwritev.c b/lib/libc/sys/pwritev.c new file mode 100644 index 00000000000..ff8c195d426 --- /dev/null +++ b/lib/libc/sys/pwritev.c @@ -0,0 +1,66 @@ +/* $OpenBSD: pwritev.c,v 1.1 2000/04/20 06:34:37 deraadt Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(SYSLIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: pwritev.c,v 1.1 2000/04/20 06:34:37 deraadt Exp $"; +#endif /* SYSLIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/syscall.h> +#include <sys/uio.h> +#include <unistd.h> + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +ssize_t +pwritev(fd, iovp, iovcnt, offset) + int fd; + const struct iovec *iovp; + int iovcnt; + off_t offset; +{ + quad_t q; + int rv; + + q = __syscall((quad_t)SYS_pwritev, fd, iovp, iovcnt, 0, offset); + if (/* LINTED constant */ sizeof (quad_t) == sizeof (register_t) || + /* LINTED constant */ BYTE_ORDER == LITTLE_ENDIAN) + rv = (int)q; + else + rv = (int)((u_quad_t)q >> 32); + return rv; +} diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2 index 72d7fc46f38..dcded040878 100644 --- a/lib/libc/sys/read.2 +++ b/lib/libc/sys/read.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: read.2,v 1.15 2000/04/12 21:48:02 aaron Exp $ +.\" $OpenBSD: read.2,v 1.16 2000/04/20 06:34:37 deraadt Exp $ .\" $NetBSD: read.2,v 1.6 1995/02/27 12:35:47 cgd Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 @@ -39,7 +39,9 @@ .Os .Sh NAME .Nm read , -.Nm readv +.Nm readv , +.Nm pread , +.Nm preadv .Nd read input .Sh SYNOPSIS .Fd #include <sys/types.h> @@ -49,6 +51,10 @@ .Fn read "int d" "void *buf" "size_t nbytes" .Ft ssize_t .Fn readv "int d" "const struct iovec *iov" "int iovcnt" +.Ft ssize_t +.Fn pread "int d" "void *buf" "size_t nbytes" "off_t offset" +.Ft ssize_t +.Fn preadv "int d" "const struct iovec *iov" "int iovcnt" "off_t offset" .Sh DESCRIPTION .Fn read attempts to read @@ -57,16 +63,23 @@ of data from the object referenced by the descriptor .Fa d into the buffer pointed to by .Fa buf . -.Fn \ Readv +.Fn readv performs the same action, but scatters the input data into the .Fa iovcnt buffers specified by the members of the .Fa iov array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1]. +.Fn pread +and +.Fn preadv +perform the same functions, but read from the specified position in +the file without modifying the file pointer. .Pp For -.Fn readv , +.Fn readv +and +.Fn preadv , the .Fa iovec structure is defined as: @@ -103,8 +116,10 @@ object is undefined. .Pp Upon successful completion, .Fn read +.Fn readv , +.Fn pread , and -.Fn readv +.Fn preadv return the number of bytes actually read and placed in the buffer. The system guarantees to read the number of bytes requested if the descriptor references a normal file that has that many bytes left @@ -112,6 +127,8 @@ before the end-of-file, but in no other case. .Pp Note that .Fn readv +and +.Fn preadv will fail if the value of .Fa iovcnt exceedes the constant @@ -125,8 +142,10 @@ Otherwise, a \-1 is returned and the global variable is set to indicate the error. .Sh ERRORS .Fn read +.Fn readv , +.Fn pread , and -.Fn readv +.Fn preadv will succeed unless: .Bl -tag -width Er .It Bq Er EBADF @@ -151,6 +170,8 @@ and no data were ready to be read. .Pp In addition, .Fn read +and +.Fn pread may return the following error: .Bl -tag -width Er .It Bq Er EINVAL @@ -161,6 +182,8 @@ was larger than .Pp Also, .Fn readv +and +.Fn preadv may return one of the following errors: .Bl -tag -width Er .It Bq Er EINVAL @@ -191,8 +214,14 @@ points outside the process's allocated address space. .Sh STANDARDS The .Fn read -function is expected to conform to -.St -p1003.1-88 . +function conforms to +.St -p1003.1-90 . +The +.Fn readv +and +.Fn pread +functions conform to +.St -xpg4.2 . .Sh CAVEATS Error checks should explicitly test for \-1. Code such as @@ -215,6 +244,14 @@ Proper loops should use .Ed .Sh HISTORY The +.Fn preadv +function first appeared in +.Ox 2.7 . +The +.Fn pread +function appeared in +.At V.4 . +The .Fn readv function call appeared in diff --git a/lib/libc/sys/write.2 b/lib/libc/sys/write.2 index 5503da85413..e2bf3d95162 100644 --- a/lib/libc/sys/write.2 +++ b/lib/libc/sys/write.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: write.2,v 1.19 2000/04/15 11:46:04 aaron Exp $ +.\" $OpenBSD: write.2,v 1.20 2000/04/20 06:34:37 deraadt Exp $ .\" $NetBSD: write.2,v 1.6 1995/02/27 12:39:43 cgd Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 @@ -39,7 +39,9 @@ .Os .Sh NAME .Nm write , -.Nm writev +.Nm writev , +.Nm pwrite , +.Nm pwritev .Nd write output .Sh SYNOPSIS .Fd #include <sys/types.h> @@ -49,6 +51,10 @@ .Fn write "int d" "const void *buf" "size_t nbytes" .Ft ssize_t .Fn writev "int d" "const struct iovec *iov" "int iovcnt" +.Ft ssize_t +.Fn pwrite "int d" "const void *buf" "size_t nbytes" "off_t offset" +.Ft ssize_t +.Fn pwritev "int d" "const struct iovec *iov" "int iovcnt" "off_t offset" .Sh DESCRIPTION .Fn write attempts to write @@ -57,16 +63,23 @@ of data to the object referenced by the descriptor .Fa d from the buffer pointed to by .Fa buf . -.Fn \ Writev +.Fn writev performs the same action, but gathers the output data from the .Fa iovcnt buffers specified by the members of the .Fa iov array: iov[0], iov[1], ..., iov[iovcnt\|-\|1]. +.Fn pwrite +and +.Fn pwritev +perform the same functions, but write to the specified position in +the file without modifying the file pointer. .Pp For -.Fn writev , +.Fn writev +and +.Fn pwritev , the .Fa iovec structure is defined as: @@ -83,6 +96,8 @@ Each entry specifies the base address and length of an area in memory from which data should be written. .Fn writev +and +.Fn pwritev will always write a complete area before proceeding to the next. .Pp @@ -127,6 +142,8 @@ and the remainder of the operation should be retried when possible. .Pp Note that .Fn writev +and +.Fn pwritev will fail if the value of .Fa iovcnt exceedes the constant @@ -137,9 +154,11 @@ is returned. Otherwise, a \-1 is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS -.Fn write +.Fn write , +.Fn pwrite , +.Fn writev , and -.Fn writev +.Fn pwritev will fail and the file pointer will remain unchanged if: .Bl -tag -width Er .It Bq Er EBADF @@ -174,6 +193,8 @@ and no data could be written immediately. .Pp In addition, .Fn write +and +.Fn pwrite may return the following error: .Bl -tag -width Er .It Bq Er EFAULT @@ -189,6 +210,8 @@ was larger than .Pp Also, .Fn writev +and +.Fn pwritev may return one of the following errors: .Bl -tag -width Er .It Bq Er EDESTADDRREQ @@ -219,8 +242,14 @@ array overflowed an .Sh STANDARDS The .Fn write -function is expected to conform to -.St -p1003.1-88 . +function conforms to +.St -p1003.1-90 . +The +.Fn writev +and +.Fn pwrite +functions conform to +.St -xpg4.2 . .Sh CAVEATS Error checks should explicitly test for \-1. Code such as @@ -243,6 +272,16 @@ Proper loops should use .Ed .Sh HISTORY The +.Fn pwritev +function call +appeared in +.Ox 2.7 . +The +.Fn pwrite +function call +appeared in +.At V.4 . +The .Fn writev function call appeared in |