Bug 5190 – std.stdio should have File.fdopen

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-11-09T01:24:00Z
Last change time
2015-01-25T02:23:56Z
Assigned to
nobody
Creator
d-bugzilla

Comments

Comment #0 by d-bugzilla — 2010-11-09T01:24:31Z
As far as I can tell, struct File in std.stdio does not have a direct way to construct a File object from a low-level file descriptor, à la fdopen. I ran into this issue when using fork and pipe to create a pipe between two processes; having started a child process I wanted to parse the child's standard output using high-level File functions, and for that purpose I wanted to create a File object from a file descriptor. After some head-scratching, I was finally able to work around the issue by extern-declaring fdopen and using the sparsely documented File.wrapFile function (which is labelled "unsafe") to construct a File object, but that was inconvenient and obscure. Implementing fdopen in File would make systems programming with Phobos easier.
Comment #1 by andrej.mitrovich — 2011-05-24T20:34:36Z
fdopen is declared in core\sys\posix\stdio.d It seems there's at least one function which uses it: D:\DMD\dmd2\src\phobos\std\stdio.d:2540: FILE* fp = enforce(fdopen(s, "w+".ptr)); Hope that helps in any way!
Comment #2 by andy — 2015-01-25T02:23:56Z