]> gitweb.factorcode.org Git - factor.git/blob - basis/unix/ffi/ffi.factor
Switch to https urls
[factor.git] / basis / unix / ffi / ffi.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See https://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 ! Possible values for 'ai_flags' in 'addrinfo'.
40 CONSTANT: AI_PASSIVE        0x0001
41 CONSTANT: AI_CANONNAME      0x0002
42 CONSTANT: AI_NUMERICHOST    0x0004
43 CONSTANT: AI_V4MAPPED       0x0008
44 CONSTANT: AI_ALL            0x0010
45 CONSTANT: AI_ADDRCONFIG     0x0020
46
47 CONSTANT: SHUT_RD     0
48 CONSTANT: SHUT_WR     1
49 CONSTANT: SHUT_RDWR   2
50
51 LIBRARY: libc
52
53 STRUCT: group
54     { gr_name c-string }
55     { gr_passwd c-string }
56     { gr_gid int }
57     { gr_mem c-string* } ;
58
59 STRUCT: protoent
60     { name c-string }
61     { aliases void* }
62     { proto int } ;
63
64 STRUCT: iovec
65     { iov_base void* }
66     { iov_len size_t } ;
67
68 STRUCT: servent
69     { name c-string }
70     { aliases void* }
71     { port int }
72     { proto c-string } ;
73
74 CONSTANT: F_OK 0 ! test for existence of file
75 CONSTANT: X_OK 1 ! test for execute or search permission
76 CONSTANT: W_OK 2 ! test for write permission
77 CONSTANT: R_OK 4 ! test for read permission
78
79 FUNCTION: int accept ( int s, void* sockaddr, socklen_t* socklen )
80 FUNCTION: int access ( c-string path, int amode )
81 FUNCTION: int bind ( int s, void* name, socklen_t namelen )
82 FUNCTION: int chdir ( c-string path )
83 FUNCTION: int chmod ( c-string path, mode_t mode )
84 FUNCTION: int fchmod ( int fd, mode_t mode )
85 FUNCTION: int chown ( c-string path, uid_t owner, gid_t group )
86 FUNCTION: int chroot ( c-string path )
87 FUNCTION: int close ( int fd )
88 FUNCTION: int closedir ( DIR* dirp )
89 FUNCTION: int connect ( int s, void* name, socklen_t namelen )
90 FUNCTION: int dup2 ( int oldd, int newd )
91 FUNCTION: void endpwent ( )
92 FUNCTION: int fchdir ( int fd )
93 FUNCTION: int fchown ( int fd, uid_t owner, gid_t group )
94 FUNCTION: int fcntl ( int fd, int cmd, int arg )
95 FUNCTION: int fileno ( FILE* stream )
96 FUNCTION: int flock ( int fd, int operation )
97 FUNCTION: void freeaddrinfo ( addrinfo* ai )
98 FUNCTION: int futimes ( int id, timeval[2] times )
99 FUNCTION: c-string gai_strerror ( int ecode )
100 FUNCTION: int getaddrinfo ( c-string hostname, c-string servname, addrinfo* hints, addrinfo** res )
101 FUNCTION: c-string getcwd ( c-string buf, size_t size )
102 FUNCTION: pid_t getpid ( )
103 FUNCTION: int getdtablesize ( )
104 FUNCTION: pid_t getpgrp ( )
105 FUNCTION: pid_t getpgid ( pid_t pid )
106 FUNCTION: gid_t getegid ( )
107 FUNCTION: uid_t geteuid ( )
108 FUNCTION: gid_t getgid ( )
109 FUNCTION: c-string getenv ( c-string name )
110
111 FUNCTION: int getgrgid_r ( gid_t gid, group* grp, c-string buffer, size_t bufsize, group** result )
112 FUNCTION: int getgrnam_r ( c-string name, group* grp, c-string buffer, size_t bufsize, group** result )
113 FUNCTION: passwd* getpwent ( )
114 FUNCTION: int killpg ( pid_t pgrp, int sig )
115 FUNCTION: void setpwent ( )
116 FUNCTION: void setpassent ( int stayopen )
117 FUNCTION: passwd* getpwuid ( uid_t uid )
118 FUNCTION: passwd* getpwnam ( c-string login )
119 FUNCTION: int getpwnam_r ( c-string login, passwd* pwd, c-string buffer, size_t bufsize, passwd** result )
120 FUNCTION: int getgroups ( int gidsetlen, gid_t* gidset )
121 FUNCTION: int getgrouplist ( c-string name, int basegid, int* groups, int* ngroups )
122 FUNCTION: int getrlimit ( int resource, rlimit* rlp )
123 FUNCTION: int setrlimit ( int resource, rlimit* rlp )
124 FUNCTION: int getpriority ( int which, id_t who )
125 FUNCTION: int setpriority ( int which, id_t who, int prio )
126 FUNCTION: int getrusage ( int who, rusage* r_usage )
127 FUNCTION: group* getgrent ( )
128 FUNCTION: void endgrent ( )
129 FUNCTION: int gethostname ( c-string name, int len )
130 FUNCTION: int getsockname ( int socket, sockaddr* address, socklen_t* address_len )
131 FUNCTION: int getpeername ( int socket, sockaddr* address, socklen_t* address_len )
132 FUNCTION: protoent* getprotobyname ( c-string name )
133 FUNCTION: servent* getservbyname ( c-string name, c-string prot )
134 FUNCTION: servent* getservbyport ( int port, c-string prot )
135 FUNCTION: uid_t getuid ( )
136 FUNCTION: uint htonl ( uint n )
137 FUNCTION: ushort htons ( ushort n )
138 ! FUNCTION: int issetugid ;
139 FUNCTION: int isatty ( int fildes )
140 FUNCTION: int ioctl ( int fd, ulong request, void* argp )
141 FUNCTION: int lchown ( c-string path, uid_t owner, gid_t group )
142 FUNCTION: int listen ( int s, int backlog )
143 FUNCTION: off_t lseek ( int fildes, off_t offset, int whence )
144 FUNCTION: int mkdir ( c-string path, mode_t mode )
145 FUNCTION: int mkfifo ( c-string path, mode_t mode )
146 FUNCTION: void* mmap ( void* addr, size_t len, int prot, int flags, int fd, off_t offset )
147 FUNCTION: int munmap ( void* addr, size_t len )
148 FUNCTION: uint ntohl ( uint n )
149 FUNCTION: ushort ntohs ( ushort n )
150 FUNCTION: int shutdown ( int fd, int how )
151 FUNCTION: int open ( c-string path, int flags, int prot )
152 FUNCTION: DIR* opendir ( c-string path )
153
154 STRUCT: utimbuf
155     { actime time_t }
156     { modtime time_t } ;
157
158 FUNCTION: int utime ( c-string path, utimbuf* buf )
159
160 FUNCTION: int pclose ( void* file )
161 FUNCTION: int pipe ( int* filedes )
162 FUNCTION: void* popen ( c-string command, c-string type )
163 FUNCTION: ssize_t read ( int fd, void* buf, size_t nbytes )
164 FUNCTION: ssize_t readv ( int fd, iovec* iov, int iovcnt )
165
166 FUNCTION: dirent* readdir ( DIR* dirp )
167 FUNCTION: int readdir_r ( void* dirp, dirent* entry, dirent** result )
168 FUNCTION: ssize_t readlink ( c-string path, c-string buf, size_t bufsize )
169
170 CONSTANT: PATH_MAX 1024
171
172 FUNCTION: ssize_t recv ( int s, void* buf, size_t nbytes, int flags )
173 FUNCTION: ssize_t recvfrom ( int s, void* buf, size_t nbytes, int flags, sockaddr-in* from, socklen_t* fromlen )
174 FUNCTION: int rename ( c-string from, c-string to )
175 FUNCTION: int rmdir ( c-string path )
176 FUNCTION: int select ( int nfds, void* readfds, void* writefds, void* exceptfds, timeval* timeout )
177 FUNCTION: ssize_t sendto ( int s, void* buf, size_t len, int flags, sockaddr-in* to, socklen_t tolen )
178
179 FUNCTION: int setenv ( c-string name, c-string value, int overwrite )
180 FUNCTION: int unsetenv ( c-string name )
181 FUNCTION: int setegid ( gid_t egid )
182 FUNCTION: int seteuid ( uid_t euid )
183 FUNCTION: int setgid ( gid_t gid )
184 FUNCTION: int setgroups ( int ngroups, gid_t* gidset )
185 FUNCTION: int setpgid ( pid_t pid, pid_t gid )
186 FUNCTION: int setregid ( gid_t rgid, gid_t egid )
187 FUNCTION: int setreuid ( uid_t ruid, uid_t euid )
188 FUNCTION: pid_t setsid ( )
189 FUNCTION: int getsockopt ( int s, int level, int optname, void* optval, socklen_t* optlen )
190 FUNCTION: int setsockopt ( int s, int level, int optname, void* optval, socklen_t optlen )
191 FUNCTION: int setuid ( uid_t uid )
192 FUNCTION: int socket ( int domain, int type, int protocol )
193 FUNCTION: int symlink ( c-string path1, c-string path2 )
194 FUNCTION: int link ( c-string path1, c-string path2 )
195 FUNCTION: int ftruncate ( int fd, int length )
196 FUNCTION: int truncate ( c-string path, int length )
197 FUNCTION: int unlink ( c-string path )
198 FUNCTION: int utimes ( c-string path, timeval[2] times )
199 FUNCTION: ssize_t write ( int fd, void* buf, size_t nbytes )
200 FUNCTION: ssize_t writev ( int fds, iovec* iov, int iovcnt )
201 TYPEDEF: void* sighandler_t
202 FUNCTION: sighandler_t signal ( int signum, sighandler_t handler )
203
204 "librt" "librt.so" cdecl add-library