2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
8 #include <exec/memory.h>
9 #include <proto/exec.h>
11 #include <dos/stdio.h>
12 #include <dos/dosextens.h>
14 #include "dos_intern.h"
17 /*****************************************************************************
20 #include <proto/dos.h>
25 AROS_LHA(BPTR
, file
, D1
),
28 struct DosLibrary
*, DOSBase
, 51, Dos
)
31 Get a character from a buffered file. Buffered I/O is more efficient
32 for small amounts of data but less for big chunks. You have to
33 use Flush() between buffered and non-buffered I/O or you'll
34 clutter your I/O stream.
40 The character read or EOF if the file ended or an error happened.
41 IoErr() gives additional information in that case.
54 *****************************************************************************/
57 AROS_LIBBASE_EXT_DECL(struct DosLibrary
*,DOSBase
)
59 /* Get pointer to filehandle */
60 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(file
);
69 /* If the file is in write mode... */
70 if(fh
->fh_Flags
& FHF_WRITE
)
72 /* write the buffer (in many pieces if the first one isn't enough). */
73 UBYTE
*pos
= fh
->fh_Buf
;
75 while(pos
!= fh
->fh_Pos
)
77 size
= Write(file
, pos
, fh
->fh_Pos
- pos
);
79 /* An error happened? Return it. */
88 /* Reinit filehandle. */
89 fh
->fh_Flags
&= ~FHF_WRITE
;
90 fh
->fh_Pos
= fh
->fh_End
= fh
->fh_Buf
;
93 /* No normal characters left. */
94 if(fh
->fh_Pos
>= fh
->fh_End
)
96 /* Check for a pushed back EOF. */
97 if(fh
->fh_Pos
> fh
->fh_End
)
99 /* Reinit filehandle and return EOF. */
100 fh
->fh_Pos
= fh
->fh_End
;
106 /* Is there a buffer? */
107 if(fh
->fh_Buf
== NULL
)
109 if (NULL
== vbuf_alloc(fh
, IOBUFSIZE
, DOSBase
))
115 /* Fill the buffer. */
116 size
= Read(file
, fh
->fh_Buf
, fh
->fh_Size
);
118 /* Prepare filehandle for data. */
122 fh
->fh_Pos
= fh
->fh_Buf
;
123 fh
->fh_End
= fh
->fh_Buf
+ size
;
125 /* No data read? Return EOF. */
132 /* All OK. Get data. */
133 return *fh
->fh_Pos
++;