Commit 3d61cf00 authored by Bas Lijnse's avatar Bas Lijnse

Added _Posix for linux

git-svn-id: https://svn.cs.ru.nl/repos/clean-platform/trunk@169 2afc29ad-3112-4e41-907a-9359c7e6e986
parent 505df31a
definition module _Posix
from _Pointer import :: Pointer
from Time import :: Tm
WNOHANG :== 0x00000001
WUNTRACED :== 0x00000002
MAXPATHLEN :== 1024
DIRENT_D_NAME_OFFSET :== 8
S_IFMT :== 0170000
S_IFIFO :== 0010000
S_IFCHR :== 0020000
S_IFDIR :== 0040000
S_IFBLK :== 0060000
S_IFREG :== 0100000
S_IFLNK :== 0120000
S_IFSOCK :== 0140000
S_IFWHT :== 0160000
//Posix API calls
errno :: !*World -> (!Int,!*World)
strerr :: !Int -> Pointer
stat :: !{#Char} !{#Char} !*World -> (!Int,!*World)
unlink :: !{#Char} !*World -> (!Int,!*World)
fork :: !*World -> (!Int,!*World)
execvp :: !{#Char} !{#Pointer} !*World -> (!Int,!*World)
waitpid :: !Int !{#Int} !Int !*World -> (!Int,!*World)
exit :: !Int !*World -> (!.a,!*World)
getcwd :: !{#Char} !Int !*World -> (!Pointer,!*World)
chdir :: !{#Char} !*World -> (!Int,!*World)
mkdir :: !{#Char} !Int !*World -> (!Int,!*World)
rmdir :: !{#Char} !*World -> (!Int,!*World)
rename :: !{#Char} !{#Char} !*World -> (!Int,!*World)
opendir :: !{#Char} !*World -> (!Pointer,!*World)
closedir :: !Pointer !*World -> (!Int,!*World)
readdir :: !Pointer !*World -> (!Pointer,!*World)
//Memory (impure)
malloc :: !Int -> Pointer
free :: !Pointer -> Int
memcpy_string_to_pointer :: !Pointer !{#Char} !Int -> Pointer
//Posix datastructures
:: Stat =
{ st_dev :: !Int
, st_ino :: !Int
, st_mode :: !Int
, st_nlink :: !Int
, st_uid :: !Int
, st_gid :: !Int
, st_rdev :: !Int
, st_size :: !Int
, st_blocks :: !Int
, st_blksize :: !Int
, st_ctimespec :: !Int
, st_mtimespec :: !Int
, st_atimespec :: !Int
}
//Mapping to/from byte arrays
unpackStat :: !{#Char} -> Stat
sizeOfStat :: Int
implementation module _Posix
import _Pointer, Time
import StdInt
errno :: !*World -> (!Int,!*World)
errno world = (getErrno,world)
where
getErrno :: Int
getErrno = readInt4S errnoAddr 0
errnoAddr :: Pointer
errnoAddr = code {
ccall __errno_location ":p"
}
strerr :: !Int -> Pointer
strerr world = code {
ccall strerror "I:p"
}
stat :: !{#Char} !{#Char} !*World -> (!Int,!*World)
stat path buf world = code {
ccall stat "ss:I:A"
}
unlink :: !{#Char} !*World -> (!Int,!*World)
unlink path world = code {
ccall unlink "s:I:A"
}
fork :: !*World -> (!Int,!*World)
fork world = code {
ccall fork ":I:A"
}
execvp :: !{#Char} !{#Pointer} !*World -> (!Int,!*World)
execvp name argv world = code {
ccall execvp "sA:I:A"
}
waitpid :: !Int !{#Int} !Int !*World -> (!Int,!*World)
waitpid pid status_p options world = code {
ccall waitpid "IAI:I:A"
}
exit :: !Int !*World -> (!.a,!*World)
exit num world = code {
ccall exit "I:p:A"
}
getcwd :: !{#Char} !Int !*World -> (!Pointer,!*World)
getcwd buf size_t world = code {
ccall getcwd "sI:p:A"
}
chdir :: !{#Char} !*World -> (!Int,!*World)
chdir name world = code {
ccall chdir "s:I:A"
}
mkdir :: !{#Char} !Int !*World -> (!Int,!*World)
mkdir name mode world = code {
ccall mkdir "sI:I:A"
}
rmdir :: !{#Char} !*World -> (!Int,!*World)
rmdir name world = code {
ccall rmdir "s:I:A"
}
rename :: !{#Char} !{#Char} !*World -> (!Int,!*World)
rename old new world = code {
ccall rename "ss:I:A"
}
opendir :: !{#Char} !*World -> (!Pointer,!*World)
opendir path world = code {
ccall opendir "s:p:A"
}
closedir :: !Pointer !*World -> (!Int,!*World)
closedir dir world = code {
ccall closedir "p:I:A"
}
readdir :: !Pointer !*World -> (!Pointer,!*World)
readdir dir world = code {
ccall readdir "p:p:A"
}
malloc :: !Int -> Pointer
malloc num = code {
ccall malloc "p:p"
}
free :: !Pointer -> Int
free ptr = code {
ccall free "p:I"
}
memcpy_string_to_pointer :: !Pointer !{#Char} !Int -> Pointer
memcpy_string_to_pointer p s n = code {
ccall memcpy "psp:p"
}
//Mapping to/from byte arrays
unpackStat :: !{#Char} -> Stat
unpackStat s =
{ st_dev = IF_INT_64_OR_32 (unpackInt8 s 0) (unpackInt4S s 0 /*8 bytes*/)
, st_ino = IF_INT_64_OR_32 (unpackInt8 s 8) (unpackInt4S s 12)
, st_mode = IF_INT_64_OR_32 (unpackInt4S s 24) (unpackInt4S s 16)
, st_nlink = IF_INT_64_OR_32 (unpackInt8 s 16) (unpackInt4S s 20)
, st_uid = IF_INT_64_OR_32 (unpackInt4S s 28) (unpackInt4S s 24)
, st_gid = IF_INT_64_OR_32 (unpackInt4S s 32) (unpackInt4S s 28)
, st_rdev = IF_INT_64_OR_32 (unpackInt8 s 40) (unpackInt4S s 32 /*8 bytes*/)
, st_size = IF_INT_64_OR_32 (unpackInt8 s 48) (unpackInt4S s 44)
, st_blocks = IF_INT_64_OR_32 (unpackInt8 s 64) (unpackInt4S s 52)
, st_blksize = IF_INT_64_OR_32 (unpackInt8 s 56) (unpackInt4S s 48)
, st_atimespec = IF_INT_64_OR_32 (unpackInt8 s 72 /*16 bytes*/) (unpackInt4S 56 /*8 bytes*/)
, st_mtimespec = IF_INT_64_OR_32 (unpackInt8 s 88 /*16 bytes*/) (unpackInt4S 64 /*8 bytes*/)
, st_ctimespec = IF_INT_64_OR_32 (unpackInt8 s 104 /*16 bytes*/) (unpackInt4S 72 /*8 bytes*/)
}
sizeOfStat :: Int
sizeOfStat = IF_INT_64_OR_32 144 88
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment