Zero-dependency system substrate for plain C: cross-platform sockets, event polling, pluggable logging, process diagnostics, monotonic timing, advisory file locking, lock-free workqueues and compute worker pools, zero-alloc JSON and JSON DO
git clone https://github.com/tty-pt/libsteleDocumentation
libstele
Zero-dependency system substrate for plain C: cross-platform sockets, event polling, pluggable logging, process diagnostics, monotonic timing, advisory file locking, lock-free workqueues and compute worker pools, zero-alloc JSON and JSON DOM, isomorphic C contracts, and the integrated portablemk/build system. Canonical headers live under<ttypt/*.h>.
1. Quick Example: Cross-Platform Echo Server
#include <stdio.h>
#include <string.h>
#include <ttypt/stele.h>
int main(void) {
if (stl_sock_init() != 0) {
ERR("Failed to initialize socket runtime: %s", stl_sock_strerror());
return 1;
}
stl_ignore_pipe(); // Ignore SIGPIPE on client disconnects
stl_socket_t server = stl_sock_create(AF_INET, SOCK_STREAM, 0);
stl_sock_set_nonblock(server, 1);
struct sockaddr_in addr = {
.sin_family = AF_INET,
.sin_port = htons(8080),
.sin_addr.s_addr = htonl(INADDR_ANY)
};
stl_sock_bind(server, (struct sockaddr *)&addr, sizeof(addr));
stl_sock_listen(server, 128);
printf("Echo server listening on port 8080...\n");
struct pollfd pfd = { .fd = server, .events = POLLIN };
if (stl_poll(&pfd, 1, 5000) > 0 && (pfd.revents & POLLIN)) {
struct sockaddr_in client_addr;
socklen_t len = sizeof(client_addr);
stl_socket_t client = stl_sock_accept(server, (struct sockaddr *)&client_addr, &len);
if (client >= 0) {
char buf[128];
stl_sock_send(client, "HELLO\n", 6, 0);
stl_sock_close(client);
}
}
stl_sock_close(server);
return 0;
}
Compile natively on any platform:
cc server.c $(pkg-config --cflags --libs stele) -o server
2. Capabilities & Architecture
libstele serves as the bedrock Layer 0 substrate across the tty.pt C platform ecosystem.
| Subsystem | Header | Key Functions & Macros |
|---|---|---|
| Logging & Assertions | <ttypt/stele.h> | LOG(), WARN(), ERR(), CBUG(cond, ...), stllog_set(), stl_syslog() |
| Sockets & Multiplexing | <ttypt/stele.h> | stl_sock_create(), stl_sock_set_nonblock(), stl_sock_set_timeout(), stl_poll(), stl_ignore_pipe() |
| Local IPC & Wake Primitives | <ttypt/stele.h> | stl_ipc_listen(), stl_ipc_accept(), stl_ipc_connect(), stl_ipc_close_listener(), stl_wake_init(), stl_wake_signal(), stl_wake_drain() |
| Subprocess Management | <ttypt/stele.h> | stl_spawn(), stl_spawn_detached(), stl_proc_wait(), stl_proc_kill(), stl_proc_close(), STL_SPAWN_* |
| User, Path & Library Helpers | <ttypt/stele.h> | stl_username(), stl_home_dir(), stl_temp_dir(), stl_config_dir(), stl_data_dir(), stl_exe_dir(), stl_so_ext(), stl_mkdir_p() |
| High-Res Timing & Diagnostics | <ttypt/stele.h> | stl_now_ms(), stl_sleep_ms(), stl_pid_alive(), stl_self_rss_bytes() |
| Advisory File Locking | <ttypt/stele.h> | stl_file_lock_t, stl_file_lock_try(), stl_file_lock_acquire(), stl_file_lock_release(), stl_file_lock_is_held(), stl_flock(fd, STL_LOCK_EX \| STL_LOCK_NB), stl_dprintf(), stl_ftruncate() |
| Dynamic Loading | <ttypt/stele.h> | stl_dlopen(), stl_dlsym(), stl_dlclose() with STL_RTLD_NODELETE |
| Isomorphic C Export ABI | <ttypt/iso.h> | ISO_EXPORT(), ISO_EXPORT_AS(), ISO_IMPORT() |
| Zero-Alloc JSON (Header-Only) | <ttypt/iso_json.h> | iso_json_w_init(), iso_json_escape(), iso_json_obj_begin(), iso_json_kv_*(), iso_json_raw(), iso_json_parse(), iso_json_obj_get(), iso_json_unescape() (with html_safe mode and BMP/UTF-16 surrogate pair unescape; WASM-safe) |
| Single-Owner JSON DOM & Writer | <ttypt/stl_json.h> | stl_json_parse(), stl_json_parse_len(), stl_json_stringify(), stl_json_stringify_ext(), stl_json_new_*(), stl_json_obj_*(), stl_json_arr_*(), stl_json_buf_*() |
| Lock-Free Workqueue & Threads | <ttypt/wq.h> | stl_cpu_count(), stl_wq_thread_count(), stl_wq_create(), stl_wq_submit(), stl_wq_step(), stl_wq_wait(), stl_wq_drain(), stl_wq_destroy(), STL_THREAD_LOCAL |
| Multi-Core Compute Worker Pool | <ttypt/stl_job.h> | stl_job_init(), stl_job_worker_count(), stl_job_submit(), stl_job_poll(), stl_job_take(), stl_job_step(), stl_job_shutdown() (native stl_wq_t threads + WASM Web Workers without SharedArrayBuffer) |
| WASM Substrate & Slots | <ttypt/stele_wasm.h> | stl_kernel_boot(), stl_kernel_mount(), stl_kernel_mount_bin(), stl_invalidate(), stl_slot_invalidate(), STL_WASM_MODULE(), STL_WASM_MODULE_BIN(), STL_WASM_MODULE_EXT() |
| Cross-Slot Event Bus | <ttypt/stele_wasm.h> | stl_event_on(), stl_event_off(), stl_event_emit(), stl_on_event() |
3. Integrated Portable Build System (mk/)
libstele ships the shared portable Makefile infrastructure (mk/) used across tty.pt C and WebAssembly projects (GNU Make, BSD bmake, and OpenBSD make):
- Installed assets (
share/ttypt/mk/):portable.mk,portable-gnu.mk,portable-bsd.mk,include.mk,service.mk,cx.mk,iso.mk,glfw.mk,wasm_alloc_shim.c,Doxyfile,Doxyfile-bin,scripts/wasm-audit.sh,scripts/wasm-allowed-exports.lst, and WASI-isolated substrate headers undershare/ttypt/mk/include/ttypt/. - Make search-path shims (
ttypt/include.mk,ttypt/portable.mk):make installinstalls shims into Make's system search path so downstream repositories caninclude ttypt/include.mk(orttypt/portable.mk) directly without relative../discovery or subprocess forks. - Declarative rules & portable link variables: Supports declarative
TESTS=/test-suite/clean-tests, gated toolchain probes (NEED_WASI_CC), portableLDLIBS_DL/LDLIBS_PTHREAD, per-libraryWASM_GLOBAL_BASEandwasm-allowed-exports.lst, and daemon rules viaservice.mk. stele.pcbuild variables: exposesdatadir,mk_dir,include_mk,portable_mk, andwasm_includedirviapkg-config:
`sh pkg-config --variable=include_mk stele # .../share/ttypt/mk/include.mk pkg-config --variable=wasm_includedir stele # .../share/ttypt/mk/include `
- Backward compatibility:
make installalso generateslib/pkgconfig/ttypt-mk.pcpointing atshare/ttypt/mk/for projects queryingpkg-config ttypt-mk.
4. Installation & Build
Prebuilt Packages
Prebuilt packages for Linux (APT / Alpine / Arch / Fedora-RHEL), macOS (Homebrew), Windows (winget / MSYS2), OpenBSD, and mobile static sysroots (Android arm64-v8a/x86_64 at https://tty.pt/android/ and iOS libstele.xcframework.zip at https://tty.pt/ios/) are distributed via tty.pt packages. Use libstele as the package name.
Build from Source
make # builds lib/libstele.so and test binaries
make test # runs portability, file lock, dlopen, iso_json, stl_json, and stl_job tests
sudo make install # installs headers, libstele, share/ttypt/mk/, ttypt/*.mk shims, stele.pc, and ttypt-mk.pc
5. JavaScript & WebAssembly Bindings (@tty-pt/stele)
For browser, Node.js, and edge runtimes, libstele ships an isomorphic WebAssembly kernel and slot transport runtime on npm (primary registry https://tty.pt/npm/, mirrored to npmjs.org):
# Primary tty.pt registry (recommended)
npm config set @tty-pt:registry https://tty.pt/npm/
npm install @tty-pt/stele
See npm/README.md for the full TypeScript and WebAssembly API reference.
License
BSD 2-Clause License. Copyright (c) 2026, Paulo André Azevedo Quirino. See LICENSE.