Skip to content

Instantly share code, notes, and snippets.

@cpu
Created March 21, 2020 15:30
Show Gist options
  • Save cpu/4280a148aad1619e9b71139b48e6fc8f to your computer and use it in GitHub Desktop.
Save cpu/4280a148aad1619e9b71139b48e6fc8f to your computer and use it in GitHub Desktop.
Broken attempt at fixing the libc style linter for `cfg_if`.
diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs
index c1705a94e..e3933b4f1 100644
--- a/src/unix/linux_like/linux/mod.rs
+++ b/src/unix/linux_like/linux/mod.rs
@@ -3393,25 +3393,28 @@ extern "C" {
) -> ::c_int;
pub fn fanotify_init(flags: ::c_uint, event_f_flags: ::c_uint) -> ::c_int;
- #[cfg(not(target_env = "musl"))]
- pub fn fanotify_mark(
- fd: ::c_int,
- flags: ::c_uint,
- mask: u64,
- dirfd: ::c_int,
- path: *const ::c_char,
- ) -> ::c_int;
- // Musl targets need the `mask` argument of `fanotify_mark` be specified `::c_ulonglong`
- // instead of `u64` or there will be a type mismatch between `long long unsigned int` and the
- // expected `uint64_t`.
- #[cfg(target_env = "musl")]
- pub fn fanotify_mark(
- fd: ::c_int,
- flags: ::c_uint,
- mask: ::c_ulonglong,
- dirfd: ::c_int,
- path: *const ::c_char,
- ) -> ::c_int;
+ cfg_if! {
+ if #[cfg(not(target_env = "musl"))] {
+ pub fn fanotify_mark(
+ fd: ::c_int,
+ flags: ::c_uint,
+ mask: u64,
+ dirfd: ::c_int,
+ path: *const ::c_char,
+ ) -> ::c_int;
+ } else if #[cfg(target_env = "musl")] {
+ // Musl targets need the `mask` argument of `fanotify_mark` be specified `::c_ulonglong`
+ // instead of `u64` or there will be a type mismatch between `long long unsigned int` and the
+ // expected `uint64_t`.
+ pub fn fanotify_mark(
+ fd: ::c_int,
+ flags: ::c_uint,
+ mask: ::c_ulonglong,
+ dirfd: ::c_int,
+ path: *const ::c_char,
+ ) -> ::c_int;
+ }
+ }
}
cfg_if! {
$> cargo build
Compiling libc v0.2.68 (/home/daniel/Code/libc)
error: expected one of `!`, `(`, `+`, `::`, `<`, `where`, or `{`, found `;`
--> src/unix/linux_like/linux/mod.rs:3404:25
|
3404 | ) -> ::c_int;
| ^ expected one of 7 possible tokens
error: aborting due to previous error
error: could not compile `libc`.
To learn more, run the command again with --verbose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment