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

  1. /*------------------------------------------------------------------------
  2.  * filename - closeall.c
  3.  *
  4.  * function(s)
  5.  *        fcloseall - close open streams
  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. #include <stdio.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 fcloseall( void )
  39.   {
  40.   FILE *fp;
  41.   int   i, cnt;
  42.  
  43.   for( i = 5, fp = _streams + 5, cnt = 0; i < FOPEN_MAX; fp++, i++ )
  44.     {
  45.     if( fp->fd >= 0 )
  46.       {
  47.       if( fclose( fp ) )  cnt = -9999;
  48.       else                cnt++;
  49.       }
  50.     }
  51.  
  52.   return( cnt < 0 ? EOF : cnt );
  53.   }
  54.