Update contrib.
3 * Portions Copyright (c) 1990-2005 Nokia Corporation and/or its subsidiary(-ies).
8 * Copyright (c) 1990 The Regents of the University of California.
11 * Redistribution and use in source and binary forms are permitted
12 * provided that the above copyright notice and this paragraph are
13 * duplicated in all such forms and that any documentation,
14 * advertising materials, and other materials related to such
15 * distribution and use acknowledge that the software was developed
16 * by the University of California, Berkeley. The name of the
17 * University may not be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 <<fread>>---read array elements from a file
33 size_t fread(void *<[buf]>, size_t <[size]>, size_t <[count]>,
38 size_t fread(<[buf]>, <[size]>, <[count]>, <[fp]>)
45 <<fread>> attempts to copy, from the file or stream identified by
46 <[fp]>, <[count]> elements (each of size <[size]>) into memory,
47 starting at <[buf]>. <<fread>> may copy fewer elements than
48 <[count]> if an error, or end of file, intervenes.
50 <<fread>> also advances the file position indicator (if any) for
51 <[fp]> by the number of @emph{characters} actually read.
54 The result of <<fread>> is the number of elements it succeeded in
58 ANSI C requires <<fread>>.
60 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
61 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
69 Read block of data from a stream.
70 Read count number of items each one with a size of size bytes from the stream
71 and stores it in the specified buffer.
72 Stream's postion indicator is increased by the number of bytes readed.
73 Total amount of bytes read is (size x count).
74 @return The total number of items readed is returned.
75 @param buf Pointer to the destination structure with a minimum size of (size*count) bytes.
76 @param size Size in bytes of each item to be read.
77 @param count Number of items, each one with a size of size bytes.
78 @param fp pointer to an open file.
81 fread (void *buf, size_t size, size_t count, FILE * fp)
83 register size_t resid;
88 if ((resid = count * size) == 0)
94 while ((int)resid > (r = fp->_r))
96 (void) memcpy ((void *) p, (void *) fp->_p, (size_t) r);
98 /* fp->_r = 0 ... done in __srefill */
103 /* no more input: return partial result */
104 return (total - resid) / size;
107 (void) memcpy ((void *) p, (void *) fp->_p, resid);