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

Why not use OwnedFd and BorrowFd instead of RawFd for fd params? #3665

Open
creonico opened this issue Apr 26, 2024 · 1 comment
Open

Why not use OwnedFd and BorrowFd instead of RawFd for fd params? #3665

creonico opened this issue Apr 26, 2024 · 1 comment
Labels
C-API-request Category: API request

Comments

@creonico
Copy link

creonico commented Apr 26, 2024

I just learned that OwnedFd and BorrowedFd are I/O safe alternatives to RawFd, especially for FFI, https://rust-lang.github.io/rfcs/3128-io-safety.html#ownedfd-and-borrowedfdfd-1. So why not use this types instead? For example, currently mmap receives a file descriptor parameter as an i32,

pub unsafe extern "C" fn mmap(
    addr: *mut c_void,
    len: size_t,
    prot: c_int,
    flags: c_int,
    fd: c_int,
    offset: off_t
) -> *mut c_void

But why not define it with OwnedFd or BorrowedFd instead as in this examples: https://github.com/sunfishcode/io-lifetimes?tab=readme-ov-file#the-magic-of-transparency.
Please accept my apology for any oversight on my part, especially if there is an evident explanation for the situation as it stands.

@creonico creonico added the C-API-request Category: API request label Apr 26, 2024
@magicant
Copy link
Contributor

magicant commented May 1, 2024

This crate is intended to expose the raw API of the underlying platform. If you want a fancy, safe API, you can use nix or rustix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-API-request Category: API request
Projects
None yet
Development

No branches or pull requests

2 participants