dos.library: Reverted 49008, mixing buffered and unbuffered reads causes wrong data...
[AROS.git] / rom / dos / write.c
blob1ffc1cfc317ce2964ecc6aa6e7db980afec1cd1e
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Write a couple of bytes from a file.
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <proto/exec.h>
11 #include <dos/dosextens.h>
12 #include "dos_intern.h"
14 /*****************************************************************************
16 NAME */
17 #include <proto/dos.h>
19 AROS_LH3(LONG, Write,
21 /* SYNOPSIS */
22 AROS_LHA(BPTR, file, D1),
23 AROS_LHA(APTR, buffer, D2),
24 AROS_LHA(LONG, length, D3),
26 /* LOCATION */
27 struct DosLibrary *, DOSBase, 8, Dos)
29 /* FUNCTION
30 Write some data from a given file. The request is directly
31 given to the filesystem - no buffering is involved. For
32 small amounts of data it's probably better to use the
33 buffered I/O routines.
35 INPUTS
36 file - filehandle
37 buffer - pointer to buffer for the data
38 length - number of bytes to write. The filesystem is
39 advised to try to fulfill the request as good
40 as possible.
42 RESULT
43 The number of bytes actually written, 0 if the end of the
44 file was reached, -1 if an error happened. IoErr() will
45 give additional information in that case.
47 NOTES
49 EXAMPLE
51 BUGS
53 SEE ALSO
55 INTERNALS
57 *****************************************************************************/
59 AROS_LIBFUNC_INIT
61 /* Get pointer to filehandle */
62 struct FileHandle *fh = BADDR(file);
63 LONG ret = -1;
65 ASSERT_VALID_PTR(fh);
66 ASSERT_VALID_PTR(buffer);
68 D(bug("[Write] %x %x %d\n", fh, buffer, length));
69 if (fh == NULL)
70 SetIoErr(ERROR_INVALID_LOCK);
71 else
72 ret = dopacket3(DOSBase, NULL, fh->fh_Type, ACTION_WRITE, fh->fh_Arg1, (SIPTR)buffer, length);
73 D(bug("[Write]=%d\n", ret));
75 return ret;
77 AROS_LIBFUNC_EXIT
78 } /* Read */