Skip to content

Commit 676d9fb

Browse files
committed
1. use s_no_extra_traits! for structs with big size(>32 bytes) arrary
2. implement Debug for big size array 3. remove code related to epoll 4. use 'pub enum' for _Vx_semaphore
1 parent f35970f commit 676d9fb

File tree

1 file changed

+105
-91
lines changed

1 file changed

+105
-91
lines changed

src/vxworks/mod.rs

+105-91
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ impl ::Clone for DIR {
1212
}
1313
}
1414

15-
// Throughout we use usize / isize for types that are
16-
// (unsigned) int in ILP32 and (unsigned) long in ILP64
17-
1815
pub type c_schar = i8;
1916
pub type c_uchar = u8;
2017
pub type c_short = i16;
@@ -28,11 +25,23 @@ pub type c_ulonglong = u64;
2825
pub type intmax_t = i64;
2926
pub type uintmax_t = u64;
3027

31-
pub type size_t = usize;
32-
pub type ptrdiff_t = isize;
33-
pub type intptr_t = isize;
34-
pub type uintptr_t = usize;
35-
pub type ssize_t = isize;
28+
cfg_if! {
29+
if #[cfg(target_pointer_width = "32")] {
30+
pub type size_t = c_uint;
31+
pub type ssize_t = c_int;
32+
pub type ptrdiff_t = c_int;
33+
pub type intptr_t = c_int;
34+
pub type uintptr_t = c_uint;
35+
} else if #[cfg(target_pointer_width = "64")] {
36+
pub type size_t = c_ulonglong;
37+
pub type ssize_t = c_longlong;
38+
pub type ptrdiff_t = c_longlong;
39+
pub type intptr_t = c_longlong;
40+
pub type uintptr_t = c_ulonglong;
41+
} else {
42+
// Unknown target_pointer_width
43+
}
44+
}
3645

3746
pub type pid_t = i32;
3847
pub type in_addr_t = u32;
@@ -103,10 +112,17 @@ pub type _Vx_ticks64_t = ::c_ulonglong;
103112

104113
pub type sa_family_t = ::c_uchar;
105114

