Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ jobs:
run: |
set -eux
if [ "${{ matrix.toolchain }}" = "1.65.0" ]; then
# Remove `-Dwarnings` at the MSRV since lints may be different, and allow
# `improper_ctypes` since pointers to ZSTs got the warning prior to 1.72.
# FIXME(msrv): remove this flag when possible.
export RUSTFLAGS="-Aimproper_ctypes"
# * Remove `-Dwarnings` at the MSRV since lints may be different
# * Allow `improper_ctypes` since pointers to ZSTs got the warning prior
# to 1.72.
# * Enable `unknown_lints` since we have some config not known at this
# version.
# FIXME(msrv): update this list when possible.
export RUSTFLAGS="-Aimproper_ctypes -Aunknown_lints"
# Remove `ctest` which uses the 2024 edition
perl -i -ne 'print unless /"ctest(-test)?",/ || /"libc-test",/' Cargo.toml
fi
Expand Down
8 changes: 4 additions & 4 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ pub const EPOLLWRBAND: c_int = 0x200;
pub const EPOLLMSG: c_int = 0x400;
pub const EPOLLERR: c_int = 0x8;
pub const EPOLLHUP: c_int = 0x10;
pub const EPOLLET: c_int = 0x80000000;
pub const EPOLLET: c_int = u32_cast_int(0x80000000);

pub const EPOLL_CTL_ADD: c_int = 1;
pub const EPOLL_CTL_MOD: c_int = 3;
Expand Down Expand Up @@ -1698,7 +1698,7 @@ pub const CLONE_NEWIPC: c_int = 0x08000000;
pub const CLONE_NEWUSER: c_int = 0x10000000;
pub const CLONE_NEWPID: c_int = 0x20000000;
pub const CLONE_NEWNET: c_int = 0x40000000;
pub const CLONE_IO: c_int = 0x80000000;
pub const CLONE_IO: c_int = u32_cast_int(0x80000000);
pub const CLONE_NEWCGROUP: c_int = 0x02000000;

pub const WNOHANG: c_int = 0x00000001;
Expand Down Expand Up @@ -1734,7 +1734,7 @@ pub const PTRACE_EVENT_SECCOMP: c_int = 7;

pub const __WNOTHREAD: c_int = 0x20000000;
pub const __WALL: c_int = 0x40000000;
pub const __WCLONE: c_int = 0x80000000;
pub const __WCLONE: c_int = u32_cast_int(0x80000000);

pub const SPLICE_F_MOVE: c_uint = 0x01;
pub const SPLICE_F_NONBLOCK: c_uint = 0x02;
Expand Down Expand Up @@ -2551,7 +2551,7 @@ pub const EPROTO: c_int = 71;
pub const EDOTDOT: c_int = 73;

pub const SA_NODEFER: c_int = 0x40000000;
pub const SA_RESETHAND: c_int = 0x80000000;
pub const SA_RESETHAND: c_int = u32_cast_int(0x80000000);
pub const SA_RESTART: c_int = 0x10000000;
pub const SA_NOCLDSTOP: c_int = 0x00000001;

Expand Down
2 changes: 1 addition & 1 deletion src/hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub const F_SETFL: i32 = 4;

pub const FD_CLOEXEC: i32 = 1;

pub const FIONBIO: i32 = 0x8008667e;
pub const FIONBIO: i32 = u32_cast_int(0x8008667e);

pub const FUTEX_RELATIVE_TIMEOUT: u32 = 1;

Expand Down
38 changes: 17 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,30 +144,26 @@
//! practice, breakage is rare and following the above-discussed [Usage Guidelines](#usage-guidelines)
//! means that most `libc` users will never encounter a problem.

