home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / CLOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.5 KB  |  54 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - close.c
  3.  *
  4.  * function(s)
  5.  *        close - close a file handle
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <io.h>
  18. #include <_io.h>
  19. #include <RtlData.h>
  20.  
  21. #if CPM_ctlZ  /* see commentary in file "zapctlz.cas" */
  22. #include <fcntl.h>
  23. #endif
  24.  
  25. /*-------------------------------------------------------------------------*
  26.  
  27. Name            close - close a file handle
  28.  
  29. Usage           int close(int handle);
  30.  
  31. Prototype in    io.h
  32.  
  33. Description     close closes the  file handle indicated by handle  which is
  34.                 obtained  from a  _creat, creat,  creatnew, creattemp, dup,
  35.                 dup2, _open or open call.
  36.  
  37. Return value    Upon  successful completion,  close returns  0 otherwise,  a
  38.                 value of  -1 is returned  and, errno is  set to
  39.                 EBADF Bad file number
  40.  
  41. *---------------------------------------------------------------------------*/
  42. int _CType _FARFUNC close (register int handle)
  43. {
  44.   if ((unsigned)handle >= _nfile)
  45.     return __IOerror (e_badHandle);
  46.  
  47. #if CPM_ctlZ  /* see commentary in file "zapctlz.cas" */
  48.   if ( !(_openfd[handle] & (O_BINARY | O_DEVICE)) && _openfd[handle] & O_CHANGED)
  49.     __AppendCtlZ (handle);
  50. #endif
  51.   _RTLInstanceData(_openfd) [handle] = 0;
  52.   return _close(handle);
  53. }
  54.