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