Skip to content

Commit b8c6cd0

Browse files
committed
Delete unportable parts and add rule for clockid_t
1 parent 76b2692 commit b8c6cd0

6 files changed

Lines changed: 20 additions & 200 deletions

File tree

‎rules/time/src.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ int f8(struct timeval *tv, void *tz) {
4141
#else
4242
#error "Unsupported platform for gettimeofday"
4343
#endif
44+
45+
clockid_t f9() {
46+
return CLOCK_REALTIME;
47+
}

‎rules/time/tgt_refcount.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ fn f1(a0: Ptr<::libc::time_t>) -> ::libc::time_t {
3232
}
3333
}
3434

35-
fn f2(a0: ::libc::clockid_t, a1: Ptr<Timespec>) -> i32 {
36-
match nix::time::clock_gettime(nix::time::ClockId::from_raw(a0)) {
35+
fn f2(a0: nix::time::ClockId, a1: Ptr<Timespec>) -> i32 {
36+
match nix::time::clock_gettime(a0) {
3737
Ok(__ts) => {
3838
a1.with_mut(|__t| {
3939
*__t.tv_sec.borrow_mut() = __ts.tv_sec() as i64;
@@ -146,3 +146,7 @@ fn f8(a0: Ptr<Timeval>, a1: AnyPtr) -> i32 {
146146
}
147147
}
148148
}
149+
150+
unsafe fn f9() -> nix::time::ClockId {
151+
nix::time::ClockId::CLOCK_REALTIME
152+
}

‎rules/time/tgt_unsafe.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ unsafe fn f8(a0: *mut libc::timeval, a1: *mut libc::timezone) -> i32 {
5151
unsafe fn f8(a0: *mut libc::timeval, a1: *mut libc::c_void) -> i32 {
5252
libc::gettimeofday(a0, a1)
5353
}
54+
55+
unsafe fn f9() -> libc::clockid_t {
56+
libc::CLOCK_REALTIME
57+
}

‎tests/unit/out/refcount/sys_time.rs‎

Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn test_time_0() {
4747
pub fn test_clock_gettime_1() {
4848
let ts: Value<libcc2rs::Timespec> = Rc::new(RefCell::new(Default::default()));
4949
assert!(
50-
(((match nix::time::clock_gettime(nix::time::ClockId::from_raw(0)) {
50+
(((match nix::time::clock_gettime(nix::time::ClockId::CLOCK_REALTIME) {
5151
Ok(__ts) => {
5252
(ts.as_pointer()).with_mut(|__t| {
5353
*__t.tv_sec.borrow_mut() = __ts.tv_sec() as i64;
@@ -283,137 +283,6 @@ pub fn test_strftime_4() {
283283
!= 0)
284284
);
285285
}
286-
pub fn test_gettimeofday_5() {
287-
let tv: Value<libcc2rs::Timeval> = Rc::new(RefCell::new(Default::default()));
288-
assert!(
289-
(((match nix::time::clock_gettime(nix::time::ClockId::CLOCK_REALTIME) {
290-
Ok(__ts) => {
291-
(tv.as_pointer()).with_mut(|__tv| {
292-
*__tv.tv_sec.borrow_mut() = __ts.tv_sec() as i64;
293-
*__tv.tv_usec.borrow_mut() = (__ts.tv_nsec() / 1000) as i64;
294-
});
295-
0
296-
}
297-
Err(__e) => {
298-
libcc2rs::cpp2rust_errno().write(__e as i32);
299-
-1
300-
}
301-
} == 0) as i32)
302-
!= 0)
303-
);
304-
assert!(((((*(*tv.borrow()).tv_sec.borrow()) > 1500000000_i64) as i32) != 0));
305-
assert!(
306-
(((((((*(*tv.borrow()).tv_usec.borrow()) >= 0_i64) as i32) != 0)
307-
&& ((((*(*tv.borrow()).tv_usec.borrow()) < 1000000_i64) as i32) != 0))
308-
as i32)
309-
!= 0)
310-
);
311-
}
312-
pub fn test_utimes_6() {
313-
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
314-
b"/tmp/cpp2rust_utimes_test.tmp",
315-
)));
316-
let fp: Value<Ptr<::std::fs::File>> = Rc::new(RefCell::new(
317-
match Ptr::from_string_literal(b"wb").to_rust_string() {
318-
v if v == "rb" => std::fs::OpenOptions::new()
319-
.read(true)
320-
.open((*path.borrow()).to_rust_string())
321-
.ok()
322-
.map_or(Ptr::null(), |f| Ptr::alloc(f)),
323-
v if v == "wb" => std::fs::OpenOptions::new()
324-
.write(true)
325-
.create(true)
326-
.truncate(true)
327-
.open((*path.borrow()).to_rust_string())
328-
.ok()
329-
.map_or(Ptr::null(), |f| Ptr::alloc(f)),
330-
_ => panic!("unsupported mode"),
331-
},
332-
));
333-
assert!((((!((*fp.borrow()).is_null())) as i32) != 0));
334-
assert!(
335-
((({
336-
(*fp.borrow()).delete();
337-
0
338-
} == 0) as i32)
339-
!= 0)
340-
);
341-
let times: Value<Box<[libcc2rs::Timeval]>> = Rc::new(RefCell::new(
342-
(0..2)
343-
.map(|_| Default::default())
344-
.collect::<Box<[libcc2rs::Timeval]>>(),
345-
));
346-
(*(*times.borrow())[(0) as usize].tv_sec.borrow_mut()) = 1000000000_i64;
347-
(*(*times.borrow())[(0) as usize].tv_usec.borrow_mut()) = 0_i64;
348-
(*(*times.borrow())[(1) as usize].tv_sec.borrow_mut()) = 1000000001_i64;
349-
(*(*times.borrow())[(1) as usize].tv_usec.borrow_mut()) = 0_i64;
350-
assert!(
351-
((({
352-
let __times = (times.as_pointer() as Ptr<libcc2rs::Timeval>);
353-
let __at = __times.with(|__tv| {
354-
nix::sys::time::TimeVal::new(
355-
*__tv.tv_sec.borrow() as ::libc::time_t,
356-
*__tv.tv_usec.borrow() as ::libc::suseconds_t,
357-
)
358-
});
359-
let __mt = __times.offset(1).with(|__tv| {
360-
nix::sys::time::TimeVal::new(
361-
*__tv.tv_sec.borrow() as ::libc::time_t,
362-
*__tv.tv_usec.borrow() as ::libc::suseconds_t,
363-
)
364-
});
365-
match nix::sys::stat::utimes((*path.borrow()).to_rust_string().as_str(), &__at, &__mt) {
366-
Ok(()) => 0,
367-
Err(__e) => {
368-
libcc2rs::cpp2rust_errno().write(__e as i32);
369-
-1
370-
}
371-
}
372-
} == 0) as i32)
373-
!= 0)
374-
);
375-
assert!(
376-
((({
377-
let __times = (times.as_pointer() as Ptr<libcc2rs::Timeval>);
378-
let __at = __times.with(|__tv| {
379-
nix::sys::time::TimeVal::new(
380-
*__tv.tv_sec.borrow() as ::libc::time_t,
381-
*__tv.tv_usec.borrow() as ::libc::suseconds_t,
382-
)
383-
});
384-
let __mt = __times.offset(1).with(|__tv| {
385-
nix::sys::time::TimeVal::new(
386-
*__tv.tv_sec.borrow() as ::libc::time_t,
387-
*__tv.tv_usec.borrow() as ::libc::suseconds_t,
388-
)
389-
});
390-
match nix::sys::stat::utimes(
391-
Ptr::from_string_literal(b"/tmp/cpp2rust_utimes_test_missing.tmp")
392-
.to_rust_string()
393-
.as_str(),
394-
&__at,
395-
&__mt,
396-
) {
397-
Ok(()) => 0,
398-
Err(__e) => {
399-
libcc2rs::cpp2rust_errno().write(__e as i32);
400-
-1
401-
}
402-
}
403-
} == -1_i32) as i32)
404-
!= 0)
405-
);
406-
assert!(
407-
(((match nix::unistd::unlink((*path.borrow()).to_rust_string().as_str()) {
408-
Ok(()) => 0,
409-
Err(__e) => {
410-
libcc2rs::cpp2rust_errno().write(__e as i32);
411-
-1
412-
}
413-
} == 0) as i32)
414-
!= 0)
415-
);
416-
}
417286
pub fn main() {
418287
std::process::exit(main_0());
419288
}
@@ -422,7 +291,5 @@ fn main_0() -> i32 {
422291
({ test_clock_gettime_1() });
423292
({ test_gmtime_r_3() });
424293
({ test_strftime_4() });
425-
({ test_gettimeofday_5() });
426-
({ test_utimes_6() });
427294
return 0;
428295
}

‎tests/unit/out/unsafe/sys_time.rs‎

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ pub unsafe fn test_time_0() {
1616
}
1717
pub unsafe fn test_clock_gettime_1() {
1818
let mut ts: ::libc::timespec = unsafe { std::mem::zeroed() };
19-
assert!(((((libc::clock_gettime(0, (&mut ts as *mut ::libc::timespec))) == (0)) as i32) != 0));
19+
assert!(
20+
((((libc::clock_gettime(libc::CLOCK_REALTIME, (&mut ts as *mut ::libc::timespec))) == (0))
21+
as i32)
22+
!= 0)
23+
);
2024
assert!(((((ts.tv_sec) > (1500000000_i64)) as i32) != 0));
2125
assert!(
2226
(((((((ts.tv_nsec) >= (0_i64)) as i32) != 0)
@@ -139,43 +143,6 @@ pub unsafe fn test_strftime_4() {
139143
!= 0)
140144
);
141145
}
142-
pub unsafe fn test_gettimeofday_5() {
143-
let mut tv: ::libc::timeval = unsafe { std::mem::zeroed() };
144-
assert!(
145-
((((libc::gettimeofday(
146-
(&mut tv as *mut ::libc::timeval),
147-
(0 as *mut ::libc::c_void) as *mut libc::timezone
148-
)) == (0)) as i32)
149-
!= 0)
150-
);
151-
assert!(((((tv.tv_sec) > (1500000000_i64)) as i32) != 0));
152-
assert!(
153-
(((((((tv.tv_usec) >= (0_i64)) as i32) != 0)
154-
&& ((((tv.tv_usec) < (1000000_i64)) as i32) != 0)) as i32)
155-
!= 0)
156-
);
157-
}
158-
pub unsafe fn test_utimes_6() {
159-
let mut path: *const libc::c_char =
160-
(c"/tmp/cpp2rust_utimes_test.tmp".as_ptr().cast_mut()).cast_const();
161-
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
162-
assert!((((!((fp).is_null())) as i32) != 0));
163-
assert!(((((libc::fclose(fp)) == (0)) as i32) != 0));
164-
let mut times: [::libc::timeval; 2] = [unsafe { std::mem::zeroed() }; 2];
165-
times[(0) as usize].tv_sec = 1000000000_i64;
166-
times[(0) as usize].tv_usec = 0_i64;
167-
times[(1) as usize].tv_sec = 1000000001_i64;
168-
times[(1) as usize].tv_usec = 0_i64;
169-
assert!(((((libc::utimes(path, (times.as_mut_ptr()).cast_const())) == (0)) as i32) != 0));
170-
assert!(
171-
((((libc::utimes(
172-
(c"/tmp/cpp2rust_utimes_test_missing.tmp".as_ptr().cast_mut()).cast_const(),
173-
(times.as_mut_ptr()).cast_const()
174-
)) == (-1_i32)) as i32)
175-
!= 0)
176-
);
177-
assert!(((((libc::unlink(path)) == (0)) as i32) != 0));
178-
}
179146
pub fn main() {
180147
unsafe {
181148
std::process::exit(main_0() as i32);
@@ -186,7 +153,5 @@ unsafe fn main_0() -> i32 {
186153
(unsafe { test_clock_gettime_1() });
187154
(unsafe { test_gmtime_r_3() });
188155
(unsafe { test_strftime_4() });
189-
(unsafe { test_gettimeofday_5() });
190-
(unsafe { test_utimes_6() });
191156
return 0;
192157
}

‎tests/unit/sys_time.c‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,10 @@ static void test_strftime(void) {
5858
assert(strftime(small, sizeof(small), "%Y-%m-%d", &tm) == 0);
5959
}
6060

61-
static void test_gettimeofday(void) {
62-
struct timeval tv;
63-
assert(gettimeofday(&tv, NULL) == 0);
64-
assert(tv.tv_sec > 1500000000);
65-
assert(tv.tv_usec >= 0 && tv.tv_usec < 1000000);
66-
}
67-
68-
static void test_utimes(void) {
69-
const char *path = "/tmp/cpp2rust_utimes_test.tmp";
70-
FILE *fp = fopen(path, "wb");
71-
assert(fp != NULL);
72-
assert(fclose(fp) == 0);
73-
struct timeval times[2];
74-
times[0].tv_sec = 1000000000;
75-
times[0].tv_usec = 0;
76-
times[1].tv_sec = 1000000001;
77-
times[1].tv_usec = 0;
78-
assert(utimes(path, times) == 0);
79-
assert(utimes("/tmp/cpp2rust_utimes_test_missing.tmp", times) == -1);
80-
assert(unlink(path) == 0);
81-
}
82-
8361
int main(void) {
8462
test_time();
8563
test_clock_gettime();
8664
test_gmtime_r();
8765
test_strftime();
88-
test_gettimeofday();
89-
test_utimes();
9066
return 0;
9167
}

0 commit comments

Comments
 (0)