[Haskell] Win32 process spawning, POpen and Hugs, revisited

Graham Klyne gk at ninebynine.org
Wed Mar 17 10:47:59 EST 2004


At 18:14 16/03/04 +0000, Ross Paterson wrote:
>It could well be Hugs.  In this situation it calls fdopen(fd, "w+"),
>but I think it should be fdopen(fd, "w").

Ah... in "iomonad.c", I see:

[[
static
String local modeString(hmode,binary) /* return mode string for f(d)open */
Int  hmode;
Bool binary; {
     if (binary) {
         return (hmode&HAPPEND)    ? "ab+" :
                (hmode&HWRITE)     ? "wb+" :
                (hmode&HREADWRITE) ? "wb+" :
                (hmode&HREAD)      ? "rb"  : (String)0;
     } else {
         return (hmode&HAPPEND)     ? "a+" :
                (hmode&HWRITE)      ? "w+" :
                (hmode&HREADWRITE)  ? "w+" :
                (hmode&HREAD)       ? "r"  : (String)0;
     }
}
]]

I tried changing w+ to w, and wb+ to wb for the write-only modes, thus:

[[
static
String local modeString(hmode,binary) /* return mode string for f(d)open */
Int  hmode;
Bool binary; {
     // printf("Access mode %i,%i\n",hmode,binary) ;  // [[[GK]]]
     if (binary) {
         return (hmode&HAPPEND)    ? "ab+" :
                (hmode&HWRITE)     ? "wb"  :    // [[[GK]]]
                (hmode&HREADWRITE) ? "wb+" :
                (hmode&HREAD)      ? "rb"  : (String)0;
     } else {
         return (hmode&HAPPEND)     ? "a+" :
                (hmode&HWRITE)      ? "w"  :    // [[[GK]]]
                (hmode&HREADWRITE)  ? "w+" :
                (hmode&HREAD)       ? "r"  : (String)0;
     }
}
]]

But the result is the same:
[[
SpawnEchoShiftLetters> runTest
wIn 3
Access mode 4,0

Program error: openFd: does not exist (file does not exist)

SpawnEchoShiftLetters>
]]

(The access mode trace was mainly to prove to myself that my changes were 
indeed being picked up.  The value 4 is equal to HWRITE.)

So this (alone) is not enough.  I did also try using "a" and "ab", but no 
joy there, either.  This starts to point to some interaction between the 
I/O library and Windows anonymous pipe.  My C code (which works as 
expected) uses the _write function (equiv. Unix "write") directly on the 
returned file descriptor.

#g


------------
Graham Klyne
For email:
http://www.ninebynine.org/#Contact



More information about the Cvs-hugs mailing list