// Make it a bit easier to build without Cargo
#![crate_name = "libc"]
#![crate_type = "rlib"]
#![allow(
renamed_and_removed_lints, // Keep this order.
unknown_lints, // Keep this order.
nonstandard_style,
overflowing_literals,
unused_macros,
unused_macro_rules,
)]
#![warn(
missing_copy_implementations,
missing_debug_implementations,
safe_packed_borrows
)]
// Prepare for a future upgrade
// Pretty much all C API doesn't match Rust conventions.
#![allow(nonstandard_style)]
// Not all macros and all patterns are used on all targets.
#![allow(unused_macros)]
#![allow(unused_macro_rules)]
// All traits should be `Copy` and `Debug`.
#![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
// Downgrade deny to a warning.
#![warn(overflowing_literals)]
// Prepare for a future upgrade.
#![warn(rust_2024_compatibility)]
// Things missing for 2024 that are blocked on MSRV or breakage
#![allow(
missing_unsafe_on_extern,
edition_2024_expr_fragment_specifier,
// Allowed globally, the warning is enabled in individual modules as we work through them
unsafe_op_in_unsafe_fn
)]
// Things missing for 2024 that are blocked on MSRV or breakage.
#![allow(missing_unsafe_on_extern)]
#![allow(edition_2024_expr_fragment_specifier)]
// Allowed globally, the warning is enabled in individual modules as we work through them
#![allow(unsafe_op_in_unsafe_fn)]
#![cfg_attr(libc_deny_warnings, deny(warnings))]
// Attributes needed when building as part of the standard library
#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]
Expand Down
7 changes: 7 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ macro_rules! prelude {
pub(crate) use core::prelude::v1::derive;
#[allow(unused_imports)]
pub(crate) use core::{
assert,
cfg,
fmt,
hash,
Expand All @@ -105,8 +106,14 @@ macro_rules! prelude {
size_of_val,
};

#[allow(unused_imports)]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "l4re"))]
pub(crate) use crate::types::u32_cast_ioctl;
#[allow(unused_imports)]
pub(crate) use crate::types::{
u16_cast_short,
u32_cast_int,
u32_cast_long,
CEnumRepr,
Padding,
};
Expand Down
2 changes: 1 addition & 1 deletion src/new/linux_uapi/linux/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub const FUTEX_WAITERS: u32 = 0x80000000;
pub const FUTEX_OWNER_DIED: u32 = 0x40000000;
pub const FUTEX_TID_MASK: u32 = 0x3fffffff;

pub const FUTEX_BITSET_MATCH_ANY: c_int = 0xffffffff;
pub const FUTEX_BITSET_MATCH_ANY: c_int = u32_cast_int(0xffffffff);

pub const FUTEX_OP_SET: c_int = 0;
pub const FUTEX_OP_ADD: c_int = 1;
Expand Down
6 changes: 3 additions & 3 deletions src/new/qurt/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pub const UCHAR_MAX: c_uchar = 255;

// Integer properties
pub const INT_MAX: c_int = 2147483647;
pub const INT_MIN: c_int = (-2147483647 - 1);
pub const INT_MIN: c_int = -2147483647 - 1;
pub const UINT_MAX: c_uint = 4294967295;

pub const LONG_MAX: c_long = 2147483647;
pub const LONG_MIN: c_long = (-2147483647 - 1);
pub const LONG_MIN: c_long = -2147483647 - 1;
pub const ULONG_MAX: c_ulong = 4294967295;

pub const SHRT_MAX: c_short = 32767;
pub const SHRT_MIN: c_short = (-32768);
pub const SHRT_MIN: c_short = -32768;
pub const USHRT_MAX: c_ushort = 65535;

// POSIX Limits
Expand Down
4 changes: 2 additions & 2 deletions src/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ pub const S_IWRITE: c_short = 0o0200;
pub const S_IREAD: c_short = 0o0400;
pub const S_IFCHR: c_short = 0o2_0000;
pub const S_IFDIR: c_short = 0o4_0000;
pub const S_IFMT: c_short = 0o16_0000;
pub const S_IFMT: c_short = u16_cast_short(0o16_0000);
pub const S_IFIFO: c_short = 0o1_0000;
pub const S_IFBLK: c_short = 0o6_0000;
pub const S_IFREG: c_short = 0o10_0000;
pub const S_IFREG: c_short = u16_cast_short(0o10_0000);

pub const LC_ALL: c_int = 0;
pub const LC_COLLATE: c_int = 1;
Expand Down
34 changes: 34 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,37 @@ pub(crate) type CEnumRepr = c_int;
#[cfg(not(target_env = "msvc"))]
#[allow(unused)]
pub(crate) type CEnumRepr = c_uint;

/// Used to avoid `overflowing_literals` when the value is in-range for the unsigned number but
/// out-of-range for signed.
#[allow(unused)]
pub(crate) const fn u16_cast_short(x: u16) -> c_short {
assert!(size_of::<u16>() <= size_of::<c_short>()); // Should always be true
x as i16
}

/// Used to avoid `overflowing_literals` when the value is in-range for the unsigned number but
/// out-of-range for signed.
#[allow(unused)]
pub(crate) const fn u32_cast_int(x: u32) -> c_int {
// May not be true on 16-bit platforms, but should be everywhere this is used.
assert!(size_of::<u32>() <= size_of::<c_int>());
x as i32
}

/// Used to avoid `overflowing_literals` when the value is in-range for the unsigned number but
/// out-of-range for signed.
#[allow(unused)]
pub(crate) const fn u32_cast_long(x: u32) -> c_long {
assert!(size_of::<u32>() <= size_of::<c_long>()); // Should always be true
x as c_long
}

/// Used to avoid `overflowing_literals` when the value is in-range for the unsigned number but
/// out-of-range for signed.
#[allow(unused)]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "l4re"))]
pub(crate) const fn u32_cast_ioctl(x: u32) -> crate::Ioctl {
assert!(size_of::<u32>() <= size_of::<crate::Ioctl>()); // Should always be true
x as crate::Ioctl
}
Loading