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_FORCE: ::c_int = 0x80000; 341 342 pub const Q_SYNC: ::c_int = 0x600; 343 pub const Q_QUOTAON: ::c_int = 0x100; 344 pub const Q_QUOTAOFF: ::c_int = 0x200; 345 346 pub const TCIOFF: ::c_int = 3; 347 pub const TCION: ::c_int = 4; 348 pub const TCOOFF: ::c_int = 1; 349 pub const TCOON: ::c_int = 2; 350 pub const TCIFLUSH: ::c_int = 1; 351 pub const TCOFLUSH: ::c_int = 2; 352 pub const TCIOFLUSH: ::c_int = 3; 353 pub const TCSANOW: ::c_int = 0; 354 pub const TCSADRAIN: ::c_int = 1; 355 pub const TCSAFLUSH: ::c_int = 2; 356 pub const VEOF: usize = 0; 357 pub const VEOL: usize = 1; 358 pub const VEOL2: usize = 2; 359 pub const VERASE: usize = 3; 360 pub const VWERASE: usize = 4; 361 pub const VKILL: usize = 5; 362 pub const VREPRINT: usize = 6; 363 pub const VINTR: usize = 8; 364 pub const VQUIT: usize = 9; 365 pub const VSUSP: usize = 10; 366 pub const VDSUSP: usize = 11; 367 pub const VSTART: usize = 12; 368 pub const VSTOP: usize = 13; 369 pub const VLNEXT: usize = 14; 370 pub const VDISCARD: usize = 15; 371 pub const VMIN: usize = 16; 372 pub const VTIME: usize = 17; 373 pub const VSTATUS: usize = 18; 374 pub const _POSIX_VDISABLE: ::cc_t = 0xff; 375 pub const IGNBRK: ::tcflag_t = 0x00000001; 376 pub const BRKINT: ::tcflag_t = 0x00000002; 377 pub const IGNPAR: ::tcflag_t = 0x00000004; 378 pub const PARMRK: ::tcflag_t = 0x00000008; 379 pub const INPCK: ::tcflag_t = 0x00000010; 380 pub const ISTRIP: ::tcflag_t = 0x00000020; 381 pub const INLCR: ::tcflag_t = 0x00000040; 382 pub const IGNCR: ::tcflag_t = 0x00000080; 383 pub const ICRNL: ::tcflag_t = 0x00000100; 384 pub const IXON: ::tcflag_t = 0x00000200; 385 pub const IXOFF: ::tcflag_t = 0x00000400; 386 pub const IXANY: ::tcflag_t = 0x00000800; 387 pub const IMAXBEL: ::tcflag_t = 0x00002000; 388 pub const OPOST: ::tcflag_t = 0x1; 389 pub const ONLCR: ::tcflag_t = 0x2; 390 pub const OXTABS: ::tcflag_t = 0x4; 391 pub const ONOEOT: ::tcflag_t = 0x8; 392 pub const CIGNORE: ::tcflag_t = 0x00000001; 393 pub const CSIZE: ::tcflag_t = 0x00000300; 394 pub const CS5: ::tcflag_t = 0x00000000; 395 pub const CS6: ::tcflag_t = 0x00000100; 396 pub const CS7: ::tcflag_t = 0x00000200; 397 pub const CS8: ::tcflag_t = 0x00000300; 398 pub const CSTOPB: ::tcflag_t = 0x00000400; 399 pub const CREAD: ::tcflag_t = 0x00000800; 400 pub const PARENB: ::tcflag_t = 0x00001000; 401 pub const PARODD: ::tcflag_t = 0x00002000; 402 pub const HUPCL: ::tcflag_t = 0x00004000; 403 pub const CLOCAL: ::tcflag_t = 0x00008000; 404 pub const ECHOKE: ::tcflag_t = 0x00000001; 405 pub const ECHOE: ::tcflag_t = 0x00000002; 406 pub const ECHOK: ::tcflag_t = 0x00000004; 407 pub const ECHO: ::tcflag_t = 0x00000008; 408 pub const ECHONL: ::tcflag_t = 0x00000010; 409 pub const ECHOPRT: ::tcflag_t = 0x00000020; 410 pub const ECHOCTL: ::tcflag_t = 0x00000040; 411 pub const ISIG: ::tcflag_t = 0x00000080; 412 pub const ICANON: ::tcflag_t = 0x00000100; 413 pub const ALTWERASE: ::tcflag_t = 0x00000200; 414 pub const IEXTEN: ::tcflag_t = 0x00000400; 415 pub const EXTPROC: ::tcflag_t = 0x00000800; 416 pub const TOSTOP: ::tcflag_t = 0x00400000; 417 pub const FLUSHO: ::tcflag_t = 0x00800000; 418 pub const NOKERNINFO: ::tcflag_t = 0x02000000; 419 pub const PENDIN: ::tcflag_t = 0x20000000; 420 pub const NOFLSH: ::tcflag_t = 0x80000000; 421 pub const MDMBUF: ::tcflag_t = 0x00100000; 422 423 pub const WNOHANG: ::c_int = 0x00000001; 424 pub const WUNTRACED: ::c_int = 0x00000002; 425 426 pub const RTLD_LAZY: ::c_int = 0x1; 427 pub const RTLD_NOW: ::c_int = 0x2; 428 pub const RTLD_NEXT: *mut ::c_void = -1isize as *mut ::c_void; 429 pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void; 430 pub const RTLD_SELF: *mut ::c_void = -3isize as *mut ::c_void; 431 432 pub const LOG_CRON: ::c_int = 9 << 3; 433 pub const LOG_AUTHPRIV: ::c_int = 10 << 3; 434 pub const LOG_FTP: ::c_int = 11 << 3; 435 pub const LOG_PERROR: ::c_int = 0x20; 436 437 pub const TCP_NODELAY: ::c_int = 1; 438 pub const TCP_MAXSEG: ::c_int = 2; 439 440 pub const PIPE_BUF: usize = 512; 441 442 pub const CLD_EXITED: ::c_int = 1; 443 pub const CLD_KILLED: ::c_int = 2; 444 pub const CLD_DUMPED: ::c_int = 3; 445 pub const CLD_TRAPPED: ::c_int = 4; 446 pub const CLD_STOPPED: ::c_int = 5; 447 pub const CLD_CONTINUED: ::c_int = 6; 448 449 pub const POLLIN: ::c_short = 0x1; 450 pub const POLLPRI: ::c_short = 0x2; 451 pub const POLLOUT: ::c_short = 0x4; 452 pub const POLLERR: ::c_short = 0x8; 453 pub const POLLHUP: ::c_short = 0x10; 454 pub const POLLNVAL: ::c_short = 0x20; 455 pub const POLLRDNORM: ::c_short = 0x040; 456 pub const POLLWRNORM: ::c_short = 0x004; 457 pub const POLLRDBAND: ::c_short = 0x080; 458 pub const POLLWRBAND: ::c_short = 0x100; 459 460 pub const BIOCGBLEN: ::c_ulong = 0x40044266; 461 pub const BIOCSBLEN: ::c_ulong = 0xc0044266; 462 pub const BIOCFLUSH: ::c_uint = 0x20004268; 463 pub const BIOCPROMISC: ::c_uint = 0x20004269; 464 pub const BIOCGDLT: ::c_ulong = 0x4004426a; 465 pub const BIOCGETIF: ::c_ulong = 0x4020426b; 466 pub const BIOCSETIF: ::c_ulong = 0x8020426c; 467 pub const BIOCGSTATS: ::c_ulong = 0x4008426f; 468 pub const BIOCIMMEDIATE: ::c_ulong = 0x80044270; 469 pub const BIOCVERSION: ::c_ulong = 0x40044271; 470 pub const BIOCGHDRCMPLT: ::c_ulong = 0x40044274; 471 pub const BIOCSHDRCMPLT: ::c_ulong = 0x80044275; 472 pub const SIOCGIFADDR: ::c_ulong = 0xc0206921; 473 474 pub const REG_BASIC: ::c_int = 0o0000; 475 pub const REG_EXTENDED: ::c_int = 0o0001; 476 pub const REG_ICASE: ::c_int = 0o0002; 477 pub const REG_NOSUB: ::c_int = 0o0004; 478 pub const REG_NEWLINE: ::c_int = 0o0010; 479 pub const REG_NOSPEC: ::c_int = 0o0020; 480 pub const REG_PEND: ::c_int = 0o0040; 481 pub const REG_DUMP: ::c_int = 0o0200; 482 483 pub const REG_NOMATCH: ::c_int = 1; 484 pub const REG_BADPAT: ::c_int = 2; 485 pub const REG_ECOLLATE: ::c_int = 3; 486 pub const REG_ECTYPE: ::c_int = 4; 487 pub const REG_EESCAPE: ::c_int = 5; 488 pub const REG_ESUBREG: ::c_int = 6; 489 pub const REG_EBRACK: ::c_int = 7; 490 pub const REG_EPAREN: ::c_int = 8; 491 pub const REG_EBRACE: ::c_int = 9; 492 pub const REG_BADBR: ::c_int = 10; 493 pub const REG_ERANGE: ::c_int = 11; 494 pub const REG_ESPACE: ::c_int = 12; 495 pub const REG_BADRPT: ::c_int = 13; 496 pub const REG_EMPTY: ::c_int = 14; 497 pub const REG_ASSERT: ::c_int = 15; 498 pub const REG_INVARG: ::c_int = 16; 499 pub const REG_ATOI: ::c_int = 255; 500 pub const REG_ITOA: ::c_int = 0o0400; 501 502 pub const REG_NOTBOL: ::c_int = 0o00001; 503 pub const REG_NOTEOL: ::c_int = 0o00002; 504 pub const REG_STARTEND: ::c_int = 0o00004; 505 pub const REG_TRACE: ::c_int = 0o00400; 506 pub const REG_LARGE: ::c_int = 0o01000; 507 pub const REG_BACKR: ::c_int = 0o02000; 508 509 pub const TIOCCBRK: ::c_uint = 0x2000747a; 510 pub const TIOCSBRK: ::c_uint = 0x2000747b; 511 512 pub const PRIO_PROCESS: ::c_int = 0; 513 pub const PRIO_PGRP: ::c_int = 1; 514 pub const PRIO_USER: ::c_int = 2; 515 516 pub const ITIMER_REAL: ::c_int = 0; 517 pub const ITIMER_VIRTUAL: ::c_int = 1; 518 pub const ITIMER_PROF: ::c_int = 2; 519 520 f! { 521 pub fn CMSG_FIRSTHDR(mhdr: *const ::msghdr) -> *mut ::cmsghdr { 522 if (*mhdr).msg_controllen as usize >= ::mem::size_of::<::cmsghdr>() { 523 (*mhdr).msg_control as *mut ::cmsghdr 524 } else { 525 0 as *mut ::cmsghdr 526 } 527 } 528 529 pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { 530 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 531 let fd = fd as usize; 532 (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); 533 return 534 } 535 536 pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { 537 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 538 let fd = fd as usize; 539 return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 540 } 541 542 pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { 543 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 544 let fd = fd as usize; 545 (*set).fds_bits[fd / bits] |= 1 << (fd % bits); 546 return 547 } 548 549 pub fn FD_ZERO(set: *mut fd_set) -> () { 550 for slot in (*set).fds_bits.iter_mut() { 551 *slot = 0; 552 } 553 } 554 } 555 556 safe_f! { 557 pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int { 558 status & 0o177 559 } 560 561 pub {const} fn WIFEXITED(status: ::c_int) -> bool { 562 (status & 0o177) == 0 563 } 564 565 pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int { 566 status >> 8 567 } 568 569 pub {const} fn WCOREDUMP(status: ::c_int) -> bool { 570 (status & 0o200) != 0 571 } 572 573 pub {const} fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { 574 (cmd << 8) | (type_ & 0x00ff) 575 } 576 } 577 578 extern "C" { 579 #[cfg_attr( 580 all(target_os = "macos", target_arch = "x86"), 581 link_name = "getrlimit$UNIX2003" 582 )] getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int583 pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; 584 #[cfg_attr( 585 all(target_os = "macos", target_arch = "x86"), 586 link_name = "setrlimit$UNIX2003" 587 )] setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int588 pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; 589 strerror_r( errnum: ::c_int, buf: *mut c_char, buflen: ::size_t, ) -> ::c_int590 pub fn strerror_r( 591 errnum: ::c_int, 592 buf: *mut c_char, 593 buflen: ::size_t, 594 ) -> ::c_int; abs(i: ::c_int) -> ::c_int595 pub fn abs(i: ::c_int) -> ::c_int; atof(s: *const ::c_char) -> ::c_double596 pub fn atof(s: *const ::c_char) -> ::c_double; labs(i: ::c_long) -> ::c_long597 pub fn labs(i: ::c_long) -> ::c_long; 598 #[cfg_attr( 599 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), 600 link_name = "rand@FBSD_1.0" 601 )] rand() -> ::c_int602 pub fn rand() -> ::c_int; 603 #[cfg_attr( 604 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), 605 link_name = "srand@FBSD_1.0" 606 )] srand(seed: ::c_uint)607 pub fn srand(seed: ::c_uint); 608 getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int609 pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; freeifaddrs(ifa: *mut ::ifaddrs)610 pub fn freeifaddrs(ifa: *mut ::ifaddrs); setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int611 pub fn setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int; ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int612 pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; kqueue() -> ::c_int613 pub fn kqueue() -> ::c_int; unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int614 pub fn unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int; syscall(num: ::c_int, ...) -> ::c_int615 pub fn syscall(num: ::c_int, ...) -> ::c_int; 616 #[cfg_attr(target_os = "netbsd", link_name = "__getpwent50")] getpwent() -> *mut passwd617 pub fn getpwent() -> *mut passwd; setpwent()618 pub fn setpwent(); endpwent()619 pub fn endpwent(); endgrent()620 pub fn endgrent(); getgrent() -> *mut ::group621 pub fn getgrent() -> *mut ::group; 622 getprogname() -> *const ::c_char623 pub fn getprogname() -> *const ::c_char; setprogname(name: *const ::c_char)624 pub fn setprogname(name: *const ::c_char); getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int625 pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int; if_nameindex() -> *mut if_nameindex626 pub fn if_nameindex() -> *mut if_nameindex; if_freenameindex(ptr: *mut if_nameindex)627 pub fn if_freenameindex(ptr: *mut if_nameindex); 628 getpeereid( socket: ::c_int, euid: *mut ::uid_t, egid: *mut ::gid_t, ) -> ::c_int629 pub fn getpeereid( 630 socket: ::c_int, 631 euid: *mut ::uid_t, 632 egid: *mut ::gid_t, 633 ) -> ::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< 648 extern "C" fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int, 649 >, 650 pglob: *mut ::glob_t, 651 ) -> ::c_int; 652 #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")] 653 #[cfg_attr( 654 all(target_os = "freebsd", any(freebsd11, freebsd10)), 655 link_name = "globfree@FBSD_1.0" 656 )] globfree(pglob: *mut ::glob_t)657 pub fn globfree(pglob: *mut ::glob_t); 658 posix_madvise( addr: *mut ::c_void, len: ::size_t, advice: ::c_int, ) -> ::c_int659 pub fn posix_madvise( 660 addr: *mut ::c_void, 661 len: ::size_t, 662 advice: ::c_int, 663 ) -> ::c_int; 664 shm_unlink(name: *const ::c_char) -> ::c_int665 pub fn shm_unlink(name: *const ::c_char) -> ::c_int; 666 667 #[cfg_attr( 668 all(target_os = "macos", target_arch = "x86_64"), 669 link_name = "seekdir$INODE64" 670 )] 671 #[cfg_attr( 672 all(target_os = "macos", target_arch = "x86"), 673 link_name = "seekdir$INODE64$UNIX2003" 674 )] seekdir(dirp: *mut ::DIR, loc: ::c_long)675 pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); 676 677 #[cfg_attr( 678 all(target_os = "macos", target_arch = "x86_64"), 679 link_name = "telldir$INODE64" 680 )] 681 #[cfg_attr( 682 all(target_os = "macos", target_arch = "x86"), 683 link_name = "telldir$INODE64$UNIX2003" 684 )] telldir(dirp: *mut ::DIR) -> ::c_long685 pub fn telldir(dirp: *mut ::DIR) -> ::c_long; madvise( addr: *mut ::c_void, len: ::size_t, advice: ::c_int, ) -> ::c_int686 pub fn madvise( 687 addr: *mut ::c_void, 688 len: ::size_t, 689 advice: ::c_int, 690 ) -> ::c_int; 691 692 #[cfg_attr( 693 all(target_os = "macos", target_arch = "x86"), 694 link_name = "msync$UNIX2003" 695 )] 696 #[cfg_attr(target_os = "netbsd", link_name = "__msync13")] msync( addr: *mut ::c_void, len: ::size_t, flags: ::c_int, ) -> ::c_int697 pub fn msync( 698 addr: *mut ::c_void, 699 len: ::size_t, 700 flags: ::c_int, 701 ) -> ::c_int; 702 703 #[cfg_attr( 704 all(target_os = "macos", target_arch = "x86"), 705 link_name = "recvfrom$UNIX2003" 706 )] recvfrom( socket: ::c_int, buf: *mut ::c_void, len: ::size_t, flags: ::c_int, addr: *mut ::sockaddr, addrlen: *mut ::socklen_t, ) -> ::ssize_t707 pub fn recvfrom( 708 socket: ::c_int, 709 buf: *mut ::c_void, 710 len: ::size_t, 711 flags: ::c_int, 712 addr: *mut ::sockaddr, 713 addrlen: *mut ::socklen_t, 714 ) -> ::ssize_t; mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int715 pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; 716 #[cfg_attr(target_os = "netbsd", link_name = "__futimes50")] futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int717 pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; nl_langinfo(item: ::nl_item) -> *mut ::c_char718 pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; 719 720 #[cfg_attr( 721 all(target_os = "macos", target_arch = "x86"), 722 link_name = "bind$UNIX2003" 723 )] bind( socket: ::c_int, address: *const ::sockaddr, address_len: ::socklen_t, ) -> ::c_int724 pub fn bind( 725 socket: ::c_int, 726 address: *const ::sockaddr, 727 address_len: ::socklen_t, 728 ) -> ::c_int; 729 730 #[cfg_attr( 731 all(target_os = "macos", target_arch = "x86"), 732 link_name = "writev$UNIX2003" 733 )] writev( fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int, ) -> ::ssize_t734 pub fn writev( 735 fd: ::c_int, 736 iov: *const ::iovec, 737 iovcnt: ::c_int, 738 ) -> ::ssize_t; 739 #[cfg_attr( 740 all(target_os = "macos", target_arch = "x86"), 741 link_name = "readv$UNIX2003" 742 )] readv( fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int, ) -> ::ssize_t743 pub fn readv( 744 fd: ::c_int, 745 iov: *const ::iovec, 746 iovcnt: ::c_int, 747 ) -> ::ssize_t; 748 749 #[cfg_attr( 750 all(target_os = "macos", target_arch = "x86"), 751 link_name = "sendmsg$UNIX2003" 752 )] sendmsg( fd: ::c_int, msg: *const ::msghdr, flags: ::c_int, ) -> ::ssize_t753 pub fn sendmsg( 754 fd: ::c_int, 755 msg: *const ::msghdr, 756 flags: ::c_int, 757 ) -> ::ssize_t; 758 #[cfg_attr( 759 all(target_os = "macos", target_arch = "x86"), 760 link_name = "recvmsg$UNIX2003" 761 )] recvmsg( fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int, ) -> ::ssize_t762 pub fn recvmsg( 763 fd: ::c_int, 764 msg: *mut ::msghdr, 765 flags: ::c_int, 766 ) -> ::ssize_t; 767 sync()768 pub fn sync(); getgrgid_r( gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut ::group, ) -> ::c_int769 pub fn getgrgid_r( 770 gid: ::gid_t, 771 grp: *mut ::group, 772 buf: *mut ::c_char, 773 buflen: ::size_t, 774 result: *mut *mut ::group, 775 ) -> ::c_int; 776 #[cfg_attr( 777 all(target_os = "macos", target_arch = "x86"), 778 link_name = "sigaltstack$UNIX2003" 779 )] 780 #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int781 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; sem_close(sem: *mut sem_t) -> ::c_int782 pub fn sem_close(sem: *mut sem_t) -> ::c_int; getdtablesize() -> ::c_int783 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_int784 pub fn getgrnam_r( 785 name: *const ::c_char, 786 grp: *mut ::group, 787 buf: *mut ::c_char, 788 buflen: ::size_t, 789 result: *mut *mut ::group, 790 ) -> ::c_int; 791 #[cfg_attr( 792 all(target_os = "macos", target_arch = "x86"), 793 link_name = "pthread_sigmask$UNIX2003" 794 )] pthread_sigmask( how: ::c_int, set: *const sigset_t, oldset: *mut sigset_t, ) -> ::c_int795 pub fn pthread_sigmask( 796 how: ::c_int, 797 set: *const sigset_t, 798 oldset: *mut sigset_t, 799 ) -> ::c_int; sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t800 pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; getgrnam(name: *const ::c_char) -> *mut ::group801 pub fn getgrnam(name: *const ::c_char) -> *mut ::group; 802 #[cfg_attr( 803 all(target_os = "macos", target_arch = "x86"), 804 link_name = "pthread_cancel$UNIX2003" 805 )] pthread_cancel(thread: ::pthread_t) -> ::c_int806 pub fn pthread_cancel(thread: ::pthread_t) -> ::c_int; pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int807 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; sem_unlink(name: *const ::c_char) -> ::c_int808 pub fn sem_unlink(name: *const ::c_char) -> ::c_int; 809 #[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_int810 pub fn getpwnam_r( 811 name: *const ::c_char, 812 pwd: *mut passwd, 813 buf: *mut ::c_char, 814 buflen: ::size_t, 815 result: *mut *mut passwd, 816 ) -> ::c_int; 817 #[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_int818 pub fn getpwuid_r( 819 uid: ::uid_t, 820 pwd: *mut passwd, 821 buf: *mut ::c_char, 822 buflen: ::size_t, 823 result: *mut *mut passwd, 824 ) -> ::c_int; 825 #[cfg_attr( 826 all(target_os = "macos", target_arch = "x86"), 827 link_name = "sigwait$UNIX2003" 828 )] sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int829 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_int830 pub fn pthread_atfork( 831 prepare: ::Option<unsafe extern "C" fn()>, 832 parent: ::Option<unsafe extern "C" fn()>, 833 child: ::Option<unsafe extern "C" fn()>, 834 ) -> ::c_int; getgrgid(gid: ::gid_t) -> *mut ::group835 pub fn getgrgid(gid: ::gid_t) -> *mut ::group; 836 #[cfg_attr( 837 all(target_os = "macos", target_arch = "x86"), 838 link_name = "popen$UNIX2003" 839 )] popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE840 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_int841 pub fn faccessat( 842 dirfd: ::c_int, 843 pathname: *const ::c_char, 844 mode: ::c_int, 845 flags: ::c_int, 846 ) -> ::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_int847 pub fn pthread_create( 848 native: *mut ::pthread_t, 849 attr: *const ::pthread_attr_t, 850 f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, 851 value: *mut ::c_void, 852 ) -> ::c_int; acct(filename: *const ::c_char) -> ::c_int853 pub fn acct(filename: *const ::c_char) -> ::c_int; 854 #[cfg_attr( 855 all(target_os = "macos", target_arch = "x86"), 856 link_name = "wait4$UNIX2003" 857 )] 858 #[cfg_attr( 859 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), 860 link_name = "wait4@FBSD_1.0" 861 )] wait4( pid: ::pid_t, status: *mut ::c_int, options: ::c_int, rusage: *mut ::rusage, ) -> ::pid_t862 pub fn wait4( 863 pid: ::pid_t, 864 status: *mut ::c_int, 865 options: ::c_int, 866 rusage: *mut ::rusage, 867 ) -> ::pid_t; 868 #[cfg_attr( 869 all(target_os = "macos", target_arch = "x86"), 870 link_name = "getitimer$UNIX2003" 871 )] getitimer(which: ::c_int, curr_value: *mut ::itimerval) -> ::c_int872 pub fn getitimer(which: ::c_int, curr_value: *mut ::itimerval) -> ::c_int; 873 #[cfg_attr( 874 all(target_os = "macos", target_arch = "x86"), 875 link_name = "setitimer$UNIX2003" 876 )] setitimer( which: ::c_int, new_value: *const ::itimerval, old_value: *mut ::itimerval, ) -> ::c_int877 pub fn setitimer( 878 which: ::c_int, 879 new_value: *const ::itimerval, 880 old_value: *mut ::itimerval, 881 ) -> ::c_int; 882 regcomp( preg: *mut regex_t, pattern: *const ::c_char, cflags: ::c_int, ) -> ::c_int883 pub fn regcomp( 884 preg: *mut regex_t, 885 pattern: *const ::c_char, 886 cflags: ::c_int, 887 ) -> ::c_int; 888 regexec( preg: *const regex_t, input: *const ::c_char, nmatch: ::size_t, pmatch: *mut regmatch_t, eflags: ::c_int, ) -> ::c_int889 pub fn regexec( 890 preg: *const regex_t, 891 input: *const ::c_char, 892 nmatch: ::size_t, 893 pmatch: *mut regmatch_t, 894 eflags: ::c_int, 895 ) -> ::c_int; 896 regerror( errcode: ::c_int, preg: *const regex_t, errbuf: *mut ::c_char, errbuf_size: ::size_t, ) -> ::size_t897 pub fn regerror( 898 errcode: ::c_int, 899 preg: *const regex_t, 900 errbuf: *mut ::c_char, 901 errbuf_size: ::size_t, 902 ) -> ::size_t; 903 regfree(preg: *mut regex_t)904 pub fn regfree(preg: *mut regex_t); 905 } 906 907 cfg_if! { 908 if #[cfg(any(target_os = "macos", target_os = "ios"))] { 909 mod apple; 910 pub use self::apple::*; 911 } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] { 912 mod netbsdlike; 913 pub use self::netbsdlike::*; 914 } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { 915 mod freebsdlike; 916 pub use self::freebsdlike::*; 917 } else { 918 // Unknown target_os 919 } 920 } 921