-
-
Notifications
You must be signed in to change notification settings - Fork 701
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
Add std.stdio.File.setRawMode(). #3929
Conversation
094827b
to
8e32de3
Compare
Especially for files that cannot be opened by the user in binary mode (like stdin and stdout), rawWrite and rawRead are very limiting. To enable binary/raw file operation for stdin and stdout, the code to set those streams to binary mode is non-trivial. setRawMode() resolves this issue.
8e32de3
to
1180f52
Compare
(made fixes, squashed into one commit again) |
Looks reasonable. |
Hmm. I don't like exposing OS-level implementation details like this. I prefer |
I don't disagree with the idea, but this needs to be a toggle. "Binary mode" is also the correct term here. An alternative would be to provide a way to reopen stdin/out/err with arbitrary modes.
For the record this is the C library API and Windows-only, so nothing OS-level. BTW, this needs a correspoding Bugzilla issue. |
Perhaps these can be combined into a property, |
About lockingBinaryWriter: yes, would be great! But, it is not exactly the same: it locks. About OS-level stuff: I think the basic problem is not setmode, it is the Digital Mars IO stuff that is troublesome. There should be a function (with sane name) for I first thought about setBinaryMode, setTextMode, but then I thought that that would somehow expose to much detail (and it doesn't actually set binary mode on non-Windows). Then I figured that the functionality is basically a permanent rawWrite, so "raw" stuck. |
version(DIGITAL_MARS_STDIO) | ||
{ | ||
import core.atomic; | ||
immutable info = __fhnd_info[fd]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variable not used, remove.
Note that if you include |
$(LREF rawRead) | ||
$(LREF rawWrite) | ||
*/ | ||
void setRawMode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The terminology is binary vs. text. Then we probably need a means to get the current mode, so there's no escaping the API:
enum FileMode { text, binary }
void getMode(FileMode);
void setMode(FileMode);
ping? |
sorry, guess I should have closed this. |
Especially for files that cannot be opened by the user in binary mode (like stdin and stdout), having only rawWrite and rawRead available is very limiting. To enable binary/raw file operation for stdin and stdout, the code to set those streams to binary mode is non-trivial. setRawMode() resolves this issue.