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