[Haskell-cafe] how to handle FILE* with c2hs
allbery.b at gmail.com
Wed Dec 17 15:51:58 UTC 2014
On Wed, Dec 17, 2014 at 10:44 AM, Donn Cave <donn at avvanta.com> wrote:
> You could move that logic into Haskell, as illustrated in a previous
> follow-up, but I can't think of any direct interface between C FILE
> and Haskell Handle, and I guess that because of the essential internal
> nature of the two, that's to be expected. (Or maybe I just don't
> know where to look!)
About the only one is the underlying OS file descriptor; GHC's runtime
implements its own native file handles, it does not wrap C stdio, and you
cannot round-trip between a stdio (FILE *) and a GHC Handle.
Using the file descriptor should work on both POSIX and Windows, as long as
it's an ordinary file (that is, not a device, fifo, socket, directory
(netbsd/freebsd), mailbox, etc.). You will need to use fdToHandle /
handleToFd on the Haskell side and fdopen()/fileno() on the C side; the
Haskell ones will ensure the buffers are properly dealt with, the C ones
you must make sure to do so yourself.
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe