tools/toollib: remove from main Makefile.in
[AROS.git] / compiler / posixc / fread.c
blob5465e7a5efc289958ff2a6e52797494da3f5fabf
1 /*
2 Copyright © 1995-2013, 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 |= __POSIXC_STDIO_ERROR;
62 errno = EBADF;
63 return 0;
66 FLUSHONREADCHECK
68 cnt = FRead (fdesc->fcb->handle, buf, size, nblocks);
70 if (cnt == -1)
72 errno = __stdc_ioerr2errno (IoErr ());
73 stream->flags |= __POSIXC_STDIO_ERROR;
75 cnt = 0;
77 else if (cnt == 0 || cnt < nblocks)
79 stream->flags |= __POSIXC_STDIO_EOF;
82 return cnt;
83 } /* fread */