]> gitweb.factorcode.org Git - factor.git/blob - basis/unix/ffi/ffi.factor
10346cff2cd7b1ff1100e561629fc7ab95fda9a6
[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: char* strerror ( int errno ) ;
48
49 STRUCT: group
50     { gr_name char* }
51     { gr_passwd char* }
52     { gr_gid int }
53     { gr_mem char** } ;
54
55 FUNCTION: int accept ( int s, void* sockaddr, socklen_t* socklen ) ;
56 FUNCTION: int bind ( int s, void* name, socklen_t namelen ) ;
57 FUNCTION: int chdir ( char* path ) ;
58 FUNCTION: int chmod ( char* path, mode_t mode ) ;
59 FUNCTION: int fchmod ( int fd, mode_t mode ) ;
60 FUNCTION: int chown ( char* path, uid_t owner, gid_t group ) ;
61 FUNCTION: int chroot ( char* path ) ;
62 FUNCTION: int close ( int fd ) ;
63 FUNCTION: int closedir ( DIR* dirp ) ;
64 FUNCTION: int connect ( int s, void* name, socklen_t namelen ) ;
65 FUNCTION: int dup2 ( int oldd, int newd ) ;
66 FUNCTION: void endpwent ( ) ;
67 FUNCTION: int fchdir ( int fd ) ;
68 FUNCTION: int fchown ( int fd, uid_t owner, gid_t group ) ;
69 FUNCTION: int fcntl ( int fd, int cmd, int arg ) ;
70 FUNCTION: int flock ( int fd, int operation ) ;
71 FUNCTION: void freeaddrinfo ( addrinfo* ai ) ;
72 FUNCTION: int futimes ( int id, timeval[2] times ) ;
73 FUNCTION: char* gai_strerror ( int ecode ) ;
74 FUNCTION: int getaddrinfo ( char* hostname, char* servname, addrinfo* hints, addrinfo** res ) ;
75 FUNCTION: char* getcwd ( char* buf, size_t size ) ;
76 FUNCTION: pid_t getpid ;
77 FUNCTION: int getdtablesize ;
78 FUNCTION: gid_t getegid ;
79 FUNCTION: uid_t geteuid ;
80 FUNCTION: gid_t getgid ;
81 FUNCTION: char* getenv ( char* name ) ;
82
83 FUNCTION: int getgrgid_r ( gid_t gid, group* grp, char* buffer, size_t bufsize, group** result ) ;
84 FUNCTION: int getgrnam_r ( char* name, group* grp, char* buffer, size_t bufsize, group** result ) ;
85 FUNCTION: passwd* getpwent ( ) ;
86 FUNCTION: passwd* getpwuid ( uid_t uid ) ;
87 FUNCTION: passwd* getpwnam ( char* login ) ;
88 FUNCTION: int getpwnam_r ( char* login, passwd* pwd, char* buffer, size_t bufsize, passwd** result ) ;
89 FUNCTION: int getgroups ( int gidsetlen, gid_t* gidset ) ;
90 FUNCTION: int getgrouplist ( char* name, int basegid, int* groups, int* ngroups ) ;
91 FUNCTION: int getrlimit ( int resource, rlimit* rlp ) ;
92 FUNCTION: int setrlimit ( int resource, rlimit* rlp ) ;
93 FUNCTION: int getpriority ( int which, id_t who ) ;
94 FUNCTION: int setpriority ( int which, id_t who, int prio ) ;
95 FUNCTION: int getrusage ( int who, rusage* r_usage ) ;
96 FUNCTION: group* getgrent ;
97 FUNCTION: int gethostname ( char* name, int len ) ;
98 FUNCTION: int getsockname ( int socket, sockaddr* address, socklen_t* address_len ) ;
99 FUNCTION: int getpeername ( int socket, sockaddr* address, socklen_t* address_len ) ;
100 FUNCTION: uid_t getuid ;
101 FUNCTION: uint htonl ( uint n ) ;
102 FUNCTION: ushort htons ( ushort n ) ;
103 ! FUNCTION: int issetugid ;
104 FUNCTION: int isatty ( int fildes ) ;
105 FUNCTION: int ioctl ( int fd, ulong request, char* argp ) ;
106 FUNCTION: int lchown ( char* path, uid_t owner, gid_t group ) ;
107 FUNCTION: int listen ( int s, int backlog ) ;
108 FUNCTION: off_t lseek ( int fildes, off_t offset, int whence ) ;
109 FUNCTION: int mkdir ( char* path, mode_t mode ) ;
110 FUNCTION: void* mmap ( void* addr, size_t len, int prot, int flags, int fd, off_t offset ) ;
111 FUNCTION: int munmap ( void* addr, size_t len ) ;
112 FUNCTION: uint ntohl ( uint n ) ;
113 FUNCTION: ushort ntohs ( ushort n ) ;
114 FUNCTION: int shutdown ( int fd, int how ) ;
115 FUNCTION: int open ( char* path, int flags, int prot ) ;
116 FUNCTION: DIR* opendir ( char* path ) ;
117
118 STRUCT: utimbuf
119     { actime time_t }
120     { modtime time_t } ;
121
122 FUNCTION: int utime ( char* path, utimbuf* buf ) ;
123
124 FUNCTION: int pclose ( void* file ) ;
125 FUNCTION: int pipe ( int* filedes ) ;
126 FUNCTION: void* popen ( char* command, char* type ) ;
127 FUNCTION: ssize_t read ( int fd, void* buf, size_t nbytes ) ;
128
129 FUNCTION: dirent* readdir ( DIR* dirp ) ;
130 FUNCTION: int readdir_r ( void* dirp, dirent* entry, dirent** result ) ;
131 FUNCTION: ssize_t readlink ( char* path, char* buf, size_t bufsize ) ;
132
133 CONSTANT: PATH_MAX 1024
134
135 FUNCTION: ssize_t recv ( int s, void* buf, size_t nbytes, int flags ) ;
136 FUNCTION: ssize_t recvfrom ( int s, void* buf, size_t nbytes, int flags, sockaddr-in* from, socklen_t* fromlen ) ;
137 FUNCTION: int rename ( char* from, char* to ) ;
138 FUNCTION: int rmdir ( char* path ) ;
139 FUNCTION: int select ( int nfds, void* readfds, void* writefds, void* exceptfds, timeval* timeout ) ;
140 FUNCTION: ssize_t sendto ( int s, void* buf, size_t len, int flags, sockaddr-in* to, socklen_t tolen ) ;
141 FUNCTION: int setenv ( char* name, char* value, int overwrite ) ;
142 FUNCTION: int unsetenv ( char* name ) ;
143 FUNCTION: int setegid ( gid_t egid ) ;
144 FUNCTION: int seteuid ( uid_t euid ) ;
145 FUNCTION: int setgid ( gid_t gid ) ;
146 FUNCTION: int setgroups ( int ngroups, gid_t* gidset ) ;
147 FUNCTION: int setregid ( gid_t rgid, gid_t egid ) ;
148 FUNCTION: int setreuid ( uid_t ruid, uid_t euid ) ;
149 FUNCTION: int setsockopt ( int s, int level, int optname, void* optval, socklen_t optlen ) ;
150 FUNCTION: int setuid ( uid_t uid ) ;
151 FUNCTION: int socket ( int domain, int type, int protocol ) ;
152 FUNCTION: int symlink ( char* path1, char* path2 ) ;
153 FUNCTION: int link ( char* path1, char* path2 ) ;
154 FUNCTION: int system ( char* command ) ;
155 FUNCTION: int unlink ( char* path ) ;
156 FUNCTION: int utimes ( char* path, timeval[2] times ) ;
157 FUNCTION: ssize_t write ( int fd, void* buf, size_t nbytes ) ;
158
159 "librt" "librt.so" "cdecl" add-library