1989-05-30 13:34:25 +00:00
|
|
|
/*
|
|
|
|
* fclose.c - flush a stream and close the file
|
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1989-05-30 13:34:25 +00:00
|
|
|
|
2007-04-21 23:18:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "loc_incl.h"
|
1989-05-30 13:34:25 +00:00
|
|
|
|
2019-06-15 11:07:10 +00:00
|
|
|
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE
|
2018-06-23 16:54:40 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
int fclose(FILE* fp)
|
1989-05-30 13:34:25 +00:00
|
|
|
{
|
|
|
|
register int i, retval = 0;
|
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
for (i = 0; i < FOPEN_MAX; i++)
|
|
|
|
if (fp == __iotab[i])
|
|
|
|
{
|
1989-12-18 15:04:14 +00:00
|
|
|
__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;
|
2018-06-21 20:33:47 +00:00
|
|
|
if (fflush(fp))
|
|
|
|
retval = EOF;
|
|
|
|
if (close(fileno(fp)))
|
|
|
|
retval = EOF;
|
|
|
|
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)
|
2018-06-21 20:33:47 +00:00
|
|
|
free((void*)fp);
|
1989-06-26 10:37:05 +00:00
|
|
|
return retval;
|
1989-05-30 13:34:25 +00:00
|
|
|
}
|
2018-06-23 16:54:40 +00:00
|
|
|
|
|
|
|
#endif
|