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 __convertFunctions
function atof(s: *u8): f64C atof; converts a string to double with C error semantics.
function atoi(s: *u8): i32C atoi; converts a string to int with C error semantics.
function atol(s: *u8): i64C atol; converts a string to long with C error semantics.
namespace __ctypeFunctions
function isalnum(c: i32): i32C isalnum character classifier.
function isalpha(c: i32): i32C isalpha character classifier.
function iscntrl(c: i32): i32C iscntrl character classifier.
function isdigit(c: i32): i32C isdigit character classifier.
function isgraph(c: i32): i32C isgraph character classifier.
function islower(c: i32): i32C islower character classifier.
function isprint(c: i32): i32C isprint character classifier.
function ispunct(c: i32): i32C ispunct character classifier.
function isspace(c: i32): i32C isspace character classifier.
function isupper(c: i32): i32C isupper character classifier.
function isxdigit(c: i32): i32C isxdigit character classifier.
function tolower(c: i32): i32C tolower conversion.
function toupper(c: i32): i32C toupper conversion.
namespace __math_hFunctions
function abs(x: i32): i32C integer absolute value for int.
function labs(x: i64): i64C integer absolute value for long.
namespace __time_hFunctions
function clock(): i64C clock; returns processor time used by the process.
function clock_gettime(clockId: i32, tp: *mut Timespec): i32C clock_gettime; fills a timespec with the selected clock value.
function time(tloc: *mut i64): i64C time; returns seconds since the epoch and optionally stores them.
Constants
const CLOCK_MONOTONIC: i32const CLOCK_REALTIME: i32const CLOCKS_PER_SEC: i64namespace CharacterCharacter classification (ctype.h)
namespace ConversionConversion (stdlib.h)
namespace MathInteger math (stdlib.h)
namespace TimeTime (time.h)
Functions
function abs(x: i32): i32Returns the absolute value of x.
function atof(s: *u8): f64Converts a string to CDouble.
function atoi(s: *u8): i32Converts a decimal string to CInt.
function atol(s: *u8): i64Converts a decimal string to CLong.
function clock(): i64Returns 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): i32Reads the selected clock into tp.
function isalnum(c: i32): i32Tests if c is alphanumeric.
function isalpha(c: i32): i32Tests if c is alphabetic.
function iscntrl(c: i32): i32Tests if c is a control character.
function isdigit(c: i32): i32Tests if c is a decimal digit.
function isgraph(c: i32): i32Tests if c is a printable character excluding space.
function islower(c: i32): i32Tests if c is a lowercase letter.
function isprint(c: i32): i32Tests if c is a printable character (including space).
function ispunct(c: i32): i32Tests if c is a punctuation character.
function isspace(c: i32): i32Tests if c is a whitespace character.
function isupper(c: i32): i32Tests if c is an uppercase letter.
function isxdigit(c: i32): i32Tests if c is a hexadecimal digit.
function labs(x: i64): i64Returns the absolute value of x (long version).
function time(tloc: *mut i64): i64Returns the current calendar time (seconds since epoch).
If tloc is non-null, the result is also stored there.
function tolower(c: i32): i32Converts c to lowercase if it is an uppercase letter.
function toupper(c: i32): i32Converts c to uppercase if it is a lowercase letter.
Constants
const CLOCK_MONOTONIC: i32const CLOCK_REALTIME: i32const CLOCKS_PER_SEC: i64