From 26e1d2d10d8831a6a1d711ae096824cddcd29145 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 18 Dec 2001 10:37:52 +0000 Subject: [PATCH] [project @ 2001-12-18 10:37:52 by simonmar] Allow opening char & block devices with openFile. Opening a char device gets you a stream, and a block device a file (these are heuristics since we can't really tell without trying to lseek() on the device whether it supports seeking or not, but the defaults are at least safe). --- ghc/lib/std/PrelPosix.hsc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ghc/lib/std/PrelPosix.hsc b/ghc/lib/std/PrelPosix.hsc index 35dacc6..c18124d 100644 --- a/ghc/lib/std/PrelPosix.hsc +++ b/ghc/lib/std/PrelPosix.hsc @@ -86,10 +86,16 @@ fdType fd = c_fstat (fromIntegral fd) p_stat c_mode <- (#peek struct stat, st_mode) p_stat :: IO CMode case () of - _ | s_isdir c_mode -> return Directory - | s_isfifo c_mode || s_issock c_mode -> return Stream - | s_isreg c_mode -> return RegularFile - | otherwise -> ioException ioe_unknownfiletype + _ | s_isdir c_mode -> return Directory + | s_isfifo c_mode -> return Stream + | s_issock c_mode -> return Stream + | s_ischr c_mode -> return Stream + | s_isreg c_mode -> return RegularFile + | s_isblk c_mode -> return RegularFile + | otherwise -> ioException ioe_unknownfiletype + -- we consider character devices to be streams (eg. ttys), + -- whereas block devices are more like regular files because they + -- are seekable. ioe_unknownfiletype = IOError Nothing UnsupportedOperation "fdType" "unknown file type" Nothing @@ -103,6 +109,12 @@ foreign import "s_isdir_PrelPosix_wrap" unsafe s_isdir :: CMode -> Bool foreign import "s_isfifo_PrelPosix_wrap" unsafe s_isfifo :: CMode -> Bool #def inline int s_isfifo_PrelPosix_wrap(m) { return S_ISFIFO(m); } +foreign import "s_ischr_PrelPosix_wrap" unsafe s_ischr :: CMode -> Bool +#def inline int s_ischr_PrelPosix_wrap(m) { return S_ISCHR(m); } + +foreign import "s_isblk_PrelPosix_wrap" unsafe s_isblk :: CMode -> Bool +#def inline int s_isblk_PrelPosix_wrap(m) { return S_ISBLK(m); } + #ifndef mingw32_TARGET_OS foreign import "s_issock_PrelPosix_wrap" unsafe s_issock :: CMode -> Bool #def inline int s_issock_PrelPosix_wrap(m) { return S_ISSOCK(m); } -- 1.7.10.4