home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / language / fixes / fclose.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-04  |  570 b   |  25 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3.  
  4. int fclose(fp)
  5.     register FILE *fp;
  6.     {
  7.     register int f, frv;
  8.  
  9.     if(fp == NULL)
  10.         return(EOF);        /* NULL file pointer file */
  11.     f = fp->_flag;
  12.     if((f & (_IOREAD | _IOWRT)) == 0)
  13.         return(EOF);        /* file not open! */
  14.     frv = fflush(fp);        /* flush and save return value */
  15.     if(fp->_bsiz != BUFSIZ)        /* throw away non-standard buffer */
  16.         {
  17.         fp->_base = NULL;
  18.         fp->_ptr = NULL;
  19.         fp->_bsiz = 0;
  20.         }
  21.     fp->_flag = 0;            /* clear status */
  22.     f = ((f & _IODEV) ? 0 : close(fp->_file));
  23.     return((frv || f) ? EOF : 0);
  24.     }
  25.