Start of port of AsyncIO library.
[AROS-Contrib.git] / workbench / libs / asyncio / src / ReadCharAsync.c
blobf78125174deb7ba681bc605a89dee170bf23d4b3
1 #include "async.h"
4 _CALL LONG
5 ReadCharAsync( _REG( a0 ) AsyncFile *file )
7 UBYTE ch;
9 if( file->af_BytesLeft )
11 /* if there is at least a byte left in the current buffer, get it
12 * directly. Also update all counters
15 ch = *file->af_Offset;
16 --file->af_BytesLeft;
17 ++file->af_Offset;
19 return( ( LONG ) ch );
22 /* there were no characters in the current buffer, so call the main read
23 * routine. This has the effect of sending a request to the file system to
24 * have the current buffer refilled. After that request is done, the
25 * character is extracted for the alternate buffer, which at that point
26 * becomes the "current" buffer
29 if( ReadAsync( file, &ch, 1 ) > 0 )
31 return( ( LONG ) ch );
34 /* We couldn't read above, so fail */
36 return( -1 );