std::libc
LibC
Raw bindings to a POSIX-oriented subset of the C standard library.
All types use the CType namespace (re-exported from std::libc/primitives).
No safety guarantees are added – the caller is responsible for pointer
validity, buffer sizes, and lifetime management.
Sub-namespaces
| Namespace | Source file | C Headers | Description |
|---|---|---|---|
LibC::Allocator |
memory.ign | stdlib.h |
malloc, calloc, realloc, free |
LibC::MemoryOperations |
memory.ign | string.h |
memcpy, memmove, memset, memcmp |
LibC::Memory |
memory.ign | sys/mman.h, unistd.h |
mmap, munmap, mprotect, sbrk, brk |
LibC::String |
string.ign | string.h |
strlen, strcmp, strcpy, strcat, … |
LibC::File |
io.ign | unistd.h, fcntl.h |
open, close, read, write, lseek, … |
LibC::Stdio |
stdio.ign | stdio.h |
fopen, fclose, fread, fwrite, … |
LibC::Errno |
errno.ign | errno.h |
get, set + 26 POSIX error constants |
LibC::Process |
process.ign | stdlib.h, unistd.h |
exit, fork, getpid, sleep, … |
LibC::Signals |
process.ign | signal.h |
raise, kill |
LibC::Wait |
process.ign | sys/wait.h |
wait, waitpid |
LibC::Conversion |
misc.ign | stdlib.h |
atoi, atol, atof |
LibC::Math |
misc.ign | stdlib.h |
abs, labs |
LibC::Character |
misc.ign | ctype.h |
isalnum, isdigit, toupper, tolower, … |
LibC::Time |
misc.ign | time.h |
time, clock, clock_gettime, clock IDs |
Constants
Each sub-namespace exposes relevant C constants as extern const
declarations. Values come from the C headers at compile time, not
hardcoded in Ignis source.
| Namespace | Constants |
|---|---|
LibC::File |
SEEK_SET, SEEK_CUR, SEEK_END, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_APPEND |
LibC::Stdio |
SEEK_SET, SEEK_CUR, SEEK_END, EOF |
LibC::Errno |
EPERM, ENOENT, EACCES, EINVAL, ENOMEM, EAGAIN, … |
LibC::Process |
EXIT_SUCCESS, EXIT_FAILURE |
LibC::Signals |
SIGINT, SIGKILL, SIGSEGV, SIGTERM |
LibC::Memory |
PROT_NONE, PROT_READ, PROT_WRITE, PROT_EXEC, MAP_SHARED, MAP_PRIVATE, MAP_ANONYMOUS |
LibC::Time |
CLOCKS_PER_SEC, CLOCK_REALTIME, CLOCK_MONOTONIC |
Platform
Type sizes assume LP64 (Linux/macOS 64-bit). See CType for the
full type mapping.
Example
import LibC, CType from "std::libc";
function main(): i32 {
// Write to stdout via file descriptor
let msg: *u8 = "hello from libc\n";
LibC::File::write(LibC::File::STDOUT_FILENO, msg as CType::CConstVoidPtr, 16);
// Open a file, write to it, close it
let fd: CType::CInt = LibC::File::open("out.txt", LibC::File::O_WRONLY | LibC::File::O_CREAT | LibC::File::O_TRUNC);
if fd != -1 {
let data: *u8 = "written via libc\n";
LibC::File::write(fd, data as CType::CConstVoidPtr, 17);
LibC::File::close(fd);
}
// Check errno after a failed operation
let bad: CType::CInt = LibC::File::open("/nonexistent", LibC::File::O_RDONLY);
if bad == -1 {
let err: CType::CInt = LibC::Errno::get();
if err == LibC::Errno::ENOENT {
LibC::Process::exit(LibC::Process::EXIT_SUCCESS);
}
}
return 0;
}
namespace LibCAggregate namespace for C library bindings.
Submodules contribute nested namespaces such as LibC::Memory,
LibC::String, LibC::Process, and LibC::File through imports above.