Skip to content

Commit 998460f

Browse files
committed
std.os: spring-cleanup and specify organization
- 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.
1 parent 4789cc0 commit 998460f

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

lib/std/os.zig

+23-20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
//! for UTF-16LE encoding.
77
//! * Where operating systems share APIs, e.g. POSIX, these thin wrappers provide
88
//! cross platform abstracting.
9+
//! - If operating systems API semantics can be unified without significant
10+
//! drawback, then only the most portable abstraction or wrapper is provided.
11+
//! This usually means, that there is no POSIX function, if Windows and POSIX
12+
//! API can be used with the same semantics.
913
//! * When there exists a corresponding libc function and linking libc, the libc
1014
//! implementation is used. Exceptions are made for known buggy areas of libc.
1115
//! On Linux libc can be side-stepped by using `std.os.linux` directly.
@@ -15,50 +19,49 @@
1519
//! in general EINTR is handled by trying again.
1620

1721
const root = @import("root");
18-
const std = @import("std.zig");
1922
const builtin = @import("builtin");
23+
const std = @import("std.zig");
24+
const dl = @import("dynamic_library.zig");
2025
const assert = std.debug.assert;
2126
const math = std.math;
2227
const mem = std.mem;
2328
const elf = std.elf;
2429
const fs = std.fs;
25-
const dl = @import("dynamic_library.zig");
2630
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
2731
const is_windows = builtin.os.tag == .windows;
2832
const Allocator = std.mem.Allocator;
2933
const Preopen = std.fs.wasi.Preopen;
3034
const PreopenList = std.fs.wasi.PreopenList;
3135

3236
pub const darwin = @import("os/darwin.zig");
37+
pub const linux = @import("os/linux.zig");
38+
pub const plan9 = @import("os/plan9.zig");
39+
pub const uefi = @import("os/uefi.zig");
40+
pub const wasi = @import("os/wasi.zig");
41+
pub const windows = @import("os/windows.zig");
42+
43+
pub const posix_spawn = @import("os/posix_spawn.zig"); // posix
44+
pub const ptrace = @import("os/ptrace.zig"); // posix
3345
pub const dragonfly = std.c;
3446
pub const freebsd = std.c;
3547
pub const haiku = std.c;
3648
pub const netbsd = std.c;
3749
pub const openbsd = std.c;
3850
pub const solaris = std.c;
39-
pub const linux = @import("os/linux.zig");
40-
pub const plan9 = @import("os/plan9.zig");
41-
pub const uefi = @import("os/uefi.zig");
42-
pub const wasi = @import("os/wasi.zig");
43-
pub const windows = @import("os/windows.zig");
44-
pub const posix_spawn = @import("os/posix_spawn.zig");
45-
pub const ptrace = @import("os/ptrace.zig");
4651

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

5156
test {
57+
_ = @import("os/test.zig");
5258
_ = darwin;
5359
_ = linux;
60+
_ = wasi;
61+
_ = windows;
5462
if (builtin.os.tag == .uefi) {
5563
_ = uefi;
5664
}
57-
_ = wasi;
58-
_ = windows;
59-
_ = posix_spawn;
60-
61-
_ = @import("os/test.zig");
6265
}
6366

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

@@ -98,10 +101,10 @@ pub const Kevent = system.Kevent;
98101
pub const LOCK = system.LOCK;
99102
pub const MADV = system.MADV;
100103
pub const MAP = system.MAP;
101-
pub const MSF = system.MSF;
102104
pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
103105
pub const MFD = system.MFD;
104106
pub const MMAP2_UNIT = system.MMAP2_UNIT;
107+
pub const MSF = system.MSF;
105108
pub const MSG = system.MSG;
106109
pub const NAME_MAX = system.NAME_MAX;
107110
pub const O = switch (builtin.os.tag) {
@@ -122,7 +125,6 @@ pub const RR = system.RR;
122125
pub const S = system.S;
123126
pub const SA = system.SA;
124127
pub const SC = system.SC;
125-
pub const _SC = system._SC;
126128
pub const SEEK = system.SEEK;
127129
pub const SHUT = system.SHUT;
128130
pub const SIG = system.SIG;
@@ -136,10 +138,11 @@ pub const STDOUT_FILENO = system.STDOUT_FILENO;
136138
pub const SYS = system.SYS;
137139
pub const Sigaction = system.Sigaction;
138140
pub const Stat = system.Stat;
139-
pub const TCSA = system.TCSA;
140141
pub const TCP = system.TCP;
142+
pub const TCSA = system.TCSA;
141143
pub const VDSO = system.VDSO;
142144
pub const W = system.W;
145+
pub const _SC = system._SC;
143146
pub const addrinfo = system.addrinfo;
144147
pub const blkcnt_t = system.blkcnt_t;
145148
pub const blksize_t = system.blksize_t;
@@ -151,6 +154,7 @@ pub const empty_sigset = system.empty_sigset;
151154
pub const fd_t = system.fd_t;
152155
pub const fdflags_t = system.fdflags_t;
153156
pub const fdstat_t = system.fdstat_t;
157+
pub const file_obj = system.file_obj;
154158
pub const gid_t = system.gid_t;
155159
pub const ifreq = system.ifreq;
156160
pub const ino_t = system.ino_t;
@@ -165,10 +169,9 @@ pub const off_t = system.off_t;
165169
pub const oflags_t = system.oflags_t;
166170
pub const pid_t = system.pid_t;
167171
pub const pollfd = system.pollfd;
168-
pub const port_t = system.port_t;
169172
pub const port_event = system.port_event;
170173
pub const port_notify = system.port_notify;
171-
pub const file_obj = system.file_obj;
174+
pub const port_t = system.port_t;
172175
pub const rights_t = system.rights_t;
173176
pub const rlim_t = system.rlim_t;
174177
pub const rlimit = system.rlimit;

0 commit comments

Comments
 (0)