revert between 56095 -> 55830 in arch
[AROS.git] / compiler / posixc / fwrite.c
blobad955c40fa17a3db0e28b91111b1a3561a238607
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function fwrite().
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 #define DEBUG 0
14 #include <aros/debug.h>
15 #include "__stdio.h"
16 #include "__fdesc.h"
18 /*****************************************************************************
20 NAME */
21 #include <unistd.h>
23 size_t fwrite (
25 /* SYNOPSIS */
26 const void * restrict buf,
27 size_t size,
28 size_t nblocks,
29 FILE * restrict stream)
31 /* FUNCTION
32 Write an amount of bytes to a stream.
34 INPUTS
35 buf - The buffer to write to the stream
36 size - Size of one block to write
37 nblocks - The number of blocks to write
38 stream - Write to this stream
40 RESULT
41 The number of blocks written. If no error occurred, this is
42 nblocks. Otherwise examine errno for the reason of the error.
44 SEE ALSO
45 fopen(), fwrite()
47 ******************************************************************************/
49 size_t cnt;
51 D(bug("[fwrite]: buf=%p, size=%d, nblocks=%d, stream=%p\n",
52 buf, size, nblocks, stream
53 ));
55 fdesc *fdesc = __getfdesc(stream->fd);
57 if (!fdesc)
59 errno = EBADF;
61 return 0;
64 if (nblocks > 0 && size > 0)
65 cnt = FWrite (fdesc->fcb->handle, (CONST APTR)buf, size, nblocks);
66 else
67 cnt = 0;
69 if (cnt == -1)
71 errno = __stdc_ioerr2errno (IoErr ());
73 cnt = 0;
76 return cnt;
77 } /* fwrite */