r6831@lvps87-230-33-50: verhaegs | 2008-02-03 14:08:57 +0100
[tangerine.git] / compiler / clib / fwrite.c
blob99ae9fae94ce43a622bc55cf9a6e1f72a11bd18d
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 "__open.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 cnt = FWrite ((BPTR)fdesc->fh, (CONST APTR)buf, size, nblocks);
62 if (cnt == -1)
64 errno = IoErr2errno (IoErr ());
66 cnt = 0;
69 return cnt;
70 } /* fwrite */