home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / IO / FCLOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  802 b   |  34 lines

  1. /* fclose.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <io.h>
  8.  
  9. int fclose (FILE *stream)
  10. {
  11.   int result;
  12.   char buf[L_tmpnam];
  13.  
  14.   result = EOF;
  15.   if ((stream->flags & _IOOPEN) && !(stream->flags & _IOSTRING))
  16.     {
  17.       result = 0;
  18.       result = fflush (stream);
  19.       if (close (fileno (stream)) < 0)
  20.         result = EOF;
  21.       if (result == 0 && (stream->flags & _IOTMP))
  22.         {
  23.           _itoa (stream->tmpidx, buf, 10);
  24.           strcat (buf, ".tmp");
  25.           if (remove (buf) != 0)
  26.             result = EOF;
  27.         }
  28.       if ((stream->flags & _IOBUFMASK) == _IOBUFLIB)
  29.         free (stream->buffer);
  30.     }
  31.   stream->flags = 0;
  32.   return (result);
  33. }
  34.