source: trunk/minix/lib/stdio/fclose.c@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 635 bytes
Line 
1/*
2 * fclose.c - flush a stream and close the file
3 */
4/* $Header: /cvsup/minix/src/lib/stdio/fclose.c,v 1.1.1.1 2005/04/21 14:56:35 beng Exp $ */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include "loc_incl.h"
9
10int _close(int d);
11
12int
13fclose(FILE *fp)
14{
15 register int i, retval = 0;
16
17 for (i=0; i<FOPEN_MAX; i++)
18 if (fp == __iotab[i]) {
19 __iotab[i] = 0;
20 break;
21 }
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;
31}
Note: See TracBrowser for help on using the repository browser.