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

  1. #include "async.h"
  2.  
  3.  
  4. _LIBCALL LONG
  5. CloseAsync( _REG( a0 ) AsyncFile *file )
  6. {
  7.     LONG    result;
  8.  
  9.     if( file )
  10.     {
  11. #ifdef ASIO_NOEXTERNALS
  12.         struct ExecBase        *SysBase = file->af_SysBase;
  13.         struct DosLibrary    *DOSBase = file->af_DOSBase;
  14. #endif
  15.         result = AS_WaitPacket( file );
  16.  
  17.         if( result >= 0 )
  18.         {
  19.             if( !file->af_ReadMode )
  20.             {
  21.                 /* this will flush out any pending data in the write buffer */
  22.                 if( file->af_BufferSize > file->af_BytesLeft )
  23.                 {
  24.                     result = Write(
  25.                         file->af_File,
  26.                         file->af_Buffers[ file->af_CurrentBuf ],
  27.                         file->af_BufferSize - file->af_BytesLeft );
  28.                 }
  29.             }
  30.         }
  31.  
  32.         if( file->af_CloseFH )
  33.         {
  34.             Close( file->af_File );
  35.         }
  36.  
  37.         FreeVec(file);
  38.     }
  39.     else
  40.     {
  41. #ifndef ASIO_NOEXTERNALS
  42.         SetIoErr( ERROR_INVALID_LOCK );
  43. #endif
  44.         result = -1;
  45.     }
  46.  
  47.     return( result );
  48. }
  49.