1 //! Interface to VxWorks C library 2 3 use core::mem::size_of; 4 use core::ptr::null_mut; 5 6 use crate::prelude::*; 7 8 #[cfg_attr(feature = "extra_traits", derive(Debug))] 9 pub enum DIR {} 10 impl Copy for DIR {} 11 impl Clone for DIR { 12 fn clone(&self) -> DIR { 13 *self 14 } 15 } 16 17 pub type intmax_t = i64; 18 pub type uintmax_t = u64; 19 20 pub type uintptr_t = usize; 21 pub type intptr_t = isize; 22 pub type ptrdiff_t = isize; 23 pub type size_t = crate::uintptr_t; 24 pub type ssize_t = intptr_t; 25 26 pub type pid_t = c_int; 27 pub type in_addr_t = u32; 28 pub type sighandler_t = size_t; 29 pub type cpuset_t = u32; 30 31 pub type blkcnt_t = c_long; 32 pub type blksize_t = c_long; 33 pub type ino_t = c_ulong; 34 35 pub type rlim_t = c_ulong; 36 pub type suseconds_t = c_long; 37 pub type time_t = c_longlong; 38 39 pub type errno_t = c_int; 40 41 pub type useconds_t = c_ulong; 42 43 pub type socklen_t = c_uint; 44 45 pub type pthread_t = c_ulong; 46 47 pub type clockid_t = c_int; 48 49 //defined for the structs 50 pub type dev_t = c_ulong; 51 pub type mode_t = c_int; 52 pub type nlink_t = c_ulong; 53 pub type uid_t = c_ushort; 54 pub type gid_t = c_ushort; 55 pub type sigset_t = c_ulonglong; 56 pub type key_t = c_long; 57 58 pub type nfds_t = c_uint; 59 pub type stat64 = crate::stat; 60 61 pub type pthread_key_t = c_ulong; 62 63 // From b_off_t.h 64 pub type off_t = c_longlong; 65 pub type off64_t = off_t; 66 67 // From b_BOOL.h 68 pub type BOOL = c_int; 69 70 // From vxWind.h .. 71 pub type _Vx_OBJ_HANDLE = c_int; 72 pub type _Vx_TASK_ID = crate::_Vx_OBJ_HANDLE; 73 pub type _Vx_MSG_Q_ID = crate::_Vx_OBJ_HANDLE; 74 pub type _Vx_SEM_ID_KERNEL = crate::_Vx_OBJ_HANDLE; 75 pub type _Vx_RTP_ID = crate::_Vx_OBJ_HANDLE; 76 pub type _Vx_SD_ID = crate::_Vx_OBJ_HANDLE; 77 pub type _Vx_CONDVAR_ID = crate::_Vx_OBJ_HANDLE; 78 pub type _Vx_SEM_ID = *mut crate::_Vx_semaphore; 79 pub type OBJ_HANDLE = crate::_Vx_OBJ_HANDLE; 80 pub type TASK_ID = crate::OBJ_HANDLE; 81 pub type MSG_Q_ID = crate::OBJ_HANDLE; 82 pub type SEM_ID_KERNEL = crate::OBJ_HANDLE; 83 pub type RTP_ID = crate::OBJ_HANDLE; 84 pub type SD_ID = crate::OBJ_HANDLE; 85 pub type CONDVAR_ID = crate::OBJ_HANDLE; 86 pub type STATUS = crate::OBJ_HANDLE; 87 88 // From vxTypes.h 89 pub type _Vx_usr_arg_t = isize; 90 pub type _Vx_exit_code_t = isize; 91 pub type _Vx_ticks_t = c_uint; 92 pub type _Vx_ticks64_t = c_ulonglong; 93 94 pub type sa_family_t = c_uchar; 95 96 // mqueue.h 97 pub type mqd_t = c_int; 98 99 #[cfg_attr(feature = "extra_traits", derive(Debug))] 100 pub enum _Vx_semaphore {} 101 impl Copy for _Vx_semaphore {} 102 impl Clone for _Vx_semaphore { 103 fn clone(&self) -> _Vx_semaphore { 104 *self 105 } 106 } 107 108 impl siginfo_t { 109 pub unsafe fn si_addr(&self) -> *mut c_void { 110 self.si_addr 111 } 112 113 pub unsafe fn si_value(&self) -> crate::sigval { 114 self.si_value 115 } 116 117 pub unsafe fn si_pid(&self) -> crate::pid_t { 118 self.si_pid 119 } 120 121 pub unsafe fn si_uid(&self) -> crate::uid_t { 122 self.si_uid 123 } 124 125 pub unsafe fn si_status(&self) -> c_int { 126 self.si_status 127 } 128 } 129 130 s! { 131 // b_pthread_condattr_t.h 132 pub struct pthread_condattr_t { 133 pub condAttrStatus: c_int, 134 pub condAttrPshared: c_int, 135 pub condAttrClockId: crate::clockid_t, 136 } 137 138 // b_pthread_cond_t.h 139 pub struct pthread_cond_t { 140 pub condSemId: crate::_Vx_SEM_ID, 141 pub condValid: c_int, 142 pub condInitted: c_int, 143 pub condRefCount: c_int, 144 pub condMutex: *mut crate::pthread_mutex_t, 145 pub condAttr: crate::pthread_condattr_t, 146 pub condSemName: [c_char; _PTHREAD_SHARED_SEM_NAME_MAX], 147 } 148 149 // b_pthread_rwlockattr_t.h 150 pub struct pthread_rwlockattr_t { 151 pub rwlockAttrStatus: c_int, 152 pub rwlockAttrPshared: c_int, 153 pub rwlockAttrMaxReaders: c_uint, 154 pub rwlockAttrConformOpt: c_uint, 155 } 156 157 // b_pthread_rwlock_t.h 158 pub struct pthread_rwlock_t { 159 pub rwlockSemId: crate::_Vx_SEM_ID, 160 pub rwlockReadersRefCount: c_uint, 161 pub rwlockValid: c_int, 162 pub rwlockInitted: c_int, 163 pub rwlockAttr: crate::pthread_rwlockattr_t, 164 pub rwlockSemName: [c_char; _PTHREAD_SHARED_SEM_NAME_MAX], 165 } 166 167 // b_struct_timeval.h 168 pub struct timeval { 169 pub tv_sec: crate::time_t, 170 pub tv_usec: crate::suseconds_t, 171 } 172 173 // socket.h 174 pub struct linger { 175 pub l_onoff: c_int, 176 pub l_linger: c_int, 177 } 178 179 pub struct sockaddr { 180 pub sa_len: c_uchar, 181 pub sa_family: sa_family_t, 182 pub sa_data: [c_char; 14], 183 } 184 185 pub struct iovec { 186 pub iov_base: *mut c_void, 187 pub iov_len: size_t, 188 } 189 190 pub struct msghdr { 191 pub msg_name: *mut c_void, 192 pub msg_namelen: socklen_t, 193 pub msg_iov: *mut iovec, 194 pub msg_iovlen: c_int, 195 pub msg_control: *mut c_void, 196 pub msg_controllen: socklen_t, 197 pub msg_flags: c_int, 198 } 199 200 pub struct cmsghdr { 201 pub cmsg_len: socklen_t, 202 pub cmsg_level: c_int, 203 pub cmsg_type: c_int, 204 } 205 206 // poll.h 207 pub struct pollfd { 208 pub fd: c_int, 209 pub events: c_short, 210 pub revents: c_short, 211 } 212 213 // resource.h 214 pub struct rlimit { 215 pub rlim_cur: crate::rlim_t, 216 pub rlim_max: crate::rlim_t, 217 } 218 219 // stat.h 220 pub struct stat { 221 pub st_dev: crate::dev_t, 222 pub st_ino: crate::ino_t, 223 pub st_mode: crate::mode_t, 224 pub st_nlink: crate::nlink_t, 225 pub st_uid: crate::uid_t, 226 pub st_gid: crate::gid_t, 227 pub st_rdev: crate::dev_t, 228 pub st_size: off_t, 229 pub st_atime: crate::time_t, 230 pub st_mtime: crate::time_t, 231 pub st_ctime: crate::time_t, 232 pub st_blksize: crate::blksize_t, 233 pub st_blocks: crate::blkcnt_t, 234 pub st_attrib: c_uchar, 235 pub st_reserved1: c_int, 236 pub st_reserved2: c_int, 237 pub st_reserved3: c_int, 238 pub st_reserved4: c_int, 239 } 240 241 //b_struct__Timespec.h 242 pub struct _Timespec { 243 pub tv_sec: crate::time_t, 244 pub tv_nsec: c_long, 245 } 246 247 // b_struct__Sched_param.h 248 pub struct sched_param { 249 pub sched_priority: c_int, /* scheduling priority */ 250 pub sched_ss_low_priority: c_int, /* low scheduling priority */ 251 pub sched_ss_repl_period: crate::_Timespec, /* replenishment period */ 252 pub sched_ss_init_budget: crate::_Timespec, /* initial budget */ 253 pub sched_ss_max_repl: c_int, /* max pending replenishment */ 254 } 255 256 // b_pthread_attr_t.h 257 pub struct pthread_attr_t { 258 pub threadAttrStatus: c_int, 259 pub threadAttrStacksize: size_t, 260 pub threadAttrStackaddr: *mut c_void, 261 pub threadAttrGuardsize: size_t, 262 pub threadAttrDetachstate: c_int, 263 pub threadAttrContentionscope: c_int, 264 pub threadAttrInheritsched: c_int, 265 pub threadAttrSchedpolicy: c_int, 266 pub threadAttrName: *mut c_char, 267 pub threadAttrOptions: c_int, 268 pub threadAttrSchedparam: crate::sched_param, 269 } 270 271 // signal.h 272 273 pub struct sigaction { 274 pub sa_u: crate::sa_u_t, 275 pub sa_mask: crate::sigset_t, 276 pub sa_flags: c_int, 277 } 278 279 // b_stack_t.h 280 pub struct stack_t { 281 pub ss_sp: *mut c_void, 282 pub ss_size: size_t, 283 pub ss_flags: c_int, 284 } 285 286 // signal.h 287 pub struct siginfo_t { 288 pub si_signo: c_int, 289 pub si_code: c_int, 290 pub si_value: crate::sigval, 291 pub si_errno: c_int, 292 pub si_status: c_int, 293 pub si_addr: *mut c_void, 294 pub si_uid: crate::uid_t, 295 pub si_pid: crate::pid_t, 296 } 297 298 // pthread.h (krnl) 299 // b_pthread_mutexattr_t.h (usr) 300 pub struct pthread_mutexattr_t { 301 mutexAttrStatus: c_int, 302 mutexAttrPshared: c_int, 303 mutexAttrProtocol: c_int, 304 mutexAttrPrioceiling: c_int, 305 mutexAttrType: c_int, 306 } 307 308 // pthread.h (krnl) 309 // b_pthread_mutex_t.h (usr) 310 pub struct pthread_mutex_t { 311 pub mutexSemId: crate::_Vx_SEM_ID, /*_Vx_SEM_ID ..*/ 312 pub mutexValid: c_int, 313 pub mutexInitted: c_int, 314 pub mutexCondRefCount: c_int, 315 pub mutexSavPriority: c_int, 316 pub mutexAttr: crate::pthread_mutexattr_t, 317 pub mutexSemName: [c_char; _PTHREAD_SHARED_SEM_NAME_MAX], 318 } 319 320 // b_struct_timespec.h 321 pub struct timespec { 322 pub tv_sec: crate::time_t, 323 pub tv_nsec: c_long, 324 } 325 326 // time.h 327 pub struct tm { 328 pub tm_sec: c_int, 329 pub tm_min: c_int, 330 pub tm_hour: c_int, 331 pub tm_mday: c_int, 332 pub tm_mon: c_int, 333 pub tm_year: c_int, 334 pub tm_wday: c_int, 335 pub tm_yday: c_int, 336 pub tm_isdst: c_int, 337 } 338 339 // in.h 340 pub struct in_addr { 341 pub s_addr: in_addr_t, 342 } 343 344 // in.h 345 pub struct ip_mreq { 346 pub imr_multiaddr: in_addr, 347 pub imr_interface: in_addr, 348 } 349 350 // in6.h 351 #[repr(align(4))] 352 pub struct in6_addr { 353 pub s6_addr: [u8; 16], 354 } 355 356 // in6.h 357 pub struct ipv6_mreq { 358 pub ipv6mr_multiaddr: in6_addr, 359 pub ipv6mr_interface: c_uint, 360 } 361 362 // netdb.h 363 pub struct addrinfo { 364 pub ai_flags: c_int, 365 pub ai_family: c_int, 366 pub ai_socktype: c_int, 367 pub ai_protocol: c_int, 368 pub ai_addrlen: size_t, 369 pub ai_canonname: *mut c_char, 370 pub ai_addr: *mut crate::sockaddr, 371 pub ai_next: *mut crate::addrinfo, 372 } 373 374 // in.h 375 pub struct sockaddr_in { 376 pub sin_len: u8, 377 pub sin_family: u8, 378 pub sin_port: u16, 379 pub sin_addr: crate::in_addr, 380 pub sin_zero: [c_char; 8], 381 } 382 383 // in6.h 384 pub struct sockaddr_in6 { 385 pub sin6_len: u8, 386 pub sin6_family: u8, 387 pub sin6_port: u16, 388 pub sin6_flowinfo: u32, 389 pub sin6_addr: crate::in6_addr, 390 pub sin6_scope_id: u32, 391 } 392 393 pub struct Dl_info { 394 pub dli_fname: *const c_char, 395 pub dli_fbase: *mut c_void, 396 pub dli_sname: *const c_char, 397 pub dli_saddr: *mut c_void, 398 } 399 400 pub struct mq_attr { 401 pub mq_maxmsg: c_long, 402 pub mq_msgsize: c_long, 403 pub mq_flags: c_long, 404 pub mq_curmsgs: c_long, 405 } 406 } 407 408 s_no_extra_traits! { 409 // dirent.h 410 pub struct dirent { 411 pub d_ino: crate::ino_t, 412 pub d_name: [c_char; _PARM_NAME_MAX as usize + 1], 413 } 414 415 pub struct sockaddr_un { 416 pub sun_len: u8, 417 pub sun_family: sa_family_t, 418 pub sun_path: [c_char; 104], 419 } 420 421 // rtpLibCommon.h 422 pub struct RTP_DESC { 423 pub status: c_int, 424 pub options: u32, 425 pub entrAddr: *mut c_void, 426 pub initTaskId: crate::TASK_ID, 427 pub parentId: crate::RTP_ID, 428 pub pathName: [c_char; VX_RTP_NAME_LENGTH as usize + 1], 429 pub taskCnt: c_int, 430 pub textStart: *mut c_void, 431 pub textEnd: *mut c_void, 432 } 433 // socket.h 434 pub struct sockaddr_storage { 435 pub ss_len: c_uchar, 436 pub ss_family: crate::sa_family_t, 437 pub __ss_pad1: [c_char; _SS_PAD1SIZE], 438 pub __ss_align: i32, 439 pub __ss_pad2: [c_char; _SS_PAD2SIZE], 440 } 441 442 pub union sa_u_t { 443 pub sa_handler: Option<unsafe extern "C" fn(c_int) -> !>, 444 pub sa_sigaction: 445 Option<unsafe extern "C" fn(c_int, *mut crate::siginfo_t, *mut c_void) -> !>, 446 } 447 448 pub union sigval { 449 pub sival_int: c_int, 450 pub sival_ptr: *mut c_void, 451 } 452 } 453 454 cfg_if! { 455 if #[cfg(feature = "extra_traits")] { 456 impl fmt::Debug for dirent { 457 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 458 f.debug_struct("dirent") 459 .field("d_ino", &self.d_ino) 460 .field("d_name", &&self.d_name[..]) 461 .finish() 462 } 463 } 464 465 impl fmt::Debug for sockaddr_un { 466 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 467 f.debug_struct("sockaddr_un") 468 .field("sun_len", &self.sun_len) 469 .field("sun_family", &self.sun_family) 470 .field("sun_path", &&self.sun_path[..]) 471 .finish() 472 } 473 } 474 475 impl fmt::Debug for RTP_DESC { 476 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 477 f.debug_struct("RTP_DESC") 478 .field("status", &self.status) 479 .field("options", &self.options) 480 .field("entrAddr", &self.entrAddr) 481 .field("initTaskId", &self.initTaskId) 482 .field("parentId", &self.parentId) 483 .field("pathName", &&self.pathName[..]) 484 .field("taskCnt", &self.taskCnt) 485 .field("textStart", &self.textStart) 486 .field("textEnd", &self.textEnd) 487 .finish() 488 } 489 } 490 impl fmt::Debug for sockaddr_storage { 491 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 492 f.debug_struct("sockaddr_storage") 493 .field("ss_len", &self.ss_len) 494 .field("ss_family", &self.ss_family) 495 .field("__ss_pad1", &&self.__ss_pad1[..]) 496 .field("__ss_align", &self.__ss_align) 497 .field("__ss_pad2", &&self.__ss_pad2[..]) 498 .finish() 499 } 500 } 501 502 impl PartialEq for sa_u_t { 503 fn eq(&self, other: &sa_u_t) -> bool { 504 unsafe { 505 let h1 = match self.sa_handler { 506 Some(handler) => handler as usize, 507 None => 0 as usize, 508 }; 509 let h2 = match other.sa_handler { 510 Some(handler) => handler as usize, 511 None => 0 as usize, 512 }; 513 h1 == h2 514 } 515 } 516 } 517 impl Eq for sa_u_t {} 518 impl hash::Hash for sa_u_t { 519 fn hash<H: hash::Hasher>(&self, state: &mut H) { 520 unsafe { 521 let h = match self.sa_handler { 522 Some(handler) => handler as usize, 523 None => 0 as usize, 524 }; 525 h.hash(state) 526 } 527 } 528 } 529 530 impl PartialEq for sigval { 531 fn eq(&self, other: &sigval) -> bool { 532 unsafe { self.sival_ptr as usize == other.sival_ptr as usize } 533 } 534 } 535 impl Eq for sigval {} 536 impl hash::Hash for sigval { 537 fn hash<H: hash::Hasher>(&self, state: &mut H) { 538 unsafe { (self.sival_ptr as usize).hash(state) }; 539 } 540 } 541 } 542 } 543 544 pub const STDIN_FILENO: c_int = 0; 545 pub const STDOUT_FILENO: c_int = 1; 546 pub const STDERR_FILENO: c_int = 2; 547 548 pub const EXIT_SUCCESS: c_int = 0; 549 pub const EXIT_FAILURE: c_int = 1; 550 551 pub const EAI_SERVICE: c_int = 9; 552 pub const EAI_SOCKTYPE: c_int = 10; 553 pub const EAI_SYSTEM: c_int = 11; 554 555 // FIXME(vxworks): This is not defined in vxWorks, but we have to define it here 556 // to make the building pass for getrandom and std 557 pub const RTLD_DEFAULT: *mut c_void = 0i64 as *mut c_void; 558 559 //Clock Lib Stuff 560 pub const CLOCK_REALTIME: c_int = 0x0; 561 pub const CLOCK_MONOTONIC: c_int = 0x1; 562 pub const CLOCK_PROCESS_CPUTIME_ID: c_int = 0x2; 563 pub const CLOCK_THREAD_CPUTIME_ID: c_int = 0x3; 564 pub const TIMER_ABSTIME: c_int = 0x1; 565 pub const TIMER_RELTIME: c_int = 0x0; 566 567 // PTHREAD STUFF 568 pub const PTHREAD_INITIALIZED_OBJ: c_int = 0xF70990EF; 569 pub const PTHREAD_DESTROYED_OBJ: c_int = -1; 570 pub const PTHREAD_VALID_OBJ: c_int = 0xEC542A37; 571 pub const PTHREAD_INVALID_OBJ: c_int = -1; 572 pub const PTHREAD_UNUSED_YET_OBJ: c_int = -1; 573 574 pub const PTHREAD_PRIO_NONE: c_int = 0; 575 pub const PTHREAD_PRIO_INHERIT: c_int = 1; 576 pub const PTHREAD_PRIO_PROTECT: c_int = 2; 577 578 pub const PTHREAD_MUTEX_NORMAL: c_int = 0; 579 pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 1; 580 pub const PTHREAD_MUTEX_RECURSIVE: c_int = 2; 581 pub const PTHREAD_MUTEX_DEFAULT: c_int = PTHREAD_MUTEX_NORMAL; 582 pub const PTHREAD_STACK_MIN: usize = 4096; 583 pub const _PTHREAD_SHARED_SEM_NAME_MAX: usize = 30; 584 585 //sched.h 586 pub const SCHED_FIFO: c_int = 0x01; 587 pub const SCHED_RR: c_int = 0x02; 588 pub const SCHED_OTHER: c_int = 0x04; 589 pub const SCHED_SPORADIC: c_int = 0x08; 590 pub const PRIO_PROCESS: c_uint = 0; 591 pub const SCHED_FIFO_HIGH_PRI: c_int = 255; 592 pub const SCHED_FIFO_LOW_PRI: c_int = 0; 593 pub const SCHED_RR_HIGH_PRI: c_int = 255; 594 pub const SCHED_RR_LOW_PRI: c_int = 0; 595 pub const SCHED_SPORADIC_HIGH_PRI: c_int = 255; 596 pub const SCHED_SPORADIC_LOW_PRI: c_int = 0; 597 598 // ERRNO STUFF 599 pub const ERROR: c_int = -1; 600 pub const OK: c_int = 0; 601 pub const EPERM: c_int = 1; /* Not owner */ 602 pub const ENOENT: c_int = 2; /* No such file or directory */ 603 pub const ESRCH: c_int = 3; /* No such process */ 604 pub const EINTR: c_int = 4; /* Interrupted system call */ 605 pub const EIO: c_int = 5; /* I/O error */ 606 pub const ENXIO: c_int = 6; /* No such device or address */ 607 pub const E2BIG: c_int = 7; /* Arg list too long */ 608 pub const ENOEXEC: c_int = 8; /* Exec format error */ 609 pub const EBADF: c_int = 9; /* Bad file number */ 610 pub const ECHILD: c_int = 10; /* No children */ 611 pub const EAGAIN: c_int = 11; /* No more processes */ 612 pub const ENOMEM: c_int = 12; /* Not enough core */ 613 pub const EACCES: c_int = 13; /* Permission denied */ 614 pub const EFAULT: c_int = 14; 615 pub const ENOTEMPTY: c_int = 15; 616 pub const EBUSY: c_int = 16; 617 pub const EEXIST: c_int = 17; 618 pub const EXDEV: c_int = 18; 619 pub const ENODEV: c_int = 19; 620 pub const ENOTDIR: c_int = 20; 621 pub const EISDIR: c_int = 21; 622 pub const EINVAL: c_int = 22; 623 pub const ENFILE: c_int = 23; 624 pub const EMFILE: c_int = 24; 625 pub const ENOTTY: c_int = 25; 626 pub const ENAMETOOLONG: c_int = 26; 627 pub const EFBIG: c_int = 27; 628 pub const ENOSPC: c_int = 28; 629 pub const ESPIPE: c_int = 29; 630 pub const EROFS: c_int = 30; 631 pub const EMLINK: c_int = 31; 632 pub const EPIPE: c_int = 32; 633 pub const EDEADLK: c_int = 33; 634 pub const ENOLCK: c_int = 34; 635 pub const ENOTSUP: c_int = 35; 636 pub const EMSGSIZE: c_int = 36; 637 pub const EDOM: c_int = 37; 638 pub const ERANGE: c_int = 38; 639 pub const EDOOM: c_int = 39; 640 pub const EDESTADDRREQ: c_int = 40; 641 pub const EPROTOTYPE: c_int = 41; 642 pub const ENOPROTOOPT: c_int = 42; 643 pub const EPROTONOSUPPORT: c_int = 43; 644 pub const ESOCKTNOSUPPORT: c_int = 44; 645 pub const EOPNOTSUPP: c_int = 45; 646 pub const EPFNOSUPPORT: c_int = 46; 647 pub const EAFNOSUPPORT: c_int = 47; 648 pub const EADDRINUSE: c_int = 48; 649 pub const EADDRNOTAVAIL: c_int = 49; 650 pub const ENOTSOCK: c_int = 50; 651 pub const ENETUNREACH: c_int = 51; 652 pub const ENETRESET: c_int = 52; 653 pub const ECONNABORTED: c_int = 53; 654 pub const ECONNRESET: c_int = 54; 655 pub const ENOBUFS: c_int = 55; 656 pub const EISCONN: c_int = 56; 657 pub const ENOTCONN: c_int = 57; 658 pub const ESHUTDOWN: c_int = 58; 659 pub const ETOOMANYREFS: c_int = 59; 660 pub const ETIMEDOUT: c_int = 60; 661 pub const ECONNREFUSED: c_int = 61; 662 pub const ENETDOWN: c_int = 62; 663 pub const ETXTBSY: c_int = 63; 664 pub const ELOOP: c_int = 64; 665 pub const EHOSTUNREACH: c_int = 65; 666 pub const ENOTBLK: c_int = 66; 667 pub const EHOSTDOWN: c_int = 67; 668 pub const EINPROGRESS: c_int = 68; 669 pub const EALREADY: c_int = 69; 670 pub const EWOULDBLOCK: c_int = 70; 671 pub const ENOSYS: c_int = 71; 672 pub const ECANCELED: c_int = 72; 673 pub const ENOSR: c_int = 74; 674 pub const ENOSTR: c_int = 75; 675 pub const EPROTO: c_int = 76; 676 pub const EBADMSG: c_int = 77; 677 pub const ENODATA: c_int = 78; 678 pub const ETIME: c_int = 79; 679 pub const ENOMSG: c_int = 80; 680 pub const EFPOS: c_int = 81; 681 pub const EILSEQ: c_int = 82; 682 pub const EDQUOT: c_int = 83; 683 pub const EIDRM: c_int = 84; 684 pub const EOVERFLOW: c_int = 85; 685 pub const EMULTIHOP: c_int = 86; 686 pub const ENOLINK: c_int = 87; 687 pub const ESTALE: c_int = 88; 688 pub const EOWNERDEAD: c_int = 89; 689 pub const ENOTRECOVERABLE: c_int = 90; 690 691 // NFS errnos: Refer to pkgs_v2/storage/fs/nfs/h/nfs/nfsCommon.h 692 const M_nfsStat: c_int = 48 << 16; 693 enum nfsstat { 694 NFSERR_REMOTE = 71, 695 NFSERR_WFLUSH = 99, 696 NFSERR_BADHANDLE = 10001, 697 NFSERR_NOT_SYNC = 10002, 698 NFSERR_BAD_COOKIE = 10003, 699 NFSERR_TOOSMALL = 10005, 700 NFSERR_BADTYPE = 10007, 701 NFSERR_JUKEBOX = 10008, 702 } 703 704 pub const S_nfsLib_NFS_OK: c_int = OK; 705 pub const S_nfsLib_NFSERR_PERM: c_int = EPERM; 706 pub const S_nfsLib_NFSERR_NOENT: c_int = ENOENT; 707 pub const S_nfsLib_NFSERR_IO: c_int = EIO; 708 pub const S_nfsLib_NFSERR_NXIO: c_int = ENXIO; 709 pub const S_nfsLib_NFSERR_ACCESS: c_int = EACCES; 710 pub const S_nfsLib_NFSERR_EXIST: c_int = EEXIST; 711 pub const S_nfsLib_NFSERR_ENODEV: c_int = ENODEV; 712 pub const S_nfsLib_NFSERR_NOTDIR: c_int = ENOTDIR; 713 pub const S_nfsLib_NFSERR_ISDIR: c_int = EISDIR; 714 pub const S_nfsLib_NFSERR_INVAL: c_int = EINVAL; 715 pub const S_nfsLib_NFSERR_FBIG: c_int = EFBIG; 716 pub const S_nfsLib_NFSERR_NOSPC: c_int = ENOSPC; 717 pub const S_nfsLib_NFSERR_ROFS: c_int = EROFS; 718 pub const S_nfsLib_NFSERR_NAMETOOLONG: c_int = ENAMETOOLONG; 719 pub const S_nfsLib_NFSERR_NOTEMPTY: c_int = ENOTEMPTY; 720 pub const S_nfsLib_NFSERR_DQUOT: c_int = EDQUOT; 721 pub const S_nfsLib_NFSERR_STALE: c_int = ESTALE; 722 pub const S_nfsLib_NFSERR_WFLUSH: c_int = M_nfsStat | nfsstat::NFSERR_WFLUSH as c_int; 723 pub const S_nfsLib_NFSERR_REMOTE: c_int = M_nfsStat | nfsstat::NFSERR_REMOTE as c_int; 724 pub const S_nfsLib_NFSERR_BADHANDLE: c_int = M_nfsStat | nfsstat::NFSERR_BADHANDLE as c_int; 725 pub const S_nfsLib_NFSERR_NOT_SYNC: c_int = M_nfsStat | nfsstat::NFSERR_NOT_SYNC as c_int; 726 pub const S_nfsLib_NFSERR_BAD_COOKIE: c_int = M_nfsStat | nfsstat::NFSERR_BAD_COOKIE as c_int; 727 pub const S_nfsLib_NFSERR_NOTSUPP: c_int = EOPNOTSUPP; 728 pub const S_nfsLib_NFSERR_TOOSMALL: c_int = M_nfsStat | nfsstat::NFSERR_TOOSMALL as c_int; 729 pub const S_nfsLib_NFSERR_SERVERFAULT: c_int = EIO; 730 pub const S_nfsLib_NFSERR_BADTYPE: c_int = M_nfsStat | nfsstat::NFSERR_BADTYPE as c_int; 731 pub const S_nfsLib_NFSERR_JUKEBOX: c_int = M_nfsStat | nfsstat::NFSERR_JUKEBOX as c_int; 732 733 // internal offset values for below constants 734 const taskErrorBase: c_int = 0x00030000; 735 const semErrorBase: c_int = 0x00160000; 736 const objErrorBase: c_int = 0x003d0000; 737 738 // taskLibCommon.h 739 pub const S_taskLib_NAME_NOT_FOUND: c_int = taskErrorBase + 0x0065; 740 pub const S_taskLib_TASK_HOOK_TABLE_FULL: c_int = taskErrorBase + 0x0066; 741 pub const S_taskLib_TASK_HOOK_NOT_FOUND: c_int = taskErrorBase + 0x0067; 742 pub const S_taskLib_ILLEGAL_PRIORITY: c_int = taskErrorBase + 0x0068; 743 744 // FIXME(vxworks): could also be useful for TASK_DESC type 745 pub const VX_TASK_NAME_LENGTH: c_int = 31; 746 747 // semLibCommon.h 748 pub const S_semLib_INVALID_STATE: c_int = semErrorBase + 0x0065; 749 pub const S_semLib_INVALID_OPTION: c_int = semErrorBase + 0x0066; 750 pub const S_semLib_INVALID_QUEUE_TYPE: c_int = semErrorBase + 0x0067; 751 pub const S_semLib_INVALID_OPERATION: c_int = semErrorBase + 0x0068; 752 753 // objLibCommon.h 754 pub const S_objLib_OBJ_ID_ERROR: c_int = objErrorBase + 0x0001; 755 pub const S_objLib_OBJ_UNAVAILABLE: c_int = objErrorBase + 0x0002; 756 pub const S_objLib_OBJ_DELETED: c_int = objErrorBase + 0x0003; 757 pub const S_objLib_OBJ_TIMEOUT: c_int = objErrorBase + 0x0004; 758 pub const S_objLib_OBJ_NO_METHOD: c_int = objErrorBase + 0x0005; 759 760 // in.h 761 pub const IPPROTO_IP: c_int = 0; 762 pub const IPPROTO_IPV6: c_int = 41; 763 764 pub const IP_TTL: c_int = 4; 765 pub const IP_MULTICAST_IF: c_int = 9; 766 pub const IP_MULTICAST_TTL: c_int = 10; 767 pub const IP_MULTICAST_LOOP: c_int = 11; 768 pub const IP_ADD_MEMBERSHIP: c_int = 12; 769 pub const IP_DROP_MEMBERSHIP: c_int = 13; 770 771 // in6.h 772 pub const IPV6_V6ONLY: c_int = 1; 773 pub const IPV6_UNICAST_HOPS: c_int = 4; 774 pub const IPV6_MULTICAST_IF: c_int = 9; 775 pub const IPV6_MULTICAST_HOPS: c_int = 10; 776 pub const IPV6_MULTICAST_LOOP: c_int = 11; 777 pub const IPV6_ADD_MEMBERSHIP: c_int = 12; 778 pub const IPV6_DROP_MEMBERSHIP: c_int = 13; 779 780 // STAT Stuff 781 pub const S_IFMT: c_int = 0o17_0000; 782 pub const S_IFIFO: c_int = 0o1_0000; 783 pub const S_IFCHR: c_int = 0o2_0000; 784 pub const S_IFDIR: c_int = 0o4_0000; 785 pub const S_IFBLK: c_int = 0o6_0000; 786 pub const S_IFREG: c_int = 0o10_0000; 787 pub const S_IFLNK: c_int = 0o12_0000; 788 pub const S_IFSHM: c_int = 0o13_0000; 789 pub const S_IFSOCK: c_int = 0o14_0000; 790 pub const S_ISUID: c_int = 0o4000; 791 pub const S_ISGID: c_int = 0o2000; 792 pub const S_ISTXT: c_int = 0o1000; 793 pub const S_ISVTX: c_int = 0o1000; 794 pub const S_IRUSR: c_int = 0o0400; 795 pub const S_IWUSR: c_int = 0o0200; 796 pub const S_IXUSR: c_int = 0o0100; 797 pub const S_IRWXU: c_int = 0o0700; 798 pub const S_IRGRP: c_int = 0o0040; 799 pub const S_IWGRP: c_int = 0o0020; 800 pub const S_IXGRP: c_int = 0o0010; 801 pub const S_IRWXG: c_int = 0o0070; 802 pub const S_IROTH: c_int = 0o0004; 803 pub const S_IWOTH: c_int = 0o0002; 804 pub const S_IXOTH: c_int = 0o0001; 805 pub const S_IRWXO: c_int = 0o0007; 806 807 // socket.h 808 pub const SOL_SOCKET: c_int = 0xffff; 809 pub const SOMAXCONN: c_int = 128; 810 811 pub const SO_DEBUG: c_int = 0x0001; 812 pub const SO_REUSEADDR: c_int = 0x0004; 813 pub const SO_KEEPALIVE: c_int = 0x0008; 814 pub const SO_DONTROUTE: c_int = 0x0010; 815 pub const SO_RCVLOWAT: c_int = 0x0012; 816 pub const SO_SNDLOWAT: c_int = 0x0013; 817 pub const SO_SNDTIMEO: c_int = 0x1005; 818 pub const SO_ACCEPTCONN: c_int = 0x001e; 819 pub const SO_BROADCAST: c_int = 0x0020; 820 pub const SO_USELOOPBACK: c_int = 0x0040; 821 pub const SO_LINGER: c_int = 0x0080; 822 pub const SO_REUSEPORT: c_int = 0x0200; 823 824 pub const SO_VLAN: c_int = 0x8000; 825 826 pub const SO_SNDBUF: c_int = 0x1001; 827 pub const SO_RCVBUF: c_int = 0x1002; 828 pub const SO_RCVTIMEO: c_int = 0x1006; 829 pub const SO_ERROR: c_int = 0x1007; 830 pub const SO_TYPE: c_int = 0x1008; 831 pub const SO_BINDTODEVICE: c_int = 0x1010; 832 pub const SO_OOBINLINE: c_int = 0x1011; 833 pub const SO_CONNTIMEO: c_int = 0x100a; 834 835 pub const SOCK_STREAM: c_int = 1; 836 pub const SOCK_DGRAM: c_int = 2; 837 pub const SOCK_RAW: c_int = 3; 838 pub const SOCK_RDM: c_int = 4; 839 pub const SOCK_SEQPACKET: c_int = 5; 840 pub const SOCK_PACKET: c_int = 10; 841 842 pub const _SS_MAXSIZE: usize = 128; 843 pub const _SS_ALIGNSIZE: usize = size_of::<u32>(); 844 pub const _SS_PAD1SIZE: usize = 845 _SS_ALIGNSIZE - size_of::<c_uchar>() - size_of::<crate::sa_family_t>(); 846 pub const _SS_PAD2SIZE: usize = _SS_MAXSIZE 847 - size_of::<c_uchar>() 848 - size_of::<crate::sa_family_t>() 849 - _SS_PAD1SIZE 850 - _SS_ALIGNSIZE; 851 852 pub const MSG_OOB: c_int = 0x0001; 853 pub const MSG_PEEK: c_int = 0x0002; 854 pub const MSG_DONTROUTE: c_int = 0x0004; 855 pub const MSG_EOR: c_int = 0x0008; 856 pub const MSG_TRUNC: c_int = 0x0010; 857 pub const MSG_CTRUNC: c_int = 0x0020; 858 pub const MSG_WAITALL: c_int = 0x0040; 859 pub const MSG_DONTWAIT: c_int = 0x0080; 860 pub const MSG_EOF: c_int = 0x0100; 861 pub const MSG_EXP: c_int = 0x0200; 862 pub const MSG_MBUF: c_int = 0x0400; 863 pub const MSG_NOTIFICATION: c_int = 0x0800; 864 pub const MSG_COMPAT: c_int = 0x8000; 865 866 pub const AF_UNSPEC: c_int = 0; 867 pub const AF_LOCAL: c_int = 1; 868 pub const AF_UNIX: c_int = AF_LOCAL; 869 pub const AF_INET: c_int = 2; 870 pub const AF_NETLINK: c_int = 16; 871 pub const AF_ROUTE: c_int = 17; 872 pub const AF_LINK: c_int = 18; 873 pub const AF_PACKET: c_int = 19; 874 pub const pseudo_AF_KEY: c_int = 27; 875 pub const AF_KEY: c_int = pseudo_AF_KEY; 876 pub const AF_INET6: c_int = 28; 877 pub const AF_SOCKDEV: c_int = 31; 878 pub const AF_TIPC: c_int = 33; 879 pub const AF_MIPC: c_int = 34; 880 pub const AF_MIPC_SAFE: c_int = 35; 881 pub const AF_MAX: c_int = 37; 882 883 pub const SHUT_RD: c_int = 0; 884 pub const SHUT_WR: c_int = 1; 885 pub const SHUT_RDWR: c_int = 2; 886 887 pub const IPPROTO_TCP: c_int = 6; 888 pub const TCP_NODELAY: c_int = 1; 889 pub const TCP_MAXSEG: c_int = 2; 890 pub const TCP_NOPUSH: c_int = 3; 891 pub const TCP_KEEPIDLE: c_int = 4; 892 pub const TCP_KEEPINTVL: c_int = 5; 893 pub const TCP_KEEPCNT: c_int = 6; 894 895 // ioLib.h 896 pub const FIONREAD: c_int = 0x40040001; 897 pub const FIOFLUSH: c_int = 2; 898 pub const FIOOPTIONS: c_int = 3; 899 pub const FIOBAUDRATE: c_int = 4; 900 pub const FIODISKFORMAT: c_int = 5; 901 pub const FIODISKINIT: c_int = 6; 902 pub const FIOSEEK: c_int = 7; 903 pub const FIOWHERE: c_int = 8; 904 pub const FIODIRENTRY: c_int = 9; 905 pub const FIORENAME: c_int = 10; 906 pub const FIOREADYCHANGE: c_int = 11; 907 pub const FIODISKCHANGE: c_int = 13; 908 pub const FIOCANCEL: c_int = 14; 909 pub const FIOSQUEEZE: c_int = 15; 910 pub const FIOGETNAME: c_int = 18; 911 pub const FIONBIO: c_int = 0x90040010; 912 913 // limits.h 914 pub const PATH_MAX: c_int = _PARM_PATH_MAX; 915 pub const _POSIX_PATH_MAX: c_int = 256; 916 917 // Some poll stuff 918 pub const POLLIN: c_short = 0x0001; 919 pub const POLLPRI: c_short = 0x0002; 920 pub const POLLOUT: c_short = 0x0004; 921 pub const POLLRDNORM: c_short = 0x0040; 922 pub const POLLWRNORM: c_short = POLLOUT; 923 pub const POLLRDBAND: c_short = 0x0080; 924 pub const POLLWRBAND: c_short = 0x0100; 925 pub const POLLERR: c_short = 0x0008; 926 pub const POLLHUP: c_short = 0x0010; 927 pub const POLLNVAL: c_short = 0x0020; 928 929 // fnctlcom.h 930 pub const FD_CLOEXEC: c_int = 1; 931 pub const F_DUPFD: c_int = 0; 932 pub const F_GETFD: c_int = 1; 933 pub const F_SETFD: c_int = 2; 934 pub const F_GETFL: c_int = 3; 935 pub const F_SETFL: c_int = 4; 936 pub const F_GETOWN: c_int = 5; 937 pub const F_SETOWN: c_int = 6; 938 pub const F_GETLK: c_int = 7; 939 pub const F_SETLK: c_int = 8; 940 pub const F_SETLKW: c_int = 9; 941 pub const F_DUPFD_CLOEXEC: c_int = 14; 942 943 // signal.h 944 pub const SIG_DFL: sighandler_t = 0 as sighandler_t; 945 pub const SIG_IGN: sighandler_t = 1 as sighandler_t; 946 pub const SIG_ERR: sighandler_t = -1 as isize as sighandler_t; 947 948 pub const SIGHUP: c_int = 1; 949 pub const SIGINT: c_int = 2; 950 pub const SIGQUIT: c_int = 3; 951 pub const SIGILL: c_int = 4; 952 pub const SIGTRAP: c_int = 5; 953 pub const SIGABRT: c_int = 6; 954 pub const SIGEMT: c_int = 7; 955 pub const SIGFPE: c_int = 8; 956 pub const SIGKILL: c_int = 9; 957 pub const SIGBUS: c_int = 10; 958 pub const SIGSEGV: c_int = 11; 959 pub const SIGFMT: c_int = 12; 960 pub const SIGPIPE: c_int = 13; 961 pub const SIGALRM: c_int = 14; 962 pub const SIGTERM: c_int = 15; 963 pub const SIGCNCL: c_int = 16; 964 pub const SIGSTOP: c_int = 17; 965 pub const SIGTSTP: c_int = 18; 966 pub const SIGCONT: c_int = 19; 967 pub const SIGCHLD: c_int = 20; 968 pub const SIGTTIN: c_int = 21; 969 pub const SIGTTOU: c_int = 22; 970 971 pub const SIG_BLOCK: c_int = 1; 972 pub const SIG_UNBLOCK: c_int = 2; 973 pub const SIG_SETMASK: c_int = 3; 974 975 pub const SI_SYNC: c_int = 0; 976 pub const SI_USER: c_int = -1; 977 pub const SI_QUEUE: c_int = -2; 978 pub const SI_TIMER: c_int = -3; 979 pub const SI_ASYNCIO: c_int = -4; 980 pub const SI_MESGQ: c_int = -5; 981 pub const SI_CHILD: c_int = -6; 982 pub const SI_KILL: c_int = SI_USER; 983 984 // vxParams.h definitions 985 pub const _PARM_NAME_MAX: c_int = 255; 986 pub const _PARM_PATH_MAX: c_int = 1024; 987 988 // WAIT STUFF 989 pub const WNOHANG: c_int = 0x01; 990 pub const WUNTRACED: c_int = 0x02; 991 992 const PTHREAD_MUTEXATTR_INITIALIZER: pthread_mutexattr_t = pthread_mutexattr_t { 993 mutexAttrStatus: PTHREAD_INITIALIZED_OBJ, 994 mutexAttrProtocol: PTHREAD_PRIO_NONE, 995 mutexAttrPrioceiling: 0, 996 mutexAttrType: PTHREAD_MUTEX_DEFAULT, 997 mutexAttrPshared: 1, 998 }; 999 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { 1000 mutexSemId: null_mut(), 1001 mutexValid: PTHREAD_VALID_OBJ, 1002 mutexInitted: PTHREAD_UNUSED_YET_OBJ, 1003 mutexCondRefCount: 0, 1004 mutexSavPriority: -1, 1005 mutexAttr: PTHREAD_MUTEXATTR_INITIALIZER, 1006 mutexSemName: [0; _PTHREAD_SHARED_SEM_NAME_MAX], 1007 }; 1008 1009 const PTHREAD_CONDATTR_INITIALIZER: pthread_condattr_t = pthread_condattr_t { 1010 condAttrStatus: 0xf70990ef, 1011 condAttrPshared: 1, 1012 condAttrClockId: CLOCK_REALTIME, 1013 }; 1014 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { 1015 condSemId: null_mut(), 1016 condValid: PTHREAD_VALID_OBJ, 1017 condInitted: PTHREAD_UNUSED_YET_OBJ, 1018 condRefCount: 0, 1019 condMutex: null_mut(), 1020 condAttr: PTHREAD_CONDATTR_INITIALIZER, 1021 condSemName: [0; _PTHREAD_SHARED_SEM_NAME_MAX], 1022 }; 1023 1024 const PTHREAD_RWLOCKATTR_INITIALIZER: pthread_rwlockattr_t = pthread_rwlockattr_t { 1025 rwlockAttrStatus: PTHREAD_INITIALIZED_OBJ, 1026 rwlockAttrPshared: 1, 1027 rwlockAttrMaxReaders: 0, 1028 rwlockAttrConformOpt: 1, 1029 }; 1030 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { 1031 rwlockSemId: null_mut(), 1032 rwlockReadersRefCount: 0, 1033 rwlockValid: PTHREAD_VALID_OBJ, 1034 rwlockInitted: PTHREAD_UNUSED_YET_OBJ, 1035 rwlockAttr: PTHREAD_RWLOCKATTR_INITIALIZER, 1036 rwlockSemName: [0; _PTHREAD_SHARED_SEM_NAME_MAX], 1037 }; 1038 1039 pub const SEEK_SET: c_int = 0; 1040 pub const SEEK_CUR: c_int = 1; 1041 pub const SEEK_END: c_int = 2; 1042 1043 // rtpLibCommon.h 1044 pub const VX_RTP_NAME_LENGTH: c_int = 255; 1045 pub const RTP_ID_ERROR: crate::RTP_ID = -1; 1046 1047 // h/public/unistd.h 1048 pub const _SC_GETPW_R_SIZE_MAX: c_int = 21; // Via unistd.h 1049 pub const _SC_PAGESIZE: c_int = 39; 1050 pub const O_ACCMODE: c_int = 3; 1051 pub const O_CLOEXEC: c_int = 0x100000; // fcntlcom 1052 pub const O_EXCL: c_int = 0x0800; 1053 pub const O_CREAT: c_int = 0x0200; 1054 pub const O_TRUNC: c_int = 0x0400; 1055 pub const O_APPEND: c_int = 0x0008; 1056 pub const O_RDWR: c_int = 0x0002; 1057 pub const O_WRONLY: c_int = 0x0001; 1058 pub const O_RDONLY: c_int = 0; 1059 pub const O_NONBLOCK: c_int = 0x4000; 1060 1061 // mman.h 1062 pub const PROT_NONE: c_int = 0x0000; 1063 pub const PROT_READ: c_int = 0x0001; 1064 pub const PROT_WRITE: c_int = 0x0002; 1065 pub const PROT_EXEC: c_int = 0x0004; 1066 1067 pub const MAP_SHARED: c_int = 0x0001; 1068 pub const MAP_PRIVATE: c_int = 0x0002; 1069 pub const MAP_ANON: c_int = 0x0004; 1070 pub const MAP_ANONYMOUS: c_int = MAP_ANON; 1071 pub const MAP_FIXED: c_int = 0x0010; 1072 pub const MAP_CONTIG: c_int = 0x0020; 1073 1074 pub const MAP_FAILED: *mut c_void = !0 as *mut c_void; 1075 1076 #[cfg_attr(feature = "extra_traits", derive(Debug))] 1077 pub enum FILE {} 1078 impl Copy for FILE {} 1079 impl Clone for FILE { 1080 fn clone(&self) -> FILE { 1081 *self 1082 } 1083 } 1084 #[cfg_attr(feature = "extra_traits", derive(Debug))] 1085 pub enum fpos_t {} // FIXME(vxworks): fill this out with a struct 1086 impl Copy for fpos_t {} 1087 impl Clone for fpos_t { 1088 fn clone(&self) -> fpos_t { 1089 *self 1090 } 1091 } 1092 1093 f! { 1094 pub {const} fn CMSG_ALIGN(len: usize) -> usize { 1095 len + mem::size_of::<usize>() - 1 & !(mem::size_of::<usize>() - 1) 1096 } 1097 1098 pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { 1099 let next = cmsg as usize 1100 + CMSG_ALIGN((*cmsg).cmsg_len as usize) 1101 + CMSG_ALIGN(mem::size_of::<cmsghdr>()); 1102 let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; 1103 if next <= max { 1104 (cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr 1105 } else { 1106 0 as *mut cmsghdr 1107 } 1108 } 1109 1110 pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { 1111 if (*mhdr).msg_controllen as usize > 0 { 1112 (*mhdr).msg_control as *mut cmsghdr 1113 } else { 1114 0 as *mut cmsghdr 1115 } 1116 } 1117 1118 pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { 1119 (cmsg as *mut c_uchar).offset(CMSG_ALIGN(mem::size_of::<cmsghdr>()) as isize) 1120 } 1121 1122 pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { 1123 (CMSG_ALIGN(length as usize) + CMSG_ALIGN(mem::size_of::<cmsghdr>())) as c_uint 1124 } 1125 1126 pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { 1127 CMSG_ALIGN(mem::size_of::<cmsghdr>()) as c_uint + length 1128 } 1129 } 1130 1131 extern "C" { 1132 pub fn isalnum(c: c_int) -> c_int; 1133 pub fn isalpha(c: c_int) -> c_int; 1134 pub fn iscntrl(c: c_int) -> c_int; 1135 pub fn isdigit(c: c_int) -> c_int; 1136 pub fn isgraph(c: c_int) -> c_int; 1137 pub fn islower(c: c_int) -> c_int; 1138 pub fn isprint(c: c_int) -> c_int; 1139 pub fn ispunct(c: c_int) -> c_int; 1140 pub fn isspace(c: c_int) -> c_int; 1141 pub fn isupper(c: c_int) -> c_int; 1142 pub fn isxdigit(c: c_int) -> c_int; 1143 pub fn isblank(c: c_int) -> c_int; 1144 pub fn tolower(c: c_int) -> c_int; 1145 pub fn toupper(c: c_int) -> c_int; 1146 pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; 1147 pub fn freopen(filename: *const c_char, mode: *const c_char, file: *mut FILE) -> *mut FILE; 1148 pub fn fflush(file: *mut FILE) -> c_int; 1149 pub fn fclose(file: *mut FILE) -> c_int; 1150 pub fn remove(filename: *const c_char) -> c_int; 1151 pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; 1152 pub fn tmpfile() -> *mut FILE; 1153 pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int, size: size_t) -> c_int; 1154 pub fn setbuf(stream: *mut FILE, buf: *mut c_char); 1155 pub fn getchar() -> c_int; 1156 pub fn putchar(c: c_int) -> c_int; 1157 pub fn fgetc(stream: *mut FILE) -> c_int; 1158 pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; 1159 pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; 1160 pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; 1161 pub fn puts(s: *const c_char) -> c_int; 1162 pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; 1163 pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t, stream: *mut FILE) -> size_t; 1164 pub fn fwrite(ptr: *const c_void, size: size_t, nobj: size_t, stream: *mut FILE) -> size_t; 1165 pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; 1166 pub fn ftell(stream: *mut FILE) -> c_long; 1167 pub fn rewind(stream: *mut FILE); 1168 pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; 1169 pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; 1170 pub fn feof(stream: *mut FILE) -> c_int; 1171 pub fn ferror(stream: *mut FILE) -> c_int; 1172 pub fn perror(s: *const c_char); 1173 pub fn atof(s: *const c_char) -> c_double; 1174 pub fn atoi(s: *const c_char) -> c_int; 1175 pub fn atol(s: *const c_char) -> c_long; 1176 pub fn atoll(s: *const c_char) -> c_longlong; 1177 pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; 1178 pub fn strtof(s: *const c_char, endp: *mut *mut c_char) -> c_float; 1179 pub fn strtol(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_long; 1180 pub fn strtoll(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_longlong; 1181 pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulong; 1182 pub fn strtoull(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulonglong; 1183 pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; 1184 pub fn malloc(size: size_t) -> *mut c_void; 1185 pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; 1186 pub fn free(p: *mut c_void); 1187 pub fn abort() -> !; 1188 pub fn exit(status: c_int) -> !; 1189 pub fn atexit(cb: extern "C" fn()) -> c_int; 1190 pub fn system(s: *const c_char) -> c_int; 1191 pub fn getenv(s: *const c_char) -> *mut c_char; 1192 1193 pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; 1194 pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char; 1195 pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; 1196 pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char; 1197 pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; 1198 pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; 1199 pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; 1200 pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; 1201 pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; 1202 pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; 1203 pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; 1204 pub fn strdup(cs: *const c_char) -> *mut c_char; 1205 pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; 1206 pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; 1207 pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int; 1208 pub fn strncasecmp(s1: *const c_char, s2: *const c_char, n: size_t) -> c_int; 1209 pub fn strlen(cs: *const c_char) -> size_t; 1210 pub fn strerror(n: c_int) -> *mut c_char; 1211 pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; 1212 pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; 1213 pub fn wcslen(buf: *const wchar_t) -> size_t; 1214 pub fn wcstombs(dest: *mut c_char, src: *const wchar_t, n: size_t) -> size_t; 1215 1216 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; 1217 pub fn wmemchr(cx: *const wchar_t, c: wchar_t, n: size_t) -> *mut wchar_t; 1218 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; 1219 pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; 1220 pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; 1221 pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; 1222 } 1223 1224 extern "C" { 1225 pub fn fprintf(stream: *mut crate::FILE, format: *const c_char, ...) -> c_int; 1226 pub fn printf(format: *const c_char, ...) -> c_int; 1227 pub fn snprintf(s: *mut c_char, n: size_t, format: *const c_char, ...) -> c_int; 1228 pub fn sprintf(s: *mut c_char, format: *const c_char, ...) -> c_int; 1229 pub fn fscanf(stream: *mut crate::FILE, format: *const c_char, ...) -> c_int; 1230 pub fn scanf(format: *const c_char, ...) -> c_int; 1231 pub fn sscanf(s: *const c_char, format: *const c_char, ...) -> c_int; 1232 pub fn getchar_unlocked() -> c_int; 1233 pub fn putchar_unlocked(c: c_int) -> c_int; 1234 pub fn stat(path: *const c_char, buf: *mut stat) -> c_int; 1235 pub fn fdopen(fd: c_int, mode: *const c_char) -> *mut crate::FILE; 1236 pub fn fileno(stream: *mut crate::FILE) -> c_int; 1237 pub fn creat(path: *const c_char, mode: mode_t) -> c_int; 1238 pub fn rewinddir(dirp: *mut crate::DIR); 1239 pub fn fchown(fd: c_int, owner: crate::uid_t, group: crate::gid_t) -> c_int; 1240 pub fn access(path: *const c_char, amode: c_int) -> c_int; 1241 pub fn alarm(seconds: c_uint) -> c_uint; 1242 pub fn fchdir(dirfd: c_int) -> c_int; 1243 pub fn chown(path: *const c_char, uid: uid_t, gid: gid_t) -> c_int; 1244 pub fn fpathconf(filedes: c_int, name: c_int) -> c_long; 1245 pub fn getegid() -> gid_t; 1246 pub fn geteuid() -> uid_t; 1247 pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t) -> c_int; 1248 pub fn getlogin() -> *mut c_char; 1249 pub fn getopt(argc: c_int, argv: *const *mut c_char, optstr: *const c_char) -> c_int; 1250 pub fn pathconf(path: *const c_char, name: c_int) -> c_long; 1251 pub fn pause() -> c_int; 1252 pub fn seteuid(uid: uid_t) -> c_int; 1253 pub fn setegid(gid: gid_t) -> c_int; 1254 pub fn sleep(secs: c_uint) -> c_uint; 1255 pub fn ttyname(fd: c_int) -> *mut c_char; 1256 pub fn wait(status: *mut c_int) -> pid_t; 1257 pub fn umask(mask: mode_t) -> mode_t; 1258 pub fn mlock(addr: *const c_void, len: size_t) -> c_int; 1259 pub fn mlockall(flags: c_int) -> c_int; 1260 pub fn munlock(addr: *const c_void, len: size_t) -> c_int; 1261 pub fn munlockall() -> c_int; 1262 1263 pub fn mmap( 1264 addr: *mut c_void, 1265 len: size_t, 1266 prot: c_int, 1267 flags: c_int, 1268 fd: c_int, 1269 offset: off_t, 1270 ) -> *mut c_void; 1271 pub fn munmap(addr: *mut c_void, len: size_t) -> c_int; 1272 1273 pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int; 1274 pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int; 1275 1276 pub fn truncate(path: *const c_char, length: off_t) -> c_int; 1277 pub fn shm_open(name: *const c_char, oflag: c_int, mode: crate::mode_t) -> c_int; 1278 pub fn shm_unlink(name: *const c_char) -> c_int; 1279 1280 pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut c_void) -> c_int; 1281 pub fn pthread_exit(value: *mut c_void) -> !; 1282 pub fn pthread_attr_setdetachstate(attr: *mut crate::pthread_attr_t, state: c_int) -> c_int; 1283 1284 pub fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int; 1285 1286 pub fn sigaddset(set: *mut sigset_t, signum: c_int) -> c_int; 1287 1288 pub fn sigaction(signum: c_int, act: *const sigaction, oldact: *mut sigaction) -> c_int; 1289 1290 pub fn utimes(filename: *const c_char, times: *const crate::timeval) -> c_int; 1291 1292 pub fn futimens(fd: c_int, times: *const crate::timespec) -> c_int; 1293 1294 #[link_name = "_rtld_dlopen"] 1295 pub fn dlopen(filename: *const c_char, flag: c_int) -> *mut c_void; 1296 1297 #[link_name = "_rtld_dlerror"] 1298 pub fn dlerror() -> *mut c_char; 1299 1300 #[link_name = "_rtld_dlsym"] 1301 pub fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void; 1302 1303 #[link_name = "_rtld_dlclose"] 1304 pub fn dlclose(handle: *mut c_void) -> c_int; 1305 1306 #[link_name = "_rtld_dladdr"] 1307 pub fn dladdr(addr: *mut c_void, info: *mut Dl_info) -> c_int; 1308 1309 // time.h 1310 pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; 1311 pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; 1312 pub fn mktime(tm: *mut tm) -> time_t; 1313 pub fn time(time: *mut time_t) -> time_t; 1314 pub fn gmtime(time_p: *const time_t) -> *mut tm; 1315 pub fn localtime(time_p: *const time_t) -> *mut tm; 1316 pub fn timegm(tm: *mut tm) -> time_t; 1317 pub fn difftime(time1: time_t, time0: time_t) -> c_double; 1318 pub fn gethostname(name: *mut c_char, len: size_t) -> c_int; 1319 pub fn usleep(secs: crate::useconds_t) -> c_int; 1320 pub fn putenv(string: *mut c_char) -> c_int; 1321 pub fn setlocale(category: c_int, locale: *const c_char) -> *mut c_char; 1322 1323 pub fn sigprocmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int; 1324 pub fn sigpending(set: *mut sigset_t) -> c_int; 1325 1326 pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int; 1327 1328 pub fn fseeko(stream: *mut crate::FILE, offset: off_t, whence: c_int) -> c_int; 1329 pub fn ftello(stream: *mut crate::FILE) -> off_t; 1330 pub fn mkstemp(template: *mut c_char) -> c_int; 1331 1332 pub fn tmpnam(ptr: *mut c_char) -> *mut c_char; 1333 1334 pub fn openlog(ident: *const c_char, logopt: c_int, facility: c_int); 1335 pub fn closelog(); 1336 pub fn setlogmask(maskpri: c_int) -> c_int; 1337 pub fn syslog(priority: c_int, message: *const c_char, ...); 1338 pub fn getline(lineptr: *mut *mut c_char, n: *mut size_t, stream: *mut FILE) -> ssize_t; 1339 1340 } 1341 1342 extern "C" { 1343 // stdlib.h 1344 pub fn memalign(block_size: size_t, size_arg: size_t) -> *mut c_void; 1345 1346 // ioLib.h 1347 pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char; 1348 1349 // ioLib.h 1350 pub fn chdir(attr: *const c_char) -> c_int; 1351 1352 // pthread.h 1353 pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> c_int; 1354 1355 // pthread.h 1356 pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> c_int; 1357 1358 // pthread.h 1359 pub fn pthread_mutexattr_settype(pAttr: *mut crate::pthread_mutexattr_t, pType: c_int) 1360 -> c_int; 1361 1362 // pthread.h 1363 pub fn pthread_mutex_init( 1364 mutex: *mut pthread_mutex_t, 1365 attr: *const pthread_mutexattr_t, 1366 ) -> c_int; 1367 1368 // pthread.h 1369 pub fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> c_int; 1370 1371 // pthread.h 1372 pub fn pthread_mutex_lock(mutex: *mut pthread_mutex_t) -> c_int; 1373 1374 // pthread.h 1375 pub fn pthread_mutex_trylock(mutex: *mut pthread_mutex_t) -> c_int; 1376 1377 // pthread.h 1378 pub fn pthread_mutex_timedlock(attr: *mut pthread_mutex_t, spec: *const timespec) -> c_int; 1379 1380 // pthread.h 1381 pub fn pthread_mutex_unlock(mutex: *mut pthread_mutex_t) -> c_int; 1382 1383 // pthread.h 1384 pub fn pthread_attr_setname(pAttr: *mut crate::pthread_attr_t, name: *mut c_char) -> c_int; 1385 1386 // pthread.h 1387 pub fn pthread_attr_setstacksize(attr: *mut crate::pthread_attr_t, stacksize: size_t) -> c_int; 1388 1389 // pthread.h 1390 pub fn pthread_attr_getstacksize( 1391 attr: *const crate::pthread_attr_t, 1392 size: *mut size_t, 1393 ) -> c_int; 1394 1395 // pthread.h 1396 pub fn pthread_attr_init(attr: *mut crate::pthread_attr_t) -> c_int; 1397 1398 // pthread.h 1399 pub fn pthread_create( 1400 pThread: *mut crate::pthread_t, 1401 pAttr: *const crate::pthread_attr_t, 1402 start_routine: extern "C" fn(*mut c_void) -> *mut c_void, 1403 value: *mut c_void, 1404 ) -> c_int; 1405 1406 //pthread.h 1407 pub fn pthread_setschedparam( 1408 native: crate::pthread_t, 1409 policy: c_int, 1410 param: *const crate::sched_param, 1411 ) -> c_int; 1412 1413 //pthread.h 1414 pub fn pthread_getschedparam( 1415 native: crate::pthread_t, 1416 policy: *mut c_int, 1417 param: *mut crate::sched_param, 1418 ) -> c_int; 1419 1420 //pthread.h 1421 pub fn pthread_attr_setinheritsched( 1422 attr: *mut crate::pthread_attr_t, 1423 inheritsched: c_int, 1424 ) -> c_int; 1425 1426 //pthread.h 1427 pub fn pthread_attr_setschedpolicy(attr: *mut crate::pthread_attr_t, policy: c_int) -> c_int; 1428 1429 // pthread.h 1430 pub fn pthread_attr_destroy(thread: *mut crate::pthread_attr_t) -> c_int; 1431 1432 // pthread.h 1433 pub fn pthread_detach(thread: crate::pthread_t) -> c_int; 1434 1435 // int pthread_atfork (void (*)(void), void (*)(void), void (*)(void)); 1436 pub fn pthread_atfork( 1437 prepare: Option<unsafe extern "C" fn()>, 1438 parent: Option<unsafe extern "C" fn()>, 1439 child: Option<unsafe extern "C" fn()>, 1440 ) -> c_int; 1441 1442 // stat.h 1443 pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int; 1444 1445 // stat.h 1446 pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int; 1447 1448 // unistd.h 1449 pub fn ftruncate(fd: c_int, length: off_t) -> c_int; 1450 1451 // dirent.h 1452 pub fn readdir_r( 1453 pDir: *mut crate::DIR, 1454 entry: *mut crate::dirent, 1455 result: *mut *mut crate::dirent, 1456 ) -> c_int; 1457 1458 // dirent.h 1459 pub fn readdir(pDir: *mut crate::DIR) -> *mut crate::dirent; 1460 1461 // fcntl.h or 1462 // ioLib.h 1463 pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int; 1464 1465 // poll.h 1466 pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: c_int) -> c_int; 1467 1468 // pthread.h 1469 pub fn pthread_condattr_init(attr: *mut crate::pthread_condattr_t) -> c_int; 1470 1471 // pthread.h 1472 pub fn pthread_condattr_destroy(attr: *mut crate::pthread_condattr_t) -> c_int; 1473 1474 // pthread.h 1475 pub fn pthread_condattr_getclock( 1476 pAttr: *const crate::pthread_condattr_t, 1477 pClockId: *mut crate::clockid_t, 1478 ) -> c_int; 1479 1480 // pthread.h 1481 pub fn pthread_condattr_setclock( 1482 pAttr: *mut crate::pthread_condattr_t, 1483 clockId: crate::clockid_t, 1484 ) -> c_int; 1485 1486 // pthread.h 1487 pub fn pthread_cond_init( 1488 cond: *mut crate::pthread_cond_t, 1489 attr: *const crate::pthread_condattr_t, 1490 ) -> c_int; 1491 1492 // pthread.h 1493 pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> c_int; 1494 1495 // pthread.h 1496 pub fn pthread_cond_signal(cond: *mut crate::pthread_cond_t) -> c_int; 1497 1498 // pthread.h 1499 pub fn pthread_cond_broadcast(cond: *mut crate::pthread_cond_t) -> c_int; 1500 1501 // pthread.h 1502 pub fn pthread_cond_wait( 1503 cond: *mut crate::pthread_cond_t, 1504 mutex: *mut crate::pthread_mutex_t, 1505 ) -> c_int; 1506 1507 // pthread.h 1508 pub fn pthread_rwlockattr_init(attr: *mut crate::pthread_rwlockattr_t) -> c_int; 1509 1510 // pthread.h 1511 pub fn pthread_rwlockattr_destroy(attr: *mut crate::pthread_rwlockattr_t) -> c_int; 1512 1513 // pthread.h 1514 pub fn pthread_rwlockattr_setmaxreaders( 1515 attr: *mut crate::pthread_rwlockattr_t, 1516 attr2: c_uint, 1517 ) -> c_int; 1518 1519 // pthread.h 1520 pub fn pthread_rwlock_init( 1521 attr: *mut crate::pthread_rwlock_t, 1522 host: *const crate::pthread_rwlockattr_t, 1523 ) -> c_int; 1524 1525 // pthread.h 1526 pub fn pthread_rwlock_destroy(attr: *mut crate::pthread_rwlock_t) -> c_int; 1527 1528 // pthread.h 1529 pub fn pthread_rwlock_rdlock(attr: *mut crate::pthread_rwlock_t) -> c_int; 1530 1531 // pthread.h 1532 pub fn pthread_rwlock_tryrdlock(attr: *mut crate::pthread_rwlock_t) -> c_int; 1533 1534 // pthread.h 1535 pub fn pthread_rwlock_timedrdlock( 1536 attr: *mut crate::pthread_rwlock_t, 1537 host: *const crate::timespec, 1538 ) -> c_int; 1539 1540 // pthread.h 1541 pub fn pthread_rwlock_wrlock(attr: *mut crate::pthread_rwlock_t) -> c_int; 1542 1543 // pthread.h 1544 pub fn pthread_rwlock_trywrlock(attr: *mut crate::pthread_rwlock_t) -> c_int; 1545 1546 // pthread.h 1547 pub fn pthread_rwlock_timedwrlock( 1548 attr: *mut crate::pthread_rwlock_t, 1549 host: *const crate::timespec, 1550 ) -> c_int; 1551 1552 // pthread.h 1553 pub fn pthread_rwlock_unlock(attr: *mut crate::pthread_rwlock_t) -> c_int; 1554 1555 // pthread.h 1556 pub fn pthread_key_create( 1557 key: *mut crate::pthread_key_t, 1558 dtor: Option<unsafe extern "C" fn(*mut c_void)>, 1559 ) -> c_int; 1560 1561 // pthread.h 1562 pub fn pthread_key_delete(key: crate::pthread_key_t) -> c_int; 1563 1564 // pthread.h 1565 pub fn pthread_setspecific(key: crate::pthread_key_t, value: *const c_void) -> c_int; 1566 1567 // pthread.h 1568 pub fn pthread_getspecific(key: crate::pthread_key_t) -> *mut c_void; 1569 1570 // pthread.h 1571 pub fn pthread_cond_timedwait( 1572 cond: *mut crate::pthread_cond_t, 1573 mutex: *mut crate::pthread_mutex_t, 1574 abstime: *const crate::timespec, 1575 ) -> c_int; 1576 1577 // pthread.h 1578 pub fn pthread_attr_getname(attr: *mut crate::pthread_attr_t, name: *mut *mut c_char) -> c_int; 1579 1580 // pthread.h 1581 pub fn pthread_join(thread: crate::pthread_t, status: *mut *mut c_void) -> c_int; 1582 1583 // pthread.h 1584 pub fn pthread_self() -> crate::pthread_t; 1585 1586 // clockLib.h 1587 pub fn clock_gettime(clock_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int; 1588 1589 // clockLib.h 1590 pub fn clock_settime(clock_id: crate::clockid_t, tp: *const crate::timespec) -> c_int; 1591 1592 // clockLib.h 1593 pub fn clock_getres(clock_id: crate::clockid_t, res: *mut crate::timespec) -> c_int; 1594 1595 // clockLib.h 1596 pub fn clock_nanosleep( 1597 clock_id: crate::clockid_t, 1598 flags: c_int, 1599 rqtp: *const crate::timespec, 1600 rmtp: *mut crate::timespec, 1601 ) -> c_int; 1602 1603 // timerLib.h 1604 pub fn nanosleep(rqtp: *const crate::timespec, rmtp: *mut crate::timespec) -> c_int; 1605 1606 // socket.h 1607 pub fn accept(s: c_int, addr: *mut crate::sockaddr, addrlen: *mut crate::socklen_t) -> c_int; 1608 1609 // socket.h 1610 pub fn bind(fd: c_int, addr: *const sockaddr, len: socklen_t) -> c_int; 1611 1612 // socket.h 1613 pub fn connect(s: c_int, name: *const crate::sockaddr, namelen: crate::socklen_t) -> c_int; 1614 1615 // socket.h 1616 pub fn getpeername( 1617 s: c_int, 1618 name: *mut crate::sockaddr, 1619 namelen: *mut crate::socklen_t, 1620 ) -> c_int; 1621 1622 // socket.h 1623 pub fn getsockname(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) 1624 -> c_int; 1625 1626 // socket.h 1627 pub fn getsockopt( 1628 sockfd: c_int, 1629 level: c_int, 1630 optname: c_int, 1631 optval: *mut c_void, 1632 optlen: *mut crate::socklen_t, 1633 ) -> c_int; 1634 1635 // socket.h 1636 pub fn listen(socket: c_int, backlog: c_int) -> c_int; 1637 1638 // socket.h 1639 pub fn recv(s: c_int, buf: *mut c_void, bufLen: size_t, flags: c_int) -> ssize_t; 1640 1641 // socket.h 1642 pub fn recvfrom( 1643 s: c_int, 1644 buf: *mut c_void, 1645 bufLen: size_t, 1646 flags: c_int, 1647 from: *mut crate::sockaddr, 1648 pFromLen: *mut crate::socklen_t, 1649 ) -> ssize_t; 1650 1651 pub fn recvmsg(socket: c_int, mp: *mut crate::msghdr, flags: c_int) -> ssize_t; 1652 1653 // socket.h 1654 pub fn send(socket: c_int, buf: *const c_void, len: size_t, flags: c_int) -> ssize_t; 1655 1656 pub fn sendmsg(socket: c_int, mp: *const crate::msghdr, flags: c_int) -> ssize_t; 1657 1658 // socket.h 1659 pub fn sendto( 1660 socket: c_int, 1661 buf: *const c_void, 1662 len: size_t, 1663 flags: c_int, 1664 addr: *const sockaddr, 1665 addrlen: socklen_t, 1666 ) -> ssize_t; 1667 1668 // socket.h 1669 pub fn setsockopt( 1670 socket: c_int, 1671 level: c_int, 1672 name: c_int, 1673 value: *const c_void, 1674 option_len: socklen_t, 1675 ) -> c_int; 1676 1677 // socket.h 1678 pub fn shutdown(s: c_int, how: c_int) -> c_int; 1679 1680 // socket.h 1681 pub fn socket(domain: c_int, _type: c_int, protocol: c_int) -> c_int; 1682 1683 // icotl.h 1684 pub fn ioctl(fd: c_int, request: c_int, ...) -> c_int; 1685 1686 // fcntl.h 1687 pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int; 1688 1689 // ntp_rfc2553.h for kernel 1690 // netdb.h for user 1691 pub fn gai_strerror(errcode: c_int) -> *mut c_char; 1692 1693 // ioLib.h or 1694 // unistd.h 1695 pub fn close(fd: c_int) -> c_int; 1696 1697 // ioLib.h or 1698 // unistd.h 1699 pub fn read(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t; 1700 1701 // ioLib.h or 1702 // unistd.h 1703 pub fn write(fd: c_int, buf: *const c_void, count: size_t) -> ssize_t; 1704 1705 // ioLib.h or 1706 // unistd.h 1707 pub fn isatty(fd: c_int) -> c_int; 1708 1709 // ioLib.h or 1710 // unistd.h 1711 pub fn dup(src: c_int) -> c_int; 1712 1713 // ioLib.h or 1714 // unistd.h 1715 pub fn dup2(src: c_int, dst: c_int) -> c_int; 1716 1717 // ioLib.h or 1718 // unistd.h 1719 pub fn pipe(fds: *mut c_int) -> c_int; 1720 1721 // ioLib.h or 1722 // unistd.h 1723 pub fn unlink(pathname: *const c_char) -> c_int; 1724 1725 // unistd.h and 1726 // ioLib.h 1727 pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t; 1728 1729 // netdb.h 1730 pub fn getaddrinfo( 1731 node: *const c_char, 1732 service: *const c_char, 1733 hints: *const addrinfo, 1734 res: *mut *mut addrinfo, 1735 ) -> c_int; 1736 1737 // netdb.h 1738 pub fn freeaddrinfo(res: *mut addrinfo); 1739 1740 // signal.h 1741 pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t; 1742 1743 // unistd.h 1744 pub fn getpid() -> pid_t; 1745 1746 // unistd.h 1747 pub fn getppid() -> pid_t; 1748 1749 // wait.h 1750 pub fn waitpid(pid: pid_t, status: *mut c_int, optons: c_int) -> pid_t; 1751 1752 // unistd.h 1753 pub fn sysconf(attr: c_int) -> c_long; 1754 1755 // stdlib.h 1756 pub fn setenv( 1757 // setenv.c 1758 envVarName: *const c_char, 1759 envVarValue: *const c_char, 1760 overwrite: c_int, 1761 ) -> c_int; 1762 1763 // stdlib.h 1764 pub fn unsetenv( 1765 // setenv.c 1766 envVarName: *const c_char, 1767 ) -> c_int; 1768 1769 // stdlib.h 1770 pub fn realpath(fileName: *const c_char, resolvedName: *mut c_char) -> *mut c_char; 1771 1772 // unistd.h 1773 pub fn link(src: *const c_char, dst: *const c_char) -> c_int; 1774 1775 // unistd.h 1776 pub fn readlink(path: *const c_char, buf: *mut c_char, bufsize: size_t) -> ssize_t; 1777 1778 // unistd.h 1779 pub fn symlink(path1: *const c_char, path2: *const c_char) -> c_int; 1780 1781 // dirent.h 1782 pub fn opendir(name: *const c_char) -> *mut crate::DIR; 1783 1784 // unistd.h 1785 pub fn rmdir(path: *const c_char) -> c_int; 1786 1787 // stat.h 1788 pub fn mkdir(dirName: *const c_char, mode: crate::mode_t) -> c_int; 1789 1790 // stat.h 1791 pub fn chmod(path: *const c_char, mode: crate::mode_t) -> c_int; 1792 1793 // stat.h 1794 pub fn fchmod(attr1: c_int, attr2: crate::mode_t) -> c_int; 1795 1796 // unistd.h 1797 pub fn fsync(fd: c_int) -> c_int; 1798 1799 // dirent.h 1800 pub fn closedir(ptr: *mut crate::DIR) -> c_int; 1801 1802 //sched.h 1803 pub fn sched_get_priority_max(policy: c_int) -> c_int; 1804 1805 //sched.h 1806 pub fn sched_get_priority_min(policy: c_int) -> c_int; 1807 1808 //sched.h 1809 pub fn sched_setparam(pid: crate::pid_t, param: *const crate::sched_param) -> c_int; 1810 1811 //sched.h 1812 pub fn sched_getparam(pid: crate::pid_t, param: *mut crate::sched_param) -> c_int; 1813 1814 //sched.h 1815 pub fn sched_setscheduler( 1816 pid: crate::pid_t, 1817 policy: c_int, 1818 param: *const crate::sched_param, 1819 ) -> c_int; 1820 1821 //sched.h 1822 pub fn sched_getscheduler(pid: crate::pid_t) -> c_int; 1823 1824 //sched.h 1825 pub fn sched_rr_get_interval(pid: crate::pid_t, tp: *mut crate::timespec) -> c_int; 1826 1827 // sched.h 1828 pub fn sched_yield() -> c_int; 1829 1830 // errnoLib.h 1831 pub fn errnoSet(err: c_int) -> c_int; 1832 1833 // errnoLib.h 1834 pub fn errnoGet() -> c_int; 1835 1836 // unistd.h 1837 pub fn _exit(status: c_int) -> !; 1838 1839 // unistd.h 1840 pub fn setgid(gid: crate::gid_t) -> c_int; 1841 1842 // unistd.h 1843 pub fn getgid() -> crate::gid_t; 1844 1845 // unistd.h 1846 pub fn setuid(uid: crate::uid_t) -> c_int; 1847 1848 // unistd.h 1849 pub fn getuid() -> crate::uid_t; 1850 1851 // signal.h 1852 pub fn sigemptyset(__set: *mut sigset_t) -> c_int; 1853 1854 // pthread.h for kernel 1855 // signal.h for user 1856 pub fn pthread_sigmask(__how: c_int, __set: *const sigset_t, __oset: *mut sigset_t) -> c_int; 1857 1858 // signal.h for user 1859 pub fn kill(__pid: pid_t, __signo: c_int) -> c_int; 1860 1861 // signal.h for user 1862 pub fn sigqueue(__pid: pid_t, __signo: c_int, __value: crate::sigval) -> c_int; 1863 1864 // signal.h for user 1865 pub fn _sigqueue( 1866 rtpId: crate::RTP_ID, 1867 signo: c_int, 1868 pValue: *const crate::sigval, 1869 sigCode: c_int, 1870 ) -> c_int; 1871 1872 // signal.h 1873 pub fn taskKill(taskId: crate::TASK_ID, signo: c_int) -> c_int; 1874 1875 // signal.h 1876 pub fn raise(__signo: c_int) -> c_int; 1877 1878 // taskLibCommon.h 1879 pub fn taskIdSelf() -> crate::TASK_ID; 1880 pub fn taskDelay(ticks: crate::_Vx_ticks_t) -> c_int; 1881 1882 // taskLib.h 1883 pub fn taskNameSet(task_id: crate::TASK_ID, task_name: *mut c_char) -> c_int; 1884 pub fn taskNameGet(task_id: crate::TASK_ID, buf_name: *mut c_char, bufsize: size_t) -> c_int; 1885 1886 // rtpLibCommon.h 1887 pub fn rtpInfoGet(rtpId: crate::RTP_ID, rtpStruct: *mut crate::RTP_DESC) -> c_int; 1888 pub fn rtpSpawn( 1889 pubrtpFileName: *const c_char, 1890 argv: *mut *const c_char, 1891 envp: *mut *const c_char, 1892 priority: c_int, 1893 uStackSize: size_t, 1894 options: c_int, 1895 taskOptions: c_int, 1896 ) -> RTP_ID; 1897 1898 // ioLib.h 1899 pub fn _realpath(fileName: *const c_char, resolvedName: *mut c_char) -> *mut c_char; 1900 1901 // pathLib.h 1902 pub fn _pathIsAbsolute(filepath: *const c_char, pNameTail: *mut *const c_char) -> BOOL; 1903 1904 pub fn writev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t; 1905 pub fn readv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t; 1906 1907 // randomNumGen.h 1908 pub fn randBytes(buf: *mut c_uchar, length: c_int) -> c_int; 1909 pub fn randABytes(buf: *mut c_uchar, length: c_int) -> c_int; 1910 pub fn randUBytes(buf: *mut c_uchar, length: c_int) -> c_int; 1911 pub fn randSecure() -> c_int; 1912 1913 // mqueue.h 1914 pub fn mq_open(name: *const c_char, oflag: c_int, ...) -> crate::mqd_t; 1915 pub fn mq_close(mqd: crate::mqd_t) -> c_int; 1916 pub fn mq_unlink(name: *const c_char) -> c_int; 1917 pub fn mq_receive( 1918 mqd: crate::mqd_t, 1919 msg_ptr: *mut c_char, 1920 msg_len: size_t, 1921 msg_prio: *mut c_uint, 1922 ) -> ssize_t; 1923 pub fn mq_timedreceive( 1924 mqd: crate::mqd_t, 1925 msg_ptr: *mut c_char, 1926 msg_len: size_t, 1927 msg_prio: *mut c_uint, 1928 abs_timeout: *const crate::timespec, 1929 ) -> ssize_t; 1930 pub fn mq_send( 1931 mqd: crate::mqd_t, 1932 msg_ptr: *const c_char, 1933 msg_len: size_t, 1934 msg_prio: c_uint, 1935 ) -> c_int; 1936 pub fn mq_timedsend( 1937 mqd: crate::mqd_t, 1938 msg_ptr: *const c_char, 1939 msg_len: size_t, 1940 msg_prio: c_uint, 1941 abs_timeout: *const crate::timespec, 1942 ) -> c_int; 1943 pub fn mq_getattr(mqd: crate::mqd_t, attr: *mut crate::mq_attr) -> c_int; 1944 pub fn mq_setattr( 1945 mqd: crate::mqd_t, 1946 newattr: *const crate::mq_attr, 1947 oldattr: *mut crate::mq_attr, 1948 ) -> c_int; 1949 1950 // vxCpuLib.h 1951 pub fn vxCpuEnabledGet() -> crate::cpuset_t; // Get set of running CPU's in the system 1952 pub fn vxCpuConfiguredGet() -> crate::cpuset_t; // Get set of Configured CPU's in the system 1953 } 1954 1955 //Dummy functions, these don't really exist in VxWorks. 1956 1957 // wait.h macros 1958 safe_f! { 1959 pub {const} fn WIFEXITED(status: c_int) -> bool { 1960 (status & 0xFF00) == 0 1961 } 1962 pub {const} fn WIFSIGNALED(status: c_int) -> bool { 1963 (status & 0xFF00) != 0 1964 } 1965 pub {const} fn WIFSTOPPED(status: c_int) -> bool { 1966 (status & 0xFF0000) != 0 1967 } 1968 pub {const} fn WEXITSTATUS(status: c_int) -> c_int { 1969 status & 0xFF 1970 } 1971 pub {const} fn WTERMSIG(status: c_int) -> c_int { 1972 (status >> 8) & 0xFF 1973 } 1974 pub {const} fn WSTOPSIG(status: c_int) -> c_int { 1975 (status >> 16) & 0xFF 1976 } 1977 } 1978 1979 pub fn pread(_fd: c_int, _buf: *mut c_void, _count: size_t, _offset: off64_t) -> ssize_t { 1980 -1 1981 } 1982 1983 pub fn pwrite(_fd: c_int, _buf: *const c_void, _count: size_t, _offset: off64_t) -> ssize_t { 1984 -1 1985 } 1986 pub fn posix_memalign(memptr: *mut *mut c_void, align: size_t, size: size_t) -> c_int { 1987 // check to see if align is a power of 2 and if align is a multiple 1988 // of sizeof(void *) 1989 if (align & align - 1 != 0) || (align as usize % size_of::<size_t>() != 0) { 1990 return crate::EINVAL; 1991 } 1992 1993 unsafe { 1994 // posix_memalign should not set errno 1995 let e = crate::errnoGet(); 1996 1997 let temp = memalign(align, size); 1998 crate::errnoSet(e as c_int); 1999 2000 if temp.is_null() { 2001 crate::ENOMEM 2002 } else { 2003 *memptr = temp; 2004 0 2005 } 2006 } 2007 } 2008 2009 cfg_if! { 2010 if #[cfg(target_arch = "aarch64")] { 2011 mod aarch64; 2012 pub use self::aarch64::*; 2013 } else if #[cfg(target_arch = "arm")] { 2014 mod arm; 2015 pub use self::arm::*; 2016 } else if #[cfg(target_arch = "x86")] { 2017 mod x86; 2018 pub use self::x86::*; 2019 } else if #[cfg(target_arch = "x86_64")] { 2020 mod x86_64; 2021 pub use self::x86_64::*; 2022 } else if #[cfg(target_arch = "powerpc")] { 2023 mod powerpc; 2024 pub use self::powerpc::*; 2025 } else if #[cfg(target_arch = "powerpc64")] { 2026 mod powerpc64; 2027 pub use self::powerpc64::*; 2028 } else if #[cfg(target_arch = "riscv32")] { 2029 mod riscv32; 2030 pub use self::riscv32::*; 2031 } else if #[cfg(target_arch = "riscv64")] { 2032 mod riscv64; 2033 pub use self::riscv64::*; 2034 } else { 2035 // Unknown target_arch 2036 } 2037 } 2038