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

Access errno for system calls from Rust code #2269

Closed
jesse99 opened this issue Apr 22, 2012 · 3 comments
Closed

Access errno for system calls from Rust code #2269

jesse99 opened this issue Apr 22, 2012 · 3 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@jesse99
Copy link
Contributor

jesse99 commented Apr 22, 2012

There should be a way to get at errno from rust code.

@Blub
Copy link

Blub commented Oct 29, 2012

It's important that we get functionality for this by either a keyword or a function in std or core. #553 cannot solve this because errno cannot reliably be expected to exist as a global variable. The manpage states that it can be implemented as a macro, and that it is thread-local.

errno  is  defined by the ISO C standard to be a modifiable lvalue of type int, and must not be explicitly declared; errno may be a macro.  errno is thread-local;

Currently you can only use a getter-function defined in an external C library, but since most C-library wrapper crates will want to use this, it should be available in the default libraries. (I was told the cargo system doesn't handle additional C-library code, so providing such a wrapper with your crate is not a good solution. Even if cargo was to allow this, it's still an ugly one.)

@erickt
Copy link
Contributor

erickt commented Oct 29, 2012

How about we add a fn with_errno<T>(f: extern fn() -> T) -> (uint, T) function to libc. It could portably capture the errno and also leaves us a convenient place to put any "block task migration while running" infrastructure if we implement task stealing.

bors added a commit that referenced this issue Feb 13, 2013
Rewrote the last pull request (#4859) to not require on llvm for core.

Also fixes #2269.
@luqmana
Copy link
Member

luqmana commented Feb 13, 2013

This can be closed now. os::errno() should give you the last system error code (GetLastError() on windows). Also, os::last_os_error() will give you the associated error string.

@graydon graydon closed this as completed Feb 13, 2013
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
make a bunch of tests look more like how they did before rustfmt
celinval added a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

5 participants