The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

fwrite - binary output

 SYNOPSIS



#include <stdio.h>

size_t fwrite(const void *ptr, size_t size, size_t nitems,
    FILE *stream);

 DESCRIPTION

The fwrite() function writes, from the array pointed to by ptr, up to nitems members whose size is specified by size, to the stream pointed to by stream. The file-position indicator for the stream (if defined) is advanced by the number of bytes successfully written. If an error occurs, the resulting value of the file-position indicator for the stream is indeterminate.

The st_ctime and st_mtime fields of the file will be marked for update between the successful execution of fwrite() and the next successful completion of a call to fflush() or fclose() on the same stream or a call to exit() or abort().

 RETURN VALUE

The fwrite() function returns the number of members successfully written, which may be less than nitems if a write error is encountered. If size or nitems is 0, fwrite() returns 0 and the state of the stream remains unchanged. Otherwise, if a write error occurs, the error indicator for the stream is set and errno is set to indicate the error.

 ERRORS

Refer to fputc().

 EXAMPLES

None.

 APPLICATION USAGE

Because of possible differences in member length and byte ordering, files written using fwrite() are application-dependent, and possibly cannot be read using fread() by a different application or by the same application on a different processor.

 FUTURE DIRECTIONS

None.

 SEE ALSO

ferror(), fopen(), printf(), putc(), puts(), write(), <stdio.h>.

DERIVATION

Derived from Issue 1 of the SVID.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]