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