home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / CLOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  1.9 KB  |  57 lines

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