Uninitialized vector entry?
[minix3.git] / lib / stdio / fclose.c
blob56bd0ac4a913fa43161138aff7927ef987f17180
1 /*
2 * fclose.c - flush a stream and close the file
3 */
4 /* $Header$ */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "loc_incl.h"
10 int _close(int d);
12 int
13 fclose(FILE *fp)
15 register int i, retval = 0;
17 for (i=0; i<FOPEN_MAX; i++)
18 if (fp == __iotab[i]) {
19 __iotab[i] = 0;
20 break;
22 if (i >= FOPEN_MAX)
23 return EOF;
24 if (fflush(fp)) retval = EOF;
25 if (_close(fileno(fp))) retval = EOF;
26 if ( io_testflag(fp,_IOMYBUF) && fp->_buf )
27 free((void *)fp->_buf);
28 if (fp != stdin && fp != stdout && fp != stderr)
29 free((void *)fp);
30 return retval;