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