use same location as .configured, etc, to store .files-touched
[AROS.git] / compiler / clib / fread.c
blobb97247954984670bae80c778ca86bb63d5f433af
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C 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 "__errno.h"
14 #include "__stdio.h"
15 #include "__fdesc.h"
17 /*****************************************************************************
19 NAME */
20 #include <stdio.h>
22 size_t fread (
24 /* SYNOPSIS */
25 void * buf,
26 size_t size,
27 size_t nblocks,
28 FILE * stream)
30 /* FUNCTION
31 Read an amount of bytes from a stream.
33 INPUTS
34 buf - The buffer to read the bytes into
35 size - Size of one block to read
36 nblocks - The number of blocks to read
37 stream - Read from this stream
39 RESULT
40 The number of blocks read. This may range from 0 when the stream
41 contains no more blocks up to nblocks. In case of an error, 0 is
42 returned.
44 NOTES
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 fopen(), fwrite()
53 INTERNALS
55 ******************************************************************************/
57 size_t cnt;
58 fdesc *fdesc = __getfdesc(stream->fd);
60 if (!fdesc)
62 stream->flags |= _STDIO_ERROR;
63 errno = EBADF;
64 return 0;
67 cnt = FRead ((BPTR)fdesc->fcb->fh, buf, size, nblocks);
69 if (cnt == -1)
71 errno = IoErr2errno (IoErr ());
72 stream->flags |= _STDIO_ERROR;
74 cnt = 0;
76 else if (cnt == 0 || cnt < nblocks)
78 stream->flags |= _STDIO_EOF;
81 return cnt;
82 } /* fread */