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