Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <libc/file.h>
  9.  
  10. int fclose(FILE *f)
  11. {
  12.   int r;
  13.  
  14.   r = EOF;
  15.   if (!f)
  16.     return r;
  17.   if (f->_flag & (_IOREAD|_IOWRT|_IORW)
  18.       && !(f->_flag&_IOSTRG))
  19.   {
  20.     r = fflush(f);
  21.     if (close(fileno(f)) < 0)
  22.       r = EOF;
  23.     if (f->_flag&_IOMYBUF)
  24.       free(f->_base);
  25.   }
  26.   if (f->_flag & _IORMONCL && f->_name_to_remove)
  27.   {
  28.     remove(f->_name_to_remove);
  29.     free(f->_name_to_remove);
  30.     f->_name_to_remove = 0;
  31.   }
  32.   f->_cnt = 0;
  33.   f->_base = 0;
  34.   f->_ptr = 0;
  35.   f->_bufsiz = 0;
  36.   f->_flag = 0;
  37.   f->_file = -1;
  38.   return r;
  39. }
  40.