openFile "/dev/null" WriteMode fails

Volker Wysk post at volker-wysk.de
Fri Apr 22 11:41:23 EDT 2005


Hello.

The following program produces an "invalid operation" IOError:

import IO

main = 
   do h <- openFile "/dev/null" WriteMode
      hPutStrLn h "bla"
   `catch` (\ioe -> putStrLn (show ioe))


When called:

/dev/null: openFile: invalid argument (Invalid argument)


It works with AppendMode. I'm not sure if that's to be considered a bug. It's 
counter-intuitive, and openFile shouldn't fail with "invalid operation", 
since the API docs (and the Language Report) say:

  This operation may fail with:

    * isAlreadyInUseError if the file is already open and cannot be reopened;
    * isDoesNotExistError if the file does not exist; or
    * isPermissionError if the user does not have permission to open the file.

I'm using GHC 6.4 on Debian Linux.

Bye,
V.W.



More information about the Glasgow-haskell-bugs mailing list