codyps / ioctl

Helpers for binding ioctls in Rust
https://docs.rs/ioctl-sys
Apache License 2.0
4 stars 14 forks source link

Add ioctl!(read0 ...) #14

Closed diwic closed 3 years ago

diwic commented 3 years ago

This version of the macro would start with a zeroed struct, call the ioctl, and return the struct if the ioctl succeeded, otherwise a proper error. Because that's usually what you want to do.

It's an untested draft, let me know what you think!

codyps commented 3 years ago

This seems like a reasonable addition. Could you add smoke test?

diwic commented 3 years ago

@jmesmon Just one design question. Read0 does two things different:

1) It returns a io::Result rather than a c_int 2) It allocates a zeroed buffer and returns it

While 2) is something specific for some read calls, 1) is something that would be useful for essentially all ioctls, although the rest of them might return io::Result<()> instead of io::Result<T>. Any thoughts on how we parametrize that, like, should we add some new macro like ioctl_with_result!, add a specific parameter like ioctl!(read io_result 'SOME_NAME' with ...), or something else?

codyps commented 3 years ago

That's a great point. It does seem like having some way to get io::Result<()> for all ioctls could be useful. I'm not too attached to either option (new macro, or extra parameter), but given that we're currently covering everything with the 1 ioctl macro, it seems like using a new parameter (or a different first argument, like try_read) could be good.

Do you have any thoughts on the upsides/downsides for the various choices?

diwic commented 3 years ago

@jmesmon Okay, I updated my patch. Feel free to merge it if you like it the way it is. I added try versions for the most common variants.

diwic commented 3 years ago

@jmesmon Ping?

codyps commented 3 years ago

Ah, sorry about that. This looks fine.

bors r+

bors[bot] commented 3 years ago

Build succeeded:

codyps commented 3 years ago

I've released this as ioctl-sys 0.7.0

codyps commented 3 years ago

I've also invited you to this repo and the associated crates on cargo.io so you don't need to wait on me for changes you'd like to make.