Module

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 __errno

Functions

function errno_location(): *mut i32

Returns the thread-local errno pointer on Linux.

namespace __errno_constants

Returns the thread-local errno pointer on macOS.

Constants

const E2BIG: i32
const EACCES: i32
const EAGAIN: i32
const EBADF: i32
const EBUSY: i32
const ECONNREFUSED: i32
const ECONNRESET: i32
const EEXIST: i32
const EINTR: i32
const EINVAL: i32
const EIO: i32
const EISDIR: i32
const EMFILE: i32
const ENFILE: i32
const ENOENT: i32
const ENOMEM: i32
const ENOSPC: i32
const ENOTDIR: i32
const ENOTEMPTY: i32
const ENXIO: i32
const EPERM: i32
const EPIPE: i32
const ERANGE: i32
const EROFS: i32
const ESRCH: i32
const ETIMEDOUT: i32
namespace Errno

Thread-local error number and POSIX error constants.

Functions

function get(): i32

Reads the current errno value.

function set(value: i32): void

Sets errno to value.

Constants

const E2BIG: i32
const EACCES: i32
const EAGAIN: i32
const EBADF: i32
const EBUSY: i32
const ECONNREFUSED: i32
const ECONNRESET: i32
const EEXIST: i32
const EINTR: i32
const EINVAL: i32
const EIO: i32
const EISDIR: i32
const EMFILE: i32
const ENFILE: i32
const ENOENT: i32
const ENOMEM: i32
const ENOSPC: i32
const ENOTDIR: i32
const ENOTEMPTY: i32
const ENXIO: i32
const EPERM: i32
const EPIPE: i32
const ERANGE: i32
const EROFS: i32
const ESRCH: i32
const ETIMEDOUT: i32
const EWOULDBLOCK: i32