3 ms·
Zig looks super cool. I've been wanting to experiment with it for some system software. Are there any guides anywhere for calling libc functions from zig? I'm
by nrclark 7y ago
Zig looks super cool. I've been wanting to experiment with it for some system software.
Are there any guides anywhere for calling libc functions from zig? I'm interested in fork/join, chmod, fcntl, and that kind of thing. Do I just import the C headers manually? Or is there some kind of built-in libc binding?
- dnautics 7y agoI think you can call libc by importing the C headers "automagically" but zig does also give you some of these things in its (admittedly still poorly documented) std lib: std.os.fork: https://github.com/ziglang/zig/blob/master/lib/std/os.zig#L2732 https://github.com/ziglang/zig/blob/master/lib/std/os.zig#L2... std.os.fcntl: https://github.com/ziglang/zig/blob/master/lib/std/os.zig#L3173 https://github.com/ziglang/zig/blob/master/lib/std/os.zig#L3...
- AndyKelley 7y agoFor POSIX, you can use the standard library: std.os.chmod std.os.fcntl Better yet, use the higher level cross platform abstractions. For example instead of fork/join, std.Thread.create std.Thread.wait These will work in Windows as well as POSIX.