mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-12-27 16:31:19 +00:00
224 lines
6.0 KiB
Groff
224 lines
6.0 KiB
Groff
.\" Copyright (c) 1980, 1991, 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.
|
|
.\"
|
|
.\" @(#)write.2 8.5 (Berkeley) 4/2/94
|
|
.\"
|
|
.TH WRITE 2 "23 January 1997" GNO "System Calls"
|
|
.SH NAME
|
|
.BR write ,
|
|
.BR writev
|
|
\- write output
|
|
.SH SYNOPSIS
|
|
#include <sys/types.h>
|
|
.br
|
|
#include <sys/uio.h>
|
|
.br
|
|
#include <unistd.h>
|
|
.sp 1
|
|
ssize_t
|
|
\fBwrite\fR (int \fId\fR, const void *\fIbuf\fR, size_t \fInbytes\fR);
|
|
.sp 1
|
|
ssize_t
|
|
\fBwritev\fR (int \fId\fR, const struct iovec *\fIiov\fR, int \fIiovcnt\fR);
|
|
.SH DESCRIPTION
|
|
.BR write
|
|
attempts to write
|
|
.I nbytes
|
|
of data to the object referenced by the descriptor
|
|
.I d
|
|
from the buffer pointed to by
|
|
.IR buf .
|
|
.BR writev
|
|
performs the same action, but gathers the output data
|
|
from the
|
|
.I iovcnt
|
|
buffers specified by the members of the
|
|
.I iov
|
|
array: iov[0], iov[1], ..., iov[iovcnt\|-\|1].
|
|
.LP
|
|
For
|
|
.BR writev ,
|
|
the
|
|
.I iovec
|
|
structure is defined as:
|
|
.LP
|
|
.nf
|
|
struct iovec {
|
|
void *iov_base;
|
|
size_t iov_len;
|
|
};
|
|
.fi
|
|
.LP
|
|
Each
|
|
.I iovec
|
|
entry specifies the base address and length of an area
|
|
in memory from which data should be written.
|
|
.BR writev
|
|
will always write a complete area before proceeding
|
|
to the next.
|
|
.LP
|
|
On objects capable of seeking, the
|
|
.BR write
|
|
starts at a position
|
|
given by the pointer associated with
|
|
.IR d
|
|
(see
|
|
.BR lseek (2)).
|
|
Upon return from
|
|
.BR write ,
|
|
the pointer is incremented by the number of bytes which were written.
|
|
.LP
|
|
Objects that are not capable of seeking always write from the current
|
|
position. The value of the pointer associated with such an object
|
|
is undefined.
|
|
.LP
|
|
If the real user is not the super-user, then
|
|
.BR write
|
|
clears the set-user-id bit on a file.
|
|
This prevents penetration of system security
|
|
by a user who captures
|
|
a writable set-user-id file
|
|
owned by the super-user.
|
|
.LP
|
|
When using non-blocking I/O on objects such as sockets that are subject
|
|
to flow control,
|
|
.BR write
|
|
and
|
|
.BR writev
|
|
may write fewer bytes than requested;
|
|
the return value must be noted,
|
|
and the remainder of the operation should be retried when possible.
|
|
.LP
|
|
If the file was opened with the GNO-specific flag
|
|
.BR O_TRANS ,
|
|
then newline translation will occur; any line feed (0x0a) character
|
|
present in
|
|
.IR buf
|
|
will be converted to a carridge return (0x0d) before the
|
|
.BR write
|
|
is done. See also the section on
|
|
.BR BUGS ,
|
|
below.
|
|
.SH RETURN VALUES
|
|
Upon successful completion the number of bytes which were written
|
|
is returned. Otherwise a -1 is returned and the global variable
|
|
.IR errno
|
|
is set to indicate the error.
|
|
.SH ERRORS
|
|
.BR Write
|
|
and
|
|
.BR writev
|
|
will fail and the file pointer will remain unchanged if:
|
|
.RS
|
|
.IP \fBEBADF\fR
|
|
.I D
|
|
is not a valid descriptor open for writing.
|
|
.IP \fBEPIPE\fR
|
|
An attempt is made to write to a pipe that is not open
|
|
for reading by any process.
|
|
.IP \fBEPIPE\fR
|
|
An attempt is made to write to a socket of type
|
|
.BR SOCK_STREAM
|
|
that is not connected to a peer socket.
|
|
.IP \fBEFBIG\fR
|
|
An attempt was made to write a file that exceeds the process's
|
|
file size limit or the maximum file size.
|
|
.IP \fBEFAULT\fR
|
|
Part of
|
|
.I iov
|
|
or data to be written to the file
|
|
points outside the process's allocated address space.
|
|
.IP \fBEINVAL\fR
|
|
The pointer associated with
|
|
.I d
|
|
was negative.
|
|
.IP \fBENOSPC\fR
|
|
There is no free space remaining on the file system
|
|
containing the file.
|
|
.IP \fBEDQUOT\fR
|
|
The user's quota of disk blocks on the file system
|
|
containing the file has been exhausted.
|
|
.IP \fBEIO\fR
|
|
An I/O error occurred while reading from or writing to the file system.
|
|
.IP \fBEAGAIN\fR
|
|
The file was marked for non-blocking I/O,
|
|
and no data could be written immediately.
|
|
.RE
|
|
.LP
|
|
In addition,
|
|
.BR writev
|
|
may return one of the following errors:
|
|
.RS
|
|
.IP \fBEINVAL\fR
|
|
.I Iovcnt
|
|
was less than or equal to 0, or greater than
|
|
.BR UIO_MAXIOV .
|
|
.IP \fBEINVAL\fR
|
|
One of the
|
|
.I iov_len
|
|
values in the
|
|
.I iov
|
|
array was negative.
|
|
.IP \fBEINVAL\fR
|
|
The sum of the
|
|
.I iov_len
|
|
values in the
|
|
.I iov
|
|
array overflowed a 32-bit integer.
|
|
.RE
|
|
.SH BUGS
|
|
If the GNO-specific flag
|
|
.BR O_TRANS
|
|
was specified when the descriptor
|
|
.IR d
|
|
was opened, then
|
|
.IR buf
|
|
may be modified by this call; the newline translation is done in-place.
|
|
.SH SEE ALSO
|
|
.BR fcntl (2),
|
|
.BR lseek (2),
|
|
.BR open (2),
|
|
.BR pipe (2),
|
|
.BR select (2)
|
|
.SH STANDARDS
|
|
.BR Write
|
|
is expected to conform to IEEE Std 1003.1-1988 (POSIX).
|
|
.SH HISTORY
|
|
The
|
|
.BR writev
|
|
function call
|
|
appeared in 4.2BSD.
|
|
A
|
|
.BR write
|
|
function call
|
|
appeared in
|
|
Version 6 AT&T UNIX.
|