*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->IRIX man pages -> fread (3s)              


FREAD(3S)							     FREAD(3S)

NAME    [Toc]    [Back]

     fread, fwrite - binary input/output

SYNOPSIS    [Toc]    [Back]

     #include <stdio.h>

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

     size_t fwrite (const void *ptr, size_t size, size_t nitems, FILE

DESCRIPTION    [Toc]    [Back]

     fread copies, into	an array pointed to by ptr, up to nitems items of data
     from the named input stream, where	an item	of data	is a sequence of bytes
     (not necessarily terminated by a null byte) of length size.  fread	stops
     reading bytes if an end-of-file or	error condition	is encountered while
     reading stream, or	if nitems items	have been read.	 The file pointer
     associated	with stream is positioned following the	last byte read,	which
     may be at end-of-file.  fread does	not change the contents	of stream.
     fread returns the number of items read.

     fwrite appends at most nitems items of data from the array	pointed	to by
     ptr to the	named output stream.  fwrite stops appending when it has
     appended nitems items of data or if an error condition is encountered on
     stream.  fwrite does not change the contents of the array pointed to by
     ptr.  fwrite increments the data-printer in the stream by the number of
     bytes written.  If	an error occurs, the resulting value of	the fileposition
 indicator	for the	stream is indeterminate.  fwrite returns the
     number of items written.

     ferror(3S)	may be used to determine if an error occurred in an fread or
     fwrite call.  The ferror(3S) or feof(3S) routines should be used to
     distinguish between an error condition and	end-of-file condition.

     The argument size is typically sizeof(*ptr) where the C operator sizeof
     is	used to	determine the length of	an item	pointed	to by ptr.

SEE ALSO    [Toc]    [Back]

     exit(2), fcntl(2),	lseek(2), read(2), write(2), abort(3C),	fclose(3S),
     fopen(3S),	ferror(3S), getc(3S), gets(3S),	printf(3S), putc(3S),
     puts(3S), scanf(3S), stdio(3S).

NOTE    [Toc]    [Back]

     To	use these functions with direct	I/O (see fcntl(2)), it is necessary to
     arrange that the buffers be correctly aligned before any I/O is done.
     One way to	do this	is:

	  char *caBuffer11;
	  caBuffer11 = memalign(dioinfo.d_mem, 8+100 * dioinfo.d_miniosz);
	  setbuffer(fpOutFile,caBuffer11,8+100 * dioinfo.d_miniosz);

     where the dioinfo structure has been filled in by the F_DIOINFO fcntl

									Page 1

FREAD(3S)							     FREAD(3S)


DIAGNOSTICS    [Toc]    [Back]

     Both fread	and fwrite always return a nonnegative integer indicating the
     number of items read or written.  This will be equal to nitems unless an
     error occurred, the value of size is zero,	or fread or fwrite detect that
     a request has been	made to	read (or write)	more data than is addressable.

									PPPPaaaaggggeeee 2222
[ Back ]
 Similar pages
Name OS Title
fwrite FreeBSD binary stream input/output
fread Linux binary stream input/output
fread FreeBSD binary stream input/output
fwrite NetBSD binary stream input/output
fwrite OpenBSD binary stream input/output
fread OpenBSD binary stream input/output
fread NetBSD binary stream input/output
poll IRIX input/output multiplexing
ios IRIX input/output formatting
intro IRIX buffering, formatting and input/output
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service