_Posix.dcl 2.89 KB
Newer Older
1
definition module System._Posix
Bas Lijnse's avatar
Bas Lijnse committed
2

3
from System._Pointer import :: Pointer
4
from StdInt import IF_INT_64_OR_32
5
from System.Time import :: Tm
Bas Lijnse's avatar
Bas Lijnse committed
6

Mart Lubbers's avatar
Mart Lubbers committed
7
WNOHANG		:==	0x00000001
Bas Lijnse's avatar
Bas Lijnse committed
8 9 10
WUNTRACED	:== 0x00000002
MAXPATHLEN	:== 1024

11
DIRENT_D_NAME_OFFSET	:== IF_INT_64_OR_32 19 11
Bas Lijnse's avatar
Bas Lijnse committed
12 13 14 15 16 17 18 19 20 21 22

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

23 24 25 26
STDIN_FILENO  :== 0
STDOUT_FILENO :== 1
STDERR_FILENO :== 2

Mart Lubbers's avatar
Mart Lubbers committed
27
FIONREAD   :== 0x541B
28

29 30
F_SETFD    :== 2
FD_CLOEXEC :== 1
31

Mart Lubbers's avatar
Mart Lubbers committed
32 33
O_RDWR     :== 02
O_NOCTTY   :== 0400
34

Mart Lubbers's avatar
Mart Lubbers committed
35 36 37 38 39 40
TCSANOW    :== 0
TIOCSCTTY  :== 0x540E

ECHO       :== 0x8
ECHONL     :== 0x40
ICANON     :== 0x2
Mart Lubbers's avatar
Mart Lubbers committed
41

Bas Lijnse's avatar
Bas Lijnse committed
42
//Posix API calls
43
errno		:: !*w -> (!Int,!*w)
Bas Lijnse's avatar
Bas Lijnse committed
44
strerr		:: !Int -> Pointer
45 46 47 48 49 50 51 52 53 54 55 56 57 58
stat		:: !{#Char} !{#Char} !*w -> (!Int,!*w)
unlink		:: !{#Char} !*w -> (!Int,!*w)
fork		:: !*w -> (!Int,!*w)
execvp		:: !{#Char} !{#Pointer} !*w -> (!Int,!*w)
waitpid		:: !Int !{#Int} !Int !*w -> (!Int,!*w)
exit		:: !Int !*w -> (!.a,!*w) 
getcwd		:: !{#Char} !Int !*w -> (!Pointer,!*w)
chdir		:: !{#Char} !*w -> (!Int,!*w)
mkdir		:: !{#Char} !Int !*w -> (!Int,!*w)
rmdir		:: !{#Char} !*w -> (!Int,!*w)
rename		:: !{#Char} !{#Char} !*w -> (!Int,!*w)
opendir		:: !{#Char} !*w -> (!Pointer,!*w)
closedir	:: !Pointer !*w -> (!Int,!*w)
readdir		:: !Pointer !*w -> (!Pointer,!*w)
59
pipe        :: !Pointer !*w -> (!Int, !*w)
60 61 62 63 64
posix_openpt :: !Int !*w -> (!Int, !*w)
grantpt     :: !Int !*w -> (!Int, !*w)
unlockpt    :: !Int !*w -> (!Int, !*w)
ptsname     :: !Int !*w -> (!Pointer, !*w)
open        :: !Pointer !Int !*w -> (!Int, !*w)
Mart Lubbers's avatar
Mart Lubbers committed
65
tcgetattr   :: !Int !Pointer !*w -> (!Int, !*w)
66
cfmakeraw   :: !Pointer !*w -> *w
Mart Lubbers's avatar
Mart Lubbers committed
67
tcsetattr   :: !Int !Int !Pointer !*w -> (!Int, !*w)
68
setsid      :: !*w -> *w
69 70
dup2        :: !Int !Int !*w -> (!Int, !*w)
close       :: !Int !*w -> (!Int, !*w)
71
ioctl       :: !Int !Int !Pointer !*w -> (!Int, !*w)
72 73
// variant requiring an argument as third parameter
fcntlArg    :: !Int !Int !Int !*w -> (!Int, !*w)
74 75 76
read        :: !Int !Pointer !Int !*w -> (!Int, !*w)
write       :: !Int !{#Char} !Int !*w -> (!Int, !*w)
select_     :: !Int !Pointer !Pointer !Pointer !Pointer !*w -> (!Int, !*w)
77
kill        :: !Int !Int !*w -> (!Int, !*w)
78
timegm      :: !{#Int} -> Int
79
clock_gettime :: !Int !Pointer !*w -> (!Int, !*w)
80
nanosleep :: !Pointer !Pointer !*w -> (!Int, !*w)
Bas Lijnse's avatar
Bas Lijnse committed
81 82 83

//Memory (impure)
malloc	:: !Int -> Pointer
84
mallocSt	:: !Int !*w -> (!Pointer, !*w)
Bas Lijnse's avatar
Bas Lijnse committed
85
free	:: !Pointer -> Int
86
freeSt  :: !Pointer !*w -> *w
Bas Lijnse's avatar
Bas Lijnse committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
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