|
|
1.1 ! root 1: /* ! 2: * libc/stdio/fclose.c ! 3: * ANSI-compliant C standard i/o library. ! 4: * fclose() ! 5: * ANSI 4.9.5.1. ! 6: * Close a stream. ! 7: */ ! 8: ! 9: #include <stdio.h> ! 10: ! 11: int ! 12: fclose(stream) register FILE *stream; ! 13: { ! 14: register int flags, status; ! 15: register _FILE2 *f2p; ! 16: ! 17: f2p = stream->_f2p; ! 18: flags = stream->_ff2; ! 19: if ((flags & _FINUSE) == 0) ! 20: return EOF; /* Not in use */ ! 21: status = fflush(stream); /* Flush unwritten data */ ! 22: #if _DONTC ! 23: if (flags & _FDONTC) ! 24: return status; /* Don't close */ ! 25: #endif ! 26: close(fileno(stream)); /* Call sys close */ ! 27: if (flags & _FFREEB) ! 28: free(f2p->_bp); /* Release allocated buffer */ ! 29: if (f2p->_nm != NULL) { ! 30: remove(f2p->_nm); /* Delete temporary file */ ! 31: free(f2p->_nm); /* and release allocated name */ ! 32: } ! 33: stream->_ff1 = stream->_ff2 = 0; /* Reset all flags */ ! 34: return status; ! 35: } ! 36: ! 37: /* end of libc/stdio/fclose.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.