Start of port of AsyncIO library.
[AROS-Contrib.git] / workbench / libs / asyncio / src / PeekAsync.c
blob4c634783229d88afcc721bf1e209e4166cffc354
1 #include "async.h"
4 _LIBCALL LONG
5 PeekAsync( _REG( a0 ) AsyncFile *file, _REG( a1 ) APTR buffer, _REG( d0 ) LONG numBytes )
7 #ifdef ASIO_NOEXTERNALS
8 struct ExecBase *SysBase = file->af_SysBase;
9 #endif
11 /* Try to fill a new buffer, if needed */
12 if( !file->af_BytesLeft )
14 LONG bytes;
16 if( ( bytes = ReadAsync( file, &bytes, 1 ) ) <= 0 )
18 return( bytes );
21 /* Unread byte */
22 --file->af_Offset;
23 ++file->af_BytesLeft;
26 /* Copy what we can */
27 numBytes = MIN( numBytes, file->af_BytesLeft );
28 CopyMem( file->af_Offset, buffer, numBytes );
29 return( numBytes );