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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: close.c,v 1.7 1997/01/27 00:36:15 ldp Exp $
  4.     $Log: close.c,v $
  5.     Revision 1.7  1997/01/27 00:36:15  ldp
  6.     Polish
  7.  
  8.     Revision 1.6  1996/12/09 13:53:22  aros
  9.     Added empty templates for all missing functions
  10.  
  11.     Moved #include's into first column
  12.  
  13.     Revision 1.5  1996/10/24 15:50:24  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.4  1996/08/13 13:52:45  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.3  1996/08/12 14:17:34  digulla
  21.     Added alias UnLock Close
  22.  
  23.     Revision 1.2  1996/08/01 17:40:48  digulla
  24.     Added standard header for all files
  25.  
  26.     Desc:
  27.     Lang: english
  28. */
  29. #include <proto/exec.h>
  30. #include <dos/dosextens.h>
  31. #include <dos/filesystem.h>
  32. #include <proto/dos.h>
  33. #include "dos_intern.h"
  34.  
  35. /*****************************************************************************
  36.  
  37.     NAME */
  38. #include <proto/dos.h>
  39.  
  40.     AROS_LH1(BOOL, Close,
  41.  
  42. /*  SYNOPSIS */
  43.     AROS_LHA(BPTR, file, D1),
  44.  
  45. /*  LOCATION */
  46.     struct DosLibrary *, DOSBase, 6, Dos)
  47.  
  48. /*  FUNCTION
  49.     Close a filehandle opened with Open(). If the file was used
  50.     with buffered I/O the final write may fail and thus Close()
  51.     return an error. The file is closed in any case.
  52.  
  53.     INPUTS
  54.     file   - filehandle
  55.  
  56.     RESULT
  57.     0 if there was an error. !=0 on success.
  58.  
  59.     NOTES
  60.     This function is identical to Lock().
  61.  
  62.     EXAMPLE
  63.  
  64.     BUGS
  65.  
  66.     SEE ALSO
  67.  
  68.     INTERNALS
  69.  
  70.     HISTORY
  71.     29-10-95    digulla automatically created from
  72.                 dos_lib.fd and clib/dos_protos.h
  73.  
  74. *****************************************************************************/
  75.  
  76. /*****************************************************************************
  77.  
  78.     NAME
  79. #include <clib/dos_protos.h>
  80.  
  81.     AROS_LH1(BOOL, UnLock,
  82.  
  83.     SYNOPSIS
  84.     AROS_LHA(BPTR, lock, D1),
  85.  
  86.     LOCATION
  87.     struct DosLibrary *, DOSBase, 15, Dos)
  88.  
  89.     FUNCTION
  90.     Free a lock created with Lock().
  91.  
  92.     INPUTS
  93.     lock - The lock to free
  94.  
  95.     RESULT
  96.  
  97.     NOTES
  98.     This function is identical to Close() - see there.
  99.  
  100.     EXAMPLE
  101.  
  102.     BUGS
  103.  
  104.     SEE ALSO
  105.  
  106.     INTERNALS
  107.  
  108.     HISTORY
  109.     29-10-95    digulla automatically created from
  110.                 dos_lib.fd and clib/dos_protos.h
  111.  
  112. *****************************************************************************/
  113. /*AROS alias UnLock Close */
  114. {
  115.     AROS_LIBFUNC_INIT
  116.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  117.  
  118.     /* Get pointer to filehandle */
  119.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  120.  
  121.     /* Get pointer to process structure */
  122.     struct Process *me=(struct Process *)FindTask(NULL);
  123.  
  124.     /* Get pointer to I/O request. Use stackspace for now. */
  125.     struct IOFileSys io,*iofs=&io;
  126.  
  127.     /* The returncode defaults to OK. */
  128.     BOOL ret=1;
  129.  
  130.     /* 0 handles are OK */
  131.     if(!file)
  132.     return ret;
  133.  
  134.     /* If the filehandle has a pending write on it Flush() the buffer. */
  135.     if(fh->fh_Flags&FHF_WRITE)
  136.     ret=Flush(file);
  137.  
  138.     /* Prepare I/O request. */
  139.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  140.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  141.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  142.     iofs->IOFS.io_Device =fh->fh_Device;
  143.     iofs->IOFS.io_Unit     =fh->fh_Unit;
  144.     iofs->IOFS.io_Command=FSA_CLOSE;
  145.     iofs->IOFS.io_Flags  =0;
  146.  
  147.     /* Send the request. No errors possible. */
  148.     (void)DoIO(&iofs->IOFS);
  149.  
  150.     FreeDosObject(DOS_FILEHANDLE,fh);
  151.  
  152.     /* All done. */
  153.     return ret;
  154.     AROS_LIBFUNC_EXIT
  155. } /* Close */
  156.