std::libc::errno
LibC Errno
Thread-local errno access and POSIX error constants, exposed as
LibC::Errno.
Functions
| Function | Description |
|---|---|
get |
Read the current thread-local errno value |
set |
Write a new value into thread-local errno |
Error Constants
All error constants are extern const declarations resolved from
<errno.h> at compile time.
| Constant | Description |
|---|---|
EPERM |
Operation not permitted |
ENOENT |
No such file or directory |
ESRCH |
No such process |
EINTR |
Interrupted system call |
EIO |
I/O error |
ENXIO |
No such device or address |
E2BIG |
Argument list too long |
EACCES |
Permission denied |
EBADF |
Bad file descriptor |
EAGAIN |
Resource temporarily unavailable |
ENOMEM |
Cannot allocate memory |
EBUSY |
Resource busy |
EEXIST |
File exists |
ENOTDIR |
Not a directory |
EISDIR |
Is a directory |
EINVAL |
Invalid argument |
ENFILE |
Too many open files in system |
EMFILE |
Too many open files (per process) |
ENOSPC |
No space left on device |
EROFS |
Read-only file system |
EPIPE |
Broken pipe |
ERANGE |
Result too large (math) |
ENOTEMPTY |
Directory not empty |
ECONNREFUSED |
Connection refused |
ECONNRESET |
Connection reset by peer |
ETIMEDOUT |
Connection timed out |
EWOULDBLOCK |
Alias for EAGAIN |
Platform Notes
On Linux/glibc, errno is a macro expanding to (*__errno_location()).
The get and set functions call __errno_location to read/write the
thread-local value.
Example
import LibC, CType from "std::libc";
function main(): i32 {
let fd: CType::CInt = LibC::File::open("/nonexistent", LibC::File::O_RDONLY);
if fd == -1 {
let err: CType::CInt = LibC::Errno::get();
if err == LibC::Errno::ENOENT {
// file not found -- expected
return 0;
}
}
return 1;
}
namespace __errnoFunctions
function errno_location(): *mut i32Returns the thread-local errno pointer on Linux.
namespace __errno_constantsReturns the thread-local errno pointer on macOS.
Constants
const E2BIG: i32const EACCES: i32const EAGAIN: i32const EBADF: i32const EBUSY: i32const ECONNREFUSED: i32const ECONNRESET: i32const EEXIST: i32const EINTR: i32const EINVAL: i32const EIO: i32const EISDIR: i32const EMFILE: i32const ENFILE: i32const ENOENT: i32const ENOMEM: i32const ENOSPC: i32const ENOTDIR: i32const ENOTEMPTY: i32const ENXIO: i32const EPERM: i32const EPIPE: i32const ERANGE: i32const EROFS: i32const ESRCH: i32const ETIMEDOUT: i32namespace ErrnoThread-local error number and POSIX error constants.
Functions
function get(): i32Reads the current errno value.
function set(value: i32): voidSets errno to value.
Constants
const E2BIG: i32const EACCES: i32const EAGAIN: i32const EBADF: i32const EBUSY: i32const ECONNREFUSED: i32const ECONNRESET: i32const EEXIST: i32const EINTR: i32const EINVAL: i32const EIO: i32const EISDIR: i32const EMFILE: i32const ENFILE: i32const ENOENT: i32const ENOMEM: i32const ENOSPC: i32const ENOTDIR: i32const ENOTEMPTY: i32const ENXIO: i32const EPERM: i32const EPIPE: i32const ERANGE: i32const EROFS: i32const ESRCH: i32const ETIMEDOUT: i32const EWOULDBLOCK: i32