Skip to content

proposal: consolidate libc::mode_t abstraction #7751

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

Open
nyurik opened this issue Apr 13, 2025 · 3 comments
Open

proposal: consolidate libc::mode_t abstraction #7751

nyurik opened this issue Apr 13, 2025 · 3 comments

Comments

@nyurik
Copy link
Contributor

nyurik commented Apr 13, 2025

I was hacking on #7728, trying to get rid of numerous suspiscious u32 casts, and realized that many of them have to do with libc::mode_t alias. In most unix-like OS, it uses u32, but some use u16 and Redux uses i32, making this somewhat problematic.

Coreutils code constantly casts from mode_t to u32 and back. I think a better paradigm might be to introduce a dedicated type, probably based on bitflags? In general, a strongly typed flag type should be better than a generic u32 passed around. My only reservation is that maybe this should be part of libc itself?

See also rust-lang/libc#4404

@sylvestre
Copy link
Contributor

yeah, makes sense!

@BenWiederhake
Copy link
Collaborator

Sounds like a good idea! Let's wait and see what libc does.

@tertsdiepraam
Copy link
Member

tertsdiepraam commented Apr 14, 2025

I doubt libc will do that, because they have 0 dependencies and are just meant to be a raw wrapper. But the nix crate already has something like this: https://docs.rs/nix/latest/nix/sys/stat/struct.Mode.html. We should probably use that instead of raw libc in most cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants