Files
rosetta/lib/libc/io/stdio/fclose.c
T

28 lines
409 B
C
Raw Normal View History

#include "file.h"
#include <errno.h>
#include <fcntl.h>
#include <mango/log.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int fclose(struct __opaque_file *stream)
{
if (stream->f_fd < 0) {
return __set_errno(EBADF);
}
close(stream->f_fd);
if (stream->f_buf.buf_ptr) {
free(stream->f_buf.buf_ptr);
}
if (!(stream->f_flags & FILE_STATIC)) {
free(stream);
}
return SUCCESS;
}