PatchworkOS
Loading...
Searching...
No Matches
fclose.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3
4#include "user/common/file.h"
6
7int fclose(struct FILE* stream)
8{
9 mtx_lock(&stream->mtx);
10
11 if (stream->flags & _FILE_WRITE)
12 {
13 if (_file_flush_buffer(stream) == ERR)
14 {
15 mtx_unlock(&stream->mtx);
16 return EOF;
17 }
18 }
19
20 mtx_unlock(&stream->mtx);
21
22 _files_remove(stream);
23 _file_deinit(stream);
24 _file_free(stream);
25 return 0;
26}
int fclose(struct FILE *stream)
Definition fclose.c:7
#define ERR
Integer error value.
Definition ERR.h:17
uint64_t _file_flush_buffer(FILE *stream)
Definition file.c:158
void _file_free(FILE *stream)
Definition file.c:92
void _file_deinit(FILE *stream)
Definition file.c:146
void _files_remove(FILE *file)
Definition file.c:271
@ _FILE_WRITE
Definition file.h:11
#define EOF
Definition stdio.h:25
Definition file.h:34
_file_flags_t flags
Definition file.h:44
mtx_t mtx
Definition file.h:45
_PUBLIC int mtx_lock(mtx_t *mtx)
Definition mtx_lock.c:11
_PUBLIC int mtx_unlock(mtx_t *mtx)
Definition mtx_unlock.c:10