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