Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add stub implementation of extract_noattr for other platforms #48

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use std::io;

#[cfg(any(
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "netbsd"
))]
pub fn extract_noattr(result: io::Result<Vec<u8>>) -> io::Result<Option<Vec<u8>>> {
#[cfg(target_os = "linux")]
const ENOATTR: i32 = rustix::io::Errno::NODATA.raw_os_error();
Expand All @@ -17,6 +23,35 @@ pub fn extract_noattr(result: io::Result<Vec<u8>>) -> io::Result<Option<Vec<u8>>
})
}

#[cfg(not(any(
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "netbsd"
)))]
pub fn extract_noattr(result: io::Result<Vec<u8>>) -> io::Result<Option<Vec<u8>>> {
// These are always expected to be unsupported.
match result {
Ok(result) => {
panic!("unexpected success on unsupported platform: {:?}", result);
}
Err(error) => {
assert_eq!(
error.kind(),
io::ErrorKind::Unsupported,
"xattrs are not supported on this platform"
);
Err(error)
}
}
}

#[cfg(any(
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "netbsd"
))]
pub fn allocate_loop<E, F: FnMut(&mut [u8]) -> Result<usize, E>>(mut f: F) -> io::Result<Vec<u8>>
where
io::Error: From<E>,
Expand Down