Removed double NAME entry.
[AROS.git] / compiler / clib / fread.c
blobfb44f1617fe7663ff02429ea20d30379de975d24
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function fread().
6 */
8 #include <errno.h>
9 #include <dos/dos.h>
10 #include <dos/dosextens.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include "__stdio.h"
14 #include "__fdesc.h"
16 /*****************************************************************************
18 NAME */
19 #include <stdio.h>
21 size_t fread (
23 /* SYNOPSIS */
24 void * buf,
25 size_t size,
26 size_t nblocks,
27 FILE * stream)
29 /* FUNCTION
30 Read an amount of bytes from a stream.
32 INPUTS
33 buf - The buffer to read the bytes into
34 size - Size of one block to read
35 nblocks - The number of blocks to read
36 stream - Read from this stream
38 RESULT
39 The number of blocks read. This may range from 0 when the stream
40 contains no more blocks up to nblocks. In case of an error, 0 is
41 returned.
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
50 fopen(), fwrite()
52 INTERNALS
54 ******************************************************************************/
56 size_t cnt;
57 fdesc *fdesc = __getfdesc(stream->fd);
59 if (!fdesc)
61 stream->flags |= _STDIO_ERROR;
62 errno = EBADF;
63 return 0;
66 cnt = FRead ((BPTR)fdesc->fcb->fh, buf, size, nblocks);
68 if (cnt == -1)
70 errno = __arosc_ioerr2errno (IoErr ());
71 stream->flags |= _STDIO_ERROR;
73 cnt = 0;
75 else if (cnt == 0 || cnt < nblocks)
77 stream->flags |= _STDIO_EOF;
80 return cnt;
81 } /* fread */