home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / biblioteki / asyncio / src / readcharasync.c < prev    next >
C/C++ Source or Header  |  1997-02-18  |  792b  |  38 lines

  1. #include "async.h"
  2.  
  3.  
  4. _CALL LONG
  5. ReadCharAsync( _REG( a0 ) AsyncFile *file )
  6. {
  7.     UBYTE    ch;
  8.  
  9.     if( file->af_BytesLeft )
  10.     {
  11.         /* if there is at least a byte left in the current buffer, get it
  12.          * directly. Also update all counters
  13.          */
  14.  
  15.         ch = *file->af_Offset;
  16.         --file->af_BytesLeft;
  17.         ++file->af_Offset;
  18.  
  19.         return( ( LONG ) ch );
  20.     }
  21.  
  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
  27.      */
  28.  
  29.     if( ReadAsync( file, &ch, 1 ) > 0 )
  30.     {
  31.         return( ( LONG ) ch );
  32.     }
  33.  
  34.     /* We couldn't read above, so fail */
  35.  
  36.     return( -1 );
  37. }
  38.