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

Expose strerror and strerror_r #545

Open
Susurrus opened this issue Mar 1, 2017 · 9 comments
Open

Expose strerror and strerror_r #545

Susurrus opened this issue Mar 1, 2017 · 9 comments

Comments

@Susurrus
Copy link
Contributor

Susurrus commented Mar 1, 2017

I'm refactoring some code of mine to use nix where possible but right now I can't get a string description for low-level errors. I used to use errno, but you can't do that easily with nix because once you have an Errno there's no way to get the underlying i32 and pass that to libc::strerror. Instead of supporting extracting this integer, it'd be useful having a safe wrapper around strerror. I'd be happy to do this since I already have code that does it, but I don't know where it should go or if this functionality is desired in nix. Should I add wrappers for strerror and strerror_r in a new /src/string.rs module?

@Susurrus Susurrus changed the title Expose strerror and friends Expose strerror and strerror_r Mar 1, 2017
@fiveop
Copy link
Contributor

fiveop commented Mar 3, 2017

You want a function strerror(Errno) -> SomeStringType? Sounds good to me. And it does belong in src/string.rs as you suggest.

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 3, 2017

So it looks like this behavior already exists in Errno::desc(). I've used it in my own library to make sure it works correctly, and it does, so I'll just use that instead. I don't see a good reason to expose strerror() or strerror_r() given that that functionality exists, but there should be a way for people trying to use those functions to find the Errno struct and related functionality.

@kamalmarhubi
Copy link
Member

once you have an Errno there's no way to get the underlying i32 and pass that to libc::strerror

You can do this via a cast: my_errno_value as i32. It may be nicer to provide a method, however.

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 6, 2017

I don't need this functionality anymore since discovering Errno::desc. Should I close this or leave it open as a TODO item?

@kamalmarhubi
Copy link
Member

We can convert it to a doc issue :-)

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 8, 2017

If you have a suggestion for how to document this, I can submit a PR for it. I just don't know where this should go.

@kamalmarhubi
Copy link
Member

@Susurrus maybe module level docs on nix::error?

@Susurrus
Copy link
Contributor Author

Re #545 (comment) would it be accepted to add impl From<i32> for Errno which I think is more ergonomic than a cast? This could possibly replace the from_i32() method as well.

Also, do you mean I should add docs to nix::errno? nix::error doesn't exist though the type nix::Error does.

@Susurrus
Copy link
Contributor Author

Susurrus commented Jun 4, 2017

Regarding this, is there any reason to have hard-coded error strings in nix versus uses strerror_r? I'm uncertain why we'd want to bloat the binary size and duplicate the descriptions by hard-coding them.

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

No branches or pull requests

3 participants