Module

std::libc::misc

LibC Miscellaneous

Conversion, integer math, character classification, and time.

Sub-namespaces

Namespace C Header Description
LibC::Conversion stdlib.h atoi, atol, atof
LibC::Math stdlib.h abs, labs
LibC::Character ctype.h isalnum, isdigit, toupper, …
LibC::Time time.h time, clock, CLOCKS_PER_SEC

Example

import LibC, CType from "std::libc";

function main(): i32 {
  // String-to-number conversion
  let n: CType::CInt = LibC::Conversion::atoi("42");

  // Character classification
  let ch: CType::CInt = 65; // 'A'
  let lower: CType::CInt = LibC::Character::tolower(ch);

  // CPU time measurement
  let start: CType::ClockT = LibC::Time::clock();
  // ... work ...
  let elapsed: CType::ClockT = LibC::Time::clock() - start;

  return 0;
}
namespace __convert

Functions

function atof(s: *u8): f64

C atof; converts a string to double with C error semantics.

function atoi(s: *u8): i32

C atoi; converts a string to int with C error semantics.

function atol(s: *u8): i64

C atol; converts a string to long with C error semantics.

namespace __ctype

Functions

function isalnum(c: i32): i32

C isalnum character classifier.

function isalpha(c: i32): i32

C isalpha character classifier.

function iscntrl(c: i32): i32

C iscntrl character classifier.

function isdigit(c: i32): i32

C isdigit character classifier.

function isgraph(c: i32): i32

C isgraph character classifier.

function islower(c: i32): i32

C islower character classifier.

function isprint(c: i32): i32

C isprint character classifier.

function ispunct(c: i32): i32

C ispunct character classifier.

function isspace(c: i32): i32

C isspace character classifier.

function isupper(c: i32): i32

C isupper character classifier.

function isxdigit(c: i32): i32

C isxdigit character classifier.

function tolower(c: i32): i32

C tolower conversion.

function toupper(c: i32): i32

C toupper conversion.

namespace __math_h

Functions

function abs(x: i32): i32

C integer absolute value for int.

function labs(x: i64): i64

C integer absolute value for long.

namespace __time_h

Functions

function clock(): i64

C clock; returns processor time used by the process.

function clock_gettime(clockId: i32, tp: *mut Timespec): i32

C clock_gettime; fills a timespec with the selected clock value.

function time(tloc: *mut i64): i64

C time; returns seconds since the epoch and optionally stores them.

Constants

const CLOCK_MONOTONIC: i32
const CLOCK_REALTIME: i32
const CLOCKS_PER_SEC: i64
namespace Character

Character classification (ctype.h)

namespace Conversion

Conversion (stdlib.h)

namespace Math

Integer math (stdlib.h)

namespace Time

Time (time.h)

Functions

function abs(x: i32): i32

Returns the absolute value of x.

function atof(s: *u8): f64

Converts a string to CDouble.

function atoi(s: *u8): i32

Converts a decimal string to CInt.

function atol(s: *u8): i64

Converts a decimal string to CLong.

function clock(): i64

Returns processor time consumed by the program in clock ticks.

Divide by CLOCKS_PER_SEC to get seconds.

function clock_gettime(clockId: i32, tp: *mut Timespec): i32

Reads the selected clock into tp.

function isalnum(c: i32): i32

Tests if c is alphanumeric.

function isalpha(c: i32): i32

Tests if c is alphabetic.

function iscntrl(c: i32): i32

Tests if c is a control character.

function isdigit(c: i32): i32

Tests if c is a decimal digit.

function isgraph(c: i32): i32

Tests if c is a printable character excluding space.

function islower(c: i32): i32

Tests if c is a lowercase letter.

function isprint(c: i32): i32

Tests if c is a printable character (including space).

function ispunct(c: i32): i32

Tests if c is a punctuation character.

function isspace(c: i32): i32

Tests if c is a whitespace character.

function isupper(c: i32): i32

Tests if c is an uppercase letter.

function isxdigit(c: i32): i32

Tests if c is a hexadecimal digit.

function labs(x: i64): i64

Returns the absolute value of x (long version).

function time(tloc: *mut i64): i64

Returns the current calendar time (seconds since epoch).

If tloc is non-null, the result is also stored there.

function tolower(c: i32): i32

Converts c to lowercase if it is an uppercase letter.

function toupper(c: i32): i32

Converts c to uppercase if it is a lowercase letter.

Constants

const CLOCK_MONOTONIC: i32
const CLOCK_REALTIME: i32
const CLOCKS_PER_SEC: i64