Skip to content

Commit

Permalink
std.os: spring-cleanup and specify organization
Browse files Browse the repository at this point in the history
- Alphabetically sort things, where reasonable.
- Document, that **only** non-portable posix things belong into posix.zig
  * If there is a portable abstraction, do not offer one in posix.zig
  * Reason: Prevent useless abstractions and needless strong coupling.
- Move posix functions into posix.zig
- Move wasi functions into wasi.zig

Closes ziglang#6600.
  • Loading branch information
matu3ba committed Mar 3, 2023
1 parent 4789cc0 commit 998460f
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions lib/std/os.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
//! for UTF-16LE encoding.
//! * Where operating systems share APIs, e.g. POSIX, these thin wrappers provide
//! cross platform abstracting.
//! - If operating systems API semantics can be unified without significant
//! drawback, then only the most portable abstraction or wrapper is provided.
//! This usually means, that there is no POSIX function, if Windows and POSIX
//! API can be used with the same semantics.
//! * When there exists a corresponding libc function and linking libc, the libc
//! implementation is used. Exceptions are made for known buggy areas of libc.
//! On Linux libc can be side-stepped by using `std.os.linux` directly.
Expand All @@ -15,50 +19,49 @@
//! in general EINTR is handled by trying again.

const root = @import("root");
const std = @import("std.zig");
const builtin = @import("builtin");
const std = @import("std.zig");
const dl = @import("dynamic_library.zig");
const assert = std.debug.assert;
const math = std.math;
const mem = std.mem;
const elf = std.elf;
const fs = std.fs;
const dl = @import("dynamic_library.zig");
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
const is_windows = builtin.os.tag == .windows;
const Allocator = std.mem.Allocator;
const Preopen = std.fs.wasi.Preopen;
const PreopenList = std.fs.wasi.PreopenList;

pub const darwin = @import("os/darwin.zig");
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 windows = @import("os/windows.zig");

pub const posix_spawn = @import("os/posix_spawn.zig"); // posix
pub const ptrace = @import("os/ptrace.zig"); // posix
pub const dragonfly = std.c;
pub const freebsd = std.c;
pub const haiku = std.c;
pub const netbsd = std.c;
pub const openbsd = std.c;
pub const solaris = std.c;
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 windows = @import("os/windows.zig");
pub const posix_spawn = @import("os/posix_spawn.zig");
pub const ptrace = @import("os/ptrace.zig");

comptime {
assert(@import("std") == std); // std lib tests require --zig-lib-dir
}

test {
_ = @import("os/test.zig");
_ = darwin;
_ = linux;
_ = wasi;
_ = windows;
if (builtin.os.tag == .uefi) {
_ = uefi;
}
_ = wasi;
_ = windows;
_ = posix_spawn;

_ = @import("os/test.zig");
}

/// Applications can override the `system` API layer in their root source file.
Expand All @@ -70,8 +73,8 @@ else if (builtin.link_libc or is_windows)
std.c
else switch (builtin.os.tag) {
.linux => linux,
.wasi => wasi,
.uefi => uefi,
.wasi => wasi,
else => struct {},
};

Expand All @@ -98,10 +101,10 @@ pub const Kevent = system.Kevent;
pub const LOCK = system.LOCK;
pub const MADV = system.MADV;
pub const MAP = system.MAP;
pub const MSF = system.MSF;
pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
pub const MFD = system.MFD;
pub const MMAP2_UNIT = system.MMAP2_UNIT;
pub const MSF = system.MSF;
pub const MSG = system.MSG;
pub const NAME_MAX = system.NAME_MAX;
pub const O = switch (builtin.os.tag) {
Expand All @@ -122,7 +125,6 @@ pub const RR = system.RR;
pub const S = system.S;
pub const SA = system.SA;
pub const SC = system.SC;
pub const _SC = system._SC;
pub const SEEK = system.SEEK;
pub const SHUT = system.SHUT;
pub const SIG = system.SIG;
Expand All @@ -136,10 +138,11 @@ pub const STDOUT_FILENO = system.STDOUT_FILENO;
pub const SYS = system.SYS;
pub const Sigaction = system.Sigaction;
pub const Stat = system.Stat;
pub const TCSA = system.TCSA;
pub const TCP = system.TCP;
pub const TCSA = system.TCSA;
pub const VDSO = system.VDSO;
pub const W = system.W;
pub const _SC = system._SC;
pub const addrinfo = system.addrinfo;
pub const blkcnt_t = system.blkcnt_t;
pub const blksize_t = system.blksize_t;
Expand All @@ -151,6 +154,7 @@ pub const empty_sigset = system.empty_sigset;
pub const fd_t = system.fd_t;
pub const fdflags_t = system.fdflags_t;
pub const fdstat_t = system.fdstat_t;
pub const file_obj = system.file_obj;
pub const gid_t = system.gid_t;
pub const ifreq = system.ifreq;
pub const ino_t = system.ino_t;
Expand All @@ -165,10 +169,9 @@ pub const off_t = system.off_t;
pub const oflags_t = system.oflags_t;
pub const pid_t = system.pid_t;
pub const pollfd = system.pollfd;
pub const port_t = system.port_t;
pub const port_event = system.port_event;
pub const port_notify = system.port_notify;
pub const file_obj = system.file_obj;
pub const port_t = system.port_t;
pub const rights_t = system.rights_t;
pub const rlim_t = system.rlim_t;
pub const rlimit = system.rlimit;
Expand Down

0 comments on commit 998460f

Please sign in to comment.