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 | 2c57e36 | 2015-09-15 17:30:53 -0700 | [diff] [blame] | 69 | cfg_if! { |
| 70 | if #[cfg(feature = "default")] { |
| 71 | // cargo build, don't pull in anything extra as the libstd libc dep |
| 72 | // already pulls in all libs. |
| 73 | } else if #[cfg(target_env = "musl")] { |
| 74 | #[link(name = "c", kind = "static")] |
| 75 | extern {} |
| 76 | } else { |
| 77 | #[link(name = "c")] |
| 78 | #[link(name = "m")] |
| 79 | extern {} |
| 80 | } |
| 81 | } |
| 82 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 83 | extern { |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 84 | 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] | 85 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 86 | link_name = "connect$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 87 | pub fn connect(socket: c_int, address: *const sockaddr, |
| 88 | len: socklen_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 89 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 90 | link_name = "bind$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 91 | pub fn bind(socket: c_int, address: *const sockaddr, |
| 92 | address_len: socklen_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 93 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 94 | link_name = "listen$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 95 | pub fn listen(socket: c_int, backlog: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 96 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 97 | link_name = "accept$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 98 | pub fn accept(socket: c_int, address: *mut sockaddr, |
| 99 | address_len: *mut socklen_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 100 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 101 | link_name = "getpeername$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 102 | pub fn getpeername(socket: c_int, address: *mut sockaddr, |
| 103 | address_len: *mut socklen_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 104 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 105 | link_name = "getsockname$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 106 | pub fn getsockname(socket: c_int, address: *mut sockaddr, |
| 107 | address_len: *mut socklen_t) -> c_int; |
| 108 | pub fn setsockopt(socket: c_int, level: c_int, name: c_int, |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 109 | value: *const ::c_void, |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 110 | option_len: socklen_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 111 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 112 | link_name = "sendto$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 113 | pub fn sendto(socket: c_int, buf: *const ::c_void, len: size_t, |
| 114 | flags: c_int, addr: *const sockaddr, |
| 115 | addrlen: socklen_t) -> ssize_t; |
| 116 | pub fn shutdown(socket: c_int, how: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 117 | |
| 118 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 119 | link_name = "chmod$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 120 | pub fn chmod(path: *const c_char, mode: mode_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 121 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 122 | link_name = "fchmod$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 123 | pub fn fchmod(fd: c_int, mode: mode_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 124 | |
| 125 | #[cfg_attr(target_os = "macos", link_name = "fstat$INODE64")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 126 | pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 127 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 128 | pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 129 | |
Alex Crichton | 084f9ea | 2015-09-11 15:11:59 -0700 | [diff] [blame] | 130 | #[cfg_attr(target_os = "macos", link_name = "stat$INODE64")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 131 | pub fn stat(path: *const c_char, buf: *mut stat) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 132 | |
| 133 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 134 | link_name = "popen$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 135 | pub fn popen(command: *const c_char, |
| 136 | mode: *const c_char) -> *mut ::FILE; |
| 137 | pub fn pclose(stream: *mut ::FILE) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 138 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 139 | link_name = "fdopen$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 140 | pub fn fdopen(fd: c_int, mode: *const c_char) -> *mut ::FILE; |
| 141 | pub fn fileno(stream: *mut ::FILE) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 142 | |
| 143 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 144 | link_name = "open$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 145 | pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 146 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 147 | link_name = "creat$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 148 | pub fn creat(path: *const c_char, mode: mode_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 149 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 150 | link_name = "fcntl$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 151 | pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 152 | |
| 153 | #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), |
| 154 | link_name = "opendir$INODE64")] |
| 155 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 156 | link_name = "opendir$INODE64$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 157 | pub fn opendir(dirname: *const c_char) -> *mut ::DIR; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 158 | #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")] |
| 159 | pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent, |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 160 | result: *mut *mut ::dirent) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 161 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 162 | link_name = "closedir$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 163 | pub fn closedir(dirp: *mut ::DIR) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 164 | #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), |
| 165 | link_name = "rewinddir$INODE64")] |
| 166 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 167 | link_name = "rewinddir$INODE64$UNIX2003")] |
| 168 | pub fn rewinddir(dirp: *mut ::DIR); |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 169 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 170 | pub fn access(path: *const c_char, amode: c_int) -> c_int; |
| 171 | pub fn alarm(seconds: c_uint) -> c_uint; |
| 172 | pub fn chdir(dir: *const c_char) -> c_int; |
| 173 | pub fn chown(path: *const c_char, uid: uid_t, |
| 174 | gid: gid_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 175 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 176 | link_name = "close$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 177 | pub fn close(fd: c_int) -> c_int; |
| 178 | pub fn dup(fd: c_int) -> c_int; |
| 179 | pub fn dup2(src: c_int, dst: c_int) -> c_int; |
| 180 | pub fn execv(prog: *const c_char, |
| 181 | argv: *const *const c_char) -> c_int; |
| 182 | pub fn execve(prog: *const c_char, argv: *const *const c_char, |
| 183 | envp: *const *const c_char) |
| 184 | -> c_int; |
| 185 | pub fn execvp(c: *const c_char, |
| 186 | argv: *const *const c_char) -> c_int; |
| 187 | pub fn fork() -> pid_t; |
| 188 | pub fn fpathconf(filedes: c_int, name: c_int) -> c_long; |
| 189 | pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char; |
| 190 | pub fn getegid() -> gid_t; |
| 191 | pub fn geteuid() -> uid_t; |
| 192 | pub fn getgid() -> gid_t; |
| 193 | pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t) |
| 194 | -> c_int; |
| 195 | pub fn getlogin() -> *mut c_char; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 196 | // GNU getopt(3) modifies its arguments despite the |
| 197 | // char * const [] prototype; see the manpage. |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 198 | pub fn getopt(argc: c_int, argv: *mut *mut c_char, |
| 199 | optstr: *const c_char) -> c_int; |
| 200 | pub fn getpgrp() -> pid_t; |
| 201 | pub fn getpid() -> pid_t; |
| 202 | pub fn getppid() -> pid_t; |
| 203 | pub fn getuid() -> uid_t; |
| 204 | pub fn isatty(fd: c_int) -> c_int; |
| 205 | pub fn link(src: *const c_char, dst: *const c_char) -> c_int; |
| 206 | pub fn lseek(fd: c_int, offset: off_t, whence: c_int) |
| 207 | -> off_t; |
| 208 | pub fn pathconf(path: *const c_char, name: c_int) -> c_long; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 209 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 210 | link_name = "pause$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 211 | pub fn pause() -> c_int; |
| 212 | pub fn pipe(fds: *mut c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 213 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 214 | link_name = "read$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 215 | pub fn read(fd: c_int, buf: *mut ::c_void, count: size_t) |
| 216 | -> ssize_t; |
| 217 | pub fn rmdir(path: *const c_char) -> c_int; |
| 218 | pub fn setgid(gid: gid_t) -> c_int; |
| 219 | pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int; |
| 220 | pub fn setsid() -> pid_t; |
| 221 | pub fn setuid(uid: uid_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 222 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 223 | link_name = "sleep$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 224 | pub fn sleep(secs: c_uint) -> c_uint; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 225 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 226 | link_name = "nanosleep$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 227 | pub fn nanosleep(rqtp: *const timespec, |
| 228 | rmtp: *mut timespec) -> c_int; |
| 229 | pub fn tcgetpgrp(fd: c_int) -> pid_t; |
| 230 | pub fn ttyname(fd: c_int) -> *mut c_char; |
| 231 | pub fn unlink(c: *const c_char) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 232 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 233 | link_name = "wait$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 234 | pub fn wait(status: *mut c_int) -> pid_t; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 235 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 236 | link_name = "waitpid$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 237 | pub fn waitpid(pid: pid_t, status: *mut c_int, options: c_int) |
| 238 | -> pid_t; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 239 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 240 | link_name = "write$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 241 | pub fn write(fd: c_int, buf: *const ::c_void, count: size_t) |
| 242 | -> ssize_t; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 243 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 244 | link_name = "pread$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 245 | pub fn pread(fd: c_int, buf: *mut ::c_void, count: size_t, |
| 246 | offset: off_t) -> ssize_t; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 247 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 248 | link_name = "pwrite$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 249 | pub fn pwrite(fd: c_int, buf: *const ::c_void, count: size_t, |
| 250 | offset: off_t) -> ssize_t; |
| 251 | pub fn utime(file: *const c_char, buf: *const utimbuf) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 252 | |
| 253 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 254 | link_name = "kill$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 255 | pub fn kill(pid: pid_t, sig: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 256 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 257 | pub fn mlock(addr: *const ::c_void, len: size_t) -> c_int; |
| 258 | pub fn munlock(addr: *const ::c_void, len: size_t) -> c_int; |
| 259 | pub fn mlockall(flags: c_int) -> c_int; |
| 260 | pub fn munlockall() -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 261 | |
| 262 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 263 | link_name = "mmap$UNIX2003")] |
| 264 | pub fn mmap(addr: *mut ::c_void, |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 265 | len: size_t, |
| 266 | prot: c_int, |
| 267 | flags: c_int, |
| 268 | fd: c_int, |
| 269 | offset: off_t) |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 270 | -> *mut ::c_void; |
| 271 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 272 | link_name = "munmap$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 273 | pub fn munmap(addr: *mut ::c_void, len: size_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 274 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 275 | pub fn if_nametoindex(ifname: *const c_char) -> c_uint; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 276 | |
| 277 | #[cfg_attr(target_os = "macos", link_name = "lstat$INODE64")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 278 | pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 279 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 280 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 281 | link_name = "fsync$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 282 | pub fn fsync(fd: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 283 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 284 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 285 | link_name = "setenv$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 286 | pub fn setenv(name: *const c_char, val: *const c_char, |
| 287 | overwrite: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 288 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 289 | link_name = "unsetenv$UNIX2003")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 290 | pub fn unsetenv(name: *const c_char) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 291 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 292 | pub fn symlink(path1: *const c_char, |
| 293 | path2: *const c_char) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 294 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 295 | pub fn ftruncate(fd: c_int, length: off_t) -> 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 signal(signum: c_int, |
| 298 | handler: sighandler_t) -> sighandler_t; |
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 getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int; |
| 301 | pub fn setrlimit(resource: c_int, rlim: *const rlimit) -> c_int; |
| 302 | pub fn getrusage(resource: c_int, usage: *mut rusage) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 303 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 304 | pub fn getdtablesize() -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 305 | #[cfg_attr(target_os = "macos", link_name = "realpath$DARWIN_EXTSN")] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 306 | pub fn realpath(pathname: *const c_char, resolved: *mut c_char) |
| 307 | -> *mut c_char; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 308 | |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 309 | pub fn flock(fd: c_int, operation: c_int) -> c_int; |
| 310 | } |
| 311 | |
Alex Crichton | 5260587 | 2015-09-15 16:49:37 -0700 | [diff] [blame] | 312 | // TODO: get rid of this #[cfg(not(...))] |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 313 | #[cfg(not(target_os = "android"))] |
| 314 | extern { |
| 315 | pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> c_int; |
| 316 | pub fn freeifaddrs(ifa: *mut ifaddrs); |
| 317 | pub fn glob(pattern: *const c_char, |
| 318 | flags: c_int, |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 319 | errfunc: ::dox::Option<extern "C" fn(epath: *const c_char, |
| 320 | errno: c_int) -> c_int>, |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 321 | pglob: *mut glob_t); |
| 322 | pub fn globfree(pglob: *mut glob_t); |
| 323 | |
| 324 | pub fn posix_madvise(addr: *mut ::c_void, len: size_t, advice: c_int) |
| 325 | -> c_int; |
| 326 | |
| 327 | pub fn shm_unlink(name: *const c_char) -> c_int; |
| 328 | |
| 329 | #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), |
| 330 | link_name = "seekdir$INODE64")] |
| 331 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 332 | link_name = "seekdir$INODE64$UNIX2003")] |
| 333 | pub fn seekdir(dirp: *mut ::DIR, loc: c_long); |
| 334 | |
| 335 | #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), |
| 336 | link_name = "telldir$INODE64")] |
| 337 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 338 | link_name = "telldir$INODE64$UNIX2003")] |
| 339 | pub fn telldir(dirp: *mut ::DIR) -> c_long; |
| 340 | |
| 341 | pub fn getsid(pid: pid_t) -> pid_t; |
| 342 | pub fn madvise(addr: *mut ::c_void, len: size_t, advice: c_int) |
| 343 | -> c_int; |
| 344 | pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int; |
| 345 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 346 | link_name = "putenv$UNIX2003")] |
| 347 | pub fn putenv(string: *mut c_char) -> c_int; |
| 348 | pub fn readlink(path: *const c_char, |
| 349 | buf: *mut c_char, |
| 350 | bufsz: size_t) |
| 351 | -> ssize_t; |
| 352 | |
| 353 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 354 | link_name = "msync$UNIX2003")] |
| 355 | pub fn msync(addr: *mut ::c_void, len: size_t, flags: c_int) -> c_int; |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 356 | pub fn sysconf(name: c_int) -> c_long; |
| 357 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 358 | link_name = "usleep$UNIX2003")] |
| 359 | pub fn usleep(secs: c_uint) -> c_int; |
| 360 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 361 | link_name = "recvfrom$UNIX2003")] |
| 362 | pub fn recvfrom(socket: c_int, buf: *mut ::c_void, len: size_t, |
| 363 | flags: c_int, addr: *mut sockaddr, |
| 364 | addrlen: *mut socklen_t) -> ssize_t; |
| 365 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 366 | link_name = "send$UNIX2003")] |
| 367 | pub fn send(socket: c_int, buf: *const ::c_void, len: size_t, |
| 368 | flags: c_int) -> ssize_t; |
| 369 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 370 | link_name = "recv$UNIX2003")] |
| 371 | pub fn recv(socket: c_int, buf: *mut ::c_void, len: size_t, |
| 372 | flags: c_int) -> ssize_t; |
| 373 | pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 374 | } |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 375 | |
| 376 | cfg_if! { |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 377 | if #[cfg(any(target_os = "linux", target_os = "android"))] { |
| 378 | mod notbsd; |
| 379 | pub use self::notbsd::*; |
| 380 | } else if #[cfg(any(target_os = "macos", |
| 381 | target_os = "freebsd", |
| 382 | target_os = "dragonfly", |
| 383 | target_os = "openbsd", |
| 384 | target_os = "netbsd", |
| 385 | target_os = "bitrig"))] { |
| 386 | mod bsd; |
| 387 | pub use self::bsd::*; |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 388 | } else { |
Alex Crichton | 50a42e2 | 2015-09-15 14:27:15 -0700 | [diff] [blame] | 389 | // ... |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 390 | } |
| 391 | } |