]> git.proxmox.com Git - rustc.git/blob - src/liblibc/src/unix/mod.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / liblibc / src / unix / mod.rs
1 //! 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
6 use dox::Option;
7
8 pub type pid_t = i32;
9 pub type uid_t = u32;
10 pub type gid_t = u32;
11 pub type in_addr_t = u32;
12 pub type in_port_t = u16;
13 pub type sighandler_t = ::size_t;
14 pub type cc_t = ::c_uchar;
15
16 pub enum DIR {}
17
18 s! {
19 pub struct utimbuf {
20 pub actime: time_t,
21 pub modtime: time_t,
22 }
23
24 pub struct timeval {
25 pub tv_sec: time_t,
26 pub tv_usec: suseconds_t,
27 }
28
29 pub struct timespec {
30 pub tv_sec: time_t,
31 pub tv_nsec: c_long,
32 }
33
34 pub struct rlimit {
35 pub rlim_cur: rlim_t,
36 pub rlim_max: rlim_t,
37 }
38
39 pub struct rusage {
40 pub ru_utime: timeval,
41 pub ru_stime: timeval,
42 pub ru_maxrss: c_long,
43 pub ru_ixrss: c_long,
44 pub ru_idrss: c_long,
45 pub ru_isrss: c_long,
46 pub ru_minflt: c_long,
47 pub ru_majflt: c_long,
48 pub ru_nswap: c_long,
49 pub ru_inblock: c_long,
50 pub ru_oublock: c_long,
51 pub ru_msgsnd: c_long,
52 pub ru_msgrcv: c_long,
53 pub ru_nsignals: c_long,
54 pub ru_nvcsw: c_long,
55 pub ru_nivcsw: c_long,
56
57 #[cfg(target_env = "musl")]
58 __reserved: [c_long; 16],
59 }
60
61 #[cfg_attr(target_os = "netbsd", repr(packed))]
62 pub struct in_addr {
63 pub s_addr: in_addr_t,
64 }
65
66 pub struct in6_addr {
67 pub s6_addr: [u8; 16],
68 __align: [u32; 0],
69 }
70
71 pub struct ip_mreq {
72 pub imr_multiaddr: in_addr,
73 pub imr_interface: in_addr,
74 }
75
76 pub struct ipv6_mreq {
77 pub ipv6mr_multiaddr: in6_addr,
78 #[cfg(target_os = "android")]
79 pub ipv6mr_interface: ::c_int,
80 #[cfg(not(target_os = "android"))]
81 pub ipv6mr_interface: ::c_uint,
82 }
83
84 pub struct hostent {
85 pub h_name: *mut ::c_char,
86 pub h_aliases: *mut *mut ::c_char,
87 pub h_addrtype: ::c_int,
88 pub h_length: ::c_int,
89 pub h_addr_list: *mut *mut ::c_char,
90 }
91
92 pub struct iovec {
93 pub iov_base: *mut ::c_void,
94 pub iov_len: ::size_t,
95 }
96
97 pub struct pollfd {
98 pub fd: ::c_int,
99 pub events: ::c_short,
100 pub revents: ::c_short,
101 }
102
103 pub struct winsize {
104 pub ws_row: ::c_ushort,
105 pub ws_col: ::c_ushort,
106 pub ws_xpixel: ::c_ushort,
107 pub ws_ypixel: ::c_ushort,
108 }
109 }
110
111 pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
112 pub const SIG_IGN: sighandler_t = 1 as sighandler_t;
113 pub const SIG_ERR: sighandler_t = !0 as sighandler_t;
114
115 pub const DT_FIFO: u8 = 1;
116 pub const DT_CHR: u8 = 2;
117 pub const DT_DIR: u8 = 4;
118 pub const DT_BLK: u8 = 6;
119 pub const DT_REG: u8 = 8;
120 pub const DT_LNK: u8 = 10;
121 pub const DT_SOCK: u8 = 12;
122
123 pub const FD_CLOEXEC: ::c_int = 0x1;
124
125 pub const USRQUOTA: ::c_int = 0;
126 pub const GRPQUOTA: ::c_int = 1;
127
128 pub const SIGIOT: ::c_int = 6;
129
130 pub const S_ISUID: ::c_int = 0x800;
131 pub const S_ISGID: ::c_int = 0x400;
132 pub const S_ISVTX: ::c_int = 0x200;
133
134 pub const POLLIN: ::c_short = 0x1;
135 pub const POLLPRI: ::c_short = 0x2;
136 pub const POLLOUT: ::c_short = 0x4;
137 pub const POLLERR: ::c_short = 0x8;
138 pub const POLLHUP: ::c_short = 0x10;
139 pub const POLLNVAL: ::c_short = 0x20;
140
141 pub const IF_NAMESIZE: ::size_t = 16;
142
143 pub const RTLD_LAZY: ::c_int = 0x1;
144
145 cfg_if! {
146 if #[cfg(dox)] {
147 // on dox builds don't pull in anything
148 } else if #[cfg(all(not(stdbuild), feature = "use_std"))] {
149 // cargo build, don't pull in anything extra as the libstd dep
150 // already pulls in all libs.
151 } else if #[cfg(all(target_env = "musl", not(any(target_arch = "mips",
152 target_arch = "arm"))))] {
153 #[link(name = "c", kind = "static")]
154 extern {}
155 } else if #[cfg(target_os = "emscripten")] {
156 #[link(name = "c")]
157 extern {}
158 } else if #[cfg(all(target_vendor = "rumprun", target_os = "netbsd"))] {
159 // Since we don't use -nodefaultlibs on Rumprun, libc is always pulled
160 // in automatically by the linker. We avoid passing it explicitly, as it
161 // causes some versions of binutils to crash with an assertion failure.
162 #[link(name = "m")]
163 extern {}
164 } else if #[cfg(any(target_os = "macos",
165 target_os = "ios",
166 target_os = "android",
167 target_os = "openbsd",
168 target_os = "bitrig"))] {
169 #[link(name = "c")]
170 #[link(name = "m")]
171 extern {}
172 } else {
173 #[link(name = "c")]
174 #[link(name = "m")]
175 #[link(name = "rt")]
176 extern {}
177 }
178 }
179
180 extern {
181 #[cfg_attr(target_os = "netbsd", link_name = "__socket30")]
182 pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int;
183 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
184 link_name = "connect$UNIX2003")]
185 pub fn connect(socket: ::c_int, address: *const sockaddr,
186 len: socklen_t) -> ::c_int;
187 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
188 link_name = "bind$UNIX2003")]
189 pub fn bind(socket: ::c_int, address: *const sockaddr,
190 address_len: socklen_t) -> ::c_int;
191 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
192 link_name = "listen$UNIX2003")]
193 pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
194 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
195 link_name = "accept$UNIX2003")]
196 pub fn accept(socket: ::c_int, address: *mut sockaddr,
197 address_len: *mut socklen_t) -> ::c_int;
198 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
199 link_name = "getpeername$UNIX2003")]
200 pub fn getpeername(socket: ::c_int, address: *mut sockaddr,
201 address_len: *mut socklen_t) -> ::c_int;
202 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
203 link_name = "getsockname$UNIX2003")]
204 pub fn getsockname(socket: ::c_int, address: *mut sockaddr,
205 address_len: *mut socklen_t) -> ::c_int;
206 pub fn setsockopt(socket: ::c_int, level: ::c_int, name: ::c_int,
207 value: *const ::c_void,
208 option_len: socklen_t) -> ::c_int;
209 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
210 link_name = "socketpair$UNIX2003")]
211 pub fn socketpair(domain: ::c_int, type_: ::c_int, protocol: ::c_int,
212 socket_vector: *mut ::c_int) -> ::c_int;
213 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
214 link_name = "sendto$UNIX2003")]
215 pub fn sendto(socket: ::c_int, buf: *const ::c_void, len: ::size_t,
216 flags: ::c_int, addr: *const sockaddr,
217 addrlen: socklen_t) -> ::ssize_t;
218 pub fn shutdown(socket: ::c_int, how: ::c_int) -> ::c_int;
219
220 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
221 link_name = "chmod$UNIX2003")]
222 pub fn chmod(path: *const c_char, mode: mode_t) -> ::c_int;
223 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
224 link_name = "fchmod$UNIX2003")]
225 pub fn fchmod(fd: ::c_int, mode: mode_t) -> ::c_int;
226
227 #[cfg_attr(target_os = "macos", link_name = "fstat$INODE64")]
228 #[cfg_attr(target_os = "netbsd", link_name = "__fstat50")]
229 pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int;
230
231 pub fn mkdir(path: *const c_char, mode: mode_t) -> ::c_int;
232
233 #[cfg_attr(target_os = "macos", link_name = "stat$INODE64")]
234 #[cfg_attr(target_os = "netbsd", link_name = "__stat50")]
235 pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int;
236
237 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
238 link_name = "popen$UNIX2003")]
239 pub fn popen(command: *const c_char,
240 mode: *const c_char) -> *mut ::FILE;
241 pub fn pclose(stream: *mut ::FILE) -> ::c_int;
242 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
243 link_name = "fdopen$UNIX2003")]
244 pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE;
245 pub fn fileno(stream: *mut ::FILE) -> ::c_int;
246
247 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
248 link_name = "open$UNIX2003")]
249 pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int;
250 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
251 link_name = "creat$UNIX2003")]
252 pub fn creat(path: *const c_char, mode: mode_t) -> ::c_int;
253 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
254 link_name = "fcntl$UNIX2003")]
255 pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int;
256
257 #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
258 link_name = "opendir$INODE64")]
259 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
260 link_name = "opendir$INODE64$UNIX2003")]
261 #[cfg_attr(target_os = "netbsd", link_name = "__opendir30")]
262 pub fn opendir(dirname: *const c_char) -> *mut ::DIR;
263 #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")]
264 #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")]
265 pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent,
266 result: *mut *mut ::dirent) -> ::c_int;
267 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
268 link_name = "closedir$UNIX2003")]
269 pub fn closedir(dirp: *mut ::DIR) -> ::c_int;
270 #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
271 link_name = "rewinddir$INODE64")]
272 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
273 link_name = "rewinddir$INODE64$UNIX2003")]
274 pub fn rewinddir(dirp: *mut ::DIR);
275
276 pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int;
277 pub fn alarm(seconds: ::c_uint) -> ::c_uint;
278 pub fn chdir(dir: *const c_char) -> ::c_int;
279 pub fn chown(path: *const c_char, uid: uid_t,
280 gid: gid_t) -> ::c_int;
281 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
282 link_name = "close$UNIX2003")]
283 pub fn close(fd: ::c_int) -> ::c_int;
284 pub fn dup(fd: ::c_int) -> ::c_int;
285 pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int;
286 pub fn execv(prog: *const c_char,
287 argv: *const *const c_char) -> ::c_int;
288 pub fn execve(prog: *const c_char, argv: *const *const c_char,
289 envp: *const *const c_char)
290 -> ::c_int;
291 pub fn execvp(c: *const c_char,
292 argv: *const *const c_char) -> ::c_int;
293 pub fn fork() -> pid_t;
294 pub fn fpathconf(filedes: ::c_int, name: ::c_int) -> c_long;
295 pub fn getcwd(buf: *mut c_char, size: ::size_t) -> *mut c_char;
296 pub fn getegid() -> gid_t;
297 pub fn geteuid() -> uid_t;
298 pub fn getgid() -> gid_t;
299 pub fn getgroups(ngroups_max: ::c_int, groups: *mut gid_t)
300 -> ::c_int;
301 pub fn getlogin() -> *mut c_char;
302 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
303 link_name = "getopt$UNIX2003")]
304 pub fn getopt(argc: ::c_int, argv: *const *mut c_char,
305 optstr: *const c_char) -> ::c_int;
306 pub fn getpgrp() -> pid_t;
307 pub fn getpid() -> pid_t;
308 pub fn getppid() -> pid_t;
309 pub fn getuid() -> uid_t;
310 pub fn isatty(fd: ::c_int) -> ::c_int;
311 pub fn link(src: *const c_char, dst: *const c_char) -> ::c_int;
312 pub fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t;
313 pub fn pathconf(path: *const c_char, name: ::c_int) -> c_long;
314 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
315 link_name = "pause$UNIX2003")]
316 pub fn pause() -> ::c_int;
317 pub fn pipe(fds: *mut ::c_int) -> ::c_int;
318 pub fn posix_memalign(memptr: *mut *mut ::c_void,
319 align: ::size_t,
320 size: ::size_t) -> ::c_int;
321 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
322 link_name = "read$UNIX2003")]
323 pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t)
324 -> ::ssize_t;
325 pub fn rmdir(path: *const c_char) -> ::c_int;
326 pub fn setgid(gid: gid_t) -> ::c_int;
327 pub fn setpgid(pid: pid_t, pgid: pid_t) -> ::c_int;
328 pub fn setsid() -> pid_t;
329 pub fn setuid(uid: uid_t) -> ::c_int;
330 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
331 link_name = "sleep$UNIX2003")]
332 pub fn sleep(secs: ::c_uint) -> ::c_uint;
333 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
334 link_name = "nanosleep$UNIX2003")]
335 #[cfg_attr(target_os = "netbsd", link_name = "__nanosleep50")]
336 pub fn nanosleep(rqtp: *const timespec,
337 rmtp: *mut timespec) -> ::c_int;
338 pub fn tcgetpgrp(fd: ::c_int) -> pid_t;
339 pub fn ttyname(fd: ::c_int) -> *mut c_char;
340 pub fn unlink(c: *const c_char) -> ::c_int;
341 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
342 link_name = "wait$UNIX2003")]
343 pub fn wait(status: *mut ::c_int) -> pid_t;
344 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
345 link_name = "waitpid$UNIX2003")]
346 pub fn waitpid(pid: pid_t, status: *mut ::c_int, options: ::c_int)
347 -> pid_t;
348 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
349 link_name = "write$UNIX2003")]
350 pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t)
351 -> ::ssize_t;
352 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
353 link_name = "pread$UNIX2003")]
354 pub fn pread(fd: ::c_int, buf: *mut ::c_void, count: ::size_t,
355 offset: off_t) -> ::ssize_t;
356 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
357 link_name = "pwrite$UNIX2003")]
358 pub fn pwrite(fd: ::c_int, buf: *const ::c_void, count: ::size_t,
359 offset: off_t) -> ::ssize_t;
360 pub fn umask(mask: mode_t) -> mode_t;
361
362 #[cfg_attr(target_os = "netbsd", link_name = "__utime50")]
363 pub fn utime(file: *const c_char, buf: *const utimbuf) -> ::c_int;
364
365 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
366 link_name = "kill$UNIX2003")]
367 pub fn kill(pid: pid_t, sig: ::c_int) -> ::c_int;
368
369 pub fn mlock(addr: *const ::c_void, len: ::size_t) -> ::c_int;
370 pub fn munlock(addr: *const ::c_void, len: ::size_t) -> ::c_int;
371 pub fn mlockall(flags: ::c_int) -> ::c_int;
372 pub fn munlockall() -> ::c_int;
373
374 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
375 link_name = "mmap$UNIX2003")]
376 pub fn mmap(addr: *mut ::c_void,
377 len: ::size_t,
378 prot: ::c_int,
379 flags: ::c_int,
380 fd: ::c_int,
381 offset: off_t)
382 -> *mut ::c_void;
383 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
384 link_name = "munmap$UNIX2003")]
385 pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int;
386
387 pub fn if_nametoindex(ifname: *const c_char) -> ::c_uint;
388 pub fn if_indextoname(ifindex: ::c_uint,
389 ifname: *mut ::c_char) -> *mut ::c_char;
390
391 #[cfg_attr(target_os = "macos", link_name = "lstat$INODE64")]
392 #[cfg_attr(target_os = "netbsd", link_name = "__lstat50")]
393 pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int;
394
395 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
396 link_name = "fsync$UNIX2003")]
397 pub fn fsync(fd: ::c_int) -> ::c_int;
398
399 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
400 link_name = "setenv$UNIX2003")]
401 pub fn setenv(name: *const c_char, val: *const c_char,
402 overwrite: ::c_int) -> ::c_int;
403 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
404 link_name = "unsetenv$UNIX2003")]
405 #[cfg_attr(target_os = "netbsd", link_name = "__unsetenv13")]
406 pub fn unsetenv(name: *const c_char) -> ::c_int;
407
408 pub fn symlink(path1: *const c_char,
409 path2: *const c_char) -> ::c_int;
410
411 pub fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int;
412
413 #[cfg_attr(target_os = "android", link_name = "bsd_signal")]
414 pub fn signal(signum: ::c_int, handler: sighandler_t) -> sighandler_t;
415
416 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
417 link_name = "getrlimit$UNIX2003")]
418 pub fn getrlimit(resource: ::c_int, rlim: *mut rlimit) -> ::c_int;
419 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
420 link_name = "setrlimit$UNIX2003")]
421 pub fn setrlimit(resource: ::c_int, rlim: *const rlimit) -> ::c_int;
422 #[cfg_attr(target_os = "netbsd", link_name = "__getrusage50")]
423 pub fn getrusage(resource: ::c_int, usage: *mut rusage) -> ::c_int;
424
425 pub fn getdtablesize() -> ::c_int;
426 #[cfg_attr(any(target_os = "macos", target_os = "ios"),
427 link_name = "realpath$DARWIN_EXTSN")]
428 pub fn realpath(pathname: *const ::c_char, resolved: *mut ::c_char)
429 -> *mut ::c_char;
430
431 pub fn flock(fd: ::c_int, operation: ::c_int) -> ::c_int;
432
433 #[cfg_attr(target_os = "netbsd", link_name = "__gettimeofday50")]
434 pub fn gettimeofday(tp: *mut ::timeval,
435 tz: *mut ::c_void) -> ::c_int;
436
437 pub fn pthread_self() -> ::pthread_t;
438 pub fn pthread_create(native: *mut ::pthread_t,
439 attr: *const ::pthread_attr_t,
440 f: extern fn(*mut ::c_void) -> *mut ::c_void,
441 value: *mut ::c_void) -> ::c_int;
442 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
443 link_name = "pthread_join$UNIX2003")]
444 pub fn pthread_join(native: ::pthread_t,
445 value: *mut *mut ::c_void) -> ::c_int;
446 pub fn pthread_attr_init(attr: *mut ::pthread_attr_t) -> ::c_int;
447 pub fn pthread_attr_destroy(attr: *mut ::pthread_attr_t) -> ::c_int;
448 pub fn pthread_attr_setstacksize(attr: *mut ::pthread_attr_t,
449 stack_size: ::size_t) -> ::c_int;
450 pub fn pthread_attr_setdetachstate(attr: *mut ::pthread_attr_t,
451 state: ::c_int) -> ::c_int;
452 pub fn pthread_detach(thread: ::pthread_t) -> ::c_int;
453 #[cfg_attr(target_os = "netbsd", link_name = "__libc_thr_yield")]
454 pub fn sched_yield() -> ::c_int;
455 pub fn pthread_key_create(key: *mut pthread_key_t,
456 dtor: Option<unsafe extern fn(*mut ::c_void)>)
457 -> ::c_int;
458 pub fn pthread_key_delete(key: pthread_key_t) -> ::c_int;
459 pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void;
460 pub fn pthread_setspecific(key: pthread_key_t, value: *const ::c_void)
461 -> ::c_int;
462 pub fn pthread_mutex_init(lock: *mut pthread_mutex_t,
463 attr: *const pthread_mutexattr_t) -> ::c_int;
464 pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> ::c_int;
465 pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> ::c_int;
466 pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> ::c_int;
467 pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> ::c_int;
468
469 pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> ::c_int;
470 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
471 link_name = "pthread_mutexattr_destroy$UNIX2003")]
472 pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> ::c_int;
473 pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t,
474 _type: ::c_int) -> ::c_int;
475
476 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
477 link_name = "pthread_cond_wait$UNIX2003")]
478 pub fn pthread_cond_wait(cond: *mut pthread_cond_t,
479 lock: *mut pthread_mutex_t) -> ::c_int;
480 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
481 link_name = "pthread_cond_timedwait$UNIX2003")]
482 pub fn pthread_cond_timedwait(cond: *mut pthread_cond_t,
483 lock: *mut pthread_mutex_t,
484 abstime: *const ::timespec) -> ::c_int;
485 pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> ::c_int;
486 pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> ::c_int;
487 pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int;
488 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
489 link_name = "pthread_rwlock_destroy$UNIX2003")]
490 pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int;
491 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
492 link_name = "pthread_rwlock_rdlock$UNIX2003")]
493 pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> ::c_int;
494 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
495 link_name = "pthread_rwlock_tryrdlock$UNIX2003")]
496 pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> ::c_int;
497 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
498 link_name = "pthread_rwlock_wrlock$UNIX2003")]
499 pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> ::c_int;
500 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
501 link_name = "pthread_rwlock_trywrlock$UNIX2003")]
502 pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> ::c_int;
503 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
504 link_name = "pthread_rwlock_unlock$UNIX2003")]
505 pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> ::c_int;
506 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
507 link_name = "pthread_sigmask$UNIX2003")]
508 pub fn pthread_sigmask(how: ::c_int, set: *const sigset_t,
509 oldset: *mut sigset_t) -> ::c_int;
510 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int;
511 #[cfg_attr(all(target_os = "linux", not(target_env = "musl")),
512 link_name = "__xpg_strerror_r")]
513 pub fn strerror_r(errnum: ::c_int, buf: *mut c_char,
514 buflen: ::size_t) -> ::c_int;
515
516 pub fn getsockopt(sockfd: ::c_int,
517 level: ::c_int,
518 optname: ::c_int,
519 optval: *mut ::c_void,
520 optlen: *mut ::socklen_t) -> ::c_int;
521 pub fn raise(signum: ::c_int) -> ::c_int;
522 #[cfg_attr(target_os = "netbsd", link_name = "__sigaction14")]
523 pub fn sigaction(signum: ::c_int,
524 act: *const sigaction,
525 oldact: *mut sigaction) -> ::c_int;
526 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
527 link_name = "sigaltstack$UNIX2003")]
528 #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")]
529 pub fn sigaltstack(ss: *const stack_t,
530 oss: *mut stack_t) -> ::c_int;
531 #[cfg_attr(all(target_os = "macos", target_arch ="x86"),
532 link_name = "sigwait$UNIX2003")]
533 pub fn sigwait(set: *const sigset_t,
534 sig: *mut ::c_int) -> ::c_int;
535
536 #[cfg_attr(target_os = "netbsd", link_name = "__utimes50")]
537 pub fn utimes(filename: *const ::c_char,
538 times: *const ::timeval) -> ::c_int;
539 pub fn dlopen(filename: *const ::c_char,
540 flag: ::c_int) -> *mut ::c_void;
541 pub fn dlerror() -> *mut ::c_char;
542 pub fn dlsym(handle: *mut ::c_void,
543 symbol: *const ::c_char) -> *mut ::c_void;
544 pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
545 pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int;
546
547 pub fn getaddrinfo(node: *const c_char,
548 service: *const c_char,
549 hints: *const addrinfo,
550 res: *mut *mut addrinfo) -> ::c_int;
551 pub fn freeaddrinfo(res: *mut addrinfo);
552 pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
553
554 #[cfg_attr(target_os = "netbsd", link_name = "__gmtime_r50")]
555 pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
556 #[cfg_attr(target_os = "netbsd", link_name = "__localtime_r50")]
557 pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
558 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
559 link_name = "mktime$UNIX2003")]
560 #[cfg_attr(target_os = "netbsd", link_name = "__mktime50")]
561 pub fn mktime(tm: *mut tm) -> time_t;
562
563 #[cfg_attr(target_os = "netbsd", link_name = "__mknod50")]
564 pub fn mknod(pathname: *const ::c_char, mode: ::mode_t,
565 dev: ::dev_t) -> ::c_int;
566 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
567 link_name = "writev$UNIX2003")]
568 pub fn writev(fd: ::c_int,
569 iov: *const ::iovec,
570 iovcnt: ::c_int) -> ::ssize_t;
571 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
572 link_name = "readv$UNIX2003")]
573 pub fn readv(fd: ::c_int,
574 iov: *const ::iovec,
575 iovcnt: ::c_int) -> ::ssize_t;
576 pub fn uname(buf: *mut ::utsname) -> ::c_int;
577 pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
578 pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int;
579 pub fn chroot(name: *const ::c_char) -> ::c_int;
580 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
581 link_name = "usleep$UNIX2003")]
582 pub fn usleep(secs: ::c_uint) -> ::c_int;
583 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
584 link_name = "send$UNIX2003")]
585 pub fn send(socket: ::c_int, buf: *const ::c_void, len: ::size_t,
586 flags: ::c_int) -> ::ssize_t;
587 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
588 link_name = "recv$UNIX2003")]
589 pub fn recv(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
590 flags: ::c_int) -> ::ssize_t;
591 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
592 link_name = "putenv$UNIX2003")]
593 #[cfg_attr(target_os = "netbsd", link_name = "__putenv50")]
594 pub fn putenv(string: *mut c_char) -> ::c_int;
595 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
596 link_name = "sendmsg$UNIX2003")]
597 pub fn sendmsg(fd: ::c_int,
598 msg: *const msghdr,
599 flags: ::c_int) -> ::ssize_t;
600 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
601 link_name = "recvmsg$UNIX2003")]
602 pub fn recvmsg(fd: ::c_int, msg: *mut msghdr, flags: ::c_int) -> ::ssize_t;
603 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
604 link_name = "poll$UNIX2003")]
605 pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int;
606 #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
607 link_name = "select$1050")]
608 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
609 link_name = "select$UNIX2003")]
610 #[cfg_attr(target_os = "netbsd", link_name = "__select50")]
611 pub fn select(nfds: ::c_int,
612 readfs: *mut fd_set,
613 writefds: *mut fd_set,
614 errorfds: *mut fd_set,
615 timeout: *mut timeval) -> ::c_int;
616 #[cfg_attr(target_os = "netbsd", link_name = "__setlocale50")]
617 pub fn setlocale(category: ::c_int,
618 locale: *const ::c_char) -> *mut ::c_char;
619 pub fn localeconv() -> *mut lconv;
620 }
621
622 // TODO: get rid of this cfg(not(...))
623 #[cfg(not(target_os = "android"))] // " if " -- appease style checker
624 extern {
625 pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> ::c_int;
626 pub fn freeifaddrs(ifa: *mut ifaddrs);
627 #[cfg_attr(target_os = "macos", link_name = "glob$INODE64")]
628 #[cfg_attr(target_os = "netbsd", link_name = "__glob30")]
629 pub fn glob(pattern: *const c_char,
630 flags: ::c_int,
631 errfunc: Option<extern fn(epath: *const c_char,
632 errno: ::c_int) -> ::c_int>,
633 pglob: *mut glob_t) -> ::c_int;
634 #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")]
635 pub fn globfree(pglob: *mut glob_t);
636
637 pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
638 -> ::c_int;
639
640 pub fn shm_unlink(name: *const c_char) -> ::c_int;
641
642 #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
643 link_name = "seekdir$INODE64")]
644 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
645 link_name = "seekdir$INODE64$UNIX2003")]
646 pub fn seekdir(dirp: *mut ::DIR, loc: c_long);
647
648 #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
649 link_name = "telldir$INODE64")]
650 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
651 link_name = "telldir$INODE64$UNIX2003")]
652 pub fn telldir(dirp: *mut ::DIR) -> c_long;
653
654 pub fn getsid(pid: pid_t) -> pid_t;
655 pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
656 -> ::c_int;
657 pub fn readlink(path: *const c_char,
658 buf: *mut c_char,
659 bufsz: ::size_t)
660 -> ::ssize_t;
661
662 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
663 link_name = "msync$UNIX2003")]
664 #[cfg_attr(target_os = "netbsd", link_name = "__msync13")]
665 pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
666 pub fn sysconf(name: ::c_int) -> c_long;
667 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
668 link_name = "recvfrom$UNIX2003")]
669 pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
670 flags: ::c_int, addr: *mut sockaddr,
671 addrlen: *mut socklen_t) -> ::ssize_t;
672 pub fn mkfifo(path: *const c_char, mode: mode_t) -> ::c_int;
673
674 #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
675 pub fn sigemptyset(set: *mut sigset_t) -> ::c_int;
676 #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")]
677 pub fn sigaddset(set: *mut sigset_t, signum: ::c_int) -> ::c_int;
678 #[cfg_attr(target_os = "netbsd", link_name = "__sigfillset14")]
679 pub fn sigfillset(set: *mut sigset_t) -> ::c_int;
680 #[cfg_attr(target_os = "netbsd", link_name = "__sigdelset14")]
681 pub fn sigdelset(set: *mut sigset_t, signum: ::c_int) -> ::c_int;
682 #[cfg_attr(target_os = "netbsd", link_name = "__sigismember14")]
683 pub fn sigismember(set: *const sigset_t, signum: ::c_int) -> ::c_int;
684 #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
685 link_name = "pselect$1050")]
686 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
687 link_name = "pselect$UNIX2003")]
688 #[cfg_attr(target_os = "netbsd", link_name = "__pselect50")]
689 pub fn pselect(nfds: ::c_int,
690 readfs: *mut fd_set,
691 writefds: *mut fd_set,
692 errorfds: *mut fd_set,
693 timeout: *const timespec,
694 sigmask: *const sigset_t) -> ::c_int;
695 pub fn fseeko(stream: *mut ::FILE,
696 offset: ::off_t,
697 whence: ::c_int) -> ::c_int;
698 pub fn ftello(stream: *mut ::FILE) -> ::off_t;
699 #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")]
700 pub fn timegm(tm: *mut ::tm) -> time_t;
701 pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int;
702 pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int;
703 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
704 link_name = "tcdrain$UNIX2003")]
705 pub fn tcdrain(fd: ::c_int) -> ::c_int;
706 pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t;
707 pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t;
708 pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
709 pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
710 pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int;
711 pub fn tcsetattr(fd: ::c_int,
712 optional_actions: ::c_int,
713 termios: *const ::termios) -> ::c_int;
714 pub fn tcflow(fd: ::c_int, action: ::c_int) -> ::c_int;
715 pub fn tcflush(fd: ::c_int, action: ::c_int) -> ::c_int;
716 pub fn tcsendbreak(fd: ::c_int, duration: ::c_int) -> ::c_int;
717 pub fn mkstemp(template: *mut ::c_char) -> ::c_int;
718 pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
719 pub fn mkdtemp(template: *mut ::c_char) -> *mut ::c_char;
720 pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
721 }
722
723 cfg_if! {
724 if #[cfg(any(target_os = "linux",
725 target_os = "android",
726 target_os = "emscripten"))] {
727 mod notbsd;
728 pub use self::notbsd::*;
729 } else if #[cfg(any(target_os = "macos",
730 target_os = "ios",
731 target_os = "freebsd",
732 target_os = "dragonfly",
733 target_os = "openbsd",
734 target_os = "netbsd",
735 target_os = "bitrig"))] {
736 mod bsd;
737 pub use self::bsd::*;
738 } else if #[cfg(target_os = "solaris")] {
739 mod solaris;
740 pub use self::solaris::*;
741 } else {
742 // Unknown target_os
743 }
744 }