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