New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / dos / read.c
blob90def8d3a0a470de84d9afb4742c4576ae3db26b
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Read a couple of bytes from a file.
6 Lang: english
7 */
8 #include <aros/debug.h>
9 #include <proto/exec.h>
10 #include <dos/dosextens.h>
11 #include <dos/filesystem.h>
12 #include "dos_intern.h"
14 /*****************************************************************************
16 NAME */
17 #include <proto/dos.h>
19 AROS_LH3(LONG, Read,
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, 7, Dos)
29 /* FUNCTION
30 Read 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 read. The filesystem is
39 advised to try to fulfill the request as good
40 as possible.
42 RESULT
43 The number of bytes actually read, 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
60 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
62 /* Get pointer to filehandle */
63 struct FileHandle *fh = (struct FileHandle *)BADDR(file);
65 /* Get pointer to I/O request. Use stackspace for now. */
66 struct IOFileSys iofs;
68 ASSERT_VALID_PTR(fh);
69 ASSERT_VALID_PTR(fh->fh_Device);
70 ASSERT_VALID_PTR(fh->fh_Unit);
71 ASSERT_VALID_PTR(buffer);
73 /* Prepare I/O request. */
74 InitIOFS(&iofs, FSA_READ, DOSBase);
76 iofs.IOFS.io_Device = fh->fh_Device;
77 iofs.IOFS.io_Unit = fh->fh_Unit;
79 iofs.io_Union.io_READ.io_Buffer = buffer;
80 iofs.io_Union.io_READ.io_Length = length;
82 /* Send the request. */
83 DosDoIO(&iofs.IOFS);
85 /* Set error code and return */
87 if(iofs.io_DosError != 0)
89 SetIoErr(iofs.io_DosError);
90 return -1;
92 else
93 return iofs.io_Union.io_READ.io_Length;
95 AROS_LIBFUNC_EXIT
96 } /* Read */