115+
#[cfg_attr(feature = "extra_traits", derive(Debug))]
116+
pub enum _Vx_semaphore {}
117+
impl ::Copy for _Vx_semaphore {}
118+
impl ::Clone for _Vx_semaphore {
119+
fn clone(&self) -> _Vx_semaphore {
120+
*self
121+
}
122+
}
123+
106124
// structs that only exist in userspace
107125
s! {
108-
pub struct _Vx_semaphore {}
109-
110126
// b_pthread_condattr_t.h
111127
pub struct pthread_condattr_t {
112128
pub condAttrStatus: ::c_int,
@@ -161,14 +177,6 @@ s! {
161177
pub sa_data : [::c_char; 14],
162178
}
163179

164-
// socket.h
165-
pub struct sockaddr_storage {
166-
pub ss_len : ::c_uchar,
167-
pub ss_family : ::sa_family_t,
168-
pub __ss_pad1 : [::c_char; _SS_PAD1SIZE],
169-
pub __ss_align : i32,
170-
pub __ss_pad2 : [::c_char; _SS_PAD2SIZE],
171-
}
172180
pub struct iovec {
173181
pub iov_base: *mut ::c_void,
174182
pub iov_len: ::size_t,
@@ -197,12 +205,6 @@ s! {
197205
pub revents : ::c_short,
198206
}
199207

200-
// dirent.h
201-
pub struct dirent {
202-
pub d_ino : ::ino_t,
203-
pub d_name : [::c_char; _PARM_NAME_MAX + 1],
204-
}
205-
206208
// resource.h
207209
pub struct rlimit { /* Is this really needed? Questionable ... */
208210
pub rlim_cur : ::rlim_t,
@@ -391,12 +393,6 @@ s! {
391393
pub sin6_scope_id: u32,
392394
}
393395

394-
pub struct sockaddr_un {
395-
pub sun_len: u8,
396-
pub sun_family: sa_family_t,
397-
pub sun_path: [::c_char; 104]
398-
}
399-
400396
pub struct passwd {
401397
pub pw_name: *mut ::c_char,
402398
pub pw_uid: ::uid_t,
@@ -405,10 +401,25 @@ s! {
405401
pub pw_shell: *mut ::c_char,
406402
}
407403

408-
// epoll.h
409-
pub struct epoll_event {
410-
pub events: u32,
411-
pub u64: u64,
404+
pub struct Dl_info {
405+
pub dli_fname: *const ::c_char,
406+
pub dli_fbase: *mut ::c_void,
407+
pub dli_sname: *const ::c_char,
408+
pub dli_saddr: *mut ::c_void,
409+
}
410+
}
411+
412+
s_no_extra_traits! {
413+
// dirent.h
414+
pub struct dirent {
415+
pub d_ino : ::ino_t,
416+
pub d_name : [::c_char; _PARM_NAME_MAX + 1],
417+
}
418+
419+
pub struct sockaddr_un {
420+
pub sun_len: u8,
421+
pub sun_family: sa_family_t,
422+
pub sun_path: [::c_char; 104]
412423
}
413424

414425
// rtpLibCommon.h
@@ -423,12 +434,64 @@ s! {
423434
pub textStart : *mut ::c_void,
424435
pub textEnd : *mut ::c_void,
425436
}
437+
// socket.h
438+
pub struct sockaddr_storage {
439+
pub ss_len : ::c_uchar,
440+
pub ss_family : ::sa_family_t,
441+
pub __ss_pad1 : [::c_char; _SS_PAD1SIZE],
442+
pub __ss_align : i32,
443+
pub __ss_pad2 : [::c_char; _SS_PAD2SIZE],
444+
}
426445

427-
pub struct Dl_info {
428-
pub dli_fname: *const ::c_char,
429-
pub dli_fbase: *mut ::c_void,
430-
pub dli_sname: *const ::c_char,
431-
pub dli_saddr: *mut ::c_void,
446+
}
447+
448+
cfg_if! {
449+
if #[cfg(feature = "extra_traits")] {
450+
impl ::fmt::Debug for dirent {
451+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
452+
f.debug_struct("dirent")
453+
.field("d_ino", &self.d_ino)
454+
.field("d_name", &&self.d_name[..])
455+
.finish()
456+
}
457+
}
458+
459+
impl ::fmt::Debug for sockaddr_un {
460+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
461+
f.debug_struct("sockaddr_un")
462+
.field("sun_len", &self.sun_len)
463+
.field("sun_family", &self.sun_family)
464+
.field("sun_path", &&self.sun_path[..])
465+
.finish()
466+
}
467+
}
468+
469+
impl ::fmt::Debug for RTP_DESC {
470+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
471+
f.debug_struct("RTP_DESC")
472+
.field("status", &self.status)
473+
.field("options", &self.options)
474+
.field("entrAddr", &self.entrAddr)
475+
.field("initTaskId", &self.initTaskId)
476+
.field("parentId", &self.parentId)
477+
.field("pathName", &&self.pathName[..])
478+
.field("taskCnt", &self.taskCnt)
479+
.field("textStart", &self.textStart)
480+
.field("textEnd", &self.textEnd)
481+
.finish()
482+
}
483+
}
484+
impl ::fmt::Debug for sockaddr_storage {
485+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
486+
f.debug_struct("sockaddr_storage")
487+
.field("ss_len", &self.ss_len)
488+
.field("ss_family", &self.ss_family)
489+
.field("__ss_pad1", &&self.__ss_pad1[..])
490+
.field("__ss_align", &self.__ss_align)
491+
.field("__ss_pad2", &&self.__ss_pad2[..])
492+
.finish()
493+
}
494+
}
432495
}
433496
}
434497

@@ -754,20 +817,6 @@ pub const FIOSQUEEZE: ::c_int = 15;
754817
pub const FIONBIO: ::c_int = 16;
755818
pub const _POSIX_PATH_MAX: ::c_int = 256;
756819

757-
// epoll.h
758-
pub const EPOLLIN: ::c_int = 0x1;
759-
pub const EPOLLPRI: ::c_int = 0x2;
760-
pub const EPOLLOUT: ::c_int = 0x4;
761-
pub const EPOLLERR: ::c_int = 0x8;
762-
pub const EPOLLHUP: ::c_int = 0x10;
763-
pub const EPOLLRDHUP: ::c_int = 0x2000;
764-
pub const EPOLLONESHOT: ::c_int = 1 << 30;
765-
pub const EPOLLET: ::c_int = 1 << 31;
766-
767-
pub const EPOLL_CTL_ADD: ::c_int = 1;
768-
pub const EPOLL_CTL_DEL: ::c_int = 2;
769-
pub const EPOLL_CTL_MOD: ::c_int = 3;
770-
771820
// Some poll stuff
772821
pub const POLLIN: ::c_short = 0x0001;
773822
pub const POLLPRI: ::c_short = 0x0002;
@@ -2111,7 +2160,9 @@ pub fn posix_memalign(
21112160
) -> ::c_int {
21122161
// check to see if align is a power of 2 and if align is a multiple
21132162
// of sizeof(void *)
2114-
if (align & align - 1 != 0) || (align % size_of::<::size_t>() != 0) {
2163+
if (align & align - 1 != 0)
2164+
|| (align as usize % size_of::<::size_t>() != 0)
2165+
{
21152166
return ::EINVAL;
21162167
}
21172168

@@ -2131,43 +2182,6 @@ pub fn posix_memalign(
21312182
}
21322183
}
21332184

2134-
// epoll.h
2135-
// Unfortunately epoll is currently only supported in the VxWorks kernel
2136-
#[allow(unused_variables)]
2137-
pub fn epoll_create(size: ::c_int) -> ::c_int {
2138-
-1
2139-
}
2140-
#[allow(unused_variables)]
2141-
pub fn epoll_create1(flags: ::c_int) -> ::c_int {
2142-
-1
2143-
}
2144-
#[allow(unused_variables)]
2145-
pub fn epoll_ctl(
2146-
epfd: ::c_int,
2147-
op: ::c_int,
2148-
fd: ::c_int,
2149-
event: *mut ::epoll_event,
2150-
) -> ::c_int {
2151-
-1
2152-
}
2153-
#[allow(unused_variables)]
2154-
pub fn epoll_create_and_ctl(
2155-
num: ::c_int,
2156-
fds: *mut ::c_int,
2157-
event: *mut ::epoll_event,
2158-
) -> ::c_int {
2159-
-1
2160-
}
2161-
#[allow(unused_variables)]
2162-
pub fn epoll_wait(
2163-
epfd: ::c_int,
2164-
events: *mut ::epoll_event,
2165-
maxevents: ::c_int,
2166-
timeout: ::c_int,
2167-
) -> ::c_int {
2168-
-1
2169-
}
2170-
21712185
// From sysconf.c -> doesn't seem to be supported?
21722186
pub fn getpwuid_r(
21732187
_uid: ::uid_t,

0 commit comments

Comments
 (0)