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

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