1989-05-30 13:34:25 +00:00
|
|
|
/*
|
|
|
|
* fclose.c - flush a stream and close the file
|
|
|
|
*/
|
|
|
|
/* $Header$ */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "loc_incl.h"
|
|
|
|
|
|
|
|
int close(int d);
|
|
|
|
|
|
|
|
int
|
|
|
|
fclose(FILE *fp)
|
|
|
|
{
|
|
|
|
register int i, retval = 0;
|
|
|
|
|
|
|
|
for (i=0; i<FOPEN_MAX; i++)
|
1989-12-18 15:04:14 +00:00
|
|
|
if (fp == __iotab[i]) {
|
|
|
|
__iotab[i] = 0;
|
1989-05-30 13:34:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= FOPEN_MAX)
|
1989-06-26 10:37:05 +00:00
|
|
|
return EOF;
|
|
|
|
if (fflush(fp)) retval = EOF;
|
|
|
|
if (close(fileno(fp))) retval = EOF;
|
1989-05-30 13:34:25 +00:00
|
|
|
if ( io_testflag(fp,_IOMYBUF) && fp->_buf )
|
|
|
|
free((void *)fp->_buf);
|
1989-06-26 10:37:05 +00:00
|
|
|
if (fp != stdin && fp != stdout && fp != stderr)
|
1989-05-30 13:34:25 +00:00
|
|
|
free((void *)fp);
|
1989-06-26 10:37:05 +00:00
|
|
|
return retval;
|
1989-05-30 13:34:25 +00:00
|
|
|
}
|