]> gitweb.factorcode.org Git - factor.git/blob - basis/unix/ffi/ffi.factor
rename current string-mangling "char*" to "c-string". char* is now just a boring...
[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 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 ( c-string path ) ;
58 FUNCTION: int chmod ( c-string path, mode_t mode ) ;
59 FUNCTION: int fchmod ( int fd, mode_t mode ) ;
60 FUNCTION: int chown ( c-string path, uid_t owner, gid_t group ) ;
61 FUNCTION: int chroot ( c-string 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: c-string gai_strerror ( int ecode ) ;
74 FUNCTION: int getaddrinfo ( c-string hostname, c-string servname, addrinfo* hints, addrinfo** res ) ;
75 FUNCTION: c-string getcwd ( c-string 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: c-string getenv ( c-string name ) ;
82
83 FUNCTION: int getgrgid_r ( gid_t gid, group* grp, c-string buffer, size_t bufsize, group** result ) ;
84 FUNCTION: int getgrnam_r ( c-string name, group* grp, c-string buffer, size_t bufsize, group** result ) ;
85 FUNCTION: passwd* getpwent ( ) ;
86 FUNCTION: passwd* getpwuid ( uid_t uid ) ;
87 FUNCTION: passwd* getpwnam ( c-string login ) ;
88 FUNCTION: int getpwnam_r ( c-string login, passwd* pwd, c-string buffer, size_t bufsize, passwd** result ) ;
89 FUNCTION: int getgroups ( int gidsetlen, gid_t* gidset ) ;
90 FUNCTION: int getgrouplist ( c-string 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 ( c-string 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, c-string argp ) ;
106 FUNCTION: int lchown ( c-string 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 ( c-string 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 ( c-string path, int flags, int prot ) ;
116 FUNCTION: DIR* opendir ( c-string path ) ;
117
118 STRUCT: utimbuf
119     { actime time_t }
120     { modtime time_t } ;
121
122 FUNCTION: int utime ( c-string path, utimbuf* buf ) ;
123
124 FUNCTION: int pclose ( void* file ) ;
125 FUNCTION: int pipe ( int* filedes ) ;
126 FUNCTION: void* popen ( c-string command, c-string 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 ( c-string path, c-string 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 ( c-string from, c-string to ) ;
138 FUNCTION: int rmdir ( c-string 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 ( c-string name, c-string value, int overwrite ) ;
142 FUNCTION: int unsetenv ( c-string 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 ( c-string path1, c-string path2 ) ;
153 FUNCTION: int link ( c-string path1, c-string path2 ) ;
154 FUNCTION: int system ( c-string command ) ;
155 FUNCTION: int unlink ( c-string path ) ;
156 FUNCTION: int utimes ( c-string path, timeval[2] times ) ;
157 FUNCTION: ssize_t write ( int fd, void* buf, size_t nbytes ) ;
158
159 "librt" "librt.so" "cdecl" add-library