home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / biblioteki / asyncio / src / peekasync.c < prev    next >
C/C++ Source or Header  |  1997-06-08  |  588b  |  31 lines

  1. #include "async.h"
  2.  
  3.  
  4. _LIBCALL LONG
  5. PeekAsync( _REG( a0 ) AsyncFile *file, _REG( a1 ) APTR buffer, _REG( d0 ) LONG numBytes )
  6. {
  7. #ifdef ASIO_NOEXTERNALS
  8.     struct ExecBase    *SysBase = file->af_SysBase;
  9. #endif
  10.  
  11.     /* Try to fill a new buffer, if needed */
  12.     if( !file->af_BytesLeft )
  13.     {
  14.         LONG    bytes;
  15.  
  16.         if( ( bytes = ReadAsync( file, &bytes, 1 ) ) <= 0 )
  17.         {
  18.             return( bytes );
  19.         }
  20.  
  21.         /* Unread byte */
  22.         --file->af_Offset;
  23.         ++file->af_BytesLeft;
  24.     }
  25.  
  26.     /* Copy what we can */
  27.     numBytes = MIN( numBytes, file->af_BytesLeft );
  28.     CopyMem( file->af_Offset, buffer, numBytes );
  29.     return( numBytes );
  30. }
  31.