Skip to content
Standard libraryZig 0.17.1Official documentation
Sourcestd/os.zig

Source line 1

std.os.builtin

constant

Source line 1

std.os.emscripten

alias

Source line 9

Alias of std.os.emscripten

std.os.linux

alias

Source line 5

Alias of std.os.linux

std.os.native_os

constant

Source line 3

std.os.plan9

alias

Source line 6

Alias of std.os.plan9

std.os.requiresLibC

function

Source line 33

Returns whether the Zig standard library requires libc in order to interface with the operating system on the current target.

pub fn requiresLibC() bool

std.os.std

alias

Source line 2

Alias of std

std.os.targetRequiresLibC

function

Source line 14

Returns whether the Zig standard library requires libc in order to interface with the operating system on the given target.

pub fn targetRequiresLibC(target: *const std.Target) bool

Parameters

target: *const std.Target

std.os.uefi

alias

Source line 7

Alias of std.os.uefi

std.os.wasi

alias

Source line 8

Alias of std.os.wasi

std.os.windows

alias

Source line 10

Alias of std.os.windows

Source code

std/os.zig

const builtin = @import("builtin");
const std = @import("std.zig");
const native_os = builtin.os.tag;

pub const linux = @import("os/linux.zig");
pub const plan9 = @import("os/plan9.zig");
pub const uefi = @import("os/uefi.zig");
pub const wasi = @import("os/wasi.zig");
pub const emscripten = @import("os/emscripten.zig");
pub const windows = @import("os/windows.zig");

/// Returns whether the Zig standard library requires libc in order to interface
/// with the operating system on the given target.
pub fn targetRequiresLibC(target: *const std.Target) bool {
    if (target.requiresLibC()) return true;
    return switch (target.os.tag) {
        .linux => switch (target.cpu.arch) {
            // https://codeberg.org/ziglang/zig/issues/30943
            .hppa,
            .hppa64,
            => true,
            else => false,
        },
        .freebsd => true, // https://codeberg.org/ziglang/zig/issues/30981
        .netbsd => true, // https://codeberg.org/ziglang/zig/issues/30980
        .openbsd => true, // https://codeberg.org/ziglang/zig/issues/30982
        else => false,
    };
}

/// Returns whether the Zig standard library requires libc in order to interface
/// with the operating system on the current target.
pub fn requiresLibC() bool {
    return targetRequiresLibC(&builtin.target);
}

test {
    _ = linux;
    if (native_os == .uefi) _ = uefi;
    _ = wasi;
    _ = windows;
}