summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-08-15 21:22:20 -0400
committerJakob Kaivo <jkk@ung.org>2020-08-15 21:22:20 -0400
commit2eff308e962c835a00123292b8e087cea4878c60 (patch)
treeb8949ccd17a29d78569cf06c89ac5d143c6e4de2 /src
parentbdc07807f4debcd6155c628a8cdbf25f2e8402f7 (diff)
clean up
Diffstat (limited to 'src')
-rw-r--r--src/stdio/fclose.c29
1 files changed, 15 insertions, 14 deletions
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 <stdio.h>
-#include "stdlib.h"
+#include <stdlib.h>
+#include <string.h>
#include "_stdio.h"
#if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE
-#include "sys/types.h"
-#include "unistd.h"
+#include <sys/types.h>
+#include <unistd.h>
#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;
}