[Haskell-cafe] problem reading /proc/interrupts with ByteString
Matthew Brecknell
haskell at brecknell.org
Sat May 26 20:44:57 EDT 2007
Leandro Lisboa Penz:
> I'm having some problems using ByteString.Char8.readFile to read
> "/proc/interrupts". I reads nothing. I guess maybe that's because the
> file is sort of special, but I could read it by opening and using
> ByteString.Char8.hGetContents.
ByteString.Char8.readFile uses hFileSize to determine the buffer size to
use:
> readFile f = bracket (openFile f ReadMode) hClose
> (\h -> hFileSize h >>= hGet h . fromIntegral)
Now, if you look at the size of /proc/interrupts, as reported by ls, you
should see the problem.
By contrast, ByteString.Char8.hGetContents determines the required
buffer size by reading to the end of the file.
More information about the Haskell-Cafe
mailing list