sp.h: A 15K-line single-header C library that ditches libc and null-terminated strings
Original source
sp.h: Fixing C by giving it a high quality, ultra portable standard library
Hacker News →A developer has spent the past year building sp.h, a single-header C99 library that aims to replace libc rather than wrap it. The library talks directly to roughly 40 platform syscalls, ships as one 15,000-line file, and runs across Linux, Windows, macOS, WASM, and exotic toolchains like Cosmopolitan and TCC. Its core thesis: the layers libc has accumulated between the kernel and user code are actively harmful, especially as performance increasingly hinges on async I/O primitives rather than compiler micro-optimization.
Two design choices anchor the project. First, there is no implicit heap — every allocating function takes an explicit allocator, treating malloc-style ambient allocation as an opt-in fiction rather than a primitive. Second, null-terminated strings are gone, replaced by a pointer-plus-length sp_str_t type that enables O(1) length, non-owning substrings, and zero-copy parsing. Errors are returned not thrown, globals are banned, and memory is zero-initialized by default.
The author explicitly rejects libc conformance, obscure-platform support, and micro-optimizations like SIMD or hand-tuned hash tables, arguing that application-specific code beats generic tuning anyway. The pitch for staying in C rather than moving to Rust or Zig: C remains the only language that compiles to essentially any target with mature optimizing backends, and a better standard library is enough to make it pleasant again.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.