Skip to content

Commit 9352dc9

Browse files
committed
Add rules for seek_set, seen_end, seek_cur
1 parent fee5aa7 commit 9352dc9

9 files changed

Lines changed: 42 additions & 17 deletions

File tree

‎rules/stdio/src.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,9 @@ int f23(FILE *stream) { return getc(stream); }
7171
int f24(FILE *stream, char *buf, int mode, size_t size) {
7272
return setvbuf(stream, buf, mode, size);
7373
}
74+
75+
int f25(void) { return SEEK_SET; }
76+
77+
int f26(void) { return SEEK_CUR; }
78+
79+
int f27(void) { return SEEK_END; }

‎rules/stdio/tgt_unsafe.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,15 @@ unsafe fn f23(a0: *mut ::libc::FILE) -> i32 {
104104
unsafe fn f24(a0: *mut ::libc::FILE, a1: *mut libc::c_char, a2: i32, a3: usize) -> i32 {
105105
libc::setvbuf(a0, a1, a2, a3)
106106
}
107+
108+
unsafe fn f25() -> i32 {
109+
::libc::SEEK_SET
110+
}
111+
112+
unsafe fn f26() -> i32 {
113+
::libc::SEEK_CUR
114+
}
115+
116+
unsafe fn f27() -> i32 {
117+
::libc::SEEK_END
118+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn test_errno_preserved_across_strdup_1() {
2828
pub fn test_errno_from_fseek_2() {
2929
libcc2rs::cpp2rust_errno().write(0);
3030
let r: Value<i32> = Rc::new(RefCell::new(
31-
match libcc2rs::c_stdin().with_mut(|__v: &mut CFile| __v.seek(0_i64, 0)) {
31+
match libcc2rs::c_stdin().with_mut(|__v: &mut CFile| __v.seek(0_i64, ::libc::SEEK_SET)) {
3232
-1 => -1,
3333
_ => 0,
3434
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn main_0() -> i32 {
5050
);
5151
assert!(
5252
((({
53-
let __whence = match 2 {
53+
let __whence = match ::libc::SEEK_END {
5454
0 => nix::unistd::Whence::SeekSet,
5555
1 => nix::unistd::Whence::SeekCur,
5656
2 => nix::unistd::Whence::SeekEnd,
@@ -70,7 +70,7 @@ fn main_0() -> i32 {
7070
);
7171
assert!(
7272
((({
73-
let __whence = match 0 {
73+
let __whence = match ::libc::SEEK_SET {
7474
0 => nix::unistd::Whence::SeekSet,
7575
1 => nix::unistd::Whence::SeekCur,
7676
2 => nix::unistd::Whence::SeekEnd,
@@ -143,7 +143,7 @@ fn main_0() -> i32 {
143143
);
144144
assert!(
145145
((({
146-
let __whence = match 2 {
146+
let __whence = match ::libc::SEEK_END {
147147
0 => nix::unistd::Whence::SeekSet,
148148
1 => nix::unistd::Whence::SeekCur,
149149
2 => nix::unistd::Whence::SeekEnd,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ pub fn test_fseeko_4() {
494494
};
495495
assert!((((!((*fp.borrow()).is_null())) as i32) != 0));
496496
assert!(
497-
(((match (*fp.borrow()).with_mut(|__f| __f.seek(6_i64, 0)) {
497+
(((match (*fp.borrow()).with_mut(|__f| __f.seek(6_i64, ::libc::SEEK_SET)) {
498498
-1 => -1,
499499
_ => 0,
500500
} == 0) as i32)
@@ -528,15 +528,15 @@ pub fn test_fseeko_4() {
528528
!= 0)
529529
);
530530
assert!(
531-
(((match (*fp.borrow()).with_mut(|__f| __f.seek((-5_i32 as i64), 2)) {
531+
(((match (*fp.borrow()).with_mut(|__f| __f.seek((-5_i32 as i64), ::libc::SEEK_END)) {
532532
-1 => -1,
533533
_ => 0,
534534
} == 0) as i32)
535535
!= 0)
536536
);
537537
assert!(((((*fp.borrow()).with_mut(|__f| __f.getc()) == ('w' as i32)) as i32) != 0));
538538
assert!(
539-
(((match (*fp.borrow()).with_mut(|__f| __f.seek(1_i64, 1)) {
539+
(((match (*fp.borrow()).with_mut(|__f| __f.seek(1_i64, ::libc::SEEK_CUR)) {
540540
-1 => -1,
541541
_ => 0,
542542
} == 0) as i32)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ pub unsafe fn test_errno_preserved_across_strdup_1() {
2626
}
2727
pub unsafe fn test_errno_from_fseek_2() {
2828
(*libcc2rs::cpp2rust_errno_unsafe()) = 0;
29-
let mut r: i32 = libc::fseek(libcc2rs::stdin_unsafe(), 0_i64 as ::libc::c_long, 0);
29+
let mut r: i32 = libc::fseek(
30+
libcc2rs::stdin_unsafe(),
31+
0_i64 as ::libc::c_long,
32+
::libc::SEEK_SET,
33+
);
3034
assert!(((((r) == (-1_i32)) as i32) != 0));
3135
assert!(((((*libcc2rs::cpp2rust_errno_unsafe()) == (libc::ESPIPE)) as i32) != 0));
3236
(*libcc2rs::cpp2rust_errno_unsafe()) = 0;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ unsafe fn main_0() -> i32 {
3030
)) == (11_isize)) as i32)
3131
!= 0)
3232
);
33-
assert!(((((libc::lseek(fd, 0_i64, 2)) == (11_i64)) as i32) != 0));
34-
assert!(((((libc::lseek(fd, 6_i64, 0)) == (6_i64)) as i32) != 0));
33+
assert!(((((libc::lseek(fd, 0_i64, ::libc::SEEK_END)) == (11_i64)) as i32) != 0));
34+
assert!(((((libc::lseek(fd, 6_i64, ::libc::SEEK_SET)) == (6_i64)) as i32) != 0));
3535
let mut buf: [libc::c_char; 16] = [(0 as libc::c_char); 16];
3636
{
3737
let byte_0 = (buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void) as *mut u8;
@@ -56,7 +56,7 @@ unsafe fn main_0() -> i32 {
5656
!= 0)
5757
);
5858
assert!(((((libc::ftruncate(fd, 5_i64)) == (0)) as i32) != 0));
59-
assert!(((((libc::lseek(fd, 0_i64, 2)) == (5_i64)) as i32) != 0));
59+
assert!(((((libc::lseek(fd, 0_i64, ::libc::SEEK_END)) == (5_i64)) as i32) != 0));
6060
assert!(((((libc::close(fd)) == (0)) as i32) != 0));
6161
assert!(((((libc::unlink(path)) == (0)) as i32) != 0));
6262
return 0;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub unsafe fn test_fseeko_4() {
231231
assert!(((((libc::fclose(fp)) == (0)) as i32) != 0));
232232
fp = libc::fopen(path, (c"rb".as_ptr().cast_mut()).cast_const());
233233
assert!((((!((fp).is_null())) as i32) != 0));
234-
assert!(((((libc::fseeko(fp, 6_i64 as ::libc::off_t, 0)) == (0)) as i32) != 0));
234+
assert!(((((libc::fseeko(fp, 6_i64 as ::libc::off_t, ::libc::SEEK_SET)) == (0)) as i32) != 0));
235235
let mut buf: [libc::c_char; 8] = [
236236
(0 as libc::c_char),
237237
(0 as libc::c_char),
@@ -273,9 +273,12 @@ pub unsafe fn test_fseeko_4() {
273273
}) == (0)) as i32)
274274
!= 0)
275275
);
276-
assert!(((((libc::fseeko(fp, (-5_i32 as i64) as ::libc::off_t, 2)) == (0)) as i32) != 0));
276+
assert!(
277+
((((libc::fseeko(fp, (-5_i32 as i64) as ::libc::off_t, ::libc::SEEK_END)) == (0)) as i32)
278+
!= 0)
279+
);
277280
assert!(((((libc::fgetc(fp)) == ('w' as i32)) as i32) != 0));
278-
assert!(((((libc::fseeko(fp, 1_i64 as ::libc::off_t, 1)) == (0)) as i32) != 0));
281+
assert!(((((libc::fseeko(fp, 1_i64 as ::libc::off_t, ::libc::SEEK_CUR)) == (0)) as i32) != 0));
279282
assert!(((((libc::fgetc(fp)) == ('r' as i32)) as i32) != 0));
280283
assert!(((((libc::fclose(fp)) == (0)) as i32) != 0));
281284
assert!(((((libc::unlink(path)) == (0)) as i32) != 0));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ pub unsafe fn test_lseek_1() {
3131
fp = libc::fopen(path, (c"rb".as_ptr().cast_mut()).cast_const());
3232
assert!((((!((fp).is_null())) as i32) != 0));
3333
let mut fd: i32 = libc::fileno(fp);
34-
assert!(((((libc::lseek(fd, 0_i64, 2)) == (11_i64)) as i32) != 0));
35-
assert!(((((libc::lseek(fd, 6_i64, 0)) == (6_i64)) as i32) != 0));
34+
assert!(((((libc::lseek(fd, 0_i64, ::libc::SEEK_END)) == (11_i64)) as i32) != 0));
35+
assert!(((((libc::lseek(fd, 6_i64, ::libc::SEEK_SET)) == (6_i64)) as i32) != 0));
3636
let mut buf: [libc::c_char; 8] = [
3737
(0 as libc::c_char),
3838
(0 as libc::c_char),
@@ -221,7 +221,7 @@ pub unsafe fn test_ftruncate_5() {
221221
fp = libc::fopen(path, (c"rb".as_ptr().cast_mut()).cast_const());
222222
assert!((((!((fp).is_null())) as i32) != 0));
223223
fd = (libc::fileno(fp)).clone();
224-
assert!(((((libc::lseek(fd, 0_i64, 2)) == (5_i64)) as i32) != 0));
224+
assert!(((((libc::lseek(fd, 0_i64, ::libc::SEEK_END)) == (5_i64)) as i32) != 0));
225225
assert!(((((libc::fclose(fp)) == (0)) as i32) != 0));
226226
libc::unlink(path);
227227
}

0 commit comments

Comments
 (0)