Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 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 | |
Alex Crichton | 084f9ea | 2015-09-11 15:11:59 -0700 | [diff] [blame] | 6 | s! { |
| 7 | pub struct utimbuf { |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 8 | pub actime: time_t, |
| 9 | pub modtime: time_t, |
| 10 | } |
| 11 | |
| 12 | pub struct timeval { |
| 13 | pub tv_sec: time_t, |
| 14 | pub tv_usec: suseconds_t, |
| 15 | } |
| 16 | |
| 17 | pub struct timespec { |
| 18 | pub tv_sec: time_t, |
| 19 | pub tv_nsec: c_long, |
| 20 | } |
| 21 | |
| 22 | pub struct rlimit { |
| 23 | pub rlim_cur: rlim_t, |
| 24 | pub rlim_max: rlim_t, |
| 25 | } |
| 26 | |
| 27 | pub struct rusage { |
| 28 | pub ru_utime: timeval, |
| 29 | pub ru_stime: timeval, |
| 30 | pub ru_maxrss: c_long, |
| 31 | pub ru_ixrss: c_long, |
| 32 | pub ru_idrss: c_long, |
| 33 | pub ru_isrss: c_long, |
| 34 | pub ru_minflt: c_long, |
| 35 | pub ru_majflt: c_long, |
| 36 | pub ru_nswap: c_long, |
| 37 | pub ru_inblock: c_long, |
| 38 | pub ru_oublock: c_long, |
| 39 | pub ru_msgsnd: c_long, |
| 40 | pub ru_msgrcv: c_long, |
| 41 | pub ru_nsignals: c_long, |
| 42 | pub ru_nvcsw: c_long, |
| 43 | pub ru_nivcsw: c_long |
| 44 | } |
| 45 | |
| 46 | pub struct in_addr { |
| 47 | pub s_addr: in_addr_t, |
| 48 | } |
| 49 | |
| 50 | pub struct in6_addr { |
Alex Crichton | 316c367 | 2015-09-16 14:32:59 -0700 | [diff] [blame] | 51 | pub s6_addr: [u8; 16], |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 52 | __align: [u32; 0], |
| 53 | } |
| 54 | |
| 55 | pub struct ip_mreq { |
| 56 | pub imr_multiaddr: in_addr, |
| 57 | pub imr_interface: in_addr, |
| 58 | } |
Alex Crichton | d809601 | 2015-09-16 16:36:30 -0700 | [diff] [blame] | 59 | |
| 60 | pub struct ipv6_mreq { |
| 61 | pub ipv6mr_multiaddr: in6_addr, |
| 62 | #[cfg(target_os = "android")] |
Alex Crichton | d809601 | 2015-09-16 16:36:30 -0700 | [diff] [blame] | 63 | pub ipv6mr_interface: c_int, |
Alex Crichton | 2482400 | 2015-09-16 17:34:54 -0700 | [diff] [blame] | 64 | #[cfg(not(target_os = "android"))] |
| 65 | pub ipv6mr_interface: c_uint, |
Alex Crichton | d809601 | 2015-09-16 16:36:30 -0700 | [diff] [blame] | 66 | } |
Alex Crichton | 084f9ea | 2015-09-11 15:11:59 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 69 | pub const WNOHANG: c_int = 1; |
| 70 | pub const SIG_DFL: sighandler_t = 0 as sighandler_t; |
| 71 | pub const SIG_IGN: sighandler_t = 1 as sighandler_t; |
| 72 | pub const SIG_ERR: sighandler_t = !0 as sighandler_t; |
| 73 | |
Alex Crichton | 2c57e36 | 2015-09-15 17:30:53 -0700 | [diff] [blame] | 74 | cfg_if! { |
| 75 | if #[cfg(feature = "default")] { |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 76 | // cargo build, don't pull in anything extra as the libstd dep |
Alex Crichton | 2c57e36 | 2015-09-15 17:30:53 -0700 | [diff] [blame] | 77 | // already pulls in all libs. |
| 78 | } else if #[cfg(target_env = "musl")] { |
| 79 | #[link(name = "c", kind = "static")] |
| 80 | extern {} |
| 81 | } else { |
| 82 | #[link(name = "c")] |
| 83 | #[link(name = "m")] |
| 84 | extern {} |
| 85 | } |
| 86 | } |
| 87 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 88 | extern { |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 89 | pub fn socket(domain: c_int, ty: c_int, protocol: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 90 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 91 | link_name = "connect$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 92 | pub fn connect(socket: c_int, address: *const sockaddr, |
| 93 | len: socklen_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 94 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 95 | link_name = "bind$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 96 | pub fn bind(socket: c_int, address: *const sockaddr, |
| 97 | address_len: socklen_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 98 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 99 | link_name = "listen$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 100 | pub fn listen(socket: c_int, backlog: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 101 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 102 | link_name = "accept$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 103 | pub fn accept(socket: c_int, address: *mut sockaddr, |
| 104 | address_len: *mut socklen_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 105 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 106 | link_name = "getpeername$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 107 | pub fn getpeername(socket: c_int, address: *mut sockaddr, |
| 108 | address_len: *mut socklen_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 109 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 110 | link_name = "getsockname$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 111 | pub fn getsockname(socket: c_int, address: *mut sockaddr, |
| 112 | address_len: *mut socklen_t) -> c_int; |
| 113 | pub fn setsockopt(socket: c_int, level: c_int, name: c_int, |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 114 | value: *const ::c_void, |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 115 | option_len: socklen_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 116 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 117 | link_name = "sendto$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 118 | pub fn sendto(socket: c_int, buf: *const ::c_void, len: size_t, |
| 119 | flags: c_int, addr: *const sockaddr, |
| 120 | addrlen: socklen_t) -> ssize_t; |
| 121 | pub fn shutdown(socket: c_int, how: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 122 | |
| 123 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 124 | link_name = "chmod$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 125 | pub fn chmod(path: *const c_char, mode: mode_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 126 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 127 | link_name = "fchmod$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 128 | pub fn fchmod(fd: c_int, mode: mode_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 129 | |
| 130 | #[cfg_attr(target_os = "macos", link_name = "fstat$INODE64")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 131 | pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 132 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 133 | pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 134 | |
Alex Crichton | 084f9ea | 2015-09-11 15:11:59 -0700 | [diff] [blame] | 135 | #[cfg_attr(target_os = "macos", link_name = "stat$INODE64")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 136 | pub fn stat(path: *const c_char, buf: *mut stat) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 137 | |
| 138 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 139 | link_name = "popen$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 140 | pub fn popen(command: *const c_char, |
| 141 | mode: *const c_char) -> *mut ::FILE; |
| 142 | pub fn pclose(stream: *mut ::FILE) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 143 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 144 | link_name = "fdopen$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 145 | pub fn fdopen(fd: c_int, mode: *const c_char) -> *mut ::FILE; |
| 146 | pub fn fileno(stream: *mut ::FILE) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 147 | |
| 148 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 149 | link_name = "open$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 150 | pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 151 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 152 | link_name = "creat$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 153 | pub fn creat(path: *const c_char, mode: mode_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 154 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 155 | link_name = "fcntl$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 156 | pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 157 | |
| 158 | #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), |
| 159 | link_name = "opendir$INODE64")] |
| 160 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 161 | link_name = "opendir$INODE64$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 162 | pub fn opendir(dirname: *const c_char) -> *mut ::DIR; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 163 | #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")] |
| 164 | pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent, |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 165 | result: *mut *mut ::dirent) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 166 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 167 | link_name = "closedir$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 168 | pub fn closedir(dirp: *mut ::DIR) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 169 | #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), |
| 170 | link_name = "rewinddir$INODE64")] |
| 171 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 172 | link_name = "rewinddir$INODE64$UNIX2003")] |
| 173 | pub fn rewinddir(dirp: *mut ::DIR); |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 174 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 175 | pub fn access(path: *const c_char, amode: c_int) -> c_int; |
| 176 | pub fn alarm(seconds: c_uint) -> c_uint; |
| 177 | pub fn chdir(dir: *const c_char) -> c_int; |
| 178 | pub fn chown(path: *const c_char, uid: uid_t, |
| 179 | gid: gid_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 180 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 181 | link_name = "close$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 182 | pub fn close(fd: c_int) -> c_int; |
| 183 | pub fn dup(fd: c_int) -> c_int; |
| 184 | pub fn dup2(src: c_int, dst: c_int) -> c_int; |
| 185 | pub fn execv(prog: *const c_char, |
| 186 | argv: *const *const c_char) -> c_int; |
| 187 | pub fn execve(prog: *const c_char, argv: *const *const c_char, |
| 188 | envp: *const *const c_char) |
| 189 | -> c_int; |
| 190 | pub fn execvp(c: *const c_char, |
| 191 | argv: *const *const c_char) -> c_int; |
| 192 | pub fn fork() -> pid_t; |
| 193 | pub fn fpathconf(filedes: c_int, name: c_int) -> c_long; |
| 194 | pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char; |
| 195 | pub fn getegid() -> gid_t; |
| 196 | pub fn geteuid() -> uid_t; |
| 197 | pub fn getgid() -> gid_t; |
| 198 | pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t) |
| 199 | -> c_int; |
| 200 | pub fn getlogin() -> *mut c_char; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 201 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 202 | link_name = "getopt$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 203 | pub fn getopt(argc: c_int, argv: *const *mut c_char, |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 204 | optstr: *const c_char) -> c_int; |
| 205 | pub fn getpgrp() -> pid_t; |
| 206 | pub fn getpid() -> pid_t; |
| 207 | pub fn getppid() -> pid_t; |
| 208 | pub fn getuid() -> uid_t; |
| 209 | pub fn isatty(fd: c_int) -> c_int; |
| 210 | pub fn link(src: *const c_char, dst: *const c_char) -> c_int; |
| 211 | pub fn lseek(fd: c_int, offset: off_t, whence: c_int) |
| 212 | -> off_t; |
| 213 | pub fn pathconf(path: *const c_char, name: c_int) -> c_long; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 214 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 215 | link_name = "pause$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 216 | pub fn pause() -> c_int; |
| 217 | pub fn pipe(fds: *mut c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 218 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 219 | link_name = "read$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 220 | pub fn read(fd: c_int, buf: *mut ::c_void, count: size_t) |
| 221 | -> ssize_t; |
| 222 | pub fn rmdir(path: *const c_char) -> c_int; |
| 223 | pub fn setgid(gid: gid_t) -> c_int; |
| 224 | pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int; |
| 225 | pub fn setsid() -> pid_t; |
| 226 | pub fn setuid(uid: uid_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 227 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 228 | link_name = "sleep$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 229 | pub fn sleep(secs: c_uint) -> c_uint; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 230 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 231 | link_name = "nanosleep$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 232 | pub fn nanosleep(rqtp: *const timespec, |
| 233 | rmtp: *mut timespec) -> c_int; |
| 234 | pub fn tcgetpgrp(fd: c_int) -> pid_t; |
| 235 | pub fn ttyname(fd: c_int) -> *mut c_char; |
| 236 | pub fn unlink(c: *const c_char) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 237 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 238 | link_name = "wait$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 239 | pub fn wait(status: *mut c_int) -> pid_t; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 240 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 241 | link_name = "waitpid$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 242 | pub fn waitpid(pid: pid_t, status: *mut c_int, options: c_int) |
| 243 | -> pid_t; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 244 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 245 | link_name = "write$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 246 | pub fn write(fd: c_int, buf: *const ::c_void, count: size_t) |
| 247 | -> ssize_t; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 248 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 249 | link_name = "pread$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 250 | pub fn pread(fd: c_int, buf: *mut ::c_void, count: size_t, |
| 251 | offset: off_t) -> ssize_t; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 252 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 253 | link_name = "pwrite$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 254 | pub fn pwrite(fd: c_int, buf: *const ::c_void, count: size_t, |
| 255 | offset: off_t) -> ssize_t; |
| 256 | pub fn utime(file: *const c_char, buf: *const utimbuf) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 257 | |
| 258 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 259 | link_name = "kill$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 260 | pub fn kill(pid: pid_t, sig: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 261 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 262 | pub fn mlock(addr: *const ::c_void, len: size_t) -> c_int; |
| 263 | pub fn munlock(addr: *const ::c_void, len: size_t) -> c_int; |
| 264 | pub fn mlockall(flags: c_int) -> c_int; |
| 265 | pub fn munlockall() -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 266 | |
| 267 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 268 | link_name = "mmap$UNIX2003")] |
| 269 | pub fn mmap(addr: *mut ::c_void, |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 270 | len: size_t, |
| 271 | prot: c_int, |
| 272 | flags: c_int, |
| 273 | fd: c_int, |
| 274 | offset: off_t) |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 275 | -> *mut ::c_void; |
| 276 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 277 | link_name = "munmap$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 278 | pub fn munmap(addr: *mut ::c_void, len: size_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 279 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 280 | pub fn if_nametoindex(ifname: *const c_char) -> c_uint; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 281 | |
| 282 | #[cfg_attr(target_os = "macos", link_name = "lstat$INODE64")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 283 | pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 284 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 285 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 286 | link_name = "fsync$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 287 | pub fn fsync(fd: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 288 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 289 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 290 | link_name = "setenv$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 291 | pub fn setenv(name: *const c_char, val: *const c_char, |
| 292 | overwrite: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 293 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 294 | link_name = "unsetenv$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 295 | pub fn unsetenv(name: *const c_char) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 296 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 297 | pub fn symlink(path1: *const c_char, |
| 298 | path2: *const c_char) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 299 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 300 | pub fn ftruncate(fd: c_int, length: off_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 301 | |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 302 | #[cfg_attr(target_os = "android", link_name = "bsd_signal")] |
| 303 | pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 304 | |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 305 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 306 | link_name = "getrlimit$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 307 | pub fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 308 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 309 | link_name = "setrlimit$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 310 | pub fn setrlimit(resource: c_int, rlim: *const rlimit) -> c_int; |
| 311 | pub fn getrusage(resource: c_int, usage: *mut rusage) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 312 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 313 | pub fn getdtablesize() -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 314 | #[cfg_attr(target_os = "macos", link_name = "realpath$DARWIN_EXTSN")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 315 | pub fn realpath(pathname: *const ::c_char, resolved: *mut ::c_char) |
| 316 | -> *mut ::c_char; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 317 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 318 | pub fn flock(fd: c_int, operation: c_int) -> c_int; |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 319 | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 320 | pub fn gettimeofday(tp: *mut ::timeval, |
| 321 | tz: *mut ::c_void) -> ::c_int; |
| 322 | |
| 323 | pub fn pthread_self() -> ::pthread_t; |
| 324 | pub fn pthread_create(native: *mut ::pthread_t, |
| 325 | attr: *const ::pthread_attr_t, |
| 326 | f: extern fn(*mut ::c_void) -> *mut ::c_void, |
| 327 | value: *mut ::c_void) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 328 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 329 | link_name = "pthread_join$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 330 | pub fn pthread_join(native: ::pthread_t, |
| 331 | value: *mut *mut ::c_void) -> ::c_int; |
| 332 | pub fn pthread_attr_init(attr: *mut ::pthread_attr_t) -> ::c_int; |
| 333 | pub fn pthread_attr_destroy(attr: *mut ::pthread_attr_t) -> ::c_int; |
| 334 | pub fn pthread_attr_setstacksize(attr: *mut ::pthread_attr_t, |
| 335 | stack_size: ::size_t) -> ::c_int; |
| 336 | pub fn pthread_attr_setdetachstate(attr: *mut ::pthread_attr_t, |
| 337 | state: ::c_int) -> ::c_int; |
| 338 | pub fn pthread_detach(thread: ::pthread_t) -> ::c_int; |
| 339 | pub fn sched_yield() -> ::c_int; |
| 340 | pub fn pthread_key_create(key: *mut pthread_key_t, |
Alex Crichton | 6de3816 | 2015-09-17 16:53:43 -0700 | [diff] [blame^] | 341 | dtor: ::dox::Option<unsafe extern fn(*mut ::c_void)>) |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 342 | -> c_int; |
| 343 | pub fn pthread_key_delete(key: pthread_key_t) -> c_int; |
| 344 | pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void; |
| 345 | pub fn pthread_setspecific(key: pthread_key_t, value: *const ::c_void) |
| 346 | -> c_int; |
| 347 | pub fn pthread_mutex_init(lock: *mut pthread_mutex_t, |
| 348 | attr: *const pthread_mutexattr_t) -> ::c_int; |
| 349 | pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> ::c_int; |
| 350 | pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> ::c_int; |
| 351 | pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> ::c_int; |
| 352 | pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> ::c_int; |
| 353 | |
| 354 | pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 355 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 356 | link_name = "pthread_mutexattr_destroy$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 357 | pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> ::c_int; |
| 358 | pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t, |
| 359 | _type: ::c_int) -> ::c_int; |
| 360 | |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 361 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 362 | link_name = "pthread_cond_wait$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 363 | pub fn pthread_cond_wait(cond: *mut pthread_cond_t, |
| 364 | lock: *mut pthread_mutex_t) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 365 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 366 | link_name = "pthread_cond_timedwait$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 367 | pub fn pthread_cond_timedwait(cond: *mut pthread_cond_t, |
| 368 | lock: *mut pthread_mutex_t, |
| 369 | abstime: *const ::timespec) -> ::c_int; |
| 370 | pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> ::c_int; |
| 371 | pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> ::c_int; |
| 372 | pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 373 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 374 | link_name = "pthread_rwlock_destroy$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 375 | pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 376 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 377 | link_name = "pthread_rwlock_rdlock$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 378 | pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 379 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 380 | link_name = "pthread_rwlock_tryrdlock$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 381 | pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 382 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 383 | link_name = "pthread_rwlock_wrlock$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 384 | pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 385 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 386 | link_name = "pthread_rwlock_trywrlock$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 387 | pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 388 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 389 | link_name = "pthread_rwlock_unlock$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 390 | pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 391 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 392 | link_name = "pthread_sigmask$UNIX2003")] |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 393 | pub fn pthread_sigmask(how: ::c_int, set: *const sigset_t, |
| 394 | oldset: *mut sigset_t) -> ::c_int; |
| 395 | |
| 396 | // #[cfg_attr(target_os = "linux", link_name = "__xpg_strerror_r")] |
| 397 | pub fn strerror_r(errnum: c_int, buf: *mut c_char, |
| 398 | buflen: size_t) -> c_int; |
| 399 | |
| 400 | pub fn getsockopt(sockfd: ::c_int, |
| 401 | level: ::c_int, |
| 402 | optname: ::c_int, |
| 403 | optval: *mut ::c_void, |
| 404 | optlen: *mut ::socklen_t) -> ::c_int; |
| 405 | pub fn raise(signum: ::c_int) -> ::c_int; |
| 406 | pub fn sigaction(signum: ::c_int, |
| 407 | act: *const sigaction, |
| 408 | oldact: *mut sigaction) -> ::c_int; |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 409 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 410 | link_name = "sigaltstack$UNIX2003")] |
| 411 | pub fn sigaltstack(ss: *const stack_t, |
| 412 | oss: *mut stack_t) -> ::c_int; |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 413 | |
| 414 | pub fn utimes(filename: *const ::c_char, |
| 415 | times: *const ::timeval) -> ::c_int; |
| 416 | pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char; |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 417 | pub fn dlopen(filename: *const ::c_char, |
| 418 | flag: ::c_int) -> *mut ::c_void; |
| 419 | pub fn dlerror() -> *mut ::c_char; |
| 420 | pub fn dlsym(handle: *mut ::c_void, |
| 421 | symbol: *const ::c_char) -> *mut ::c_void; |
| 422 | pub fn dlclose(handle: *mut ::c_void) -> ::c_int; |
| 423 | } |
| 424 | |
| 425 | // TODO: get rid of this #[cfg(not(...))] |
| 426 | #[cfg(not(target_os = "android"))] |
| 427 | extern { |
| 428 | pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> c_int; |
| 429 | pub fn freeifaddrs(ifa: *mut ifaddrs); |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 430 | #[cfg_attr(target_os = "macos", link_name = "glob$INODE64")] |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 431 | pub fn glob(pattern: *const c_char, |
| 432 | flags: c_int, |
| 433 | errfunc: ::dox::Option<extern "C" fn(epath: *const c_char, |
| 434 | errno: c_int) -> c_int>, |
| 435 | pglob: *mut glob_t) -> c_int; |
| 436 | pub fn globfree(pglob: *mut glob_t); |
| 437 | |
| 438 | pub fn posix_madvise(addr: *mut ::c_void, len: size_t, advice: c_int) |
| 439 | -> c_int; |
| 440 | |
| 441 | pub fn shm_unlink(name: *const c_char) -> c_int; |
| 442 | |
| 443 | #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), |
| 444 | link_name = "seekdir$INODE64")] |
| 445 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 446 | link_name = "seekdir$INODE64$UNIX2003")] |
| 447 | pub fn seekdir(dirp: *mut ::DIR, loc: c_long); |
| 448 | |
| 449 | #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), |
| 450 | link_name = "telldir$INODE64")] |
| 451 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 452 | link_name = "telldir$INODE64$UNIX2003")] |
| 453 | pub fn telldir(dirp: *mut ::DIR) -> c_long; |
| 454 | |
| 455 | pub fn getsid(pid: pid_t) -> pid_t; |
| 456 | pub fn madvise(addr: *mut ::c_void, len: size_t, advice: c_int) |
| 457 | -> c_int; |
| 458 | pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int; |
| 459 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 460 | link_name = "putenv$UNIX2003")] |
| 461 | pub fn putenv(string: *mut c_char) -> c_int; |
| 462 | pub fn readlink(path: *const c_char, |
| 463 | buf: *mut c_char, |
| 464 | bufsz: size_t) |
| 465 | -> ssize_t; |
| 466 | |
| 467 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 468 | link_name = "msync$UNIX2003")] |
| 469 | pub fn msync(addr: *mut ::c_void, len: size_t, flags: c_int) -> c_int; |
| 470 | pub fn sysconf(name: c_int) -> c_long; |
| 471 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 472 | link_name = "usleep$UNIX2003")] |
| 473 | pub fn usleep(secs: c_uint) -> c_int; |
| 474 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 475 | link_name = "recvfrom$UNIX2003")] |
| 476 | pub fn recvfrom(socket: c_int, buf: *mut ::c_void, len: size_t, |
| 477 | flags: c_int, addr: *mut sockaddr, |
| 478 | addrlen: *mut socklen_t) -> ssize_t; |
| 479 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 480 | link_name = "send$UNIX2003")] |
| 481 | pub fn send(socket: c_int, buf: *const ::c_void, len: size_t, |
| 482 | flags: c_int) -> ssize_t; |
| 483 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 484 | link_name = "recv$UNIX2003")] |
| 485 | pub fn recv(socket: c_int, buf: *mut ::c_void, len: size_t, |
| 486 | flags: c_int) -> ssize_t; |
| 487 | pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int; |
| 488 | |
| 489 | pub fn getpwuid_r(uid: ::uid_t, |
| 490 | pwd: *mut passwd, |
| 491 | buf: *mut ::c_char, |
| 492 | buflen: ::size_t, |
| 493 | result: *mut *mut passwd) -> ::c_int; |
| 494 | pub fn backtrace(buf: *mut *mut ::c_void, |
| 495 | sz: ::c_int) -> ::c_int; |
| 496 | pub fn posix_memalign(memptr: *mut *mut ::c_void, |
| 497 | align: ::size_t, |
| 498 | size: ::size_t) -> ::c_int; |
| 499 | pub fn sigemptyset(set: *mut sigset_t) -> ::c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 500 | } |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 501 | |
| 502 | cfg_if! { |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 503 | if #[cfg(any(target_os = "linux", target_os = "android"))] { |
| 504 | mod notbsd; |
| 505 | pub use self::notbsd::*; |
| 506 | } else if #[cfg(any(target_os = "macos", |
| 507 | target_os = "freebsd", |
| 508 | target_os = "dragonfly", |
| 509 | target_os = "openbsd", |
| 510 | target_os = "netbsd", |
| 511 | target_os = "bitrig"))] { |
| 512 | mod bsd; |
| 513 | pub use self::bsd::*; |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 514 | } else { |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 515 | // ... |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 516 | } |
| 517 | } |