2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
5 Desc: Write data to a file.
8 #include <aros/debug.h>
9 #include <proto/exec.h>
10 #include <dos/filesystem.h>
11 #include "dos_intern.h"
13 /*****************************************************************************
16 #include <proto/dos.h>
21 AROS_LHA(BPTR
, file
, D1
),
22 AROS_LHA(CONST_APTR
, buffer
, D2
),
23 AROS_LHA(LONG
, length
, D3
),
26 struct DosLibrary
*, DOSBase
, 8, Dos
)
29 Write some data to a given file. The request is directly
30 given to the filesystem - no buffering is involved. For
31 small amounts of data it's probably better to use the
32 buffered I/O routines.
36 buffer - pointer to data buffer
37 length - number of bytes to write. The filesystem is
38 advised to try to fulfill the request as good
42 The number of bytes actually written, -1 if an error happened.
43 IoErr() will give additional information in that case.
55 *****************************************************************************/
59 /* Get pointer to filehandle. */
60 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(file
);
62 /* Get pointer to I/O request. Use stackspace for now. */
63 struct IOFileSys iofs
;
65 /* Make sure the input parameters are sane. */
66 ASSERT_VALID_PTR( fh
);
67 ASSERT_VALID_PTR( fh
->fh_Device
);
68 ASSERT_VALID_PTR( fh
->fh_Unit
);
69 ASSERT_VALID_PTR( buffer
);
71 /* Handle append mode. */
72 if( fh
->fh_Flags
& FHF_APPEND
)
74 InternalSeek( fh
, 0, OFFSET_END
, DOSBase
);
77 /* Prepare I/O request */
78 InitIOFS( &iofs
, FSA_WRITE
, DOSBase
);
80 iofs
.IOFS
.io_Device
= fh
->fh_Device
;
81 iofs
.IOFS
.io_Unit
= fh
->fh_Unit
;
83 iofs
.io_Union
.io_WRITE
.io_Buffer
= (APTR
)buffer
;
84 iofs
.io_Union
.io_WRITE
.io_Length
= length
;
86 /* send the request, with error reporting */
89 } while (iofs
.io_DosError
!= 0
90 && !ErrorReport(iofs
.io_DosError
, REPORT_STREAM
, (IPTR
)fh
, NULL
));
92 SetIoErr(iofs
.io_DosError
);
94 return iofs
.io_DosError
== 0 ? iofs
.io_Union
.io_WRITE
.io_Length
: -1;