
On 04 January 2005 14:29, Malcolm Wallace wrote:
David Roundy
writes: I'm wondering if there is any equivalent to GHC.Handle.openFd which I can use with nhc98? It's nice being able to convert a file descriptor into a Handle...
I had a quick look at the documentation for openFd, and it wasn't very informative - no text, just a signature:
openFd :: FD -> Maybe FDType -> FilePath -> IOMode -> Bool -> Bool -> IO Handle
It's an internal function not intended for general comsumption, hence the lack of documentation. David: System.Posix.fdToHandle is the right way to do this. On Windows, there ought to be equivalent functionality exposed by the Win32 library (I suspect there isn't though, because on Windows we use file descriptors too, but we really should be using native Windows HANDLEs instead).
However, my guess is that these library functions are actually a thin skin over some fairly standard C library, in which case you can probably write a little bit of FFI code to interface to the same functionality.
GHC's IO library is mostly Haskell; there are only a few tiny inline C functions underneath.
nhc98's representation of a Handle as a wrapper over C's FILE* type is "struct FileDesc", defined in src/runtime.h, and an example of some FFI stuff to manipulate a Handle can be seen in src/prelude/IO/OpenFile.hs and src/runtime/Builtin/cOpen.c
So with nhc98 you'll need to convert the file descriptor into a FILE* first (using fdopen()?) before you can get a Handle. Cheers, Simon