compiler/clib/fwrite.c: Some debug output
[AROS.git] / compiler / clib / fwrite.c
blobd718b72635a9ab87dfc5179b248ccc6dd8860d99
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C 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 "__errno.h"
16 #include "__stdio.h"
17 #include "__fdesc.h"
19 /*****************************************************************************
21 NAME */
22 #include <unistd.h>
24 size_t fwrite (
26 /* SYNOPSIS */
27 const void * restrict buf,
28 size_t size,
29 size_t nblocks,
30 FILE * restrict stream)
32 /* FUNCTION
33 Write an amount of bytes to a stream.
35 INPUTS
36 buf - The buffer to write to the stream
37 size - Size of one block to write
38 nblocks - The number of blocks to write
39 stream - Write to this stream
41 RESULT
42 The number of blocks written. If no error occurred, this is
43 nblocks. Otherwise examine errno for the reason of the error.
45 SEE ALSO
46 fopen(), fwrite()
48 ******************************************************************************/
50 size_t cnt;
52 D(bug("[fwrite]: buf=%p, size=%d, nblocks=%d, stream=%p\n",
53 buf, size, nblocks, stream
54 ));
56 fdesc *fdesc = __getfdesc(stream->fd);
58 if (!fdesc)
60 errno = EBADF;
62 return 0;
65 if (nblocks > 0 && size > 0)
66 cnt = FWrite ((BPTR)fdesc->fcb->fh, (CONST APTR)buf, size, nblocks);
67 else
68 cnt = 0;
70 if (cnt == -1)
72 errno = IoErr2errno (IoErr ());
74 cnt = 0;
77 return cnt;
78 } /* fwrite */