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