[nhc-users] openFd?

David Roundy droundy at abridgegame.org
Tue Jan 4 10:37:21 EST 2005

On Tue, Jan 04, 2005 at 03:19:03PM -0000, Simon Marlow wrote:
> On 04 January 2005 14:29, Malcolm Wallace wrote:
> > David Roundy <droundy at abridgegame.org> 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).

That portability issue is precisely why I use GHC.Handle.openFd.  I'm
thinking that at some point I may switch to using something like MissingH's
VIO system so I won't need to create real Handles at all.  The current code
in darcs that relies on openFd is just a libz interface, and it's really
ugly code, which creates a (posix) thread and a pipe so that we can
read/write to a compressed file throught a standard Handle.

> > 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.

Hmmmm.  Sounds like a bit more trouble than I want to go to, just to make
darcs a bit more portable.  It looks like there are other modules that
nhc98 is missing (e.g. System.Posix.Regex), which'll be too much trouble to
deal with at the moment.

When darcs' code is a bit cleaner in the IO arena, it should be a bit
easier to port to nhc98/hugs.
David Roundy

More information about the Nhc-users mailing list