-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync stdout run into unreachable code #16735
Comments
per https://stackoverflow.com/questions/26257171/flush-kernel-buffers-for-stdout stdout does not support fsync(2) which is why it returns EINVAL and zig uses |
why we already have the error union, but we instead use |
@CGQAQ
If we added the error to the error set, that means that all correct programs (which don't |
Got it, thanks |
I really don't agree with this. The assertion that INVAL from fsync implies that your program is somehow not "correct" is not valid. How should a program know what capabilities the standard file descriptors have? They may well be pointing pretty much anywhere. What if it's not one of the standard FDs but some other FD duped to stdout? Calling something like fsync may make sense, and if the FD does not support it, it may also make sense to ignore the error. I don't see how the standard library can (or should) determine that this implies that the program is incorrect. Zig is a systems programming language and handling unexpected errors from the OS is something that should be promoted, not something that should be made difficult. I would go as far as to say BADF is not even something that should be unreachable. It may well be that the FD was opened by some other process outside the programmers control and not in a well known state. I would much rather be able to handle this and give some constructive feedback to my users than give them a panic. |
@neurocyte I imagine it's possible to query those exact capabilities using additional syscalls. I personally don't have a lot of experience with POSIX handles though. |
I'm pretty sure that calling fsync and checking for INVAL is the only standard way to check for fsync support. This is a pretty common pattern for posix APIs. |
Zig Version
zig trunk
Steps to Reproduce and Observed Behavior
https://godbolt.org/z/7qEnf35fv
Expected Behavior
At least should not reach unreachable code
The text was updated successfully, but these errors were encountered: