]> gitweb.factorcode.org Git - factor.git/blob - basis/unix/ffi/ffi.factor
8d384092edab61be3ee3fb2fa701acc7a7736fc2
[factor.git] / basis / unix / ffi / ffi.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types alien.libraries alien.syntax
4 classes.struct combinators kernel system unix.time unix.types
5 vocabs vocabs.loader ;
6 IN: unix.ffi
7
8 <<
9
10 {
11     { [ os linux? ] [ "unix.ffi.linux" require ] }
12     { [ os bsd? ] [ "unix.ffi.bsd" require ] }
13     { [ os solaris? ] [ "unix.ffi.solaris" require ] }
14 } cond
15
16 >>
17
18 CONSTANT: PROT_NONE   0
19 CONSTANT: PROT_READ   1
20 CONSTANT: PROT_WRITE  2
21 CONSTANT: PROT_EXEC   4
22                        
23 CONSTANT: MAP_FILE    0
24 CONSTANT: MAP_SHARED  1
25 CONSTANT: MAP_PRIVATE 2
26
27 CONSTANT: SEEK_SET 0
28 CONSTANT: SEEK_CUR 1
29 CONSTANT: SEEK_END 2
30
31 : MAP_FAILED ( -- alien ) -1 <alien> ; inline
32
33 CONSTANT: NGROUPS_MAX 16
34
35 CONSTANT: DT_UNKNOWN   0
36 CONSTANT: DT_FIFO      1
37 CONSTANT: DT_CHR       2
38 CONSTANT: DT_DIR       4
39 CONSTANT: DT_BLK       6
40 CONSTANT: DT_REG       8
41 CONSTANT: DT_LNK      10
42 CONSTANT: DT_SOCK     12
43 CONSTANT: DT_WHT      14
44
45 LIBRARY: libc
46
47 FUNCTION: c-string strerror ( int errno ) ;
48
49 STRUCT: group
50     { gr_name c-string }
51     { gr_passwd c-string }
52     { gr_gid int }
53     { gr_mem c-string* } ;
54
55 STRUCT: protoent
56     { name c-string }
57     { aliases void* }
58     { proto int } ;
59
60 FUNCTION: int accept ( int s, void* sockaddr, socklen_t* socklen ) ;
61 FUNCTION: int bind ( int s, void* name, socklen_t namelen ) ;
62 FUNCTION: int chdir ( c-string path ) ;
63 FUNCTION: int chmod ( c-string path, mode_t mode ) ;
64 FUNCTION: int fchmod ( int fd, mode_t mode ) ;
65 FUNCTION: int chown ( c-string path, uid_t owner, gid_t group ) ;
66 FUNCTION: int chroot ( c-string path ) ;
67 FUNCTION: int close ( int fd ) ;
68 FUNCTION: int closedir ( DIR* dirp ) ;
69 FUNCTION: int connect ( int s, void* name, socklen_t namelen ) ;
70 FUNCTION: int dup2 ( int oldd, int newd ) ;
71 FUNCTION: void endpwent ( ) ;
72 FUNCTION: int fchdir ( int fd ) ;
73 FUNCTION: int fchown ( int fd, uid_t owner, gid_t group ) ;
74 FUNCTION: int fcntl ( int fd, int cmd, int arg ) ;
75 FUNCTION: int flock ( int fd, int operation ) ;
76 FUNCTION: void freeaddrinfo ( addrinfo* ai ) ;
77 FUNCTION: int futimes ( int id, timeval[2] times ) ;
78 FUNCTION: c-string gai_strerror ( int ecode ) ;
79 FUNCTION: int getaddrinfo ( c-string hostname, c-string servname, addrinfo* hints, addrinfo** res ) ;
80 FUNCTION: c-string getcwd ( c-string buf, size_t size ) ;
81 FUNCTION: pid_t getpid ;
82 FUNCTION: int getdtablesize ;
83 FUNCTION: pid_t getpgrp ;
84 FUNCTION: pid_t getpgid ( pid_t pid ) ;
85 FUNCTION: gid_t getegid ;
86 FUNCTION: uid_t geteuid ;
87 FUNCTION: gid_t getgid ;
88 FUNCTION: c-string getenv ( c-string name ) ;
89
90 FUNCTION: int getgrgid_r ( gid_t gid, group* grp, c-string buffer, size_t bufsize, group** result ) ;
91 FUNCTION: int getgrnam_r ( c-string name, group* grp, c-string buffer, size_t bufsize, group** result ) ;
92 FUNCTION: passwd* getpwent ( ) ;
93 FUNCTION: int killpg ( pid_t pgrp, int sig ) ;
94 FUNCTION: void setpwent ( ) ;
95 FUNCTION: void setpassent ( int stayopen ) ;
96 FUNCTION: passwd* getpwuid ( uid_t uid ) ;
97 FUNCTION: passwd* getpwnam ( c-string login ) ;
98 FUNCTION: int getpwnam_r ( c-string login, passwd* pwd, c-string buffer, size_t bufsize, passwd** result ) ;
99 FUNCTION: int getgroups ( int gidsetlen, gid_t* gidset ) ;
100 FUNCTION: int getgrouplist ( c-string name, int basegid, int* groups, int* ngroups ) ;
101 FUNCTION: int getrlimit ( int resource, rlimit* rlp ) ;
102 FUNCTION: int setrlimit ( int resource, rlimit* rlp ) ;
103 FUNCTION: int getpriority ( int which, id_t who ) ;
104 FUNCTION: int setpriority ( int which, id_t who, int prio ) ;
105 FUNCTION: int getrusage ( int who, rusage* r_usage ) ;
106 FUNCTION: group* getgrent ;
107 FUNCTION: void endgrent ( ) ;
108 FUNCTION: int gethostname ( c-string name, int len ) ;
109 FUNCTION: int getsockname ( int socket, sockaddr* address, socklen_t* address_len ) ;
110 FUNCTION: int getpeername ( int socket, sockaddr* address, socklen_t* address_len ) ;
111 FUNCTION: protoent* getprotobyname ( c-string name ) ;
112 FUNCTION: uid_t getuid ;
113 FUNCTION: uint htonl ( uint n ) ;
114 FUNCTION: ushort htons ( ushort n ) ;
115 ! FUNCTION: int issetugid ;
116 FUNCTION: int isatty ( int fildes ) ;
117 FUNCTION: int ioctl ( int fd, ulong request, void* argp ) ;
118 FUNCTION: int lchown ( c-string path, uid_t owner, gid_t group ) ;
119 FUNCTION: int listen ( int s, int backlog ) ;
120 FUNCTION: off_t lseek ( int fildes, off_t offset, int whence ) ;
121 FUNCTION: int mkdir ( c-string path, mode_t mode ) ;
122 FUNCTION: void* mmap ( void* addr, size_t len, int prot, int flags, int fd, off_t offset ) ;
123 FUNCTION: int munmap ( void* addr, size_t len ) ;
124 FUNCTION: uint ntohl ( uint n ) ;
125 FUNCTION: ushort ntohs ( ushort n ) ;
126 FUNCTION: int shutdown ( int fd, int how ) ;
127 FUNCTION: int open ( c-string path, int flags, int prot ) ;
128 FUNCTION: DIR* opendir ( c-string path ) ;
129
130 STRUCT: utimbuf
131     { actime time_t }
132     { modtime time_t } ;
133
134 FUNCTION: int utime ( c-string path, utimbuf* buf ) ;
135
136 FUNCTION: int pclose ( void* file ) ;
137 FUNCTION: int pipe ( int* filedes ) ;
138 FUNCTION: void* popen ( c-string command, c-string type ) ;
139 FUNCTION: ssize_t read ( int fd, void* buf, size_t nbytes ) ;
140
141 FUNCTION: dirent* readdir ( DIR* dirp ) ;
142 FUNCTION: int readdir_r ( void* dirp, dirent* entry, dirent** result ) ;
143 FUNCTION: ssize_t readlink ( c-string path, c-string buf, size_t bufsize ) ;
144
145 CONSTANT: PATH_MAX 1024
146
147 FUNCTION: ssize_t recv ( int s, void* buf, size_t nbytes, int flags ) ;
148 FUNCTION: ssize_t recvfrom ( int s, void* buf, size_t nbytes, int flags, sockaddr-in* from, socklen_t* fromlen ) ;
149 FUNCTION: int rename ( c-string from, c-string to ) ;
150 FUNCTION: int rmdir ( c-string path ) ;
151 FUNCTION: int select ( int nfds, void* readfds, void* writefds, void* exceptfds, timeval* timeout ) ;
152 FUNCTION: ssize_t sendto ( int s, void* buf, size_t len, int flags, sockaddr-in* to, socklen_t tolen ) ;
153 FUNCTION: int setenv ( c-string name, c-string value, int overwrite ) ;
154 FUNCTION: int unsetenv ( c-string name ) ;
155 FUNCTION: int setegid ( gid_t egid ) ;
156 FUNCTION: int seteuid ( uid_t euid ) ;
157 FUNCTION: int setgid ( gid_t gid ) ;
158 FUNCTION: int setgroups ( int ngroups, gid_t* gidset ) ;
159 FUNCTION: int setpgid ( pid_t pid, pid_t gid ) ;
160 FUNCTION: int setregid ( gid_t rgid, gid_t egid ) ;
161 FUNCTION: int setreuid ( uid_t ruid, uid_t euid ) ;
162 FUNCTION: pid_t setsid ( ) ;
163 FUNCTION: int setsockopt ( int s, int level, int optname, void* optval, socklen_t optlen ) ;
164 FUNCTION: int setuid ( uid_t uid ) ;
165 FUNCTION: int socket ( int domain, int type, int protocol ) ;
166 FUNCTION: int symlink ( c-string path1, c-string path2 ) ;
167 FUNCTION: int link ( c-string path1, c-string path2 ) ;
168 FUNCTION: int unlink ( c-string path ) ;
169 FUNCTION: int utimes ( c-string path, timeval[2] times ) ;
170 FUNCTION: ssize_t write ( int fd, void* buf, size_t nbytes ) ;
171
172 "librt" "librt.so" cdecl add-library