Skip to content

Commit ac94521

Browse files
committed
[pax] linux portability fixes
1 parent 146ac1a commit ac94521

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pax/modes/read.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,13 @@ fn extract_device(path: &Path, entry: &ArchiveEntry, options: &ReadOptions) -> P
395395
let path_cstr = CString::new(path.as_os_str().as_bytes())
396396
.map_err(|_| PaxError::InvalidHeader("path contains null".to_string()))?;
397397

398+
// makedev has different signatures on different platforms:
399+
// - Linux: makedev(major: u32, minor: u32) -> u64
400+
// - macOS: makedev(major: i32, minor: i32) -> i32
401+
#[cfg(target_os = "macos")]
398402
let dev = libc::makedev(entry.devmajor as i32, entry.devminor as i32);
403+
#[cfg(not(target_os = "macos"))]
404+
let dev = libc::makedev(entry.devmajor, entry.devminor);
399405
let type_bits: libc::mode_t = match entry.entry_type {
400406
EntryType::BlockDevice => libc::S_IFBLK,
401407
EntryType::CharDevice => libc::S_IFCHR,

pax/tests/special/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ fn test_block_device_roundtrip() {
8787
fs::create_dir(&src_dir).unwrap();
8888
let dev_path = src_dir.join("myblock");
8989
let path_cstr = CString::new(dev_path.as_os_str().as_bytes()).unwrap();
90-
let dev = libc::makedev(8, 0); // /dev/sda major=8, minor=0
90+
// makedev has different signatures on different platforms
91+
#[cfg(target_os = "macos")]
92+
let dev = libc::makedev(8i32, 0i32); // /dev/sda major=8, minor=0
93+
#[cfg(not(target_os = "macos"))]
94+
let dev = libc::makedev(8u32, 0u32); // /dev/sda major=8, minor=0
9195
unsafe {
9296
let ret = libc::mknod(path_cstr.as_ptr(), libc::S_IFBLK | 0o660, dev);
9397
if ret != 0 {
@@ -144,7 +148,11 @@ fn test_char_device_roundtrip() {
144148
fs::create_dir(&src_dir).unwrap();
145149
let dev_path = src_dir.join("mychar");
146150
let path_cstr = CString::new(dev_path.as_os_str().as_bytes()).unwrap();
147-
let dev = libc::makedev(1, 3); // /dev/null major=1, minor=3
151+
// makedev has different signatures on different platforms
152+
#[cfg(target_os = "macos")]
153+
let dev = libc::makedev(1i32, 3i32); // /dev/null major=1, minor=3
154+
#[cfg(not(target_os = "macos"))]
155+
let dev = libc::makedev(1u32, 3u32); // /dev/null major=1, minor=3
148156
unsafe {
149157
let ret = libc::mknod(path_cstr.as_ptr(), libc::S_IFCHR | 0o666, dev);
150158
if ret != 0 {

0 commit comments

Comments
 (0)