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

  1. /*------------------------------------------------------------------------
  2.  * filename - closeall.c
  3.  *
  4.  * function(s)
  5.  *        fcloseall - close open streams
  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 <stdio.h>
  18. #include <RtlData.h>
  19.  
  20. /*------------------------------------------------------------------------*
  21.  
  22. Name            fcloseall - close open streams
  23.  
  24. Usage           int fcloseall(void);
  25.  
  26. Prototype in    stdio.h
  27.  
  28. Description     fcloseall closes all open  streams except stdin and stdout.
  29.                 All buffers  associated to each  stream are flushed  before
  30.                 closing. System  allocated buffers are freed  upon closing.
  31.                 Buffers   assigned   with   setbuf   or   setvbuf  are  not
  32.                 automatically freed.
  33.  
  34. Return value    fcloseall returns the total number of streams it closed or,
  35.                 EOF if any errors were detected.
  36.  
  37. *-------------------------------------------------------------------------*/
  38. int _FARFUNC fcloseall( void )
  39.   {
  40.   FILE *fp;
  41.   int   i, cnt;
  42.   _QRTLDataBlock;
  43.  
  44.   for( i = 5, fp = _QRTLInstanceData(_streams) + 5, cnt = 0;
  45.        i < _QRTLInstanceData(_nfile); fp++,
  46.        i++ )
  47.     {
  48.     if( fp->fd >= 0 )
  49.       {
  50.       if( fclose( fp ) )  cnt = -9999;
  51.       else                cnt++;
  52.       }
  53.     }
  54.  
  55.   return( cnt < 0 ? EOF : cnt );
  56.   }
  57.