summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/fclose.c
blob: 4534715bf20342adc133c112aea5258f599442b9 (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((__FILE(stream))->fd) == -1)
			return -1;
	}

	return 0;
}