
Quoth Johannes Waldmann
I want to call some "void dump (..., FILE * f)" function. I want to use this for a handle that I obtained in Haskell land.
Sure I can rewrite/add the C code so that it takes a filepath (string) and opens the file by itself, but should I?
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!) In a POSIX situation you could get the system file descriptor from the Handle, and convert that to a FILE pointer, but at the cost of closing the Handle. Don't know if that would work so well on non-POSIX platforms. If the Haskell side will simply open the file for this purpose, then I think you indeed might as well do that in C (whether by calling fopen() from Haskell or writing a C wrapper that takes a file path name.) Donn