1 pub type off_t = i64; 2 pub type useconds_t = u32; 3 pub type blkcnt_t = i64; 4 pub type socklen_t = u32; 5 pub type sa_family_t = u8; 6 pub type pthread_t = ::uintptr_t; 7 pub type nfds_t = ::c_uint; 8 pub type regoff_t = off_t; 9 10 s! { 11 pub struct sockaddr { 12 pub sa_len: u8, 13 pub sa_family: sa_family_t, 14 pub sa_data: [::c_char; 14], 15 } 16 17 pub struct sockaddr_in6 { 18 pub sin6_len: u8, 19 pub sin6_family: sa_family_t, 20 pub sin6_port: ::in_port_t, 21 pub sin6_flowinfo: u32, 22 pub sin6_addr: ::in6_addr, 23 pub sin6_scope_id: u32, 24 } 25 26 pub struct passwd { 27 pub pw_name: *mut ::c_char, 28 pub pw_passwd: *mut ::c_char, 29 pub pw_uid: ::uid_t, 30 pub pw_gid: ::gid_t, 31 pub pw_change: ::time_t, 32 pub pw_class: *mut ::c_char, 33 pub pw_gecos: *mut ::c_char, 34 pub pw_dir: *mut ::c_char, 35 pub pw_shell: *mut ::c_char, 36 pub pw_expire: ::time_t, 37 38 #[cfg(not(any(target_os = "macos", 39 target_os = "ios", 40 target_os = "tvos", 41 target_os = "watchos", 42 target_os = "netbsd", 43 target_os = "openbsd")))] 44 pub pw_fields: ::c_int, 45 } 46 47 pub struct ifaddrs { 48 pub ifa_next: *mut ifaddrs, 49 pub ifa_name: *mut ::c_char, 50 pub ifa_flags: ::c_uint, 51 pub ifa_addr: *mut ::sockaddr, 52 pub ifa_netmask: *mut ::sockaddr, 53 pub ifa_dstaddr: *mut ::sockaddr, 54 pub ifa_data: *mut ::c_void, 55 #[cfg(target_os = "netbsd")] 56 pub ifa_addrflags: ::c_uint 57 } 58 59 pub struct fd_set { 60 #[cfg(all(target_pointer_width = "64", 61 any(target_os = "freebsd", target_os = "dragonfly")))] 62 fds_bits: [i64; FD_SETSIZE / 64], 63 #[cfg(not(all(target_pointer_width = "64", 64 any(target_os = "freebsd", target_os = "dragonfly"))))] 65 fds_bits: [i32; FD_SETSIZE / 32], 66 } 67 68 pub struct tm { 69 pub tm_sec: ::c_int, 70 pub tm_min: ::c_int, 71 pub tm_hour: ::c_int, 72 pub tm_mday: ::c_int, 73 pub tm_mon: ::c_int, 74 pub tm_year: ::c_int, 75 pub tm_wday: ::c_int, 76 pub tm_yday: ::c_int, 77 pub tm_isdst: ::c_int, 78 pub tm_gmtoff: ::c_long, 79 pub tm_zone: *mut ::c_char, 80 } 81 82 pub struct msghdr { 83 pub msg_name: *mut ::c_void, 84 pub msg_namelen: ::socklen_t, 85 pub msg_iov: *mut ::iovec, 86 pub msg_iovlen: ::c_int, 87 pub msg_control: *mut ::c_void, 88 pub msg_controllen: ::socklen_t, 89 pub msg_flags: ::c_int, 90 } 91 92 pub struct cmsghdr { 93 pub cmsg_len: ::socklen_t, 94 pub cmsg_level: ::c_int, 95 pub cmsg_type: ::c_int, 96 } 97 98 pub struct fsid_t { 99 __fsid_val: [i32; 2], 100 } 101 102 pub struct if_nameindex { 103 pub if_index: ::c_uint, 104 pub if_name: *mut ::c_char, 105 } 106 107 pub struct regex_t { 108 __re_magic: ::c_int, 109 __re_nsub: ::size_t, 110 __re_endp: *const ::c_char, 111 __re_g: *mut ::c_void, 112 } 113 114 pub struct regmatch_t { 115 pub rm_so: regoff_t, 116 pub rm_eo: regoff_t, 117 } 118 } 119 120 s_no_extra_traits! { 121 pub struct sockaddr_un { 122 pub sun_len: u8, 123 pub sun_family: sa_family_t, 124 pub sun_path: [c_char; 104] 125 } 126 127 pub struct utsname { 128 #[cfg(not(target_os = "dragonfly"))] 129 pub sysname: [::c_char; 256], 130 #[cfg(target_os = "dragonfly")] 131 pub sysname: [::c_char; 32], 132 #[cfg(not(target_os = "dragonfly"))] 133 pub nodename: [::c_char; 256], 134 #[cfg(target_os = "dragonfly")] 135 pub nodename: [::c_char; 32], 136 #[cfg(not(target_os = "dragonfly"))] 137 pub release: [::c_char; 256], 138 #[cfg(target_os = "dragonfly")] 139 pub release: [::c_char; 32], 140 #[cfg(not(target_os = "dragonfly"))] 141 pub version: [::c_char; 256], 142 #[cfg(target_os = "dragonfly")] 143 pub version: [::c_char; 32], 144 #[cfg(not(target_os = "dragonfly"))] 145 pub machine: [::c_char; 256], 146 #[cfg(target_os = "dragonfly")] 147 pub machine: [::c_char; 32], 148 } 149 150 } 151 152 cfg_if! { 153 if #[cfg(feature = "extra_traits")] { 154 impl PartialEq for sockaddr_un { 155 fn eq(&self, other: &sockaddr_un) -> bool { 156 self.sun_len == other.sun_len 157 && self.sun_family == other.sun_family 158 && self 159 .sun_path 160 .iter() 161 .zip(other.sun_path.iter()) 162 .all(|(a,b)| a == b) 163 } 164 } 165 166 impl Eq for sockaddr_un {} 167 168 impl ::fmt::Debug for sockaddr_un { 169 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { 170 f.debug_struct("sockaddr_un") 171 .field("sun_len", &self.sun_len) 172 .field("sun_family", &self.sun_family) 173 // FIXME: .field("sun_path", &self.sun_path) 174 .finish() 175 } 176 } 177 178 impl ::hash::Hash for sockaddr_un { 179 fn hash<H: ::hash::Hasher>(&self, state: &mut H) { 180 self.sun_len.hash(state); 181 self.sun_family.hash(state); 182 self.sun_path.hash(state); 183 } 184 } 185 186 impl PartialEq for utsname { 187 fn eq(&self, other: &utsname) -> bool { 188 self.sysname 189 .iter() 190 .zip(other.sysname.iter()) 191 .all(|(a,b)| a == b) 192 && self 193 .nodename 194 .iter() 195 .zip(other.nodename.iter()) 196 .all(|(a,b)| a == b) 197 && self 198 .release 199 .iter() 200 .zip(other.release.iter()) 201 .all(|(a,b)| a == b) 202 && self 203 .version 204 .iter() 205 .zip(other.version.iter()) 206 .all(|(a,b)| a == b) 207 && self 208 .machine 209 .iter() 210 .zip(other.machine.iter()) 211 .all(|(a,b)| a == b) 212 } 213 } 214 215 impl Eq for utsname {} 216 217 impl ::fmt::Debug for utsname { 218 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { 219 f.debug_struct("utsname") 220 // FIXME: .field("sysname", &self.sysname) 221 // FIXME: .field("nodename", &self.nodename) 222 // FIXME: .field("release", &self.release) 223 // FIXME: .field("version", &self.version) 224 // FIXME: .field("machine", &self.machine) 225 .finish() 226 } 227 } 228 229 impl ::hash::Hash for utsname { 230 fn hash<H: ::hash::Hasher>(&self, state: &mut H) { 231 self.sysname.hash(state); 232 self.nodename.hash(state); 233 self.release.hash(state); 234 self.version.hash(state); 235 self.machine.hash(state); 236 } 237 } 238 } 239 } 240 241 pub const LC_ALL: ::c_int = 0; 242 pub const LC_COLLATE: ::c_int = 1; 243 pub const LC_CTYPE: ::c_int = 2; 244 pub const LC_MONETARY: ::c_int = 3; 245 pub const LC_NUMERIC: ::c_int = 4; 246 pub const LC_TIME: ::c_int = 5; 247 pub const LC_MESSAGES: ::c_int = 6; 248 249 pub const FIOCLEX: ::c_ulong = 0x20006601; 250 pub const FIONCLEX: ::c_ulong = 0x20006602; 251 pub const FIONREAD: ::c_ulong = 0x4004667f; 252 pub const FIONBIO: ::c_ulong = 0x8004667e; 253 pub const FIOASYNC: ::c_ulong = 0x8004667d; 254 pub const FIOSETOWN: ::c_ulong = 0x8004667c; 255 pub const FIOGETOWN: ::c_ulong = 0x4004667b; 256 257 pub const PATH_MAX: ::c_int = 1024; 258 pub const MAXPATHLEN: ::c_int = PATH_MAX; 259 260 pub const IOV_MAX: ::c_int = 1024; 261 262 pub const SA_ONSTACK: ::c_int = 0x0001; 263 pub const SA_SIGINFO: ::c_int = 0x0040; 264 pub const SA_RESTART: ::c_int = 0x0002; 265 pub const SA_RESETHAND: ::c_int = 0x0004; 266 pub const SA_NOCLDSTOP: ::c_int = 0x0008; 267 pub const SA_NODEFER: ::c_int = 0x0010; 268 pub const SA_NOCLDWAIT: ::c_int = 0x0020; 269 270 pub const SS_ONSTACK: ::c_int = 1; 271 pub const SS_DISABLE: ::c_int = 4; 272 273 pub const SIGCHLD: ::c_int = 20; 274 pub const SIGBUS: ::c_int = 10; 275 pub const SIGUSR1: ::c_int = 30; 276 pub const SIGUSR2: ::c_int = 31; 277 pub const SIGCONT: ::c_int = 19; 278 pub const SIGSTOP: ::c_int = 17; 279 pub const SIGTSTP: ::c_int = 18; 280 pub const SIGURG: ::c_int = 16; 281 pub const SIGIO: ::c_int = 23; 282 pub const SIGSYS: ::c_int = 12; 283 pub const SIGTTIN: ::c_int = 21; 284 pub const SIGTTOU: ::c_int = 22; 285 pub const SIGXCPU: ::c_int = 24; 286 pub const SIGXFSZ: ::c_int = 25; 287 pub const SIGVTALRM: ::c_int = 26; 288 pub const SIGPROF: ::c_int = 27; 289 pub const SIGWINCH: ::c_int = 28; 290 pub const SIGINFO: ::c_int = 29; 291 292 pub const SIG_SETMASK: ::c_int = 3; 293 pub const SIG_BLOCK: ::c_int = 0x1; 294 pub const SIG_UNBLOCK: ::c_int = 0x2; 295 296 pub const IP_TOS: ::c_int = 3; 297 pub const IP_MULTICAST_IF: ::c_int = 9; 298 pub const IP_MULTICAST_TTL: ::c_int = 10; 299 pub const IP_MULTICAST_LOOP: ::c_int = 11; 300 301 pub const IPV6_UNICAST_HOPS: ::c_int = 4; 302 pub const IPV6_MULTICAST_IF: ::c_int = 9; 303 pub const IPV6_MULTICAST_HOPS: ::c_int = 10; 304 pub const IPV6_MULTICAST_LOOP: ::c_int = 11; 305 pub const IPV6_V6ONLY: ::c_int = 27; 306 307 pub const IPTOS_ECN_NOTECT: u8 = 0x00; 308 pub const IPTOS_ECN_MASK: u8 = 0x03; 309 pub const IPTOS_ECN_ECT1: u8 = 0x01; 310 pub const IPTOS_ECN_ECT0: u8 = 0x02; 311 pub const IPTOS_ECN_CE: u8 = 0x03; 312 313 pub const ST_RDONLY: ::c_ulong = 1; 314 315 pub const SCM_RIGHTS: ::c_int = 0x01; 316 317 pub const NCCS: usize = 20; 318 319 pub const O_ACCMODE: ::c_int = 0x3; 320 pub const O_RDONLY: ::c_int = 0; 321 pub const O_WRONLY: ::c_int = 1; 322 pub const O_RDWR: ::c_int = 2; 323 pub const O_APPEND: ::c_int = 8; 324 pub const O_CREAT: ::c_int = 512; 325 pub const O_TRUNC: ::c_int = 1024; 326 pub const O_EXCL: ::c_int = 2048; 327 pub const O_ASYNC: ::c_int = 0x40; 328 pub const O_SYNC: ::c_int = 0x80; 329 pub const O_NONBLOCK: ::c_int = 0x4; 330 pub const O_NOFOLLOW: ::c_int = 0x100; 331 pub const O_SHLOCK: ::c_int = 0x10; 332 pub const O_EXLOCK: ::c_int = 0x20; 333 pub const O_FSYNC: ::c_int = O_SYNC; 334 pub const O_NDELAY: ::c_int = O_NONBLOCK; 335 336 pub const F_GETOWN: ::c_int = 5; 337 pub const F_SETOWN: ::c_int = 6; 338 339 pub const F_RDLCK: ::c_short = 1; 340 pub const F_UNLCK: ::c_short = 2; 341 pub const F_WRLCK: ::c_short = 3; 342 343 pub const MNT_RDONLY: ::c_int = 0x00000001; 344 pub const MNT_SYNCHRONOUS: ::c_int = 0x00000002; 345 pub const MNT_NOEXEC: ::c_int = 0x00000004; 346 pub const MNT_NOSUID: ::c_int = 0x00000008; 347 pub const MNT_ASYNC: ::c_int = 0x00000040; 348 pub const MNT_EXPORTED: ::c_int = 0x00000100; 349 pub const MNT_UPDATE: ::c_int = 0x00010000; 350 pub const MNT_RELOAD: ::c_int = 0x00040000; 351 pub const MNT_FORCE: ::c_int = 0x00080000; 352 353 pub const Q_SYNC: ::c_int = 0x600; 354 pub const Q_QUOTAON: ::c_int = 0x100; 355 pub const Q_QUOTAOFF: ::c_int = 0x200; 356 357 pub const TCIOFF: ::c_int = 3; 358 pub const TCION: ::c_int = 4; 359 pub const TCOOFF: ::c_int = 1; 360 pub const TCOON: ::c_int = 2; 361 pub const TCIFLUSH: ::c_int = 1; 362 pub const TCOFLUSH: ::c_int = 2; 363 pub const TCIOFLUSH: ::c_int = 3; 364 pub const TCSANOW: ::c_int = 0; 365 pub const TCSADRAIN: ::c_int = 1; 366 pub const TCSAFLUSH: ::c_int = 2; 367 pub const VEOF: usize = 0; 368 pub const VEOL: usize = 1; 369 pub const VEOL2: usize = 2; 370 pub const VERASE: usize = 3; 371 pub const VWERASE: usize = 4; 372 pub const VKILL: usize = 5; 373 pub const VREPRINT: usize = 6; 374 pub const VINTR: usize = 8; 375 pub const VQUIT: usize = 9; 376 pub const VSUSP: usize = 10; 377 pub const VDSUSP: usize = 11; 378 pub const VSTART: usize = 12; 379 pub const VSTOP: usize = 13; 380 pub const VLNEXT: usize = 14; 381 pub const VDISCARD: usize = 15; 382 pub const VMIN: usize = 16; 383 pub const VTIME: usize = 17; 384 pub const VSTATUS: usize = 18; 385 pub const _POSIX_VDISABLE: ::cc_t = 0xff; 386 pub const IGNBRK: ::tcflag_t = 0x00000001; 387 pub const BRKINT: ::tcflag_t = 0x00000002; 388 pub const IGNPAR: ::tcflag_t = 0x00000004; 389 pub const PARMRK: ::tcflag_t = 0x00000008; 390 pub const INPCK: ::tcflag_t = 0x00000010; 391 pub const ISTRIP: ::tcflag_t = 0x00000020; 392 pub const INLCR: ::tcflag_t = 0x00000040; 393 pub const IGNCR: ::tcflag_t = 0x00000080; 394 pub const ICRNL: ::tcflag_t = 0x00000100; 395 pub const IXON: ::tcflag_t = 0x00000200; 396 pub const IXOFF: ::tcflag_t = 0x00000400; 397 pub const IXANY: ::tcflag_t = 0x00000800; 398 pub const IMAXBEL: ::tcflag_t = 0x00002000; 399 pub const OPOST: ::tcflag_t = 0x1; 400 pub const ONLCR: ::tcflag_t = 0x2; 401 pub const OXTABS: ::tcflag_t = 0x4; 402 pub const ONOEOT: ::tcflag_t = 0x8; 403 pub const CIGNORE: ::tcflag_t = 0x00000001; 404 pub const CSIZE: ::tcflag_t = 0x00000300; 405 pub const CS5: ::tcflag_t = 0x00000000; 406 pub const CS6: ::tcflag_t = 0x00000100; 407 pub const CS7: ::tcflag_t = 0x00000200; 408 pub const CS8: ::tcflag_t = 0x00000300; 409 pub const CSTOPB: ::tcflag_t = 0x00000400; 410 pub const CREAD: ::tcflag_t = 0x00000800; 411 pub const PARENB: ::tcflag_t = 0x00001000; 412 pub const PARODD: ::tcflag_t = 0x00002000; 413 pub const HUPCL: ::tcflag_t = 0x00004000; 414 pub const CLOCAL: ::tcflag_t = 0x00008000; 415 pub const ECHOKE: ::tcflag_t = 0x00000001; 416 pub const ECHOE: ::tcflag_t = 0x00000002; 417 pub const ECHOK: ::tcflag_t = 0x00000004; 418 pub const ECHO: ::tcflag_t = 0x00000008; 419 pub const ECHONL: ::tcflag_t = 0x00000010; 420 pub const ECHOPRT: ::tcflag_t = 0x00000020; 421 pub const ECHOCTL: ::tcflag_t = 0x00000040; 422 pub const ISIG: ::tcflag_t = 0x00000080; 423 pub const ICANON: ::tcflag_t = 0x00000100; 424 pub const ALTWERASE: ::tcflag_t = 0x00000200; 425 pub const IEXTEN: ::tcflag_t = 0x00000400; 426 pub const EXTPROC: ::tcflag_t = 0x00000800; 427 pub const TOSTOP: ::tcflag_t = 0x00400000; 428 pub const FLUSHO: ::tcflag_t = 0x00800000; 429 pub const NOKERNINFO: ::tcflag_t = 0x02000000; 430 pub const PENDIN: ::tcflag_t = 0x20000000; 431 pub const NOFLSH: ::tcflag_t = 0x80000000; 432 pub const MDMBUF: ::tcflag_t = 0x00100000; 433 434 pub const WNOHANG: ::c_int = 0x00000001; 435 pub const WUNTRACED: ::c_int = 0x00000002; 436 437 pub const RTLD_LAZY: ::c_int = 0x1; 438 pub const RTLD_NOW: ::c_int = 0x2; 439 pub const RTLD_NEXT: *mut ::c_void = -1isize as *mut ::c_void; 440 pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void; 441 pub const RTLD_SELF: *mut ::c_void = -3isize as *mut ::c_void; 442 443 pub const LOG_CRON: ::c_int = 9 << 3; 444 pub const LOG_AUTHPRIV: ::c_int = 10 << 3; 445 pub const LOG_FTP: ::c_int = 11 << 3; 446 pub const LOG_PERROR: ::c_int = 0x20; 447 448 pub const TCP_NODELAY: ::c_int = 1; 449 pub const TCP_MAXSEG: ::c_int = 2; 450 451 pub const PIPE_BUF: usize = 512; 452 453 // si_code values for SIGBUS signal 454 pub const BUS_ADRALN: ::c_int = 1; 455 pub const BUS_ADRERR: ::c_int = 2; 456 pub const BUS_OBJERR: ::c_int = 3; 457 458 // si_code values for SIGCHLD signal 459 pub const CLD_EXITED: ::c_int = 1; 460 pub const CLD_KILLED: ::c_int = 2; 461 pub const CLD_DUMPED: ::c_int = 3; 462 pub const CLD_TRAPPED: ::c_int = 4; 463 pub const CLD_STOPPED: ::c_int = 5; 464 pub const CLD_CONTINUED: ::c_int = 6; 465 466 pub const POLLIN: ::c_short = 0x1; 467 pub const POLLPRI: ::c_short = 0x2; 468 pub const POLLOUT: ::c_short = 0x4; 469 pub const POLLERR: ::c_short = 0x8; 470 pub const POLLHUP: ::c_short = 0x10; 471 pub const POLLNVAL: ::c_short = 0x20; 472 pub const POLLRDNORM: ::c_short = 0x040; 473 pub const POLLWRNORM: ::c_short = 0x004; 474 pub const POLLRDBAND: ::c_short = 0x080; 475 pub const POLLWRBAND: ::c_short = 0x100; 476 477 pub const BIOCGBLEN: ::c_ulong = 0x40044266; 478 pub const BIOCSBLEN: ::c_ulong = 0xc0044266; 479 pub const BIOCFLUSH: ::c_uint = 0x20004268; 480 pub const BIOCPROMISC: ::c_uint = 0x20004269; 481 pub const BIOCGDLT: ::c_ulong = 0x4004426a; 482 pub const BIOCGETIF: ::c_ulong = 0x4020426b; 483 pub const BIOCSETIF: ::c_ulong = 0x8020426c; 484 pub const BIOCGSTATS: ::c_ulong = 0x4008426f; 485 pub const BIOCIMMEDIATE: ::c_ulong = 0x80044270; 486 pub const BIOCVERSION: ::c_ulong = 0x40044271; 487 pub const BIOCGHDRCMPLT: ::c_ulong = 0x40044274; 488 pub const BIOCSHDRCMPLT: ::c_ulong = 0x80044275; 489 pub const SIOCGIFADDR: ::c_ulong = 0xc0206921; 490 491 pub const REG_BASIC: ::c_int = 0o0000; 492 pub const REG_EXTENDED: ::c_int = 0o0001; 493 pub const REG_ICASE: ::c_int = 0o0002; 494 pub const REG_NOSUB: ::c_int = 0o0004; 495 pub const REG_NEWLINE: ::c_int = 0o0010; 496 pub const REG_NOSPEC: ::c_int = 0o0020; 497 pub const REG_PEND: ::c_int = 0o0040; 498 pub const REG_DUMP: ::c_int = 0o0200; 499 500 pub const REG_NOMATCH: ::c_int = 1; 501 pub const REG_BADPAT: ::c_int = 2; 502 pub const REG_ECOLLATE: ::c_int = 3; 503 pub const REG_ECTYPE: ::c_int = 4; 504 pub const REG_EESCAPE: ::c_int = 5; 505 pub const REG_ESUBREG: ::c_int = 6; 506 pub const REG_EBRACK: ::c_int = 7; 507 pub const REG_EPAREN: ::c_int = 8; 508 pub const REG_EBRACE: ::c_int = 9; 509 pub const REG_BADBR: ::c_int = 10; 510 pub const REG_ERANGE: ::c_int = 11; 511 pub const REG_ESPACE: ::c_int = 12; 512 pub const REG_BADRPT: ::c_int = 13; 513 pub const REG_EMPTY: ::c_int = 14; 514 pub const REG_ASSERT: ::c_int = 15; 515 pub const REG_INVARG: ::c_int = 16; 516 pub const REG_ATOI: ::c_int = 255; 517 pub const REG_ITOA: ::c_int = 0o0400; 518 519 pub const REG_NOTBOL: ::c_int = 0o00001; 520 pub const REG_NOTEOL: ::c_int = 0o00002; 521 pub const REG_STARTEND: ::c_int = 0o00004; 522 pub const REG_TRACE: ::c_int = 0o00400; 523 pub const REG_LARGE: ::c_int = 0o01000; 524 pub const REG_BACKR: ::c_int = 0o02000; 525 526 pub const TIOCCBRK: ::c_uint = 0x2000747a; 527 pub const TIOCSBRK: ::c_uint = 0x2000747b; 528 529 pub const PRIO_PROCESS: ::c_int = 0; 530 pub const PRIO_PGRP: ::c_int = 1; 531 pub const PRIO_USER: ::c_int = 2; 532 533 pub const ITIMER_REAL: ::c_int = 0; 534 pub const ITIMER_VIRTUAL: ::c_int = 1; 535 pub const ITIMER_PROF: ::c_int = 2; 536 537 f! { 538 pub fn CMSG_FIRSTHDR(mhdr: *const ::msghdr) -> *mut ::cmsghdr { 539 if (*mhdr).msg_controllen as usize >= ::mem::size_of::<::cmsghdr>() { 540 (*mhdr).msg_control as *mut ::cmsghdr 541 } else { 542 0 as *mut ::cmsghdr 543 } 544 } 545 546 pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { 547 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 548 let fd = fd as usize; 549 (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); 550 return 551 } 552 553 pub fn FD_ISSET(fd: ::c_int, set: *const fd_set) -> bool { 554 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 555 let fd = fd as usize; 556 return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 557 } 558 559 pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { 560 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 561 let fd = fd as usize; 562 (*set).fds_bits[fd / bits] |= 1 << (fd % bits); 563 return 564 } 565 566 pub fn FD_ZERO(set: *mut fd_set) -> () { 567 for slot in (*set).fds_bits.iter_mut() { 568 *slot = 0; 569 } 570 } 571 } 572 573 safe_f! { 574 pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int { 575 status & 0o177 576 } 577 578 pub {const} fn WIFEXITED(status: ::c_int) -> bool { 579 (status & 0o177) == 0 580 } 581 582 pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int { 583 status >> 8 584 } 585 586 pub {const} fn WCOREDUMP(status: ::c_int) -> bool { 587 (status & 0o200) != 0 588 } 589 590 pub {const} fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { 591 (cmd << 8) | (type_ & 0x00ff) 592 } 593 } 594 595 extern "C" { 596 #[cfg_attr( 597 all(target_os = "macos", target_arch = "x86"), 598 link_name = "getrlimit$UNIX2003" 599 )] 600 pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; 601 #[cfg_attr( 602 all(target_os = "macos", target_arch = "x86"), 603 link_name = "setrlimit$UNIX2003" 604 )] 605 pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; 606 607 pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int; 608 pub fn abs(i: ::c_int) -> ::c_int; 609 pub fn atof(s: *const ::c_char) -> ::c_double; 610 pub fn labs(i: ::c_long) -> ::c_long; 611 #[cfg_attr( 612 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), 613 link_name = "rand@FBSD_1.0" 614 )] 615 pub fn rand() -> ::c_int; 616 #[cfg_attr( 617 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), 618 link_name = "srand@FBSD_1.0" 619 )] 620 pub fn srand(seed: ::c_uint); 621 622 pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; 623 pub fn freeifaddrs(ifa: *mut ::ifaddrs); 624 pub fn setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int; 625 pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; 626 pub fn kqueue() -> ::c_int; 627 pub fn unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int; 628 pub fn syscall(num: ::c_int, ...) -> ::c_int; 629 #[cfg_attr(target_os = "netbsd", link_name = "__getpwent50")] 630 pub fn getpwent() -> *mut passwd; 631 pub fn setpwent(); 632 pub fn endpwent(); 633 pub fn endgrent(); 634 pub fn getgrent() -> *mut ::group; 635 636 pub fn getprogname() -> *const ::c_char; 637 pub fn setprogname(name: *const ::c_char); 638 pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int; 639 pub fn if_nameindex() -> *mut if_nameindex; 640 pub fn if_freenameindex(ptr: *mut if_nameindex); 641 642 pub fn getpeereid(socket: ::c_int, euid: *mut ::uid_t, egid: *mut ::gid_t) -> ::c_int; 643 644 #[cfg_attr( 645 all(target_os = "macos", not(target_arch = "aarch64")), 646 link_name = "glob$INODE64" 647 )] 648 #[cfg_attr(target_os = "netbsd", link_name = "__glob30")] 649 #[cfg_attr( 650 all(target_os = "freebsd", any(freebsd11, freebsd10)), 651 link_name = "glob@FBSD_1.0" 652 )] 653 pub fn glob( 654 pattern: *const ::c_char, 655 flags: ::c_int, 656 errfunc: ::Option<extern "C" fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int>, 657 pglob: *mut ::glob_t, 658 ) -> ::c_int; 659 #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")] 660 #[cfg_attr( 661 all(target_os = "freebsd", any(freebsd11, freebsd10)), 662 link_name = "globfree@FBSD_1.0" 663 )] 664 pub fn globfree(pglob: *mut ::glob_t); 665 666 pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int; 667 668 pub fn shm_unlink(name: *const ::c_char) -> ::c_int; 669 670 #[cfg_attr( 671 all(target_os = "macos", target_arch = "x86_64"), 672 link_name = "seekdir$INODE64" 673 )] 674 #[cfg_attr( 675 all(target_os = "macos", target_arch = "x86"), 676 link_name = "seekdir$INODE64$UNIX2003" 677 )] 678 pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); 679 680 #[cfg_attr( 681 all(target_os = "macos", target_arch = "x86_64"), 682 link_name = "telldir$INODE64" 683 )] 684 #[cfg_attr( 685 all(target_os = "macos", target_arch = "x86"), 686 link_name = "telldir$INODE64$UNIX2003" 687 )] 688 pub fn telldir(dirp: *mut ::DIR) -> ::c_long; 689 pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int; 690 691 #[cfg_attr( 692 all(target_os = "macos", target_arch = "x86"), 693 link_name = "msync$UNIX2003" 694 )] 695 #[cfg_attr(target_os = "netbsd", link_name = "__msync13")] 696 pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int; 697 698 #[cfg_attr( 699 all(target_os = "macos", target_arch = "x86"), 700 link_name = "recvfrom$UNIX2003" 701 )] 702 pub fn recvfrom( 703 socket: ::c_int, 704 buf: *mut ::c_void, 705 len: ::size_t, 706 flags: ::c_int, 707 addr: *mut ::sockaddr, 708 addrlen: *mut ::socklen_t, 709 ) -> ::ssize_t; 710 pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; 711 #[cfg_attr(target_os = "netbsd", link_name = "__futimes50")] 712 pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; 713 pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; 714 715 #[cfg_attr( 716 all(target_os = "macos", target_arch = "x86"), 717 link_name = "bind$UNIX2003" 718 )] 719 pub fn bind(socket: ::c_int, address: *const ::sockaddr, address_len: ::socklen_t) -> ::c_int; 720 721 #[cfg_attr( 722 all(target_os = "macos", target_arch = "x86"), 723 link_name = "writev$UNIX2003" 724 )] 725 pub fn writev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; 726 #[cfg_attr( 727 all(target_os = "macos", target_arch = "x86"), 728 link_name = "readv$UNIX2003" 729 )] 730 pub fn readv(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; 731 732 #[cfg_attr( 733 all(target_os = "macos", target_arch = "x86"), 734 link_name = "sendmsg$UNIX2003" 735 )] 736 pub fn sendmsg(fd: ::c_int, msg: *const ::msghdr, flags: ::c_int) -> ::ssize_t; 737 #[cfg_attr( 738 all(target_os = "macos", target_arch = "x86"), 739 link_name = "recvmsg$UNIX2003" 740 )] 741 pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::ssize_t; 742 743 pub fn sync(); 744 pub fn getgrgid_r( 745 gid: ::gid_t, 746 grp: *mut ::group, 747 buf: *mut ::c_char, 748 buflen: ::size_t, 749 result: *mut *mut ::group, 750 ) -> ::c_int; 751 #[cfg_attr( 752 all(target_os = "macos", target_arch = "x86"), 753 link_name = "sigaltstack$UNIX2003" 754 )] 755 #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] 756 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; 757 pub fn sem_close(sem: *mut sem_t) -> ::c_int; 758 pub fn getdtablesize() -> ::c_int; 759 pub fn getgrnam_r( 760 name: *const ::c_char, 761 grp: *mut ::group, 762 buf: *mut ::c_char, 763 buflen: ::size_t, 764 result: *mut *mut ::group, 765 ) -> ::c_int; 766 #[cfg_attr( 767 all(target_os = "macos", target_arch = "x86"), 768 link_name = "pthread_sigmask$UNIX2003" 769 )] 770 pub fn pthread_sigmask(how: ::c_int, set: *const sigset_t, oldset: *mut sigset_t) -> ::c_int; 771 pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; 772 pub fn getgrnam(name: *const ::c_char) -> *mut ::group; 773 #[cfg_attr( 774 all(target_os = "macos", target_arch = "x86"), 775 link_name = "pthread_cancel$UNIX2003" 776 )] 777 pub fn pthread_cancel(thread: ::pthread_t) -> ::c_int; 778 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; 779 pub fn sched_get_priority_min(policy: ::c_int) -> ::c_int; 780 pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int; 781 pub fn sem_unlink(name: *const ::c_char) -> ::c_int; 782 #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")] 783 pub fn getpwnam_r( 784 name: *const ::c_char, 785 pwd: *mut passwd, 786 buf: *mut ::c_char, 787 buflen: ::size_t, 788 result: *mut *mut passwd, 789 ) -> ::c_int; 790 #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] 791 pub fn getpwuid_r( 792 uid: ::uid_t, 793 pwd: *mut passwd, 794 buf: *mut ::c_char, 795 buflen: ::size_t, 796 result: *mut *mut passwd, 797 ) -> ::c_int; 798 #[cfg_attr( 799 all(target_os = "macos", target_arch = "x86"), 800 link_name = "sigwait$UNIX2003" 801 )] 802 pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; 803 pub fn pthread_atfork( 804 prepare: ::Option<unsafe extern "C" fn()>, 805 parent: ::Option<unsafe extern "C" fn()>, 806 child: ::Option<unsafe extern "C" fn()>, 807 ) -> ::c_int; 808 pub fn getgrgid(gid: ::gid_t) -> *mut ::group; 809 #[cfg_attr( 810 all(target_os = "macos", target_arch = "x86"), 811 link_name = "popen$UNIX2003" 812 )] 813 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; 814 pub fn faccessat( 815 dirfd: ::c_int, 816 pathname: *const ::c_char, 817 mode: ::c_int, 818 flags: ::c_int, 819 ) -> ::c_int; 820 pub fn pthread_create( 821 native: *mut ::pthread_t, 822 attr: *const ::pthread_attr_t, 823 f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, 824 value: *mut ::c_void, 825 ) -> ::c_int; 826 pub fn acct(filename: *const ::c_char) -> ::c_int; 827 #[cfg_attr( 828 all(target_os = "macos", target_arch = "x86"), 829 link_name = "wait4$UNIX2003" 830 )] 831 #[cfg_attr( 832 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), 833 link_name = "wait4@FBSD_1.0" 834 )] 835 pub fn wait4( 836 pid: ::pid_t, 837 status: *mut ::c_int, 838 options: ::c_int, 839 rusage: *mut ::rusage, 840 ) -> ::pid_t; 841 #[cfg_attr( 842 all(target_os = "macos", target_arch = "x86"), 843 link_name = "getitimer$UNIX2003" 844 )] 845 pub fn getitimer(which: ::c_int, curr_value: *mut ::itimerval) -> ::c_int; 846 #[cfg_attr( 847 all(target_os = "macos", target_arch = "x86"), 848 link_name = "setitimer$UNIX2003" 849 )] 850 pub fn setitimer( 851 which: ::c_int, 852 new_value: *const ::itimerval, 853 old_value: *mut ::itimerval, 854 ) -> ::c_int; 855 856 pub fn regcomp(preg: *mut regex_t, pattern: *const ::c_char, cflags: ::c_int) -> ::c_int; 857 858 pub fn regexec( 859 preg: *const regex_t, 860 input: *const ::c_char, 861 nmatch: ::size_t, 862 pmatch: *mut regmatch_t, 863 eflags: ::c_int, 864 ) -> ::c_int; 865 866 pub fn regerror( 867 errcode: ::c_int, 868 preg: *const regex_t, 869 errbuf: *mut ::c_char, 870 errbuf_size: ::size_t, 871 ) -> ::size_t; 872 873 pub fn regfree(preg: *mut regex_t); 874 875 pub fn arc4random() -> u32; 876 pub fn arc4random_buf(buf: *mut ::c_void, size: ::size_t); 877 pub fn arc4random_uniform(l: u32) -> u32; 878 879 pub fn drand48() -> ::c_double; 880 pub fn erand48(xseed: *mut ::c_ushort) -> ::c_double; 881 pub fn lrand48() -> ::c_long; 882 pub fn nrand48(xseed: *mut ::c_ushort) -> ::c_long; 883 pub fn mrand48() -> ::c_long; 884 pub fn jrand48(xseed: *mut ::c_ushort) -> ::c_long; 885 pub fn srand48(seed: ::c_long); 886 pub fn seed48(xseed: *mut ::c_ushort) -> *mut ::c_ushort; 887 pub fn lcong48(p: *mut ::c_ushort); 888 } 889 890 cfg_if! { 891 if #[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))] { 892 mod apple; 893 pub use self::apple::*; 894 } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] { 895 mod netbsdlike; 896 pub use self::netbsdlike::*; 897 } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { 898 mod freebsdlike; 899 pub use self::freebsdlike::*; 900 } else { 901 // Unknown target_os 902 } 903 } 904