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