New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / dos / fgetc.c
blobaf30048958be0efbec8a9d7c40db6ddddf7d54d2
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
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 /*****************************************************************************
19 NAME */
20 #include <proto/dos.h>
22 AROS_LH1(LONG, FGetC,
24 /* SYNOPSIS */
25 AROS_LHA(BPTR, file, D1),
27 /* LOCATION */
28 struct DosLibrary *, DOSBase, 51, Dos)
30 /* FUNCTION
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.
36 INPUTS
37 file - filehandle
39 RESULT
40 The character read or EOF if the file ended or an error happened.
41 IoErr() gives additional information in that case.
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
50 IoErr(), Flush()
52 INTERNALS
54 *****************************************************************************/
56 AROS_LIBFUNC_INIT
57 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
59 /* Get pointer to filehandle */
60 struct FileHandle *fh = (struct FileHandle *)BADDR(file);
62 LONG size;
64 if (fh == NULL)
66 return EOF;
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. */
80 if(size < 0)
82 return EOF;
85 pos += size;
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;
101 SetIoErr(0);
103 return EOF;
106 /* Is there a buffer? */
107 if(fh->fh_Buf == NULL)
109 if (NULL == vbuf_alloc(fh, IOBUFSIZE, DOSBase))
111 return(EOF);
115 /* Fill the buffer. */
116 size = Read(file, fh->fh_Buf, fh->fh_Size);
118 /* Prepare filehandle for data. */
119 if(size <= 0)
120 size = 0;
122 fh->fh_Pos = fh->fh_Buf;
123 fh->fh_End = fh->fh_Buf + size;
125 /* No data read? Return EOF. */
126 if(size == 0)
128 return EOF;
132 /* All OK. Get data. */
133 return *fh->fh_Pos++;
135 AROS_LIBFUNC_EXIT
136 } /* FGetC */