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