compiler/clib: Rename IoErr2errno() to __arosc_ioerr2errno(); function is now defined...
[AROS.git] / compiler / clib / read.c
blob8782f92874c4b1a4ebea7706386bae4d2aebd980
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function read().
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 <unistd.h>
21 ssize_t read (
23 /* SYNOPSIS */
24 int fd,
25 void * buf,
26 size_t count)
28 /* FUNCTION
29 Read an amount of bytes from a file descriptor.
31 INPUTS
32 fd - The file descriptor to read from
33 buf - The buffer to read the bytes into
34 count - Read this many bytes.
36 RESULT
37 The number of characters read (may range from 0 when the file
38 descriptor contains no more characters to count) or -1 on error.
40 NOTES
42 EXAMPLE
44 BUGS
46 SEE ALSO
47 open(), read(), fread()
49 INTERNALS
51 ******************************************************************************/
53 ssize_t cnt;
54 fdesc *fdesc = __getfdesc(fd);
56 if (!fdesc)
58 errno = EBADF;
59 return -1;
62 if(fdesc->fcb->isdir)
64 errno = EISDIR;
65 return -1;
68 cnt = Read ((BPTR)fdesc->fcb->fh, buf, count);
70 if (cnt == -1)
71 errno = __arosc_ioerr2errno (IoErr ());
73 return cnt;
74 } /* read */