backport
[AROS.git] / compiler / clib / read.c
blob81c44f3d9db9d4a24df59bbb4d4dd985b07b87df
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 "__fdesc.h"
15 /*****************************************************************************
17 NAME */
18 #include <unistd.h>
20 ssize_t read (
22 /* SYNOPSIS */
23 int fd,
24 void * buf,
25 size_t count)
27 /* FUNCTION
28 Read an amount of bytes from a file descriptor.
30 INPUTS
31 fd - The file descriptor to read from
32 buf - The buffer to read the bytes into
33 count - Read this many bytes.
35 RESULT
36 The number of characters read (may range from 0 when the file
37 descriptor contains no more characters to count) or -1 on error.
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 open(), read(), fread()
48 INTERNALS
50 ******************************************************************************/
52 ssize_t cnt;
53 fdesc *fdesc = __getfdesc(fd);
55 if (!fdesc)
57 errno = EBADF;
58 return -1;
61 if(fdesc->fcb->isdir)
63 errno = EISDIR;
64 return -1;
67 cnt = Read ((BPTR)fdesc->fcb->fh, buf, count);
69 if (cnt == -1)
70 errno = __arosc_ioerr2errno (IoErr ());
72 return cnt;
73 } /* read */