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 a Libc.File constructor that takes a RawFD #10535
Conversation
Twice this week, I've came across instances where C libraries wanted a FILE*, but I only had an FD. Since we have Libc.File, we might as well have this method too.
Hah @mlubin this is very related what I was asking about the other day. Could be good to mention how to deal with |
This should really be considered a bug in these libraries... that's a horribly non-portable thing to do. |
While working on this I am wondering if the conversion to |
Stuff like this is always pretty ugly. I'm not sure there is a good solution. Perhaps we should not have the method that constructs a FILE from an arbitrary IO. |
I'd be fine with keeping |
@JeffBezanson and I decided that was the best way to go about handling the issue that fdopen wants to take ownership of the file descriptor. In this way the two objects are independent and everything should work in the general case. Also add a close method to Libc.FILE, which can now always be safely called (assuming of course that it isn't closed by the C function it gets passed to). Finally, move RawFD and dup to Libc, since they're part of the C library anyway.
Add a Libc.File constructor that takes a RawFD
this does seem to have the same issue as malloc/free: you don't know if your library is linked against the same libc as julia, so it seems like this usage may sometimes corrupt the program. (edit: although, on windows, the same issue also exists for file descriptors since the canonical object is a |
Twice this week, I've came across instances where C libraries wanted
a FILE*, but I only had an FD. Since we have Libc.File, we might as
well have this method too.
[Opening PR to have Appveyor look this over]