libc: Partially implement freopen() when a null pathname is provided
All checks were successful
Build and test / build (push) Successful in 2m1s

The specification says "It is implementation-defined which changes of mode are permitted (if any)", so we can comply by not permitting any mode changes, at least for now.
This commit is contained in:
apio 2024-07-02 12:44:43 +02:00
parent 2ce2d57eff
commit 903dcfa52c
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -273,13 +273,20 @@ extern "C"
if ((flags = fopen_parse_mode(mode)) < 0) return nullptr; if ((flags = fopen_parse_mode(mode)) < 0) return nullptr;
close(stream->_fd); fflush(stream);
s_open_files[stream->_fd] = nullptr; if (!path)
{
// FIXME: No mode changes are permitted.
errno = EBADF;
return nullptr;
}
if (stream->_buf.buffer && (stream->_buf.status & FileStatusFlags::BufferIsMalloced)) free(stream->_buf.buffer); if (stream->_buf.buffer && (stream->_buf.status & FileStatusFlags::BufferIsMalloced)) free(stream->_buf.buffer);
if (!path) { fail("FIXME: freopen() called with path=nullptr"); } close(stream->_fd);
s_open_files[stream->_fd] = nullptr;
int fd = open(path, flags, 0666); int fd = open(path, flags, 0666);
if (fd < 0) { return nullptr; } if (fd < 0) { return nullptr; }