blob: 75c1855faaef3614afe5cefcdab5f53fb5c31d4e [file] [log] [blame]
Alex Crichtond3d77922015-09-11 17:03:39 -07001//! Definitions found commonly among almost all Unix derivatives
2//!
3//! More functions and definitions can be found in the more specific modules
4//! according to the platform in question.
5
Alex Crichton084f9ea2015-09-11 15:11:59 -07006s! {
7 pub struct utimbuf {
Alex Crichton50a42e22015-09-15 14:27:15 -07008 pub actime: time_t,
9 pub modtime: time_t,
10 }
11
12 pub struct timeval {
13 pub tv_sec: time_t,
14 pub tv_usec: suseconds_t,
15 }
16
17 pub struct timespec {
18 pub tv_sec: time_t,
19 pub tv_nsec: c_long,
20 }
21
22 pub struct rlimit {
23 pub rlim_cur: rlim_t,
24 pub rlim_max: rlim_t,
25 }
26
27 pub struct rusage {
28 pub ru_utime: timeval,
29 pub ru_stime: timeval,
30 pub ru_maxrss: c_long,
31 pub ru_ixrss: c_long,
32 pub ru_idrss: c_long,
33 pub ru_isrss: c_long,
34 pub ru_minflt: c_long,
35 pub ru_majflt: c_long,
36 pub ru_nswap: c_long,
37 pub ru_inblock: c_long,
38 pub ru_oublock: c_long,
39 pub ru_msgsnd: c_long,
40 pub ru_msgrcv: c_long,
41 pub ru_nsignals: c_long,
42 pub ru_nvcsw: c_long,
43 pub ru_nivcsw: c_long
44 }
45
46 pub struct in_addr {
47 pub s_addr: in_addr_t,
48 }
49
50 pub struct in6_addr {
Alex Crichton316c3672015-09-16 14:32:59 -070051 pub s6_addr: [u8; 16],
Alex Crichton50a42e22015-09-15 14:27:15 -070052 __align: [u32; 0],
53 }
54
55 pub struct ip_mreq {
56 pub imr_multiaddr: in_addr,
57 pub imr_interface: in_addr,
58 }
Alex Crichtond8096012015-09-16 16:36:30 -070059
60 pub struct ipv6_mreq {
61 pub ipv6mr_multiaddr: in6_addr,
62 #[cfg(target_os = "android")]
Alex Crichtond8096012015-09-16 16:36:30 -070063 pub ipv6mr_interface: c_int,
Alex Crichton24824002015-09-16 17:34:54 -070064 #[cfg(not(target_os = "android"))]
65 pub ipv6mr_interface: c_uint,
Alex Crichtond8096012015-09-16 16:36:30 -070066 }
Alex Crichton084f9ea2015-09-11 15:11:59 -070067}
68
Alex Crichtoncd9b33e2015-09-17 14:47:40 -070069pub const WNOHANG: c_int = 1;
70pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
71pub const SIG_IGN: sighandler_t = 1 as sighandler_t;
72pub const SIG_ERR: sighandler_t = !0 as sighandler_t;
73
Alex Crichton2c57e362015-09-15 17:30:53 -070074cfg_if! {
75 if #[cfg(feature = "default")] {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -070076 // cargo build, don't pull in anything extra as the libstd dep
Alex Crichton2c57e362015-09-15 17:30:53 -070077 // already pulls in all libs.
78 } else if #[cfg(target_env = "musl")] {
79 #[link(name = "c", kind = "static")]
80 extern {}
81 } else {
82 #[link(name = "c")]
83 #[link(name = "m")]
84 extern {}
85 }
86}
87
Alex Crichton5d6cf052015-09-11 14:52:34 -070088extern {
Alex Crichton50a42e22015-09-15 14:27:15 -070089 pub fn socket(domain: c_int, ty: c_int, protocol: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -070090 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
91 link_name = "connect$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -070092 pub fn connect(socket: c_int, address: *const sockaddr,
93 len: socklen_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -070094 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
95 link_name = "bind$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -070096 pub fn bind(socket: c_int, address: *const sockaddr,
97 address_len: socklen_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -070098 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
99 link_name = "listen$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700100 pub fn listen(socket: c_int, backlog: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700101 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
102 link_name = "accept$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700103 pub fn accept(socket: c_int, address: *mut sockaddr,
104 address_len: *mut socklen_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700105 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
106 link_name = "getpeername$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700107 pub fn getpeername(socket: c_int, address: *mut sockaddr,
108 address_len: *mut socklen_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700109 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
110 link_name = "getsockname$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700111 pub fn getsockname(socket: c_int, address: *mut sockaddr,
112 address_len: *mut socklen_t) -> c_int;
113 pub fn setsockopt(socket: c_int, level: c_int, name: c_int,
Alex Crichton5d6cf052015-09-11 14:52:34 -0700114 value: *const ::c_void,
Alex Crichton50a42e22015-09-15 14:27:15 -0700115 option_len: socklen_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700116 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
Alex Crichton5d6cf052015-09-11 14:52:34 -0700117 link_name = "sendto$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700118 pub fn sendto(socket: c_int, buf: *const ::c_void, len: size_t,
119 flags: c_int, addr: *const sockaddr,
120 addrlen: socklen_t) -> ssize_t;
121 pub fn shutdown(socket: c_int, how: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700122
123 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
124 link_name = "chmod$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700125 pub fn chmod(path: *const c_char, mode: mode_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700126 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
127 link_name = "fchmod$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700128 pub fn fchmod(fd: c_int, mode: mode_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700129
130 #[cfg_attr(target_os = "macos", link_name = "fstat$INODE64")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700131 pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700132
Alex Crichton50a42e22015-09-15 14:27:15 -0700133 pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700134
Alex Crichton084f9ea2015-09-11 15:11:59 -0700135 #[cfg_attr(target_os = "macos", link_name = "stat$INODE64")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700136 pub fn stat(path: *const c_char, buf: *mut stat) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700137
138 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
139 link_name = "popen$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700140 pub fn popen(command: *const c_char,
141 mode: *const c_char) -> *mut ::FILE;
142 pub fn pclose(stream: *mut ::FILE) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700143 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
144 link_name = "fdopen$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700145 pub fn fdopen(fd: c_int, mode: *const c_char) -> *mut ::FILE;
146 pub fn fileno(stream: *mut ::FILE) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700147
148 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
149 link_name = "open$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700150 pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700151 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
152 link_name = "creat$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700153 pub fn creat(path: *const c_char, mode: mode_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700154 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
155 link_name = "fcntl$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700156 pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700157
158 #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
159 link_name = "opendir$INODE64")]
160 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
161 link_name = "opendir$INODE64$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700162 pub fn opendir(dirname: *const c_char) -> *mut ::DIR;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700163 #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")]
164 pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent,
Alex Crichton50a42e22015-09-15 14:27:15 -0700165 result: *mut *mut ::dirent) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700166 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
167 link_name = "closedir$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700168 pub fn closedir(dirp: *mut ::DIR) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700169 #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
170 link_name = "rewinddir$INODE64")]
171 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
172 link_name = "rewinddir$INODE64$UNIX2003")]
173 pub fn rewinddir(dirp: *mut ::DIR);
Alex Crichton5d6cf052015-09-11 14:52:34 -0700174
Alex Crichton50a42e22015-09-15 14:27:15 -0700175 pub fn access(path: *const c_char, amode: c_int) -> c_int;
176 pub fn alarm(seconds: c_uint) -> c_uint;
177 pub fn chdir(dir: *const c_char) -> c_int;
178 pub fn chown(path: *const c_char, uid: uid_t,
179 gid: gid_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700180 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
181 link_name = "close$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700182 pub fn close(fd: c_int) -> c_int;
183 pub fn dup(fd: c_int) -> c_int;
184 pub fn dup2(src: c_int, dst: c_int) -> c_int;
185 pub fn execv(prog: *const c_char,
186 argv: *const *const c_char) -> c_int;
187 pub fn execve(prog: *const c_char, argv: *const *const c_char,
188 envp: *const *const c_char)
189 -> c_int;
190 pub fn execvp(c: *const c_char,
191 argv: *const *const c_char) -> c_int;
192 pub fn fork() -> pid_t;
193 pub fn fpathconf(filedes: c_int, name: c_int) -> c_long;
194 pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
195 pub fn getegid() -> gid_t;
196 pub fn geteuid() -> uid_t;
197 pub fn getgid() -> gid_t;
198 pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t)
199 -> c_int;
200 pub fn getlogin() -> *mut c_char;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700201 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
202 link_name = "getopt$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700203 pub fn getopt(argc: c_int, argv: *const *mut c_char,
Alex Crichton50a42e22015-09-15 14:27:15 -0700204 optstr: *const c_char) -> c_int;
205 pub fn getpgrp() -> pid_t;
206 pub fn getpid() -> pid_t;
207 pub fn getppid() -> pid_t;
208 pub fn getuid() -> uid_t;
209 pub fn isatty(fd: c_int) -> c_int;
210 pub fn link(src: *const c_char, dst: *const c_char) -> c_int;
211 pub fn lseek(fd: c_int, offset: off_t, whence: c_int)
212 -> off_t;
213 pub fn pathconf(path: *const c_char, name: c_int) -> c_long;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700214 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
215 link_name = "pause$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700216 pub fn pause() -> c_int;
217 pub fn pipe(fds: *mut c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700218 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
219 link_name = "read$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700220 pub fn read(fd: c_int, buf: *mut ::c_void, count: size_t)
221 -> ssize_t;
222 pub fn rmdir(path: *const c_char) -> c_int;
223 pub fn setgid(gid: gid_t) -> c_int;
224 pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int;
225 pub fn setsid() -> pid_t;
226 pub fn setuid(uid: uid_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700227 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
228 link_name = "sleep$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700229 pub fn sleep(secs: c_uint) -> c_uint;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700230 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
Alex Crichton5d6cf052015-09-11 14:52:34 -0700231 link_name = "nanosleep$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700232 pub fn nanosleep(rqtp: *const timespec,
233 rmtp: *mut timespec) -> c_int;
234 pub fn tcgetpgrp(fd: c_int) -> pid_t;
235 pub fn ttyname(fd: c_int) -> *mut c_char;
236 pub fn unlink(c: *const c_char) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700237 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
238 link_name = "wait$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700239 pub fn wait(status: *mut c_int) -> pid_t;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700240 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
241 link_name = "waitpid$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700242 pub fn waitpid(pid: pid_t, status: *mut c_int, options: c_int)
243 -> pid_t;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700244 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
245 link_name = "write$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700246 pub fn write(fd: c_int, buf: *const ::c_void, count: size_t)
247 -> ssize_t;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700248 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
249 link_name = "pread$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700250 pub fn pread(fd: c_int, buf: *mut ::c_void, count: size_t,
251 offset: off_t) -> ssize_t;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700252 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
253 link_name = "pwrite$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700254 pub fn pwrite(fd: c_int, buf: *const ::c_void, count: size_t,
255 offset: off_t) -> ssize_t;
256 pub fn utime(file: *const c_char, buf: *const utimbuf) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700257
258 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
259 link_name = "kill$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700260 pub fn kill(pid: pid_t, sig: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700261
Alex Crichton50a42e22015-09-15 14:27:15 -0700262 pub fn mlock(addr: *const ::c_void, len: size_t) -> c_int;
263 pub fn munlock(addr: *const ::c_void, len: size_t) -> c_int;
264 pub fn mlockall(flags: c_int) -> c_int;
265 pub fn munlockall() -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700266
267 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
Alex Crichton5d6cf052015-09-11 14:52:34 -0700268 link_name = "mmap$UNIX2003")]
269 pub fn mmap(addr: *mut ::c_void,
Alex Crichton50a42e22015-09-15 14:27:15 -0700270 len: size_t,
271 prot: c_int,
272 flags: c_int,
273 fd: c_int,
274 offset: off_t)
Alex Crichton5d6cf052015-09-11 14:52:34 -0700275 -> *mut ::c_void;
276 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
277 link_name = "munmap$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700278 pub fn munmap(addr: *mut ::c_void, len: size_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700279
Alex Crichton50a42e22015-09-15 14:27:15 -0700280 pub fn if_nametoindex(ifname: *const c_char) -> c_uint;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700281
282 #[cfg_attr(target_os = "macos", link_name = "lstat$INODE64")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700283 pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700284
Alex Crichton5d6cf052015-09-11 14:52:34 -0700285 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
286 link_name = "fsync$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700287 pub fn fsync(fd: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700288
Alex Crichton5d6cf052015-09-11 14:52:34 -0700289 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
290 link_name = "setenv$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700291 pub fn setenv(name: *const c_char, val: *const c_char,
292 overwrite: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700293 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
294 link_name = "unsetenv$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700295 pub fn unsetenv(name: *const c_char) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700296
Alex Crichton50a42e22015-09-15 14:27:15 -0700297 pub fn symlink(path1: *const c_char,
298 path2: *const c_char) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700299
Alex Crichton50a42e22015-09-15 14:27:15 -0700300 pub fn ftruncate(fd: c_int, length: off_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700301
Alex Crichton1ff96102015-09-17 15:09:02 -0700302 #[cfg_attr(target_os = "android", link_name = "bsd_signal")]
303 pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700304
Alex Crichtonde9736d2015-09-17 15:47:44 -0700305 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
306 link_name = "getrlimit$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700307 pub fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700308 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
309 link_name = "setrlimit$UNIX2003")]
Alex Crichton50a42e22015-09-15 14:27:15 -0700310 pub fn setrlimit(resource: c_int, rlim: *const rlimit) -> c_int;
311 pub fn getrusage(resource: c_int, usage: *mut rusage) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700312
Alex Crichton50a42e22015-09-15 14:27:15 -0700313 pub fn getdtablesize() -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700314 #[cfg_attr(target_os = "macos", link_name = "realpath$DARWIN_EXTSN")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700315 pub fn realpath(pathname: *const ::c_char, resolved: *mut ::c_char)
316 -> *mut ::c_char;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700317
Alex Crichton50a42e22015-09-15 14:27:15 -0700318 pub fn flock(fd: c_int, operation: c_int) -> c_int;
Alex Crichton50a42e22015-09-15 14:27:15 -0700319
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700320 pub fn gettimeofday(tp: *mut ::timeval,
321 tz: *mut ::c_void) -> ::c_int;
322
323 pub fn pthread_self() -> ::pthread_t;
324 pub fn pthread_create(native: *mut ::pthread_t,
325 attr: *const ::pthread_attr_t,
326 f: extern fn(*mut ::c_void) -> *mut ::c_void,
327 value: *mut ::c_void) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700328 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
329 link_name = "pthread_join$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700330 pub fn pthread_join(native: ::pthread_t,
331 value: *mut *mut ::c_void) -> ::c_int;
332 pub fn pthread_attr_init(attr: *mut ::pthread_attr_t) -> ::c_int;
333 pub fn pthread_attr_destroy(attr: *mut ::pthread_attr_t) -> ::c_int;
334 pub fn pthread_attr_setstacksize(attr: *mut ::pthread_attr_t,
335 stack_size: ::size_t) -> ::c_int;
336 pub fn pthread_attr_setdetachstate(attr: *mut ::pthread_attr_t,
337 state: ::c_int) -> ::c_int;
338 pub fn pthread_detach(thread: ::pthread_t) -> ::c_int;
339 pub fn sched_yield() -> ::c_int;
340 pub fn pthread_key_create(key: *mut pthread_key_t,
341 dtor: Option<unsafe extern fn(*mut ::c_void)>)
342 -> c_int;
343 pub fn pthread_key_delete(key: pthread_key_t) -> c_int;
344 pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void;
345 pub fn pthread_setspecific(key: pthread_key_t, value: *const ::c_void)
346 -> c_int;
347 pub fn pthread_mutex_init(lock: *mut pthread_mutex_t,
348 attr: *const pthread_mutexattr_t) -> ::c_int;
349 pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> ::c_int;
350 pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> ::c_int;
351 pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> ::c_int;
352 pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> ::c_int;
353
354 pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700355 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
356 link_name = "pthread_mutexattr_destroy$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700357 pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> ::c_int;
358 pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t,
359 _type: ::c_int) -> ::c_int;
360
Alex Crichtonde9736d2015-09-17 15:47:44 -0700361 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
362 link_name = "pthread_cond_wait$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700363 pub fn pthread_cond_wait(cond: *mut pthread_cond_t,
364 lock: *mut pthread_mutex_t) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700365 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
366 link_name = "pthread_cond_timedwait$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700367 pub fn pthread_cond_timedwait(cond: *mut pthread_cond_t,
368 lock: *mut pthread_mutex_t,
369 abstime: *const ::timespec) -> ::c_int;
370 pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> ::c_int;
371 pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> ::c_int;
372 pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700373 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
374 link_name = "pthread_rwlock_destroy$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700375 pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700376 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
377 link_name = "pthread_rwlock_rdlock$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700378 pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700379 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
380 link_name = "pthread_rwlock_tryrdlock$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700381 pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700382 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
383 link_name = "pthread_rwlock_wrlock$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700384 pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700385 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
386 link_name = "pthread_rwlock_trywrlock$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700387 pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700388 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
389 link_name = "pthread_rwlock_unlock$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700390 pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700391 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
392 link_name = "pthread_sigmask$UNIX2003")]
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700393 pub fn pthread_sigmask(how: ::c_int, set: *const sigset_t,
394 oldset: *mut sigset_t) -> ::c_int;
395
396 // #[cfg_attr(target_os = "linux", link_name = "__xpg_strerror_r")]
397 pub fn strerror_r(errnum: c_int, buf: *mut c_char,
398 buflen: size_t) -> c_int;
399
400 pub fn getsockopt(sockfd: ::c_int,
401 level: ::c_int,
402 optname: ::c_int,
403 optval: *mut ::c_void,
404 optlen: *mut ::socklen_t) -> ::c_int;
405 pub fn raise(signum: ::c_int) -> ::c_int;
406 pub fn sigaction(signum: ::c_int,
407 act: *const sigaction,
408 oldact: *mut sigaction) -> ::c_int;
Alex Crichtonde9736d2015-09-17 15:47:44 -0700409 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
410 link_name = "sigaltstack$UNIX2003")]
411 pub fn sigaltstack(ss: *const stack_t,
412 oss: *mut stack_t) -> ::c_int;
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700413
414 pub fn utimes(filename: *const ::c_char,
415 times: *const ::timeval) -> ::c_int;
416 pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
Alex Crichton1ff96102015-09-17 15:09:02 -0700417 pub fn dlopen(filename: *const ::c_char,
418 flag: ::c_int) -> *mut ::c_void;
419 pub fn dlerror() -> *mut ::c_char;
420 pub fn dlsym(handle: *mut ::c_void,
421 symbol: *const ::c_char) -> *mut ::c_void;
422 pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
423}
424
425// TODO: get rid of this #[cfg(not(...))]
426#[cfg(not(target_os = "android"))]
427extern {
428 pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> c_int;
429 pub fn freeifaddrs(ifa: *mut ifaddrs);
Alex Crichtonde9736d2015-09-17 15:47:44 -0700430 #[cfg_attr(target_os = "macos", link_name = "glob$INODE64")]
Alex Crichton1ff96102015-09-17 15:09:02 -0700431 pub fn glob(pattern: *const c_char,
432 flags: c_int,
433 errfunc: ::dox::Option<extern "C" fn(epath: *const c_char,
434 errno: c_int) -> c_int>,
435 pglob: *mut glob_t) -> c_int;
436 pub fn globfree(pglob: *mut glob_t);
437
438 pub fn posix_madvise(addr: *mut ::c_void, len: size_t, advice: c_int)
439 -> c_int;
440
441 pub fn shm_unlink(name: *const c_char) -> c_int;
442
443 #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
444 link_name = "seekdir$INODE64")]
445 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
446 link_name = "seekdir$INODE64$UNIX2003")]
447 pub fn seekdir(dirp: *mut ::DIR, loc: c_long);
448
449 #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
450 link_name = "telldir$INODE64")]
451 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
452 link_name = "telldir$INODE64$UNIX2003")]
453 pub fn telldir(dirp: *mut ::DIR) -> c_long;
454
455 pub fn getsid(pid: pid_t) -> pid_t;
456 pub fn madvise(addr: *mut ::c_void, len: size_t, advice: c_int)
457 -> c_int;
458 pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
459 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
460 link_name = "putenv$UNIX2003")]
461 pub fn putenv(string: *mut c_char) -> c_int;
462 pub fn readlink(path: *const c_char,
463 buf: *mut c_char,
464 bufsz: size_t)
465 -> ssize_t;
466
467 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
468 link_name = "msync$UNIX2003")]
469 pub fn msync(addr: *mut ::c_void, len: size_t, flags: c_int) -> c_int;
470 pub fn sysconf(name: c_int) -> c_long;
471 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
472 link_name = "usleep$UNIX2003")]
473 pub fn usleep(secs: c_uint) -> c_int;
474 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
475 link_name = "recvfrom$UNIX2003")]
476 pub fn recvfrom(socket: c_int, buf: *mut ::c_void, len: size_t,
477 flags: c_int, addr: *mut sockaddr,
478 addrlen: *mut socklen_t) -> ssize_t;
479 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
480 link_name = "send$UNIX2003")]
481 pub fn send(socket: c_int, buf: *const ::c_void, len: size_t,
482 flags: c_int) -> ssize_t;
483 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
484 link_name = "recv$UNIX2003")]
485 pub fn recv(socket: c_int, buf: *mut ::c_void, len: size_t,
486 flags: c_int) -> ssize_t;
487 pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int;
488
489 pub fn getpwuid_r(uid: ::uid_t,
490 pwd: *mut passwd,
491 buf: *mut ::c_char,
492 buflen: ::size_t,
493 result: *mut *mut passwd) -> ::c_int;
494 pub fn backtrace(buf: *mut *mut ::c_void,
495 sz: ::c_int) -> ::c_int;
496 pub fn posix_memalign(memptr: *mut *mut ::c_void,
497 align: ::size_t,
498 size: ::size_t) -> ::c_int;
499 pub fn sigemptyset(set: *mut sigset_t) -> ::c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700500}
Alex Crichtond3d77922015-09-11 17:03:39 -0700501
502cfg_if! {
Alex Crichton50a42e22015-09-15 14:27:15 -0700503 if #[cfg(any(target_os = "linux", target_os = "android"))] {
504 mod notbsd;
505 pub use self::notbsd::*;
506 } else if #[cfg(any(target_os = "macos",
507 target_os = "freebsd",
508 target_os = "dragonfly",
509 target_os = "openbsd",
510 target_os = "netbsd",
511 target_os = "bitrig"))] {
512 mod bsd;
513 pub use self::bsd::*;
Alex Crichtond3d77922015-09-11 17:03:39 -0700514 } else {
Alex Crichton50a42e22015-09-15 14:27:15 -0700515 // ...
Alex Crichtond3d77922015-09-11 17:03:39 -0700516 }
517}