Renamed include file aros/_timeval.h to aros/types/timeval_s.h.
[AROS.git] / compiler / clib / fwrite.c
blob73341dba0971e110e9771555898a741b436c72da
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 #include <aros/debug.h>
14 #include "__errno.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 fdesc *fdesc = __getfdesc(stream->fd);
53 if (!fdesc)
55 errno = EBADF;
57 return 0;
60 if (nblocks > 0 && size > 0)
61 cnt = FWrite ((BPTR)fdesc->fcb->fh, (CONST APTR)buf, size, nblocks);
62 else
63 cnt = 0;
65 if (cnt == -1)
67 errno = IoErr2errno (IoErr ());
69 cnt = 0;
72 return cnt;
73 } /* fwrite */