1 pub type blkcnt_t = i32; 2 pub type blksize_t = i32; 3 4 pub type clockid_t = ::c_ulong; 5 6 cfg_if! { 7 if #[cfg(any(target_os = "espidf"))] { 8 pub type dev_t = ::c_short; 9 pub type ino_t = ::c_ushort; 10 pub type off_t = ::c_long; 11 } else if #[cfg(any(target_os = "vita"))] { 12 pub type dev_t = ::c_short; 13 pub type ino_t = ::c_ushort; 14 pub type off_t = ::c_int; 15 } else { 16 pub type dev_t = u32; 17 pub type ino_t = u32; 18 pub type off_t = i64; 19 } 20 } 21 22 pub type fsblkcnt_t = u64; 23 pub type fsfilcnt_t = u32; 24 pub type id_t = u32; 25 pub type key_t = ::c_int; 26 pub type loff_t = ::c_longlong; 27 pub type mode_t = ::c_uint; 28 pub type nfds_t = u32; 29 pub type nlink_t = ::c_ushort; 30 pub type pthread_t = ::c_ulong; 31 pub type pthread_key_t = ::c_uint; 32 pub type rlim_t = u32; 33 34 cfg_if! { 35 if #[cfg(target_os = "horizon")] { 36 pub type sa_family_t = u16; 37 } else { 38 pub type sa_family_t = u8; 39 } 40 } 41 42 pub type socklen_t = u32; 43 pub type speed_t = u32; 44 pub type suseconds_t = i32; 45 cfg_if! { 46 if #[cfg(target_os = "espidf")] { 47 pub type tcflag_t = u16; 48 } else { 49 pub type tcflag_t = ::c_uint; 50 } 51 } 52 pub type useconds_t = u32; 53 54 cfg_if! { 55 if #[cfg(any(target_os = "horizon", all(target_os = "espidf", espidf_time64)))] { 56 pub type time_t = ::c_longlong; 57 } else { 58 pub type time_t = i32; 59 } 60 } 61 62 cfg_if! { 63 if #[cfg(not(target_os = "horizon"))] { 64 s!{ 65 pub struct hostent { 66 pub h_name: *mut ::c_char, 67 pub h_aliases: *mut *mut ::c_char, 68 pub h_addrtype: ::c_int, 69 pub h_length: ::c_int, 70 pub h_addr_list: *mut *mut ::c_char, 71 pub h_addr: *mut ::c_char, 72 } 73 } 74 } 75 } 76 77 s! { 78 // The order of the `ai_addr` field in this struct is crucial 79 // for converting between the Rust and C types. 80 pub struct addrinfo { 81 pub ai_flags: ::c_int, 82 pub ai_family: ::c_int, 83 pub ai_socktype: ::c_int, 84 pub ai_protocol: ::c_int, 85 pub ai_addrlen: socklen_t, 86 87 #[cfg(target_os = "espidf")] 88 pub ai_addr: *mut sockaddr, 89 90 pub ai_canonname: *mut ::c_char, 91 92 #[cfg(not(any( 93 target_os = "espidf", 94 all(libc_cfg_target_vendor, target_arch = "powerpc", target_vendor = "nintendo"))))] 95 pub ai_addr: *mut sockaddr, 96 97 pub ai_next: *mut addrinfo, 98 } 99 100 pub struct ip_mreq { 101 pub imr_multiaddr: in_addr, 102 pub imr_interface: in_addr, 103 } 104 105 pub struct linger { 106 pub l_onoff: ::c_int, 107 pub l_linger: ::c_int, 108 } 109 110 pub struct in_addr { 111 pub s_addr: ::in_addr_t, 112 } 113 114 pub struct pollfd { 115 pub fd: ::c_int, 116 pub events: ::c_int, 117 pub revents: ::c_int, 118 } 119 120 pub struct lconv { 121 pub decimal_point: *mut ::c_char, 122 pub thousands_sep: *mut ::c_char, 123 pub grouping: *mut ::c_char, 124 pub int_curr_symbol: *mut ::c_char, 125 pub currency_symbol: *mut ::c_char, 126 pub mon_decimal_point: *mut ::c_char, 127 pub mon_thousands_sep: *mut ::c_char, 128 pub mon_grouping: *mut ::c_char, 129 pub positive_sign: *mut ::c_char, 130 pub negative_sign: *mut ::c_char, 131 pub int_frac_digits: ::c_char, 132 pub frac_digits: ::c_char, 133 pub p_cs_precedes: ::c_char, 134 pub p_sep_by_space: ::c_char, 135 pub n_cs_precedes: ::c_char, 136 pub n_sep_by_space: ::c_char, 137 pub p_sign_posn: ::c_char, 138 pub n_sign_posn: ::c_char, 139 pub int_n_cs_precedes: ::c_char, 140 pub int_n_sep_by_space: ::c_char, 141 pub int_n_sign_posn: ::c_char, 142 pub int_p_cs_precedes: ::c_char, 143 pub int_p_sep_by_space: ::c_char, 144 pub int_p_sign_posn: ::c_char, 145 } 146 147 pub struct tm { 148 pub tm_sec: ::c_int, 149 pub tm_min: ::c_int, 150 pub tm_hour: ::c_int, 151 pub tm_mday: ::c_int, 152 pub tm_mon: ::c_int, 153 pub tm_year: ::c_int, 154 pub tm_wday: ::c_int, 155 pub tm_yday: ::c_int, 156 pub tm_isdst: ::c_int, 157 } 158 159 pub struct statvfs { 160 pub f_bsize: ::c_ulong, 161 pub f_frsize: ::c_ulong, 162 pub f_blocks: fsblkcnt_t, 163 pub f_bfree: fsblkcnt_t, 164 pub f_bavail: fsblkcnt_t, 165 pub f_files: fsfilcnt_t, 166 pub f_ffree: fsfilcnt_t, 167 pub f_favail: fsfilcnt_t, 168 pub f_fsid: ::c_ulong, 169 pub f_flag: ::c_ulong, 170 pub f_namemax: ::c_ulong, 171 } 172 173 pub struct sigaction { 174 pub sa_handler: extern fn(arg1: ::c_int), 175 pub sa_mask: sigset_t, 176 pub sa_flags: ::c_int, 177 } 178 179 pub struct stack_t { 180 pub ss_sp: *mut ::c_void, 181 pub ss_flags: ::c_int, 182 pub ss_size: usize, 183 } 184 185 pub struct fd_set { // Unverified 186 fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], 187 } 188 189 pub struct passwd { // Unverified 190 pub pw_name: *mut ::c_char, 191 pub pw_passwd: *mut ::c_char, 192 pub pw_uid: ::uid_t, 193 pub pw_gid: ::gid_t, 194 pub pw_gecos: *mut ::c_char, 195 pub pw_dir: *mut ::c_char, 196 pub pw_shell: *mut ::c_char, 197 } 198 199 pub struct termios { // Unverified 200 pub c_iflag: ::tcflag_t, 201 pub c_oflag: ::tcflag_t, 202 pub c_cflag: ::tcflag_t, 203 pub c_lflag: ::tcflag_t, 204 pub c_line: ::cc_t, 205 pub c_cc: [::cc_t; ::NCCS], 206 #[cfg(target_os = "espidf")] 207 pub c_ispeed: u32, 208 #[cfg(target_os = "espidf")] 209 pub c_ospeed: u32, 210 } 211 212 pub struct sem_t { // Unverified 213 __size: [::c_char; 16], 214 } 215 216 pub struct Dl_info { // Unverified 217 pub dli_fname: *const ::c_char, 218 pub dli_fbase: *mut ::c_void, 219 pub dli_sname: *const ::c_char, 220 pub dli_saddr: *mut ::c_void, 221 } 222 223 pub struct utsname { // Unverified 224 pub sysname: [::c_char; 65], 225 pub nodename: [::c_char; 65], 226 pub release: [::c_char; 65], 227 pub version: [::c_char; 65], 228 pub machine: [::c_char; 65], 229 pub domainname: [::c_char; 65] 230 } 231 232 pub struct cpu_set_t { // Unverified 233 bits: [u32; 32], 234 } 235 236 pub struct pthread_attr_t { // Unverified 237 #[cfg(not(target_os = "espidf"))] 238 __size: [u8; __SIZEOF_PTHREAD_ATTR_T], 239 #[cfg(target_os = "espidf")] 240 pub is_initialized: i32, 241 #[cfg(target_os = "espidf")] 242 pub stackaddr: *mut crate::c_void, 243 #[cfg(target_os = "espidf")] 244 pub stacksize: i32, 245 #[cfg(target_os = "espidf")] 246 pub contentionscope: i32, 247 #[cfg(target_os = "espidf")] 248 pub inheritsched: i32, 249 #[cfg(target_os = "espidf")] 250 pub schedpolicy: i32, 251 #[cfg(target_os = "espidf")] 252 pub schedparam: i32, 253 #[cfg(target_os = "espidf")] 254 pub detachstate: i32, 255 } 256 257 pub struct pthread_rwlockattr_t { // Unverified 258 __size: [u8; __SIZEOF_PTHREAD_RWLOCKATTR_T] 259 } 260 } 261 262 // unverified constants 263 align_const! { 264 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { 265 size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_MUTEX_T], 266 }; 267 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { 268 size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_COND_T], 269 }; 270 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { 271 size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_RWLOCK_T], 272 }; 273 } 274 275 cfg_if! { 276 if #[cfg(target_os = "espidf")] { 277 pub const NCCS: usize = 11; 278 } else { 279 pub const NCCS: usize = 32; 280 } 281 } 282 283 cfg_if! { 284 if #[cfg(target_os = "espidf")] { 285 const __PTHREAD_INITIALIZER_BYTE: u8 = 0xff; 286 pub const __SIZEOF_PTHREAD_ATTR_T: usize = 32; 287 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 4; 288 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 12; 289 pub const __SIZEOF_PTHREAD_COND_T: usize = 4; 290 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 8; 291 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4; 292 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 12; 293 pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32; 294 } else if #[cfg(target_os = "vita")] { 295 const __PTHREAD_INITIALIZER_BYTE: u8 = 0xff; 296 pub const __SIZEOF_PTHREAD_ATTR_T: usize = 4; 297 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 4; 298 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; 299 pub const __SIZEOF_PTHREAD_COND_T: usize = 4; 300 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; 301 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4; 302 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 4; 303 pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 4; 304 } else if #[cfg(target_os = "rtems")] { 305 const __PTHREAD_INITIALIZER_BYTE: u8 = 0x00; 306 pub const __SIZEOF_PTHREAD_ATTR_T: usize = 96; 307 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 64; 308 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 24; 309 pub const __SIZEOF_PTHREAD_COND_T: usize = 28; 310 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 24; 311 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32; 312 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; 313 pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32; 314 } else { 315 const __PTHREAD_INITIALIZER_BYTE: u8 = 0; 316 pub const __SIZEOF_PTHREAD_ATTR_T: usize = 56; 317 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; 318 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; 319 pub const __SIZEOF_PTHREAD_COND_T: usize = 48; 320 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; 321 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; 322 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; 323 pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32; 324 } 325 } 326 327 pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4; 328 pub const __PTHREAD_MUTEX_HAVE_PREV: usize = 1; 329 pub const __PTHREAD_RWLOCK_INT_FLAGS_SHARED: usize = 1; 330 pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; 331 pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; 332 pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2; 333 334 cfg_if! { 335 if #[cfg(any(target_os = "horizon", target_os = "espidf"))] { 336 pub const FD_SETSIZE: usize = 64; 337 } else if #[cfg(target_os = "vita")] { 338 pub const FD_SETSIZE: usize = 256; 339 } else { 340 pub const FD_SETSIZE: usize = 1024; 341 } 342 } 343 // intentionally not public, only used for fd_set 344 const ULONG_SIZE: usize = 32; 345 346 // Other constants 347 pub const EPERM: ::c_int = 1; 348 pub const ENOENT: ::c_int = 2; 349 pub const ESRCH: ::c_int = 3; 350 pub const EINTR: ::c_int = 4; 351 pub const EIO: ::c_int = 5; 352 pub const ENXIO: ::c_int = 6; 353 pub const E2BIG: ::c_int = 7; 354 pub const ENOEXEC: ::c_int = 8; 355 pub const EBADF: ::c_int = 9; 356 pub const ECHILD: ::c_int = 10; 357 pub const EAGAIN: ::c_int = 11; 358 pub const ENOMEM: ::c_int = 12; 359 pub const EACCES: ::c_int = 13; 360 pub const EFAULT: ::c_int = 14; 361 pub const EBUSY: ::c_int = 16; 362 pub const EEXIST: ::c_int = 17; 363 pub const EXDEV: ::c_int = 18; 364 pub const ENODEV: ::c_int = 19; 365 pub const ENOTDIR: ::c_int = 20; 366 pub const EISDIR: ::c_int = 21; 367 pub const EINVAL: ::c_int = 22; 368 pub const ENFILE: ::c_int = 23; 369 pub const EMFILE: ::c_int = 24; 370 pub const ENOTTY: ::c_int = 25; 371 pub const ETXTBSY: ::c_int = 26; 372 pub const EFBIG: ::c_int = 27; 373 pub const ENOSPC: ::c_int = 28; 374 pub const ESPIPE: ::c_int = 29; 375 pub const EROFS: ::c_int = 30; 376 pub const EMLINK: ::c_int = 31; 377 pub const EPIPE: ::c_int = 32; 378 pub const EDOM: ::c_int = 33; 379 pub const ERANGE: ::c_int = 34; 380 pub const ENOMSG: ::c_int = 35; 381 pub const EIDRM: ::c_int = 36; 382 pub const EDEADLK: ::c_int = 45; 383 pub const ENOLCK: ::c_int = 46; 384 pub const ENOSTR: ::c_int = 60; 385 pub const ENODATA: ::c_int = 61; 386 pub const ETIME: ::c_int = 62; 387 pub const ENOSR: ::c_int = 63; 388 pub const ENOLINK: ::c_int = 67; 389 pub const EPROTO: ::c_int = 71; 390 pub const EMULTIHOP: ::c_int = 74; 391 pub const EBADMSG: ::c_int = 77; 392 pub const EFTYPE: ::c_int = 79; 393 pub const ENOSYS: ::c_int = 88; 394 pub const ENOTEMPTY: ::c_int = 90; 395 pub const ENAMETOOLONG: ::c_int = 91; 396 pub const ELOOP: ::c_int = 92; 397 pub const EOPNOTSUPP: ::c_int = 95; 398 pub const EPFNOSUPPORT: ::c_int = 96; 399 pub const ECONNRESET: ::c_int = 104; 400 pub const ENOBUFS: ::c_int = 105; 401 pub const EAFNOSUPPORT: ::c_int = 106; 402 pub const EPROTOTYPE: ::c_int = 107; 403 pub const ENOTSOCK: ::c_int = 108; 404 pub const ENOPROTOOPT: ::c_int = 109; 405 pub const ECONNREFUSED: ::c_int = 111; 406 pub const EADDRINUSE: ::c_int = 112; 407 pub const ECONNABORTED: ::c_int = 113; 408 pub const ENETUNREACH: ::c_int = 114; 409 pub const ENETDOWN: ::c_int = 115; 410 pub const ETIMEDOUT: ::c_int = 116; 411 pub const EHOSTDOWN: ::c_int = 117; 412 pub const EHOSTUNREACH: ::c_int = 118; 413 pub const EINPROGRESS: ::c_int = 119; 414 pub const EALREADY: ::c_int = 120; 415 pub const EDESTADDRREQ: ::c_int = 121; 416 pub const EMSGSIZE: ::c_int = 122; 417 pub const EPROTONOSUPPORT: ::c_int = 123; 418 pub const EADDRNOTAVAIL: ::c_int = 125; 419 pub const ENETRESET: ::c_int = 126; 420 pub const EISCONN: ::c_int = 127; 421 pub const ENOTCONN: ::c_int = 128; 422 pub const ETOOMANYREFS: ::c_int = 129; 423 pub const EDQUOT: ::c_int = 132; 424 pub const ESTALE: ::c_int = 133; 425 pub const ENOTSUP: ::c_int = 134; 426 pub const EILSEQ: ::c_int = 138; 427 pub const EOVERFLOW: ::c_int = 139; 428 pub const ECANCELED: ::c_int = 140; 429 pub const ENOTRECOVERABLE: ::c_int = 141; 430 pub const EOWNERDEAD: ::c_int = 142; 431 pub const EWOULDBLOCK: ::c_int = 11; 432 433 pub const F_DUPFD: ::c_int = 0; 434 pub const F_GETFD: ::c_int = 1; 435 pub const F_SETFD: ::c_int = 2; 436 pub const F_GETFL: ::c_int = 3; 437 pub const F_SETFL: ::c_int = 4; 438 pub const F_GETOWN: ::c_int = 5; 439 pub const F_SETOWN: ::c_int = 6; 440 pub const F_GETLK: ::c_int = 7; 441 pub const F_SETLK: ::c_int = 8; 442 pub const F_SETLKW: ::c_int = 9; 443 pub const F_RGETLK: ::c_int = 10; 444 pub const F_RSETLK: ::c_int = 11; 445 pub const F_CNVT: ::c_int = 12; 446 pub const F_RSETLKW: ::c_int = 13; 447 pub const F_DUPFD_CLOEXEC: ::c_int = 14; 448 449 pub const O_RDONLY: ::c_int = 0; 450 pub const O_WRONLY: ::c_int = 1; 451 pub const O_RDWR: ::c_int = 2; 452 pub const O_APPEND: ::c_int = 8; 453 pub const O_CREAT: ::c_int = 512; 454 pub const O_TRUNC: ::c_int = 1024; 455 pub const O_EXCL: ::c_int = 2048; 456 pub const O_SYNC: ::c_int = 8192; 457 pub const O_NONBLOCK: ::c_int = 16384; 458 459 pub const O_ACCMODE: ::c_int = 3; 460 cfg_if! { 461 if #[cfg(target_os = "espidf")] { 462 pub const O_CLOEXEC: ::c_int = 0x40000; 463 } else { 464 pub const O_CLOEXEC: ::c_int = 0x80000; 465 } 466 } 467 468 pub const RTLD_LAZY: ::c_int = 0x1; 469 470 pub const STDIN_FILENO: ::c_int = 0; 471 pub const STDOUT_FILENO: ::c_int = 1; 472 pub const STDERR_FILENO: ::c_int = 2; 473 474 pub const SEEK_SET: ::c_int = 0; 475 pub const SEEK_CUR: ::c_int = 1; 476 pub const SEEK_END: ::c_int = 2; 477 478 pub const FIOCLEX: ::c_ulong = 0x20006601; 479 pub const FIONCLEX: ::c_ulong = 0x20006602; 480 481 pub const S_BLKSIZE: ::mode_t = 1024; 482 pub const S_IREAD: ::mode_t = 256; 483 pub const S_IWRITE: ::mode_t = 128; 484 pub const S_IEXEC: ::mode_t = 64; 485 pub const S_ENFMT: ::mode_t = 1024; 486 pub const S_IFMT: ::mode_t = 61440; 487 pub const S_IFDIR: ::mode_t = 16384; 488 pub const S_IFCHR: ::mode_t = 8192; 489 pub const S_IFBLK: ::mode_t = 24576; 490 pub const S_IFREG: ::mode_t = 32768; 491 pub const S_IFLNK: ::mode_t = 40960; 492 pub const S_IFSOCK: ::mode_t = 49152; 493 pub const S_IFIFO: ::mode_t = 4096; 494 pub const S_IRUSR: ::mode_t = 256; 495 pub const S_IWUSR: ::mode_t = 128; 496 pub const S_IXUSR: ::mode_t = 64; 497 pub const S_IRGRP: ::mode_t = 32; 498 pub const S_IWGRP: ::mode_t = 16; 499 pub const S_IXGRP: ::mode_t = 8; 500 pub const S_IROTH: ::mode_t = 4; 501 pub const S_IWOTH: ::mode_t = 2; 502 pub const S_IXOTH: ::mode_t = 1; 503 504 pub const SOL_TCP: ::c_int = 6; 505 506 pub const PF_UNSPEC: ::c_int = 0; 507 pub const PF_INET: ::c_int = 2; 508 cfg_if! { 509 if #[cfg(target_os = "espidf")] { 510 pub const PF_INET6: ::c_int = 10; 511 } else { 512 pub const PF_INET6: ::c_int = 23; 513 } 514 } 515 516 pub const AF_UNSPEC: ::c_int = 0; 517 pub const AF_INET: ::c_int = 2; 518 519 pub const CLOCK_REALTIME: ::clockid_t = 1; 520 pub const CLOCK_MONOTONIC: ::clockid_t = 4; 521 pub const CLOCK_BOOTTIME: ::clockid_t = 4; 522 523 pub const SOCK_STREAM: ::c_int = 1; 524 pub const SOCK_DGRAM: ::c_int = 2; 525 526 pub const SHUT_RD: ::c_int = 0; 527 pub const SHUT_WR: ::c_int = 1; 528 pub const SHUT_RDWR: ::c_int = 2; 529 530 pub const SO_BINTIME: ::c_int = 0x2000; 531 pub const SO_NO_OFFLOAD: ::c_int = 0x4000; 532 pub const SO_NO_DDP: ::c_int = 0x8000; 533 pub const SO_REUSEPORT_LB: ::c_int = 0x10000; 534 pub const SO_LABEL: ::c_int = 0x1009; 535 pub const SO_PEERLABEL: ::c_int = 0x1010; 536 pub const SO_LISTENQLIMIT: ::c_int = 0x1011; 537 pub const SO_LISTENQLEN: ::c_int = 0x1012; 538 pub const SO_LISTENINCQLEN: ::c_int = 0x1013; 539 pub const SO_SETFIB: ::c_int = 0x1014; 540 pub const SO_USER_COOKIE: ::c_int = 0x1015; 541 pub const SO_PROTOCOL: ::c_int = 0x1016; 542 pub const SO_PROTOTYPE: ::c_int = SO_PROTOCOL; 543 pub const SO_VENDOR: ::c_int = 0x80000000; 544 pub const SO_DEBUG: ::c_int = 0x01; 545 pub const SO_ACCEPTCONN: ::c_int = 0x0002; 546 pub const SO_REUSEADDR: ::c_int = 0x0004; 547 pub const SO_KEEPALIVE: ::c_int = 0x0008; 548 pub const SO_DONTROUTE: ::c_int = 0x0010; 549 pub const SO_BROADCAST: ::c_int = 0x0020; 550 pub const SO_USELOOPBACK: ::c_int = 0x0040; 551 pub const SO_LINGER: ::c_int = 0x0080; 552 pub const SO_OOBINLINE: ::c_int = 0x0100; 553 pub const SO_REUSEPORT: ::c_int = 0x0200; 554 pub const SO_TIMESTAMP: ::c_int = 0x0400; 555 pub const SO_NOSIGPIPE: ::c_int = 0x0800; 556 pub const SO_ACCEPTFILTER: ::c_int = 0x1000; 557 pub const SO_SNDBUF: ::c_int = 0x1001; 558 pub const SO_RCVBUF: ::c_int = 0x1002; 559 pub const SO_SNDLOWAT: ::c_int = 0x1003; 560 pub const SO_RCVLOWAT: ::c_int = 0x1004; 561 pub const SO_SNDTIMEO: ::c_int = 0x1005; 562 pub const SO_RCVTIMEO: ::c_int = 0x1006; 563 cfg_if! { 564 if #[cfg(target_os = "horizon")] { 565 pub const SO_ERROR: ::c_int = 0x1009; 566 } else { 567 pub const SO_ERROR: ::c_int = 0x1007; 568 } 569 } 570 pub const SO_TYPE: ::c_int = 0x1008; 571 572 pub const SOCK_CLOEXEC: ::c_int = O_CLOEXEC; 573 574 pub const INET_ADDRSTRLEN: ::c_int = 16; 575 576 // https://github.com/bminor/newlib/blob/HEAD/newlib/libc/sys/linux/include/net/if.h#L121 577 pub const IFF_UP: ::c_int = 0x1; // interface is up 578 pub const IFF_BROADCAST: ::c_int = 0x2; // broadcast address valid 579 pub const IFF_DEBUG: ::c_int = 0x4; // turn on debugging 580 pub const IFF_LOOPBACK: ::c_int = 0x8; // is a loopback net 581 pub const IFF_POINTOPOINT: ::c_int = 0x10; // interface is point-to-point link 582 pub const IFF_NOTRAILERS: ::c_int = 0x20; // avoid use of trailers 583 pub const IFF_RUNNING: ::c_int = 0x40; // resources allocated 584 pub const IFF_NOARP: ::c_int = 0x80; // no address resolution protocol 585 pub const IFF_PROMISC: ::c_int = 0x100; // receive all packets 586 pub const IFF_ALLMULTI: ::c_int = 0x200; // receive all multicast packets 587 pub const IFF_OACTIVE: ::c_int = 0x400; // transmission in progress 588 pub const IFF_SIMPLEX: ::c_int = 0x800; // can't hear own transmissions 589 pub const IFF_LINK0: ::c_int = 0x1000; // per link layer defined bit 590 pub const IFF_LINK1: ::c_int = 0x2000; // per link layer defined bit 591 pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit 592 pub const IFF_ALTPHYS: ::c_int = IFF_LINK2; // use alternate physical connection 593 pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast 594 595 cfg_if! { 596 if #[cfg(target_os = "vita")] { 597 pub const TCP_NODELAY: ::c_int = 1; 598 pub const TCP_MAXSEG: ::c_int = 2; 599 } else if #[cfg(target_os = "espidf")] { 600 pub const TCP_NODELAY: ::c_int = 1; 601 pub const TCP_MAXSEG: ::c_int = 8194; 602 } else { 603 pub const TCP_NODELAY: ::c_int = 8193; 604 pub const TCP_MAXSEG: ::c_int = 8194; 605 } 606 } 607 608 pub const TCP_NOPUSH: ::c_int = 4; 609 pub const TCP_NOOPT: ::c_int = 8; 610 cfg_if! { 611 if #[cfg(target_os = "espidf")] { 612 pub const TCP_KEEPIDLE: ::c_int = 3; 613 pub const TCP_KEEPINTVL: ::c_int = 4; 614 pub const TCP_KEEPCNT: ::c_int = 5; 615 } else { 616 pub const TCP_KEEPIDLE: ::c_int = 256; 617 pub const TCP_KEEPINTVL: ::c_int = 512; 618 pub const TCP_KEEPCNT: ::c_int = 1024; 619 } 620 } 621 622 cfg_if! { 623 if #[cfg(target_os = "horizon")] { 624 pub const IP_TOS: ::c_int = 7; 625 } else if #[cfg(target_os = "espidf")] { 626 pub const IP_TOS: ::c_int = 1; 627 } else { 628 pub const IP_TOS: ::c_int = 3; 629 } 630 } 631 cfg_if! { 632 if #[cfg(target_os = "vita")] { 633 pub const IP_TTL: ::c_int = 4; 634 } else if #[cfg(target_os = "espidf")] { 635 pub const IP_TTL: ::c_int = 2; 636 } else { 637 pub const IP_TTL: ::c_int = 8; 638 } 639 } 640 641 cfg_if! { 642 if #[cfg(target_os = "espidf")] { 643 pub const IP_MULTICAST_IF: ::c_int = 6; 644 pub const IP_MULTICAST_TTL: ::c_int = 5; 645 pub const IP_MULTICAST_LOOP: ::c_int = 7; 646 } else { 647 pub const IP_MULTICAST_IF: ::c_int = 9; 648 pub const IP_MULTICAST_TTL: ::c_int = 10; 649 pub const IP_MULTICAST_LOOP: ::c_int = 11; 650 } 651 } 652 653 cfg_if! { 654 if #[cfg(target_os = "vita")] { 655 pub const IP_ADD_MEMBERSHIP: ::c_int = 12; 656 pub const IP_DROP_MEMBERSHIP: ::c_int = 13; 657 } else if #[cfg(target_os = "espidf")] { 658 pub const IP_ADD_MEMBERSHIP: ::c_int = 3; 659 pub const IP_DROP_MEMBERSHIP: ::c_int = 4; 660 } else { 661 pub const IP_ADD_MEMBERSHIP: ::c_int = 11; 662 pub const IP_DROP_MEMBERSHIP: ::c_int = 12; 663 } 664 } 665 pub const IPV6_UNICAST_HOPS: ::c_int = 4; 666 cfg_if! { 667 if #[cfg(target_os = "espidf")] { 668 pub const IPV6_MULTICAST_IF: ::c_int = 768; 669 pub const IPV6_MULTICAST_HOPS: ::c_int = 769; 670 pub const IPV6_MULTICAST_LOOP: ::c_int = 770; 671 } else { 672 pub const IPV6_MULTICAST_IF: ::c_int = 9; 673 pub const IPV6_MULTICAST_HOPS: ::c_int = 10; 674 pub const IPV6_MULTICAST_LOOP: ::c_int = 11; 675 } 676 } 677 pub const IPV6_V6ONLY: ::c_int = 27; 678 pub const IPV6_JOIN_GROUP: ::c_int = 12; 679 pub const IPV6_LEAVE_GROUP: ::c_int = 13; 680 pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12; 681 pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13; 682 683 cfg_if! { 684 if #[cfg(target_os = "espidf")] { 685 pub const HOST_NOT_FOUND: ::c_int = 210; 686 pub const NO_DATA: ::c_int = 211; 687 pub const NO_RECOVERY: ::c_int = 212; 688 pub const TRY_AGAIN: ::c_int = 213; 689 690 } else { 691 pub const HOST_NOT_FOUND: ::c_int = 1; 692 pub const NO_DATA: ::c_int = 2; 693 pub const NO_RECOVERY: ::c_int = 3; 694 pub const TRY_AGAIN: ::c_int = 4; 695 } 696 } 697 pub const NO_ADDRESS: ::c_int = 2; 698 699 pub const AI_PASSIVE: ::c_int = 1; 700 pub const AI_CANONNAME: ::c_int = 2; 701 pub const AI_NUMERICHOST: ::c_int = 4; 702 cfg_if! { 703 if #[cfg(target_os = "espidf")] { 704 pub const AI_NUMERICSERV: ::c_int = 8; 705 pub const AI_ADDRCONFIG: ::c_int = 64; 706 } else { 707 pub const AI_NUMERICSERV: ::c_int = 0; 708 pub const AI_ADDRCONFIG: ::c_int = 0; 709 } 710 } 711 712 pub const NI_MAXHOST: ::c_int = 1025; 713 pub const NI_MAXSERV: ::c_int = 32; 714 pub const NI_NOFQDN: ::c_int = 1; 715 pub const NI_NUMERICHOST: ::c_int = 2; 716 pub const NI_NAMEREQD: ::c_int = 4; 717 cfg_if! { 718 if #[cfg(target_os = "espidf")] { 719 pub const NI_NUMERICSERV: ::c_int = 8; 720 pub const NI_DGRAM: ::c_int = 16; 721 } else { 722 pub const NI_NUMERICSERV: ::c_int = 0; 723 pub const NI_DGRAM: ::c_int = 0; 724 } 725 } 726 727 cfg_if! { 728 // Defined in vita/mod.rs for "vita" 729 if #[cfg(target_os = "espidf")] { 730 pub const EAI_FAMILY: ::c_int = 204; 731 pub const EAI_MEMORY: ::c_int = 203; 732 pub const EAI_NONAME: ::c_int = 200; 733 pub const EAI_SOCKTYPE: ::c_int = 10; 734 } else if #[cfg(not(target_os = "vita"))] { 735 pub const EAI_FAMILY: ::c_int = -303; 736 pub const EAI_MEMORY: ::c_int = -304; 737 pub const EAI_NONAME: ::c_int = -305; 738 pub const EAI_SOCKTYPE: ::c_int = -307; 739 } 740 } 741 742 pub const EXIT_SUCCESS: ::c_int = 0; 743 pub const EXIT_FAILURE: ::c_int = 1; 744 745 pub const PRIO_PROCESS: ::c_int = 0; 746 pub const PRIO_PGRP: ::c_int = 1; 747 pub const PRIO_USER: ::c_int = 2; 748 749 f! { 750 pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { 751 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 752 let fd = fd as usize; 753 (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); 754 return 755 } 756 757 pub fn FD_ISSET(fd: ::c_int, set: *const fd_set) -> bool { 758 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 759 let fd = fd as usize; 760 return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 761 } 762 763 pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { 764 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; 765 let fd = fd as usize; 766 (*set).fds_bits[fd / bits] |= 1 << (fd % bits); 767 return 768 } 769 770 pub fn FD_ZERO(set: *mut fd_set) -> () { 771 for slot in (*set).fds_bits.iter_mut() { 772 *slot = 0; 773 } 774 } 775 } 776 777 extern "C" { getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int778 pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int779 pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; 780 781 #[cfg_attr(target_os = "linux", link_name = "__xpg_strerror_r")] strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int782 pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int; 783 sem_destroy(sem: *mut sem_t) -> ::c_int784 pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; sem_init(sem: *mut sem_t, pshared: ::c_int, value: ::c_uint) -> ::c_int785 pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, value: ::c_uint) -> ::c_int; 786 abs(i: ::c_int) -> ::c_int787 pub fn abs(i: ::c_int) -> ::c_int; labs(i: ::c_long) -> ::c_long788 pub fn labs(i: ::c_long) -> ::c_long; rand() -> ::c_int789 pub fn rand() -> ::c_int; srand(seed: ::c_uint)790 pub fn srand(seed: ::c_uint); 791 792 #[cfg(not(all( 793 libc_cfg_target_vendor, 794 target_arch = "powerpc", 795 target_vendor = "nintendo" 796 )))] 797 #[cfg_attr(target_os = "espidf", link_name = "lwip_bind")] bind(fd: ::c_int, addr: *const sockaddr, len: socklen_t) -> ::c_int798 pub fn bind(fd: ::c_int, addr: *const sockaddr, len: socklen_t) -> ::c_int; clock_settime(clock_id: ::clockid_t, tp: *const ::timespec) -> ::c_int799 pub fn clock_settime(clock_id: ::clockid_t, tp: *const ::timespec) -> ::c_int; clock_gettime(clock_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int800 pub fn clock_gettime(clock_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; clock_getres(clock_id: ::clockid_t, res: *mut ::timespec) -> ::c_int801 pub fn clock_getres(clock_id: ::clockid_t, res: *mut ::timespec) -> ::c_int; 802 #[cfg_attr(target_os = "espidf", link_name = "lwip_close")] closesocket(sockfd: ::c_int) -> ::c_int803 pub fn closesocket(sockfd: ::c_int) -> ::c_int; ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int804 pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; 805 #[cfg(not(all( 806 libc_cfg_target_vendor, 807 target_arch = "powerpc", 808 target_vendor = "nintendo" 809 )))] 810 #[cfg_attr(target_os = "espidf", link_name = "lwip_recvfrom")] recvfrom( fd: ::c_int, buf: *mut ::c_void, n: usize, flags: ::c_int, addr: *mut sockaddr, addr_len: *mut socklen_t, ) -> isize811 pub fn recvfrom( 812 fd: ::c_int, 813 buf: *mut ::c_void, 814 n: usize, 815 flags: ::c_int, 816 addr: *mut sockaddr, 817 addr_len: *mut socklen_t, 818 ) -> isize; 819 #[cfg(not(all( 820 libc_cfg_target_vendor, 821 target_arch = "powerpc", 822 target_vendor = "nintendo" 823 )))] getnameinfo( sa: *const sockaddr, salen: socklen_t, host: *mut ::c_char, hostlen: socklen_t, serv: *mut ::c_char, servlen: socklen_t, flags: ::c_int, ) -> ::c_int824 pub fn getnameinfo( 825 sa: *const sockaddr, 826 salen: socklen_t, 827 host: *mut ::c_char, 828 hostlen: socklen_t, 829 serv: *mut ::c_char, 830 servlen: socklen_t, 831 flags: ::c_int, 832 ) -> ::c_int; memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void833 pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; fexecve( fd: ::c_int, argv: *const *const ::c_char, envp: *const *const ::c_char, ) -> ::c_int834 pub fn fexecve( 835 fd: ::c_int, 836 argv: *const *const ::c_char, 837 envp: *const *const ::c_char, 838 ) -> ::c_int; gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int839 pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; getgrgid_r( gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut ::group, ) -> ::c_int840 pub fn getgrgid_r( 841 gid: ::gid_t, 842 grp: *mut ::group, 843 buf: *mut ::c_char, 844 buflen: ::size_t, 845 result: *mut *mut ::group, 846 ) -> ::c_int; sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int847 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; sem_close(sem: *mut sem_t) -> ::c_int848 pub fn sem_close(sem: *mut sem_t) -> ::c_int; getdtablesize() -> ::c_int849 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_int850 pub fn getgrnam_r( 851 name: *const ::c_char, 852 grp: *mut ::group, 853 buf: *mut ::c_char, 854 buflen: ::size_t, 855 result: *mut *mut ::group, 856 ) -> ::c_int; pthread_sigmask(how: ::c_int, set: *const sigset_t, oldset: *mut sigset_t) -> ::c_int857 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_t858 pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; getgrnam(name: *const ::c_char) -> *mut ::group859 pub fn getgrnam(name: *const ::c_char) -> *mut ::group; pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int860 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; sem_unlink(name: *const ::c_char) -> ::c_int861 pub fn sem_unlink(name: *const ::c_char) -> ::c_int; daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int862 pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; getpwnam_r( name: *const ::c_char, pwd: *mut passwd, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut passwd, ) -> ::c_int863 pub fn getpwnam_r( 864 name: *const ::c_char, 865 pwd: *mut passwd, 866 buf: *mut ::c_char, 867 buflen: ::size_t, 868 result: *mut *mut passwd, 869 ) -> ::c_int; getpwuid_r( uid: ::uid_t, pwd: *mut passwd, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut passwd, ) -> ::c_int870 pub fn getpwuid_r( 871 uid: ::uid_t, 872 pwd: *mut passwd, 873 buf: *mut ::c_char, 874 buflen: ::size_t, 875 result: *mut *mut passwd, 876 ) -> ::c_int; sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int877 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_int878 pub fn pthread_atfork( 879 prepare: ::Option<unsafe extern "C" fn()>, 880 parent: ::Option<unsafe extern "C" fn()>, 881 child: ::Option<unsafe extern "C" fn()>, 882 ) -> ::c_int; getgrgid(gid: ::gid_t) -> *mut ::group883 pub fn getgrgid(gid: ::gid_t) -> *mut ::group; popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE884 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; uname(buf: *mut ::utsname) -> ::c_int885 pub fn uname(buf: *mut ::utsname) -> ::c_int; 886 } 887 888 mod generic; 889 890 cfg_if! { 891 if #[cfg(target_os = "espidf")] { 892 mod espidf; 893 pub use self::espidf::*; 894 } else if #[cfg(target_os = "horizon")] { 895 mod horizon; 896 pub use self::horizon::*; 897 } else if #[cfg(target_os = "vita")] { 898 mod vita; 899 pub use self::vita::*; 900 } else if #[cfg(target_arch = "arm")] { 901 mod arm; 902 pub use self::arm::*; 903 } else if #[cfg(target_arch = "aarch64")] { 904 mod aarch64; 905 pub use self::aarch64::*; 906 } else if #[cfg(target_arch = "powerpc")] { 907 mod powerpc; 908 pub use self::powerpc::*; 909 } else { 910 // Only tested on ARM so far. Other platforms might have different 911 // definitions for types and constants. 912 pub use target_arch_not_implemented; 913 } 914 } 915 916 cfg_if! { 917 if #[cfg(target_os = "rtems")] { 918 mod rtems; 919 pub use self::rtems::*; 920 } 921 } 922 923 cfg_if! { 924 if #[cfg(libc_align)] { 925 #[macro_use] 926 mod align; 927 } else { 928 #[macro_use] 929 mod no_align; 930 } 931 } 932 expand_align!(); 933