Chapter Contents

Previous

Next
write

write



Write Data to a File or Socket

Portability: POSIX.1 conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <fcntl.h>

int write(int fn, const void *buf, size_t size);

The synopsis for the POSIX implementation is

#include <unistd.h>

ssize_t write(init fn, const void *buf, size_t size)


DESCRIPTION

write writes data to the file or socket with file descriptor fn from the buffer addressed by buf . The number of bytes written is size . If fn is associated with a socket, it must either be connected or have been assigned an associated remote address by the connect function.

If size is 0, write returns a value of zero and does not attempt any other operation. Even though the size argument is defined as a size_t , the maximum value permitted is INT_MAX , the largest signed integer.


RETURN VALUE

write returns the number of bytes written or -1 if an error occurs.


EXAMPLE

#include <fcntl.h>

double matrix[100][100];
int tempfile;
.
.
.
write(tempfile, matrix, sizeof(matrix));


RELATED FUNCTIONS

fwrite , writev


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.