home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / dos / flush.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.4 KB  |  108 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: flush.c,v 1.6 1997/01/27 00:36:20 ldp Exp $
  4.     $Log: flush.c,v $
  5.     Revision 1.6  1997/01/27 00:36:20  ldp
  6.     Polish
  7.  
  8.     Revision 1.5  1996/12/09 13:53:28  aros
  9.     Added empty templates for all missing functions
  10.  
  11.     Moved #include's into first column
  12.  
  13.     Revision 1.4  1996/10/24 15:50:29  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.3  1996/08/13 13:52:46  digulla
  17.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  18.     Replaced AROS_LA by AROS_LHA
  19.  
  20.     Revision 1.2  1996/08/01 17:40:51  digulla
  21.     Added standard header for all files
  22.  
  23.     Desc:
  24.     Lang: english
  25. */
  26. #include <dos/dosextens.h>
  27. #include <proto/dos.h>
  28.  
  29. /*****************************************************************************
  30.  
  31.     NAME */
  32. #include <proto/dos.h>
  33.  
  34.     AROS_LH1(LONG, Flush,
  35.  
  36. /*  SYNOPSIS */
  37.     AROS_LHA(BPTR, file, D1),
  38.  
  39. /*  LOCATION */
  40.     struct DosLibrary *, DOSBase, 60, Dos)
  41.  
  42. /*  FUNCTION
  43.     Flushes any pending writes on the file. If the file was used
  44.     for input and there is still some data to read it tries to
  45.     seek back to the expected position.
  46.  
  47.     INPUTS
  48.     file - filehandle
  49.  
  50.     RESULT
  51.     !=0 on success, 0 on error. IoErr() gives additional information
  52.     in that case.
  53.  
  54.     NOTES
  55.  
  56.     EXAMPLE
  57.  
  58.     BUGS
  59.  
  60.     SEE ALSO
  61.  
  62.     INTERNALS
  63.  
  64.     HISTORY
  65.     29-10-95    digulla automatically created from
  66.                 dos_lib.fd and clib/dos_protos.h
  67.  
  68. *****************************************************************************/
  69. {
  70.     AROS_LIBFUNC_INIT
  71.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  72.  
  73.     /* Get pointer to filehandle */
  74.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  75.     long success=1;
  76.  
  77.     /* If the file is in write mode... */
  78.     if(fh->fh_Flags&FHF_WRITE)
  79.     {
  80.     UBYTE *pos;
  81.     /* Unset write flag */
  82.     fh->fh_Flags&=~FHF_WRITE;
  83.  
  84.     /* Write the data. (In many pieces if the first one isn't enough). */
  85.     pos=fh->fh_Buf;
  86.         while(pos!=fh->fh_Pos)
  87.         {
  88.             LONG size;
  89.         size=Write(file,pos,fh->fh_Pos-pos);
  90.  
  91.         /* An error happened? No success. */
  92.         if(size<0)
  93.         {
  94.             success=0;
  95.         break;
  96.         }
  97.         pos+=size;
  98.     }
  99.     }else if(fh->fh_Pos<fh->fh_End)
  100.         /* Read mode. Try to seek back to the current position. */
  101.         if(Seek(file,fh->fh_Pos-fh->fh_End,OFFSET_CURRENT)<0)
  102.             success=0;
  103.     /* Reinit the buffer and return. */
  104.     fh->fh_Pos=fh->fh_End=fh->fh_Buf;
  105.     return success;
  106.     AROS_LIBFUNC_EXIT
  107. } /* Flush */
  108.