import ST
import PrelIOBase
import IO
-import IOExts (unsafePerformIO)
-import PackedString (psToByteArrayST)
+import IOExts ( unsafePerformIO )
+import CString ( packStringIO, allocChars,
+ freeze, strcpy
+ )
import Addr
import CCall
import PrelBase
openDirStream :: FilePath -> IO DirStream
openDirStream name =
- psToByteArrayIO name >>= \dir ->
+ packStringIO name >>= \dir ->
_ccall_ opendir dir >>= \dirp@(A# dirp#) ->
- if dirp /= (``NULL''::Addr)
+ if dirp /= nullAddr
then return (DirStream# dirp#)
else syserr "openDirStream"
readDirStream dirp = do
setErrorCode noError
dirent <- _ccall_ readdir dirp
- if dirent /= (``NULL''::Addr)
+ if dirent /= nullAddr
then do
str <- _casm_ ``%r = ((struct dirent *)%0)->d_name;'' dirent
name <- strcpy str
-> OpenFileFlags
-> IO Fd
openFd name how maybe_mode (OpenFileFlags append exclusive noctty nonBlock truncate) =
- psToByteArrayIO name >>= \file ->
+ packStringIO name >>= \file ->
_ccall_ open file flags mode_w >>= \fd@(I# fd#) ->
if fd /= -1
then return (FD# fd#)
createFile :: FilePath -> FileMode -> IO Fd
createFile name mode =
- psToByteArrayIO name >>= \file ->
+ packStringIO name >>= \file ->
_ccall_ creat file mode >>= \fd@(I# fd#) ->
if fd /= -1
then return (FD# fd#)
createLink :: FilePath -> FilePath -> IO ()
createLink name1 name2 = do
- path1 <- psToByteArrayIO name1
- path2 <- psToByteArrayIO name2
+ path1 <- packStringIO name1
+ path2 <- packStringIO name2
rc <- _ccall_ link path1 path2
if rc == 0
then return ()
createDirectory :: FilePath -> FileMode -> IO ()
createDirectory name mode = do -- NB: diff signature from LibDirectory one!
- dir <- psToByteArrayIO name
+ dir <- packStringIO name
rc <- _ccall_ mkdir dir mode
if rc == 0
then return ()
createNamedPipe :: FilePath -> FileMode -> IO ()
createNamedPipe name mode = do
- pipe <- psToByteArrayIO name
+ pipe <- packStringIO name
rc <-_ccall_ mkfifo pipe mode
if rc == 0
then return ()
removeLink :: FilePath -> IO ()
removeLink name = do
- path <- psToByteArrayIO name
+ path <- packStringIO name
rc <-_ccall_ unlink path
if rc == 0
then return ()
rename :: FilePath -> FilePath -> IO ()
rename name1 name2 = do
- path1 <- psToByteArrayIO name1
- path2 <- psToByteArrayIO name2
+ path1 <- packStringIO name1
+ path2 <- packStringIO name2
rc <- _ccall_ rename path1 path2
if rc == 0
then return ()
else syserr "rename"
-type FileStatus = ByteArray ()
+type FileStatus = ByteArray Int
type FileID = Int
type DeviceID = Int
getFileStatus :: FilePath -> IO FileStatus
getFileStatus name = do
- path <- psToByteArrayIO name
+ path <- packStringIO name
bytes <- allocChars ``sizeof(struct stat)''
rc <- _casm_ ``%r = stat(%0,(struct stat *)%1);'' path bytes
if rc == 0
fileAccess :: FilePath -> Bool -> Bool -> Bool -> IO Bool
fileAccess name read write exec = do
- path <- psToByteArrayIO name
+ path <- packStringIO name
rc <- _ccall_ access path flags
return (rc == 0)
where
fileExist :: FilePath -> IO Bool
fileExist name = do
- path <- psToByteArrayIO name
+ path <- packStringIO name
rc <- _ccall_ access path (``F_OK''::Int)
return (rc == 0)
setFileMode :: FilePath -> FileMode -> IO ()
setFileMode name mode = do
- path <- psToByteArrayIO name
+ path <- packStringIO name
rc <- _ccall_ chmod path mode
if rc == 0
then return ()
setOwnerAndGroup :: FilePath -> UserID -> GroupID -> IO ()
setOwnerAndGroup name uid gid = do
- path <- psToByteArrayIO name
+ path <- packStringIO name
rc <- _ccall_ chown path uid gid
if rc == 0
then return ()
setFileTimes :: FilePath -> EpochTime -> EpochTime -> IO ()
setFileTimes name atime mtime = do
- path <- psToByteArrayIO name
+ path <- packStringIO name
rc <- _casm_ ``do {struct utimbuf ub; ub.actime = (time_t) %0;
ub.modtime = (time_t) %1;
%r = utime(%2, &ub);} while(0);'' atime mtime path
{- Set access and modification time to current time -}
touchFile :: FilePath -> IO ()
touchFile name = do
- path <- psToByteArrayIO name
- rc <- _ccall_ utime path (``NULL''::Addr)
+ path <- packStringIO name
+ rc <- _ccall_ utime path nullAddr
if rc == 0
then return ()
else syserr "touchFile"
pathconf :: Int -> FilePath -> IO Limit
pathconf n name = do
- path <- psToByteArrayIO name
+ path <- packStringIO name
rc <- _ccall_ pathconf path n
if rc /= -1
then return rc