Windows: map ERROR_NO_DATA to EPIPE, rather than EINVAL
authorSimon Marlow <marlowsd@gmail.com>
Wed, 15 Sep 2010 14:26:18 +0000 (14:26 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Wed, 15 Sep 2010 14:26:18 +0000 (14:26 +0000)
commit1f35ed03ae66a8a3dcc689a7bdea02b935077d44
treed4877f44d697570f3e8be84e7cf677a6c1c25e86
parent0520e41d74023fa16fd6be1d9439a747fb82ff0f
Windows: map ERROR_NO_DATA to EPIPE, rather than EINVAL
WriteFile() returns ERROR_NO_DATA when writing to a pipe that is
"closing", however by default the write() wrapper in the CRT maps this
to EINVAL so we get confusing things like

  hPutChar: invalid argument (Invalid Argumnet)

when piping the output of a Haskell program into something that closes
the pipe early.  This was happening in the testsuite in a few place.

The solution is to map ERROR_NO_DATA to EPIPE correctly, as we
explicitly check for EPIPE on stdout (in GHC.TopHandler) so we can
exit without an error in this case.
GHC/IO/FD.hs
cbits/Win32Utils.c