some fixes to accented characters
[tangerine.git] / rom / dos / write.c
blobcce02c1b451e75e07db39709dd337a9dc3d52c17
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Write data to a file.
6 Lang: English
7 */
8 #include <aros/debug.h>
9 #include <proto/exec.h>
10 #include <dos/filesystem.h>
11 #include "dos_intern.h"
13 /*****************************************************************************
15 NAME */
16 #include <proto/dos.h>
18 AROS_LH3(LONG, Write,
20 /* SYNOPSIS */
21 AROS_LHA(BPTR, file, D1),
22 AROS_LHA(CONST_APTR, buffer, D2),
23 AROS_LHA(LONG, length, D3),
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 8, Dos)
28 /* FUNCTION
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.
34 INPUTS
35 file - filehandle
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
39 as possible.
41 RESULT
42 The number of bytes actually written, -1 if an error happened.
43 IoErr() will give additional information in that case.
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
53 INTERNALS
55 *****************************************************************************/
57 AROS_LIBFUNC_INIT
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 */
87 do {
88 DosDoIO(&iofs.IOFS);
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;
96 AROS_LIBFUNC_EXIT
97 } /* Write */