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 257 pub const IOV_MAX: ::c_int = 1024; 258 259 pub const SA_ONSTACK: ::c_int = 0x0001; 260 pub const SA_SIGINFO: ::c_int = 0x0040; 261 pub const SA_RESTART: ::c_int = 0x0002; 262 pub const SA_RESETHAND: ::c_int = 0x0004; 263 pub const SA_NOCLDSTOP: ::c_int = 0x0008; 264 pub const SA_NODEFER: ::c_int = 0x0010; 265 pub const SA_NOCLDWAIT: ::c_int = 0x0020; 266 267 pub const SS_ONSTACK: ::c_int = 1; 268 pub const SS_DISABLE: ::c_int = 4; 269 270 pub const SIGCHLD: ::c_int = 20; 271 pub const SIGBUS: ::c_int = 10; 272 pub const SIGUSR1: ::c_int = 30; 273 pub const SIGUSR2: ::c_int = 31; 274 pub const SIGCONT: ::c_int = 19; 275 pub const SIGSTOP: ::c_int = 17; 276 pub const SIGTSTP: ::c_int = 18; 277 pub const SIGURG: ::c_int = 16; 278 pub const SIGIO: ::c_int = 23; 279 pub const SIGSYS: ::c_int = 12; 280 pub const SIGTTIN: ::c_int = 21; 281 pub const SIGTTOU: ::c_int = 22; 282 pub const SIGXCPU: ::c_int = 24; 283 pub const SIGXFSZ: ::c_int = 25; 284 pub const SIGVTALRM: ::c_int = 26; 285 pub const SIGPROF: ::c_int = 27; 286 pub const SIGWINCH: ::c_int = 28; 287 pub const SIGINFO: ::c_int = 29; 288 289 pub const SIG_SETMASK: ::c_int = 3; 290 pub const SIG_BLOCK: ::c_int = 0x1; 291 pub const SIG_UNBLOCK: ::c_int = 0x2; 292 293 pub const IP_TOS: ::c_int = 3; 294 pub const IP_MULTICAST_IF: ::c_int = 9; 295 pub const IP_MULTICAST_TTL: ::c_int = 10; 296 pub const IP_MULTICAST_LOOP: ::c_int = 11; 297 298 pub const IPV6_UNICAST_HOPS: ::c_int = 4; 299 pub const IPV6_MULTICAST_IF: ::c_int = 9; 300 pub const IPV6_MULTICAST_HOPS: ::c_int = 10; 301 pub const IPV6_MULTICAST_LOOP: ::c_int = 11; 302 pub const IPV6_V6ONLY: ::c_int = 27; 303 304 pub const IPTOS_ECN_NOTECT: u8 = 0x00; 305 pub const IPTOS_ECN_MASK: u8 = 0x03; 306 pub const IPTOS_ECN_ECT1: u8 = 0x01; 307 pub const IPTOS_ECN_ECT0: u8 = 0x02; 308 pub const IPTOS_ECN_CE: u8 = 0x03; 309 310 pub const ST_RDONLY: ::c_ulong = 1; 311 312 pub const SCM_RIGHTS: ::c_int = 0x01; 313 314 pub const NCCS: usize = 20; 315 316 pub const O_ACCMODE: ::c_int = 0x3; 317 pub const O_RDONLY: ::c_int = 0; 318 pub const O_WRONLY: ::c_int = 1; 319 pub const O_RDWR: ::c_int = 2; 320 pub const O_APPEND: ::c_int = 8; 321 pub const O_CREAT: ::c_int = 512; 322 pub const O_TRUNC: ::c_int = 1024; 323 pub const O_EXCL: ::c_int = 2048; 324 pub const O_ASYNC: ::c_int = 0x40; 325 pub const O_SYNC: ::c_int = 0x80; 326 pub const O_NONBLOCK: ::c_int = 0x4; 327 pub const O_NOFOLLOW: ::c_int = 0x100; 328 pub const O_SHLOCK: ::c_int = 0x10; 329 pub const O_EXLOCK: ::c_int = 0x20; 330 pub const O_FSYNC: ::c_int = O_SYNC; 331 pub const O_NDELAY: ::c_int = O_NONBLOCK; 332 333 pub const F_GETOWN: ::c_int = 5; 334 pub const F_SETOWN: ::c_int = 6; 335 336 pub const F_RDLCK: ::c_short = 1; 337 pub const F_UNLCK: ::c_short = 2; 338 pub const F_WRLCK: ::c_short = 3; 339 340 pub const MNT_RDONLY: ::c_int = 0x00000001; 341 pub const MNT_SYNCHRONOUS: ::c_int = 0x00000002; 342 pub const MNT_NOEXEC: ::c_int = 0x00000004; 343 pub const MNT_NOSUID: ::c_int = 0x00000008; 344 pub const MNT_ASYNC: ::c_int = 0x00000040; 345 pub const MNT_EXPORTED: ::c_int = 0x00000100; 346 pub const MNT_UPDATE: ::c_int = 0x00010000; 347 pub const MNT_RELOAD: ::c_int = 0x00040000; 348 pub const MNT_FORCE: ::c_int = 0x00080000; 349 350 pub const Q_SYNC: ::c_int = 0x600; 351 pub const Q_QUOTAON: ::c_int = 0x100; 352 pub const Q_QUOTAOFF: ::c_int = 0x200; 353 354 pub const TCIOFF: ::c_int = 3; 355 pub const TCION: ::c_int = 4; 356 pub const TCOOFF: ::c_int = 1; 357 pub const TCOON: ::c_int = 2; 358 pub const TCIFLUSH: ::c_int = 1; 359 pub const TCOFLUSH: ::c_int = 2; 360 pub const TCIOFLUSH: ::c_int = 3; 361 pub const TCSANOW: ::c_int = 0; 362 pub const TCSADRAIN: ::c_int = 1; 363 pub const TCSAFLUSH: ::c_int = 2; 364 pub const VEOF: usize = 0; 365 pub const VEOL: usize = 1; 366 pub const VEOL2: usize = 2; 367 pub const VERASE: usize = 3; 368 pub const VWERASE: usize = 4; 369 pub const VKILL: usize = 5; 370 pub const VREPRINT: usize = 6; 371 pub const VINTR: usize = 8; 372 pub const VQUIT: usize = 9; 373 pub const VSUSP: usize = 10; 374 pub const VDSUSP: usize = 11; 375 pub const VSTART: usize = 12; 376 pub const VSTOP: usize = 13; 377 pub const VLNEXT: usize = 14; 378 pub const VDISCARD: usize = 15; 379 pub const VMIN: usize = 16; 380 pub const VTIME: usize = 17; 381 pub const VSTATUS: usize = 18; 382 pub const _POSIX_VDISABLE: ::cc_t = 0xff; 383 pub const IGNBRK: ::tcflag_t = 0x00000001; 384 pub const BRKINT: ::tcflag_t = 0x00000002; 385 pub const IGNPAR: ::tcflag_t = 0x00000004; 386 pub const PARMRK: ::tcflag_t = 0x00000008; 387 pub const INPCK: ::tcflag_t = 0x00000010; 388 pub const ISTRIP: ::tcflag_t = 0x00000020; 389 pub const INLCR: ::tcflag_t = 0x00000040; 390 pub const IGNCR: ::tcflag_t = 0x00000080; 391 pub const ICRNL: ::tcflag_t = 0x00000100; 392 pub const IXON: ::tcflag_t = 0x00000200; 393 pub const IXOFF: ::tcflag_t = 0x00000400; 394 pub const IXANY: ::tcflag_t = 0x00000800; 395 pub const IMAXBEL: ::tcflag_t = 0x00002000; 396 pub const OPOST: ::tcflag_t = 0x1; 397 pub const ONLCR: ::tcflag_t = 0x2; 398 pub const OXTABS: ::tcflag_t = 0x4; 399 pub const ONOEOT: ::tcflag_t = 0x8; 400 pub const CIGNORE: ::tcflag_t = 0x00000001; 401 pub const CSIZE: ::tcflag_t = 0x00000300; 402 pub const CS5: ::tcflag_t = 0x00000000; 403 pub const CS6: ::tcflag_t = 0x00000100; 404 pub const CS7: ::tcflag_t = 0x00000200; 405 pub const CS8: ::tcflag_t = 0x00000300; 406 pub const CSTOPB: ::tcflag_t = 0x00000400; 407 pub const CREAD: ::tcflag_t = 0x00000800; 408 pub const PARENB: ::tcflag_t = 0x00001000; 409 pub const PARODD: ::tcflag_t = 0x00002000; 410 pub const HUPCL: ::tcflag_t = 0x00004000; 411 pub const CLOCAL: ::tcflag_t = 0x00008000; 412 pub const ECHOKE: ::tcflag_t = 0x00000001; 413 pub const ECHOE: ::tcflag_t = 0x00000002; 414 pub const ECHOK: ::tcflag_t = 0x00000004; 415 pub const ECHO: ::tcflag_t = 0x00000008; 416 pub const ECHONL: ::tcflag_t = 0x00000010; 417 pub const ECHOPRT: ::tcflag_t = 0x00000020; 418 pub const ECHOCTL: ::tcflag_t = 0x00000040; 419 pub const ISIG: ::tcflag_t = 0x00000080; 420 pub const ICANON: ::tcflag_t = 0x00000100; 421 pub const ALTWERASE: ::tcflag_t = 0x00000200; 422 pub const IEXTEN: ::tcflag_t = 0x00000400; 423 pub const EXTPROC: ::tcflag_t = 0x00000800; 424 pub const TOSTOP: ::tcflag_t = 0x00400000; 425 pub const FLUSHO: ::tcflag_t = 0x00800000; 426 pub const NOKERNINFO: ::tcflag_t = 0x02000000; 427 pub const PENDIN: ::tcflag_t = 0x20000000; 428 pub const NOFLSH: ::tcflag_t = 0x80000000; 429 pub const MDMBUF: ::tcflag_t = 0x00100000; 430 431 pub const WNOHANG: ::c_int = 0x00000001; 432 pub const WUNTRACED: ::c_int = 0x00000002; 433 434 pub const RTLD_LAZY: ::c_int = 0x1; 435 pub const RTLD_NOW: ::c_int = 0x2; 436 pub const RTLD_NEXT: *mut ::c_void = -1isize as *mut ::c_void; 437 pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void; 438 pub const RTLD_SELF: *mut ::c_void = -3isize as *mut ::c_void; 439 440 pub const LOG_CRON: ::c_int = 9 << 3; 441 pub const LOG_AUTHPRIV: ::c_int = 10 << 3; 442 pub const LOG_FTP: ::c_int = 11 << 3; 443 pub const LOG_PERROR: ::c_int = 0x20; 444 445 pub const TCP_NODELAY: ::c_int = 1; 446 pub const TCP_MAXSEG: ::c_int = 2; 447 448 pub const PIPE_BUF: usize = 512; 449 450 pub const CLD_EXITED: ::c_int = 1; 451 pub const CLD_KILLED: ::c_int = 2; 452 pub const CLD_DUMPED: ::c_int = 3; 453 pub const CLD_TRAPPED: ::c_int = 4; 454 pub const CLD_STOPPED: ::c_int = 5; 455 pub const CLD_CONTINUED: ::c_int = 6; 456 457 pub const POLLIN: ::c_short = 0x1; 458 pub const POLLPRI: ::c_short = 0x2; 459 pub const POLLOUT: ::c_short = 0x4; 460 pub const POLLERR: ::c_short = 0x8; 461 pub const POLLHUP: ::c_short = 0x10; 462 pub const POLLNVAL: ::c_short = 0x20; 463 pub const POLLRDNORM: ::c_short = 0x040; 464 pub const POLLWRNORM: ::c_short = 0x004; 465 pub const POLLRDBAND: ::c_short = 0x080; 466 pub const POLLWRBAND: ::c_short = 0x100; 467 468 pub const BIOCGBLEN: ::c_ulong = 0x40044266; 469 pub const BIOCSBLEN: ::c_ulong = 0xc0044266; 470 pub const BIOCFLUSH: ::c_uint = 0x20004268; 471 pub const BIOCPROMISC: ::c_uint = 0x20004269; 472 pub const BIOCGDLT: ::c_ulong = 0x4004426a; 473 pub const BIOCGETIF: ::c_ulong = 0x4020426b; 474 pub const BIOCSETIF: ::c_ulong = 0x8020426c; 475 pub const BIOCGSTATS: ::c_ulong = 0x4008426f; 476 pub const BIOCIMMEDIATE: ::c_ulong = 0x80044270; 477 pub const BIOCVERSION: ::c_ulong = 0x40044271; 478 pub const BIOCGHDRCMPLT: ::c_ulong = 0x40044274; 479 pub const BIOCSHDRCMPLT: ::c_ulong = 0x80044275; 480 pub const SIOCGIFADDR: ::c_ulong = 0xc0206921; 481 482 pub const REG_BASIC: ::c_int = 0o0000; 483 pub const REG_EXTENDED: ::c_int = 0o0001; 484 pub const REG_ICASE: ::c_int = 0o0002; 485 pub const REG_NOSUB: ::c_int = 0o0004; 486 pub const REG_NEWLINE: ::c_int = 0o0010; 487 pub const REG_NOSPEC: ::c_int = 0o0020; 488 pub const REG_PEND: ::c_int = 0o0040; 489 pub const REG_DUMP: ::c_int = 0o0200; 490 491 pub const REG_NOMATCH: ::c_int = 1; 492 pub const REG_BADPAT: ::c_int = 2; 493 pub const REG_ECOLLATE: ::c_int = 3; 494 pub const REG_ECTYPE: ::c_int = 4; 495 pub const REG_EESCAPE: ::c_int = 5; 496 pub const REG_ESUBREG: ::c_int = 6; 497 pub const REG_EBRACK: ::c_int = 7; 498 pub const REG_EPAREN: ::c_int = 8; 499 pub const REG_EBRACE: ::c_int = 9; 500 pub const REG_BADBR: ::c_int = 10; 501 pub const REG_ERANGE: ::c_int = 11; 502 pub const REG_ESPACE: ::c_int = 12; 503 pub const REG_BADRPT: ::c_int = 13; 504 pub const REG_EMPTY: ::c_int = 14; 505 pub const REG_ASSERT: ::c_int = 15; 506 pub const REG_INVARG: ::c_int = 16; 507 pub const REG_ATOI: ::c_int = 255; 508 pub const REG_ITOA: ::c_int = 0o0400; 509 510 pub const REG_NOTBOL: ::c_int = 0o00001; 511 pub const REG_NOTEOL: ::c_int = 0o00002; 512 pub const REG_STARTEND: ::c_int = 0o00004; 513 pub const REG_TRACE: ::c_int = 0o00400; 514 pub const REG_LARGE: ::c_int = 0o01000; 515 pub const REG_BACKR: ::c_int = 0o02000; 516 517 pub const TIOCCBRK: ::c_uint = 0x2000747a; 518 pub const TIOCSBRK: ::c_uint = 0x2000747b; 519 520 pub const PRIO_PROCESS: ::c_int = 0; 521 pub const PRIO_PGRP: ::c_int = 1; 522 pub const PRIO_USER: ::c_int = 2; 523 524 pub const ITIMER_REAL: ::c_int = 0; 525 pub const ITIMER_VIRTUAL: ::c_int = 1; 526 pub const ITIMER_PROF: ::c_int = 2; 527 528 f! { 529 pub fn CMSG_FIRSTHDR(mhdr: *const ::msghdr) -> *mut ::cmsghdr { 530 if (*mhdr).msg_controllen as usize >= ::mem::size_of::<::cmsghdr>() { 531 (*mhdr).msg_control as *mut ::cmsghdr 532 } else { 533 0 as *mut ::cmsghdr 534 } 535 } 536 537 pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { 538 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 539 let fd = fd as usize; 540 (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); 541 return 542 } 543 544 pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { 545 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 546 let fd = fd as usize; 547 return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 548 } 549 550 pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { 551 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 552 let fd = fd as usize; 553 (*set).fds_bits[fd / bits] |= 1 << (fd % bits); 554 return 555 } 556 557 pub fn FD_ZERO(set: *mut fd_set) -> () { 558 for slot in (*set).fds_bits.iter_mut() { 559 *slot = 0; 560 } 561 } 562 } 563 564 safe_f! { 565 pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int { 566 status & 0o177 567 } 568 569 pub {const} fn WIFEXITED(status: ::c_int) -> bool { 570 (status & 0o177) == 0 571 } 572 573 pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int { 574 status >> 8 575 } 576 577 pub {const} fn WCOREDUMP(status: ::c_int) -> bool { 578 (status & 0o200) != 0 579 } 580 581 pub {const} fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { 582 (cmd << 8) | (type_ & 0x00ff) 583 } 584 } 585 586 extern "C" { 587 #[cfg_attr( 588 all(target_os = "macos", target_arch = "x86"), 589 link_name = "getrlimit$UNIX2003" 590 )] getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int591 pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; 592 #[cfg_attr( 593 all(target_os = "macos", target_arch = "x86"), 594 link_name = "setrlimit$UNIX2003" 595 )] setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int596 pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; 597 strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int598 pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int; abs(i: ::c_int) -> ::c_int599 pub fn abs(i: ::c_int) -> ::c_int; atof(s: *const ::c_char) -> ::c_double600 pub fn atof(s: *const ::c_char) -> ::c_double; labs(i: ::c_long) -> ::c_long601 pub fn labs(i: ::c_long) -> ::c_long; 602 #[cfg_attr( 603 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), 604 link_name = "rand@FBSD_1.0" 605 )] rand() -> ::c_int606 pub fn rand() -> ::c_int; 607 #[cfg_attr( 608 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), 609 link_name = "srand@FBSD_1.0" 610 )] srand(seed: ::c_uint)611 pub fn srand(seed: ::c_uint); 612 getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int613 pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; freeifaddrs(ifa: *mut ::ifaddrs)614 pub fn freeifaddrs(ifa: *mut ::ifaddrs); setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int615 pub fn setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int; ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int616 pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; kqueue() -> ::c_int617 pub fn kqueue() -> ::c_int; unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int618 pub fn unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int; syscall(num: ::c_int, ...) -> ::c_int619 pub fn syscall(num: ::c_int, ...) -> ::c_int; 620 #[cfg_attr(target_os = "netbsd", link_name = "__getpwent50")] getpwent() -> *mut passwd621 pub fn getpwent() -> *mut passwd; setpwent()622 pub fn setpwent(); endpwent()623 pub fn endpwent(); endgrent()624 pub fn endgrent(); getgrent() -> *mut ::group625 pub fn getgrent() -> *mut ::group; 626 getprogname() -> *const ::c_char627 pub fn getprogname() -> *const ::c_char; setprogname(name: *const ::c_char)628 pub fn setprogname(name: *const ::c_char); getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int629 pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int; if_nameindex() -> *mut if_nameindex630 pub fn if_nameindex() -> *mut if_nameindex; if_freenameindex(ptr: *mut if_nameindex)631 pub fn if_freenameindex(ptr: *mut if_nameindex); 632 getpeereid(socket: ::c_int, euid: *mut ::uid_t, egid: *mut ::gid_t) -> ::c_int633 pub fn getpeereid(socket: ::c_int, euid: *mut ::uid_t, egid: *mut ::gid_t) -> ::c_int; 634 635 #[cfg_attr( 636 all(target_os = "macos", not(target_arch = "aarch64")), 637 link_name = "glob$INODE64" 638 )] 639 #[cfg_attr(target_os = "netbsd", link_name = "__glob30")] 640 #[cfg_attr( 641 all(target_os = "freebsd", any(freebsd11, freebsd10)), 642 link_name = "glob@FBSD_1.0" 643 )] 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_int644 pub fn glob( 645 pattern: *const ::c_char, 646 flags: ::c_int, 647 errfunc: ::Option<extern "C" fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int>, 648 pglob: *mut ::glob_t, 649 ) -> ::c_int; 650 #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")] 651 #[cfg_attr( 652 all(target_os = "freebsd", any(freebsd11, freebsd10)), 653 link_name = "globfree@FBSD_1.0" 654 )] globfree(pglob: *mut ::glob_t)655 pub fn globfree(pglob: *mut ::glob_t); 656 posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int657 pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int; 658 shm_unlink(name: *const ::c_char) -> ::c_int659 pub fn shm_unlink(name: *const ::c_char) -> ::c_int; 660 661 #[cfg_attr( 662 all(target_os = "macos", target_arch = "x86_64"), 663 link_name = "seekdir$INODE64" 664 )] 665 #[cfg_attr( 666 all(target_os = "macos", target_arch = "x86"), 667 link_name = "seekdir$INODE64$UNIX2003" 668 )] seekdir(dirp: *mut ::DIR, loc: ::c_long)669 pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); 670 671 #[cfg_attr( 672 all(target_os = "macos", target_arch = "x86_64"), 673 link_name = "telldir$INODE64" 674 )] 675 #[cfg_attr( 676 all(target_os = "macos", target_arch = "x86"), 677 link_name = "telldir$INODE64$UNIX2003" 678 )] telldir(dirp: *mut ::DIR) -> ::c_long679 pub fn telldir(dirp: *mut ::DIR) -> ::c_long; madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int680 pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int; 681 682 #[cfg_attr( 683 all(target_os = "macos", target_arch = "x86"), 684 link_name = "msync$UNIX2003" 685 )] 686 #[cfg_attr(target_os = "netbsd", link_name = "__msync13")] msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int687 pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int; 688 689 #[cfg_attr( 690 all(target_os = "macos", target_arch = "x86"), 691 link_name = "recvfrom$UNIX2003" 692 )] recvfrom( socket: ::c_int, buf: *mut ::c_void, len: ::size_t, flags: ::c_int, addr: *mut ::sockaddr, addrlen: *mut ::socklen_t, ) -> ::ssize_t693 pub fn recvfrom( 694 socket: ::c_int, 695 buf: *mut ::c_void, 696 len: ::size_t, 697 flags: ::c_int, 698 addr: *mut ::sockaddr, 699 addrlen: *mut ::socklen_t, 700 ) -> ::ssize_t; mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int701 pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; 702 #[cfg_attr(target_os = "netbsd", link_name = "__futimes50")] futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int703 pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; nl_langinfo(item: ::nl_item) -> *mut ::c_char704 pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; 705 706 #[cfg_attr( 707 all(target_os = "macos", target_arch = "x86"), 708 link_name = "bind$UNIX2003" 709 )] bind(socket: ::c_int, address: *const ::sockaddr, address_len: ::socklen_t) -> ::c_int710 pub fn bind(socket: ::c_int, address: *const ::sockaddr, address_len: ::socklen_t) -> ::c_int; 711 712 #[cfg_attr( 713 all(target_os = "macos", target_arch = "x86"), 714 link_name = "writev$UNIX2003" 715 )] writev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t716 pub fn writev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; 717 #[cfg_attr( 718 all(target_os = "macos", target_arch = "x86"), 719 link_name = "readv$UNIX2003" 720 )] readv(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t721 pub fn readv(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; 722 723 #[cfg_attr( 724 all(target_os = "macos", target_arch = "x86"), 725 link_name = "sendmsg$UNIX2003" 726 )] sendmsg(fd: ::c_int, msg: *const ::msghdr, flags: ::c_int) -> ::ssize_t727 pub fn sendmsg(fd: ::c_int, msg: *const ::msghdr, flags: ::c_int) -> ::ssize_t; 728 #[cfg_attr( 729 all(target_os = "macos", target_arch = "x86"), 730 link_name = "recvmsg$UNIX2003" 731 )] recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::ssize_t732 pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::ssize_t; 733 sync()734 pub fn sync(); getgrgid_r( gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut ::group, ) -> ::c_int735 pub fn getgrgid_r( 736 gid: ::gid_t, 737 grp: *mut ::group, 738 buf: *mut ::c_char, 739 buflen: ::size_t, 740 result: *mut *mut ::group, 741 ) -> ::c_int; 742 #[cfg_attr( 743 all(target_os = "macos", target_arch = "x86"), 744 link_name = "sigaltstack$UNIX2003" 745 )] 746 #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int747 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; sem_close(sem: *mut sem_t) -> ::c_int748 pub fn sem_close(sem: *mut sem_t) -> ::c_int; getdtablesize() -> ::c_int749 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_int750 pub fn getgrnam_r( 751 name: *const ::c_char, 752 grp: *mut ::group, 753 buf: *mut ::c_char, 754 buflen: ::size_t, 755 result: *mut *mut ::group, 756 ) -> ::c_int; 757 #[cfg_attr( 758 all(target_os = "macos", target_arch = "x86"), 759 link_name = "pthread_sigmask$UNIX2003" 760 )] pthread_sigmask(how: ::c_int, set: *const sigset_t, oldset: *mut sigset_t) -> ::c_int761 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_t762 pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; getgrnam(name: *const ::c_char) -> *mut ::group763 pub fn getgrnam(name: *const ::c_char) -> *mut ::group; 764 #[cfg_attr( 765 all(target_os = "macos", target_arch = "x86"), 766 link_name = "pthread_cancel$UNIX2003" 767 )] pthread_cancel(thread: ::pthread_t) -> ::c_int768 pub fn pthread_cancel(thread: ::pthread_t) -> ::c_int; pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int769 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; sem_unlink(name: *const ::c_char) -> ::c_int770 pub fn sem_unlink(name: *const ::c_char) -> ::c_int; 771 #[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_int772 pub fn getpwnam_r( 773 name: *const ::c_char, 774 pwd: *mut passwd, 775 buf: *mut ::c_char, 776 buflen: ::size_t, 777 result: *mut *mut passwd, 778 ) -> ::c_int; 779 #[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_int780 pub fn getpwuid_r( 781 uid: ::uid_t, 782 pwd: *mut passwd, 783 buf: *mut ::c_char, 784 buflen: ::size_t, 785 result: *mut *mut passwd, 786 ) -> ::c_int; 787 #[cfg_attr( 788 all(target_os = "macos", target_arch = "x86"), 789 link_name = "sigwait$UNIX2003" 790 )] sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int791 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_int792 pub fn pthread_atfork( 793 prepare: ::Option<unsafe extern "C" fn()>, 794 parent: ::Option<unsafe extern "C" fn()>, 795 child: ::Option<unsafe extern "C" fn()>, 796 ) -> ::c_int; getgrgid(gid: ::gid_t) -> *mut ::group797 pub fn getgrgid(gid: ::gid_t) -> *mut ::group; 798 #[cfg_attr( 799 all(target_os = "macos", target_arch = "x86"), 800 link_name = "popen$UNIX2003" 801 )] popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE802 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_int803 pub fn faccessat( 804 dirfd: ::c_int, 805 pathname: *const ::c_char, 806 mode: ::c_int, 807 flags: ::c_int, 808 ) -> ::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_int809 pub fn pthread_create( 810 native: *mut ::pthread_t, 811 attr: *const ::pthread_attr_t, 812 f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, 813 value: *mut ::c_void, 814 ) -> ::c_int; acct(filename: *const ::c_char) -> ::c_int815 pub fn acct(filename: *const ::c_char) -> ::c_int; 816 #[cfg_attr( 817 all(target_os = "macos", target_arch = "x86"), 818 link_name = "wait4$UNIX2003" 819 )] 820 #[cfg_attr( 821 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), 822 link_name = "wait4@FBSD_1.0" 823 )] wait4( pid: ::pid_t, status: *mut ::c_int, options: ::c_int, rusage: *mut ::rusage, ) -> ::pid_t824 pub fn wait4( 825 pid: ::pid_t, 826 status: *mut ::c_int, 827 options: ::c_int, 828 rusage: *mut ::rusage, 829 ) -> ::pid_t; 830 #[cfg_attr( 831 all(target_os = "macos", target_arch = "x86"), 832 link_name = "getitimer$UNIX2003" 833 )] getitimer(which: ::c_int, curr_value: *mut ::itimerval) -> ::c_int834 pub fn getitimer(which: ::c_int, curr_value: *mut ::itimerval) -> ::c_int; 835 #[cfg_attr( 836 all(target_os = "macos", target_arch = "x86"), 837 link_name = "setitimer$UNIX2003" 838 )] setitimer( which: ::c_int, new_value: *const ::itimerval, old_value: *mut ::itimerval, ) -> ::c_int839 pub fn setitimer( 840 which: ::c_int, 841 new_value: *const ::itimerval, 842 old_value: *mut ::itimerval, 843 ) -> ::c_int; 844 regcomp(preg: *mut regex_t, pattern: *const ::c_char, cflags: ::c_int) -> ::c_int845 pub fn regcomp(preg: *mut regex_t, pattern: *const ::c_char, cflags: ::c_int) -> ::c_int; 846 regexec( preg: *const regex_t, input: *const ::c_char, nmatch: ::size_t, pmatch: *mut regmatch_t, eflags: ::c_int, ) -> ::c_int847 pub fn regexec( 848 preg: *const regex_t, 849 input: *const ::c_char, 850 nmatch: ::size_t, 851 pmatch: *mut regmatch_t, 852 eflags: ::c_int, 853 ) -> ::c_int; 854 regerror( errcode: ::c_int, preg: *const regex_t, errbuf: *mut ::c_char, errbuf_size: ::size_t, ) -> ::size_t855 pub fn regerror( 856 errcode: ::c_int, 857 preg: *const regex_t, 858 errbuf: *mut ::c_char, 859 errbuf_size: ::size_t, 860 ) -> ::size_t; 861 regfree(preg: *mut regex_t)862 pub fn regfree(preg: *mut regex_t); 863 arc4random() -> u32864 pub fn arc4random() -> u32; arc4random_buf(buf: *mut ::c_void, size: ::size_t)865 pub fn arc4random_buf(buf: *mut ::c_void, size: ::size_t); arc4random_uniform(l: u32) -> u32866 pub fn arc4random_uniform(l: u32) -> u32; 867 } 868 869 cfg_if! { 870 if #[cfg(any(target_os = "macos", target_os = "ios"))] { 871 mod apple; 872 pub use self::apple::*; 873 } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] { 874 mod netbsdlike; 875 pub use self::netbsdlike::*; 876 } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { 877 mod freebsdlike; 878 pub use self::freebsdlike::*; 879 } else { 880 // Unknown target_os 881 } 882 } 883