summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/fclose.c
blob: 8b0586c6ee9353b525b378556128c5ea68bbb52f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <libc.h>   // for __IMPL
#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(__IMPL(stream)->fd) == -1)
			return -1;
	}

	return 0;
}