r4548@vps: verhaegs | 2007-04-23 10:55:24 -0400
[AROS.git] / compiler / clib / write.c
blobbe7c5d6245a4f674f75892064c2ea77f593106c6
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function write().
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 "__errno.h"
15 #include "__open.h"
17 /*****************************************************************************
19 NAME */
20 #include <unistd.h>
22 ssize_t write (
24 /* SYNOPSIS */
25 int fd,
26 const void * buf,
27 size_t count)
29 /* FUNCTION
30 Write an amount of characters to the specified file descriptor.
32 INPUTS
33 fd - The file descriptor to write to
34 buf - Write these bytes into the file descriptor
35 count - Write that many bytes
37 RESULT
38 The number of characters written or -1 on error.
40 NOTES
42 EXAMPLE
44 BUGS
46 SEE ALSO
48 INTERNALS
50 ******************************************************************************/
52 ssize_t cnt;
54 fdesc *fdesc = __getfdesc(fd);
55 if (!fdesc)
57 errno = EBADF;
58 return -1;
61 cnt = Write ((BPTR)fdesc->fh, (void *)buf, count);
63 if (cnt == -1)
64 errno = IoErr2errno (IoErr ());
66 return cnt;
67 } /* write */