Present day, present time.
A lightweight header-only C library inspired by low-level Unix programming and some of the ergonomic ideas found in modern languages such as Rust.
lain provides small, composable modules for strings, file handling,
I/O, containers, and other foundational utilities while remaining
simple, explicit, and close to the operating system.
The goal is not to replace libc.
The goal is to explore how such abstractions can be built from first principles while preserving the simplicity and transparency of C.
lain follows a few simple principles:
- Header-only whenever practical.
- Explicit behavior over hidden magic.
- Minimal dependencies.
- POSIX-first design.
- Small, composable modules.
- Learn by rebuilding fundamental abstractions.
The project is heavily inspired by Unix design and by the ergonomics of modern systems languages, particularly Rust.
Fundamental types used throughout the library.
i8 i16 i32 i64
u8 u16 u32 u64
f32 f64
usize
isizeBasic string utilities and string abstractions.
String
lain_string()
lain_stringlen()
lain_reverse()
lain_itoa()Low-level output and error handling.
lain_print()
lain_perror()Filesystem and file descriptor helpers.
lain_open()
lain_create()
lain_read()
lain_write()
lain_close()
lain_mkdir()
lain_exists()
lain_is_dir()#include <lain/lain_fs.h>
int main(void)
{
i32 fd = lain_open(
lain_string("hello.txt"));
if (fd == -1)
{
return 1;
}
lain_close(fd);
return 0;
}- Dynamic vectors (
Vec) - String builders
- Iterators
- Result types
- Option types
- Argument parsing
- Directory traversal
- Logging utilities
- Memory utilities
The objective is to provide useful abstractions without hiding how the underlying system works.
lain is not:
- A replacement for libc
- A framework
- A language extension
- A Rust clone
The project borrows ideas where they are useful while remaining idiomatic C.
Currently developed and tested on:
- Linux
- POSIX-compatible environments
The project is in an early refactoring stage and the API is expected to evolve significantly.