Compare commits

...

2 Commits

Author SHA1 Message Date
511ad67a9a fdopen: Check for malloc errors 2022-10-17 20:54:32 +02:00
e17a21dbad libc: Use fdopen() after calling open() in fopen() 2022-10-17 20:54:09 +02:00

View File

@ -30,14 +30,11 @@ extern "C"
return 0; // FIXME: Implement buffered IO.
}
FILE* fopen(const char* pathname, const char*)
FILE* fopen(const char* pathname, const char* mode)
{
int fd = open(pathname, O_RDWR); // FIXME: Use the mode string.
if (fd < 0) { return 0; }
FILE* stream = (FILE*)malloc(sizeof(FILE));
stream->f_fd = fd;
clearerr(stream);
return stream;
return fdopen(fd, mode);
}
FILE* fdopen(int fd, const char*)
@ -48,6 +45,7 @@ extern "C"
return 0;
}
FILE* stream = (FILE*)malloc(sizeof(FILE));
if (!stream) { return 0; }
stream->f_fd = fd;
clearerr(stream);
return stream;