1 use dox::mem; 2 3 pub type c_char = i8; 4 pub type wchar_t = i32; 5 pub type off_t = i64; 6 pub type useconds_t = u32; 7 pub type blkcnt_t = i64; 8 pub type socklen_t = u32; 9 pub type sa_family_t = u8; 10 pub type pthread_t = ::uintptr_t; 11 pub type nfds_t = ::c_uint; 12 13 s! { 14 pub struct sockaddr { 15 pub sa_len: u8, 16 pub sa_family: sa_family_t, 17 pub sa_data: [::c_char; 14], 18 } 19 20 pub struct sockaddr_in6 { 21 pub sin6_len: u8, 22 pub sin6_family: sa_family_t, 23 pub sin6_port: ::in_port_t, 24 pub sin6_flowinfo: u32, 25 pub sin6_addr: ::in6_addr, 26 pub sin6_scope_id: u32, 27 } 28 29 pub struct sockaddr_un { 30 pub sun_len: u8, 31 pub sun_family: sa_family_t, 32 pub sun_path: [c_char; 104] 33 } 34 35 pub struct passwd { 36 pub pw_name: *mut ::c_char, 37 pub pw_passwd: *mut ::c_char, 38 pub pw_uid: ::uid_t, 39 pub pw_gid: ::gid_t, 40 pub pw_change: ::time_t, 41 pub pw_class: *mut ::c_char, 42 pub pw_gecos: *mut ::c_char, 43 pub pw_dir: *mut ::c_char, 44 pub pw_shell: *mut ::c_char, 45 pub pw_expire: ::time_t, 46 47 #[cfg(not(any(target_os = "macos", 48 target_os = "ios", 49 target_os = "netbsd", 50 target_os = "openbsd")))] 51 pub pw_fields: ::c_int, 52 } 53 54 pub struct ifaddrs { 55 pub ifa_next: *mut ifaddrs, 56 pub ifa_name: *mut ::c_char, 57 pub ifa_flags: ::c_uint, 58 pub ifa_addr: *mut ::sockaddr, 59 pub ifa_netmask: *mut ::sockaddr, 60 pub ifa_dstaddr: *mut ::sockaddr, 61 pub ifa_data: *mut ::c_void 62 } 63 64 pub struct fd_set { 65 #[cfg(all(target_pointer_width = "64", 66 any(target_os = "freebsd", target_os = "dragonfly")))] 67 fds_bits: [i64; FD_SETSIZE / 64], 68 #[cfg(not(all(target_pointer_width = "64", 69 any(target_os = "freebsd", target_os = "dragonfly"))))] 70 fds_bits: [i32; FD_SETSIZE / 32], 71 } 72 73 pub struct tm { 74 pub tm_sec: ::c_int, 75 pub tm_min: ::c_int, 76 pub tm_hour: ::c_int, 77 pub tm_mday: ::c_int, 78 pub tm_mon: ::c_int, 79 pub tm_year: ::c_int, 80 pub tm_wday: ::c_int, 81 pub tm_yday: ::c_int, 82 pub tm_isdst: ::c_int, 83 pub tm_gmtoff: ::c_long, 84 pub tm_zone: *mut ::c_char, 85 } 86 87 pub struct utsname { 88 #[cfg(not(target_os = "dragonfly"))] 89 pub sysname: [::c_char; 256], 90 #[cfg(target_os = "dragonfly")] 91 pub sysname: [::c_char; 32], 92 #[cfg(not(target_os = "dragonfly"))] 93 pub nodename: [::c_char; 256], 94 #[cfg(target_os = "dragonfly")] 95 pub nodename: [::c_char; 32], 96 #[cfg(not(target_os = "dragonfly"))] 97 pub release: [::c_char; 256], 98 #[cfg(target_os = "dragonfly")] 99 pub release: [::c_char; 32], 100 #[cfg(not(target_os = "dragonfly"))] 101 pub version: [::c_char; 256], 102 #[cfg(target_os = "dragonfly")] 103 pub version: [::c_char; 32], 104 #[cfg(not(target_os = "dragonfly"))] 105 pub machine: [::c_char; 256], 106 #[cfg(target_os = "dragonfly")] 107 pub machine: [::c_char; 32], 108 } 109 110 pub struct msghdr { 111 pub msg_name: *mut ::c_void, 112 pub msg_namelen: ::socklen_t, 113 pub msg_iov: *mut ::iovec, 114 pub msg_iovlen: ::c_int, 115 pub msg_control: *mut ::c_void, 116 pub msg_controllen: ::socklen_t, 117 pub msg_flags: ::c_int, 118 } 119 120 pub struct fsid_t { 121 __fsid_val: [::int32_t; 2], 122 } 123 124 pub struct if_nameindex { 125 pub if_index: ::c_uint, 126 pub if_name: *mut ::c_char, 127 } 128 } 129 130 pub const LC_ALL: ::c_int = 0; 131 pub const LC_COLLATE: ::c_int = 1; 132 pub const LC_CTYPE: ::c_int = 2; 133 pub const LC_MONETARY: ::c_int = 3; 134 pub const LC_NUMERIC: ::c_int = 4; 135 pub const LC_TIME: ::c_int = 5; 136 pub const LC_MESSAGES: ::c_int = 6; 137 138 pub const FIOCLEX: ::c_ulong = 0x20006601; 139 pub const FIONBIO: ::c_ulong = 0x8004667e; 140 141 pub const PATH_MAX: ::c_int = 1024; 142 143 pub const SA_ONSTACK: ::c_int = 0x0001; 144 pub const SA_SIGINFO: ::c_int = 0x0040; 145 pub const SA_RESTART: ::c_int = 0x0002; 146 pub const SA_RESETHAND: ::c_int = 0x0004; 147 pub const SA_NOCLDSTOP: ::c_int = 0x0008; 148 pub const SA_NODEFER: ::c_int = 0x0010; 149 pub const SA_NOCLDWAIT: ::c_int = 0x0020; 150 151 pub const SS_ONSTACK: ::c_int = 1; 152 pub const SS_DISABLE: ::c_int = 4; 153 154 pub const SIGCHLD: ::c_int = 20; 155 pub const SIGBUS: ::c_int = 10; 156 pub const SIGUSR1: ::c_int = 30; 157 pub const SIGUSR2: ::c_int = 31; 158 pub const SIGCONT: ::c_int = 19; 159 pub const SIGSTOP: ::c_int = 17; 160 pub const SIGTSTP: ::c_int = 18; 161 pub const SIGURG: ::c_int = 16; 162 pub const SIGIO: ::c_int = 23; 163 pub const SIGSYS: ::c_int = 12; 164 pub const SIGTTIN: ::c_int = 21; 165 pub const SIGTTOU: ::c_int = 22; 166 pub const SIGXCPU: ::c_int = 24; 167 pub const SIGXFSZ: ::c_int = 25; 168 pub const SIGVTALRM: ::c_int = 26; 169 pub const SIGPROF: ::c_int = 27; 170 pub const SIGWINCH: ::c_int = 28; 171 pub const SIGINFO: ::c_int = 29; 172 173 pub const SIG_SETMASK: ::c_int = 3; 174 pub const SIG_BLOCK: ::c_int = 0x1; 175 pub const SIG_UNBLOCK: ::c_int = 0x2; 176 177 pub const IPV6_MULTICAST_LOOP: ::c_int = 11; 178 pub const IPV6_V6ONLY: ::c_int = 27; 179 180 pub const ST_RDONLY: ::c_ulong = 1; 181 182 pub const NCCS: usize = 20; 183 184 pub const O_ASYNC: ::c_int = 0x40; 185 pub const O_FSYNC: ::c_int = 0x80; 186 pub const O_NDELAY: ::c_int = 0x4; 187 pub const O_NOFOLLOW: ::c_int = 0x100; 188 189 pub const F_GETOWN: ::c_int = 5; 190 pub const F_SETOWN: ::c_int = 6; 191 192 pub const MNT_FORCE: ::c_int = 0x80000; 193 194 pub const Q_SYNC: ::c_int = 0x600; 195 pub const Q_QUOTAON: ::c_int = 0x100; 196 pub const Q_QUOTAOFF: ::c_int = 0x200; 197 198 pub const TCIOFF: ::c_int = 3; 199 pub const TCION: ::c_int = 4; 200 pub const TCOOFF: ::c_int = 1; 201 pub const TCOON: ::c_int = 2; 202 pub const TCIFLUSH: ::c_int = 1; 203 pub const TCOFLUSH: ::c_int = 2; 204 pub const TCIOFLUSH: ::c_int = 3; 205 pub const TCSANOW: ::c_int = 0; 206 pub const TCSADRAIN: ::c_int = 1; 207 pub const TCSAFLUSH: ::c_int = 2; 208 pub const VEOF: usize = 0; 209 pub const VEOL: usize = 1; 210 pub const VEOL2: usize = 2; 211 pub const VERASE: usize = 3; 212 pub const VWERASE: usize = 4; 213 pub const VKILL: usize = 5; 214 pub const VREPRINT: usize = 6; 215 pub const VINTR: usize = 8; 216 pub const VQUIT: usize = 9; 217 pub const VSUSP: usize = 10; 218 pub const VSTART: usize = 12; 219 pub const VSTOP: usize = 13; 220 pub const VLNEXT: usize = 14; 221 pub const VDISCARD: usize = 15; 222 pub const VMIN: usize = 16; 223 pub const VTIME: usize = 17; 224 pub const IGNBRK: ::tcflag_t = 0x00000001; 225 pub const BRKINT: ::tcflag_t = 0x00000002; 226 pub const IGNPAR: ::tcflag_t = 0x00000004; 227 pub const PARMRK: ::tcflag_t = 0x00000008; 228 pub const INPCK: ::tcflag_t = 0x00000010; 229 pub const ISTRIP: ::tcflag_t = 0x00000020; 230 pub const INLCR: ::tcflag_t = 0x00000040; 231 pub const IGNCR: ::tcflag_t = 0x00000080; 232 pub const ICRNL: ::tcflag_t = 0x00000100; 233 pub const IXON: ::tcflag_t = 0x00000200; 234 pub const IXOFF: ::tcflag_t = 0x00000400; 235 pub const IXANY: ::tcflag_t = 0x00000800; 236 pub const IMAXBEL: ::tcflag_t = 0x00002000; 237 pub const OPOST: ::tcflag_t = 0x1; 238 pub const ONLCR: ::tcflag_t = 0x2; 239 pub const CSIZE: ::tcflag_t = 0x00000300; 240 pub const CS5: ::tcflag_t = 0x00000000; 241 pub const CS6: ::tcflag_t = 0x00000100; 242 pub const CS7: ::tcflag_t = 0x00000200; 243 pub const CS8: ::tcflag_t = 0x00000300; 244 pub const CSTOPB: ::tcflag_t = 0x00000400; 245 pub const CREAD: ::tcflag_t = 0x00000800; 246 pub const PARENB: ::tcflag_t = 0x00001000; 247 pub const PARODD: ::tcflag_t = 0x00002000; 248 pub const HUPCL: ::tcflag_t = 0x00004000; 249 pub const CLOCAL: ::tcflag_t = 0x00008000; 250 pub const ECHOKE: ::tcflag_t = 0x00000001; 251 pub const ECHOE: ::tcflag_t = 0x00000002; 252 pub const ECHOK: ::tcflag_t = 0x00000004; 253 pub const ECHO: ::tcflag_t = 0x00000008; 254 pub const ECHONL: ::tcflag_t = 0x00000010; 255 pub const ECHOPRT: ::tcflag_t = 0x00000020; 256 pub const ECHOCTL: ::tcflag_t = 0x00000040; 257 pub const ISIG: ::tcflag_t = 0x00000080; 258 pub const ICANON: ::tcflag_t = 0x00000100; 259 pub const IEXTEN: ::tcflag_t = 0x00000400; 260 pub const EXTPROC: ::tcflag_t = 0x00000800; 261 pub const TOSTOP: ::tcflag_t = 0x00400000; 262 pub const FLUSHO: ::tcflag_t = 0x00800000; 263 pub const PENDIN: ::tcflag_t = 0x20000000; 264 pub const NOFLSH: ::tcflag_t = 0x80000000; 265 266 pub const WNOHANG: ::c_int = 0x00000001; 267 pub const WUNTRACED: ::c_int = 0x00000002; 268 269 pub const RTLD_NOW: ::c_int = 0x2; 270 pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void; 271 272 pub const LOG_CRON: ::c_int = 9 << 3; 273 pub const LOG_AUTHPRIV: ::c_int = 10 << 3; 274 pub const LOG_FTP: ::c_int = 11 << 3; 275 pub const LOG_PERROR: ::c_int = 0x20; 276 277 pub const PIPE_BUF: usize = 512; 278 279 f! { 280 pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { 281 let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; 282 let fd = fd as usize; 283 (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); 284 return 285 } 286 287 pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { 288 let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; 289 let fd = fd as usize; 290 return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 291 } 292 293 pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { 294 let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; 295 let fd = fd as usize; 296 (*set).fds_bits[fd / bits] |= 1 << (fd % bits); 297 return 298 } 299 300 pub fn FD_ZERO(set: *mut fd_set) -> () { 301 for slot in (*set).fds_bits.iter_mut() { 302 *slot = 0; 303 } 304 } 305 306 pub fn WTERMSIG(status: ::c_int) -> ::c_int { 307 status & 0o177 308 } 309 310 pub fn WIFEXITED(status: ::c_int) -> bool { 311 (status & 0o177) == 0 312 } 313 314 pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { 315 status >> 8 316 } 317 318 pub fn WCOREDUMP(status: ::c_int) -> bool { 319 (status & 0o200) != 0 320 } 321 } 322 323 extern { setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int324 pub fn setgroups(ngroups: ::c_int, 325 ptr: *const ::gid_t) -> ::c_int; ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int326 pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; kqueue() -> ::c_int327 pub fn kqueue() -> ::c_int; unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int328 pub fn unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int; syscall(num: ::c_int, ...) -> ::c_int329 pub fn syscall(num: ::c_int, ...) -> ::c_int; 330 #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")] getpwnam_r(name: *const ::c_char, pwd: *mut passwd, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut passwd) -> ::c_int331 pub fn getpwnam_r(name: *const ::c_char, 332 pwd: *mut passwd, 333 buf: *mut ::c_char, 334 buflen: ::size_t, 335 result: *mut *mut passwd) -> ::c_int; 336 #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] getpwuid_r(uid: ::uid_t, pwd: *mut passwd, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut passwd) -> ::c_int337 pub fn getpwuid_r(uid: ::uid_t, 338 pwd: *mut passwd, 339 buf: *mut ::c_char, 340 buflen: ::size_t, 341 result: *mut *mut passwd) -> ::c_int; 342 #[cfg_attr(target_os = "netbsd", link_name = "__getpwent50")] getpwent() -> *mut passwd343 pub fn getpwent() -> *mut passwd; setpwent()344 pub fn setpwent(); getprogname() -> *const ::c_char345 pub fn getprogname() -> *const ::c_char; setprogname(name: *const ::c_char)346 pub fn setprogname(name: *const ::c_char); getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int347 pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int; if_nameindex() -> *mut if_nameindex348 pub fn if_nameindex() -> *mut if_nameindex; if_freenameindex(ptr: *mut if_nameindex)349 pub fn if_freenameindex(ptr: *mut if_nameindex); 350 } 351 352 cfg_if! { 353 if #[cfg(any(target_os = "macos", target_os = "ios"))] { 354 mod apple; 355 pub use self::apple::*; 356 } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd", 357 target_os = "bitrig"))] { 358 mod openbsdlike; 359 pub use self::openbsdlike::*; 360 } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { 361 mod freebsdlike; 362 pub use self::freebsdlike::*; 363 } else { 364 // Unknown target_os 365 } 366 } 367