Recommended way to interact with OS APIs in Zig

I’m interested in learning how to interact with operating systems such as Linux and Windows via Zig. Specifically, I would like to know how to use the OS APIs, such as the methods exposed by libc for Linux, and kernel32 or ntdll for Windows.

Could you please recommend the best practices or any resources that could help me understand this better?

Zig standard library already uses linux and windows API and it is the best place to look for best practices.

Windows declaration examples:

They use extern "kernel32" that means link with kernel32.dll and callconv(WINAPI) that means use the windows API calling convention.
In std.os.windows you will find examples of how to call these functions by converting between UTF-16 and UTF-8.

Linux calls are at std.os.linux.
These functions are direct system calls to the linux kernel, C standard library is not required. For example:

6 Likes