From 2eff308e962c835a00123292b8e087cea4878c60 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sat, 15 Aug 2020 21:22:20 -0400 Subject: clean up --- src/stdio/fclose.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/stdio') diff --git a/src/stdio/fclose.c b/src/stdio/fclose.c index cd5b4417..1e55a0f0 100644 --- a/src/stdio/fclose.c +++ b/src/stdio/fclose.c @@ -1,15 +1,17 @@ #include -#include "stdlib.h" +#include +#include #include "_stdio.h" #if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE -#include "sys/types.h" -#include "unistd.h" +#include +#include #else #define close(fd) -1 #endif /** close a file stream **/ + int fclose(FILE *stream) { flockfile(stream); @@ -18,26 +20,25 @@ int fclose(FILE *stream) return EOF; } - if (stream->mem.buf) { - if (stream->mem.allocated) { - free(stream->mem.buf); + if (stream->buf != stream->ibuf) { + if (stream->ibuf[0] == 'a') { + free(stream->buf); } - } else if (close(stream->fd) == -1) { - /* set errno */ - return EOF; } - /* - if (!(stream->flags & FF_USERBUF) && stream->buf != NULL) { - free(stream->buf); + if (close(stream->fd) == -1) { + /* errno is set automatically */ + funlockfile(stream); + return EOF; } - */ - funlockfile(stream); + memset(stream, '\0', sizeof(*stream)); + /* RETURN_SUCCESS(0); RETURN_FAILURE(CONSTANT(EOF)); */ + return 0; } -- cgit v1.2.1