home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / biblioteki / c_library / asyncio / source / readcharasync.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  804b  |  37 lines

  1. #include "async.h"
  2.  
  3. _ASM LibCall _ARGS LONG
  4. ReadCharAsync( _REG( a0 ) AsyncFile *file )
  5. {
  6.     UBYTE    ch;
  7.  
  8.     if( file->af_BytesLeft )
  9.     {
  10.         /* if there is at least a byte left in the current buffer, get it
  11.          * directly. Also update all counters
  12.          */
  13.  
  14.         ch = *file->af_Offset;
  15.         --file->af_BytesLeft;
  16.         ++file->af_Offset;
  17.  
  18.         return( ( LONG ) ch );
  19.     }
  20.  
  21.     /* there were no characters in the current buffer, so call the main read
  22.      * routine. This has the effect of sending a request to the file system to
  23.      * have the current buffer refilled. After that request is done, the
  24.      * character is extracted for the alternate buffer, which at that point
  25.      * becomes the "current" buffer
  26.      */
  27.  
  28.     if( ReadAsync( file, &ch, 1 ) > 0 )
  29.     {
  30.         return( ( LONG ) ch );
  31.     }
  32.  
  33.     /* We couldn't read above, so fail */
  34.  
  35.     return( -1 );
  36. }
  37.