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