On Wed, Dec 17, 2014 at 10:44 AM, Donn Cave <donn@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@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net