problem reading /proc/interrupts with ByteString

Hi 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. The part of interest is: findInterrupts :: B.ByteString -> Int findInterrupts str = findI where findI = read $ B.unpack $ getNums $ skipSpaces $ skip1 from1 = case B.findSubstring (B.pack "1:") str of Nothing -> error $ "Not found in [" ++ B.unpack str ++ "]" Just a -> a skip1 = B.drop from1 str skipSpaces = B.dropWhile (\c -> c == ' ') getNums = B.takeWhile (\c -> c `elem` "1234567890") getNumInterrupts :: IO Int getNumInterrupts = do h <- openFile "/proc/interrupts" ReadMode c <- B.hGetContents h hClose h -- c <- B.readFile "/proc/interrupts" -- With readFile the contents are emtpy -- B.putStrLn c return $ findInterrupts c Whole code can be found at http://hpaste.org/63 Thanks in advance Leandro Penz

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.
participants (2)
-
Leandro Lisboa Penz
-
Matthew Brecknell