Repository: Stebalien/xattr (language: rust)

Issue:
Solaris ENOATTR build failure
The commit https://github.com/Stebalien/xattr/commit/0d637ae981645ac6ae441b42d782aa95cd9b71cf switches to `ENOATTR` in preference to `ENODATA`, however this causes the build to fail on Solaris which does not provide `ENOATTR`.  I assume the same will be true of all unsupported platforms.

```
error[E0432]: unresolved import `libc::ENOATTR`
 --> vendor/xattr/src/util.rs:8:20
  |
8 | use libc::{ERANGE, ENOATTR, ssize_t};
  |                    ^^^^^^^ no `ENOATTR` in the root. Did you mean to use `ENOTTY`?
```

Is the correct fix here to work around it in the module, or add a dummy `libc::ENOATTR` alias for `libc::NODATA` to rust?


Discussion / hints:

Fix patch:
diff --git a/src/sys/bsd.rs b/src/sys/bsd.rs
index 910fbbdf9..7f489a570 100644
--- a/src/sys/bsd.rs
+++ b/src/sys/bsd.rs
@@ -10,6 +10,8 @@ use std::path::Path;
 use libc::{c_char, c_int, c_void, size_t, ssize_t, EPERM};
 use util::{allocate_loop, path_to_c};
 
+pub const ENOATTR: ::libc::c_int = ::libc::ENOATTR;
+
 const EXTATTR_NAMESPACE_USER_STRING: &'static str = "user";
 const EXTATTR_NAMESPACE_SYSTEM_STRING: &'static str = "system";
 const EXTATTR_NAMESPACE_NAMES: [&'static str; 3] = [
diff --git a/src/sys/linux_macos/mod.rs b/src/sys/linux_macos/mod.rs
index 85f1b5d73..f2b2f309c 100644
--- a/src/sys/linux_macos/mod.rs
+++ b/src/sys/linux_macos/mod.rs
@@ -21,6 +21,8 @@ use libc::{c_char, c_void, size_t};
 
 use util::{allocate_loop, name_to_c, path_to_c};
 
+pub const ENOATTR: ::libc::c_int = ::libc::ENOATTR;
+
 /// An iterator over a set of extended attributes names.
 pub struct XAttrs {
     data: Box<[u8]>,
diff --git a/src/sys/unsupported.rs b/src/sys/unsupported.rs
index 7eb48a5d4..dba1d8810 100644
--- a/src/sys/unsupported.rs
+++ b/src/sys/unsupported.rs
@@ -5,6 +5,9 @@ use std::path::Path;
 
 use UnsupportedPlatformError;
 
+// Need to use something.
+pub const ENOATTR: ::libc::c_int = 0;
+
 /// An iterator over a set of extended attributes names.
 #[derive(Clone, Debug)]
 pub struct XAttrs;
diff --git a/src/util.rs b/src/util.rs
index 076159c95..d107694b6 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -5,7 +5,12 @@ use std::os::unix::ffi::OsStrExt;
 use std::path::Path;
 use std::ptr;
 
-use libc::{ssize_t, ENOATTR, ERANGE};
+use libc::{ssize_t, ERANGE};
+
+// Need to use this one as libc only defines this on supported platforms. Given
+// that we want to at least compile on unsupported platforms, we define this in
+// our platform-specific modules.
+use sys::ENOATTR;
 
 #[allow(dead_code)]
 pub fn name_to_c(name: &OsStr) -> io::Result<CString> {


Test patch: