Lygaen/zig-libc
A rewrite of the LIBC library in Zig !
A rewrite of the LIBC library in Zig ! Currently in a very, very alpha state, doesn't do a lot of things.
It aims to ONLY depend on zig's std.
If the behavior is different from musl
/glibc
/... then it is a bug. It aims for seamless integration / replacement.
It also has a tracing feature to allow you to follow your libc calls.
Here is the current progress on the implementation of the different headers.
See headers iso.
assert.h
ctype.h
errno.h
float.h
limits.h
locale.h
math.h
setjmp.h
signal.h
stdarg.h
stddef.h
stdio.h
stdlib.h
string.h
time.h
Because I cannot find the C95
iso file for free online, I will not implement the following headers until it changes.
iso646.h
wchar.h
wctype.h
See headers iso.
complex.h
fenv.h
inttypes.h
stdbool.h
(deprecated C23, to be removed ?)
stdint.h
tgmath.h
See headers iso.
stdalign.h
(deprecated C23, to be removed ?)
stdatomic.h
stdnoreturn.h
threads.h
uchar.h
See headers iso p.191.
stdbit.h
stdckdint.h
Same as for C95
, cannot find a free iso online. Will not implement.
stdmchar.h
Exemple usage can be found in the tests/
directory in the form of *.c
files. Basically, use it like libc :D
For building, use the following command :
zig build
It will produce the following structure in the zig-out
directory :
.
├── include
│ ├── assert.h
│ ├── stddef.h
│ └── ...
└── lib
└── libzig_libc.a
If you want to run and build the tests, do :
zig build test
which will generate :
.
├── bin
└── hello_world
└── ...
You can pass additional arguments to all the tests using :
zig build test -- arg1 arg2 ...
Additional parameters can be given at build time to modify the behavior of the library.
zig build -Dtrace
Will output tracing to stderr
which will satisfy the format :
[TRACE] LIBC '<function>' : <message>
This will clutter quite a lot your terminal but hopefully will help you trace back the error.
There a multiple reasons why I wanted to create this project :
All these mad reasons have lead me to the most reasonable choice : write the entire LIBC in zig.
A lot of inspiration and help was taken from the following projects :