You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This allows for daemonization and output-redirection sorts of code
in libc-linked Zig projects on *nix-y platforms to affect the
stdio stream usage of other libc-based library code the project
may be linking, e.g.:
// Set stderr to go nowhere without errors:
_ = std.c.freopen("/dev/null", "r+", std.c.stderr());
// Append stdout to a file:
_ = std.c.freopen("/tmp/output.txt", "a", std.c.stdout());
The stdio streams are returned from function calls because they're
commonly #defines in the libc headers pointing at variously-named
externs, and one doesn't generally assign to them directly anyways
(freopen() is the portable way to assign something new to a stdio
stream).
NetBSD, OpenBSD, and Solaris stdio streams are not supported in
this patch and will cause a compileError if you try to use the
them, for now. Supporting them would require a more complex and
fragile solution using a definition of "FILE" that is not just an
opaque type (because their C libraries publish an extern array of
FILE objects and then #define the stdio stream names as pointers
to the array elements).
0 commit comments