Skip to content

Commit be76b59

Browse files
committed
handle all linux archs instead of explictly defining them
1 parent 87db293 commit be76b59

File tree

2 files changed

+5
-64
lines changed

2 files changed

+5
-64
lines changed

src/fcntl.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -487,23 +487,8 @@ pub fn renameat2<P1: ?Sized + NixPath, P2: ?Sized + NixPath, Fd1: std::os::fd::A
487487
new_path.with_nix_path(|new_cstr| unsafe {
488488
// Use raw syscall instead of libc::renameat2 to support musl libc and other
489489
// environments where the libc function may not be available.
490-
//
491-
// Syscall numbers from the Linux kernel source:
492-
// https://github.com/torvalds/linux/blob/master/arch/x86/entry/syscalls/syscall_64.tbl
493-
// https://github.com/torvalds/linux/blob/master/arch/arm64/include/asm/unistd32.h
494-
#[cfg(target_arch = "x86_64")]
495-
const SYS_RENAMEAT2: libc::c_long = 316;
496-
#[cfg(target_arch = "x86")]
497-
const SYS_RENAMEAT2: libc::c_long = 353;
498-
#[cfg(target_arch = "aarch64")]
499-
const SYS_RENAMEAT2: libc::c_long = 276;
500-
#[cfg(target_arch = "arm")]
501-
const SYS_RENAMEAT2: libc::c_long = 382;
502-
#[cfg(target_arch = "riscv64")]
503-
const SYS_RENAMEAT2: libc::c_long = 276;
504-
505490
libc::syscall(
506-
SYS_RENAMEAT2,
491+
libc::SYS_renameat2,
507492
old_dirfd.as_fd().as_raw_fd(),
508493
old_cstr.as_ptr(),
509494
new_dirfd.as_fd().as_raw_fd(),

test/test_fcntl.rs

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,7 @@ use nix::fcntl::{openat, readlinkat, renameat};
88
#[cfg(target_os = "linux")]
99
use nix::fcntl::{openat2, OpenHow, ResolveFlag};
1010

11-
#[cfg(all(
12-
target_os = "linux",
13-
any(
14-
target_arch = "x86_64",
15-
target_arch = "x86",
16-
target_arch = "aarch64",
17-
target_arch = "arm",
18-
target_arch = "riscv64",
19-
target_arch = "powerpc",
20-
target_arch = "s390x"
21-
)
22-
))]
11+
#[cfg(target_os = "linux")]
2312
use nix::fcntl::{renameat2, RenameFlags};
2413
#[cfg(not(target_os = "redox"))]
2514
use nix::sys::stat::Mode;
@@ -135,18 +124,7 @@ fn test_renameat() {
135124
}
136125

137126
#[test]
138-
#[cfg(all(
139-
target_os = "linux",
140-
any(
141-
target_arch = "x86_64",
142-
target_arch = "x86",
143-
target_arch = "aarch64",
144-
target_arch = "arm",
145-
target_arch = "riscv64",
146-
target_arch = "powerpc",
147-
target_arch = "s390x"
148-
)
149-
))]
127+
#[cfg(target_os = "linux")]
150128
fn test_renameat2_behaves_like_renameat_with_no_flags() {
151129
let old_dir = tempfile::tempdir().unwrap();
152130
let old_dirfd =
@@ -167,18 +145,7 @@ fn test_renameat2_behaves_like_renameat_with_no_flags() {
167145
}
168146

169147
#[test]
170-
#[cfg(all(
171-
target_os = "linux",
172-
any(
173-
target_arch = "x86_64",
174-
target_arch = "x86",
175-
target_arch = "aarch64",
176-
target_arch = "arm",
177-
target_arch = "riscv64",
178-
target_arch = "powerpc",
179-
target_arch = "s390x"
180-
)
181-
))]
148+
#[cfg(target_os = "linux")]
182149
fn test_renameat2_exchange() {
183150
let old_dir = tempfile::tempdir().unwrap();
184151
let old_dirfd =
@@ -215,18 +182,7 @@ fn test_renameat2_exchange() {
215182
}
216183

217184
#[test]
218-
#[cfg(all(
219-
target_os = "linux",
220-
any(
221-
target_arch = "x86_64",
222-
target_arch = "x86",
223-
target_arch = "aarch64",
224-
target_arch = "arm",
225-
target_arch = "riscv64",
226-
target_arch = "powerpc",
227-
target_arch = "s390x"
228-
)
229-
))]
185+
#[cfg(target_os = "linux")]
230186
fn test_renameat2_noreplace() {
231187
let old_dir = tempfile::tempdir().unwrap();
232188
let old_dirfd =

0 commit comments

Comments
 (0)