I'm writing some C library bindings using inline-c, and some of the C functions take FILE* parameters. Is there a preferred way to convert a Haskell Handle to a FILE*? Or is this the wrong approach to interfacing with the library?
My initial thoughts were to use handleToFd to first convert a given Handle to a file-descriptor and then call fopen() to get a FILE* to pass to library functions. The docs for handleToFd state that using it on a Handle has the effect of flushing and closing it, so do do the aforementioned I'd have to record the state of the Handle(?) and reinstate it when calling fopen(). This seems like a bad idea to me because AFAIK there's no way to reopen a standard stream, and I might have to resort to black magic if I use Handle internals.