[libc-commits] [libc] [libc] Implement freopen (PR #207837)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Aug 18 10:10:39 PDT 2026
================
@@ -385,6 +397,12 @@ class File {
// The implementation of this function is provided by the platform_file
// library.
ErrorOr<File *> openfile(const char *path, const char *mode);
+// Reopens a file stream.
+// Note: On failure, `reopenfile` will place the file stream in an invalid state
+// (closing the underlying file descriptor) but will not deallocate the `File`
+// object itself, ensuring static streams like stdin/stdout/stderr are
+// preserved.
+int reopenfile(File *f, const char *path, const char *mode);
----------------
michaelrj-google wrote:
Yes, that was one option I considered. Putting this inside the `File` class would mean we need some way to call into the platform file's specific `freopen`. The way we do that with the other operations in the class is by passing a function pointer, but adding another function pointer to `File` would be problematic for `fopencookie` which expects the specific set we currently have. We could theoretically have that function pointer default to null and we check that before calling down, but I figured this was a more straightforward way to implement it.
https://github.com/llvm/llvm-project/pull/207837
More information about the libc-commits
mailing list