summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/fclose.c
blob: 06cda8303bd5bb5a7eaf673b108919da40fcd6f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>  // for fflush, FILE, fclose, stderr, stdin, stdout
#include <unistd.h> // for close

int fclose(FILE *stream)
{
	if (fflush(stream) == -1)
		return -1;

	if (stream != stdin && stream != stdout && stream != stderr) {
		if (close(fileno(stream)) == -1)
			return -1;
	}

	return 0;
}