+ buffer_mode <- wantReadableHandle "hGetLine" h
+ (\ handle_ -> do return (haBufferMode__ handle_))
+ case buffer_mode of
+ NoBuffering -> hGetLineUnBuffered h
+ LineBuffering -> hGetLineBuf' []
+ BlockBuffering _ -> hGetLineBuf' []
+
+ where hGetLineBuf' xss = do
+ (eol, xss) <- catch
+ ( do
+ mayBlockRead' "hGetLine" h
+ (\fo -> readLine fo)
+ (\fo bytes -> do
+ buf <- getBufStart fo bytes
+ eol <- readCharOffPtr buf (bytes-1)
+ xs <- if (eol == '\n')
+ then stToIO (unpackNBytesST buf (bytes-1))
+ else stToIO (unpackNBytesST buf bytes)
+ return (eol, xs:xss)
+ )
+ )
+ (\e -> if isEOFError e && not (null xss)
+ then return ('\n', xss)
+ else ioError e)
+
+ if (eol == '\n')
+ then return (concat (reverse xss))
+ else hGetLineBuf' xss
+
+
+hGetLineUnBuffered :: Handle -> IO String
+hGetLineUnBuffered h = do