CONTENTS | INDEX | PREV | NEXT
write
NAME
write - write data to a file
SYNOPSIS
int r = write(fd, buf, bytes);
int fd;
void *buf;
int bytes;
FUNCTION
writes data to a file starting at the current seek position. This
call extends the file if necessary, else writes over existing data.
With normal files, write will always return the number of bytes
requested and fewer only if an error occurs.
With devices write may or may not return the number of bytes
requested depending on the device, though usually it does.
NOTE
refer to the file_descriptor manual page for general information
Unlike file pointers and file handles, the file descriptor is
checked for validity and will simply return an error if illegal.
EXAMPLE
#include <fcntl.h>
#include <assert.h>
main()
{
int fd;
int r;
fd = open("T:xx", O_WRONLY|O_CREAT|O_TRUNC);
assert(fd >= 0);
r = write(fd, "FuBarn", 6);
assert(r == 6);
lseek(fd, 0L, 0); /* seek back to beginning of file */
r = write(fd, "XX", 2);
assert(r == 2);
close(fd);
}
1> sampleprg
1> type t:xx
XXBar
1>
INPUTS
int fd; file descriptor to write to
void *buf; pointer to buffer to write data from
int len; number of bytes to write
RESULTS
int r; number of bytes actually written, usually an error if r != len.