Use bitfield `flags` flags in file instead of `int` variables `mode`, `error`, `eof`. And rewrite weird logic opening/close files Reviewed-on: #691 Reviewed-by: Ivan B <1+dunkaist@noreply.localhost> Reviewed-by: Kiril Lipatov <lipatov.kiril@gmail.com> Co-authored-by: Egor00f <y.yarin@inbox.ru>
23 lines
409 B
C
23 lines
409 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
#include "_stdio.h"
|
|
|
|
FILE* fopen(const char* restrict _name, const char* restrict _mode)
|
|
{
|
|
FILE* stream = malloc(sizeof(FILE));
|
|
|
|
if (stream == NULL) {
|
|
errno = ENOMEM;
|
|
return NULL;
|
|
}
|
|
|
|
FILE* out = fopen_r(_name, _mode, stream);
|
|
|
|
if (out == NULL) {
|
|
free(stream);
|
|
}
|
|
|
|
return out;
|
|
}
|