| author | |
| committer | |
| log | 01337e209366bf7eed9a8aca0b80be0e8c9c04f5 |
| tree | 82d84ded03cf82eca3662acc1b16b100964937b4 |
| parent | 7157189143e83dedb29d25553d2841ff2576dc5c |
* common symbols are now public from std.c even if they live in
std.posix
* LOCK is now one of the common symbols since it is the same on 100% of
operating systems.
* flock is now void value on wasi and windows
* std.fs.Dir now uses flock being void as feature detection, avoiding
trying to call it on wasi and windows14 files changed, 27 insertions(+), 88 deletions(-)
lib/std/c.zig+17-14| ... | ... | @@ -4,9 +4,6 @@ const c = @This(); |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | const assert = std.debug.assert; |
| 6 | 6 | const page_size = std.mem.page_size; |
| 7 | const iovec = std.posix.iovec; | |
| 8 | const iovec_const = std.posix.iovec_const; | |
| 9 | const winsize = std.posix.winsize; | |
| 10 | 7 | const native_abi = builtin.abi; |
| 11 | 8 | const native_arch = builtin.cpu.arch; |
| 12 | 9 | const native_os = builtin.os.tag; |
| ... | ... | @@ -23,6 +20,14 @@ const dragonfly = @import("c/dragonfly.zig"); |
| 23 | 20 | const haiku = @import("c/haiku.zig"); |
| 24 | 21 | const openbsd = @import("c/openbsd.zig"); |
| 25 | 22 | |
| 23 | // These constants are shared among all operating systems even when not linking | |
| 24 | // libc. | |
| 25 | ||
| 26 | pub const iovec = std.posix.iovec; | |
| 27 | pub const iovec_const = std.posix.iovec_const; | |
| 28 | pub const LOCK = std.posix.LOCK; | |
| 29 | pub const winsize = std.posix.winsize; | |
| 30 | ||
| 26 | 31 | /// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address |
| 27 | 32 | /// of the mach header in a Mach-O executable file type. It does not appear in |
| 28 | 33 | /// any file type other than a MH_EXECUTE file type. The type of the symbol is |
| ... | ... | @@ -1330,16 +1335,6 @@ pub const KERN = switch (native_os) { |
| 1330 | 1335 | }, |
| 1331 | 1336 | else => void, |
| 1332 | 1337 | }; |
| 1333 | pub const LOCK = switch (native_os) { | |
| 1334 | .linux => linux.LOCK, | |
| 1335 | .emscripten => emscripten.LOCK, | |
| 1336 | else => struct { | |
| 1337 | pub const SH = 1; | |
| 1338 | pub const EX = 2; | |
| 1339 | pub const NB = 4; | |
| 1340 | pub const UN = 8; | |
| 1341 | }, | |
| 1342 | }; | |
| 1343 | 1338 | pub const MADV = switch (native_os) { |
| 1344 | 1339 | .linux => linux.MADV, |
| 1345 | 1340 | .emscripten => emscripten.MADV, |
| ... | ... | @@ -9032,6 +9027,11 @@ pub const sf_hdtr = switch (native_os) { |
| 9032 | 9027 | else => void, |
| 9033 | 9028 | }; |
| 9034 | 9029 | |
| 9030 | pub const flock = switch (native_os) { | |
| 9031 | .windows, .wasi => {}, | |
| 9032 | else => private.flock, | |
| 9033 | }; | |
| 9034 | ||
| 9035 | 9035 | pub extern "c" var environ: [*:null]?[*:0]u8; |
| 9036 | 9036 | |
| 9037 | 9037 | pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE; |
| ... | ... | @@ -9116,7 +9116,6 @@ pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*u |
| 9116 | 9116 | pub extern "c" fn tcgetattr(fd: fd_t, termios_p: *termios) c_int; |
| 9117 | 9117 | pub extern "c" fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) c_int; |
| 9118 | 9118 | pub extern "c" fn fcntl(fd: fd_t, cmd: c_int, ...) c_int; |
| 9119 | pub extern "c" fn flock(fd: fd_t, operation: c_int) c_int; | |
| 9120 | 9119 | pub extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int; |
| 9121 | 9120 | pub extern "c" fn uname(buf: *utsname) c_int; |
| 9122 | 9121 | |
| ... | ... | @@ -9396,6 +9395,9 @@ pub extern "c" fn pthread_getthreadid_np() c_int; |
| 9396 | 9395 | pub extern "c" fn pthread_set_name_np(thread: pthread_t, name: [*:0]const u8) void; |
| 9397 | 9396 | pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usize) void; |
| 9398 | 9397 | |
| 9398 | // OS-specific bits. These are protected from being used on the wrong OS by | |
| 9399 | // comptime assertions inside each OS-specific file. | |
| 9400 | ||
| 9399 | 9401 | pub const AF_SUN = solaris.AF_SUN; |
| 9400 | 9402 | pub const AT_SUN = solaris.AT_SUN; |
| 9401 | 9403 | pub const FILE_EVENT = solaris.FILE_EVENT; |
| ... | ... | @@ -9675,6 +9677,7 @@ const private = struct { |
| 9675 | 9677 | extern "c" fn clock_getres(clk_id: clockid_t, tp: *timespec) c_int; |
| 9676 | 9678 | extern "c" fn clock_gettime(clk_id: clockid_t, tp: *timespec) c_int; |
| 9677 | 9679 | extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: c_uint) isize; |
| 9680 | extern "c" fn flock(fd: fd_t, operation: c_int) c_int; | |
| 9678 | 9681 | extern "c" fn fork() c_int; |
| 9679 | 9682 | extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int; |
| 9680 | 9683 | extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int; |
lib/std/fs/Dir.zig+3-2| ... | ... | @@ -881,7 +881,7 @@ pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File |
| 881 | 881 | const fd = try posix.openatZ(self.fd, sub_path, os_flags, 0); |
| 882 | 882 | errdefer posix.close(fd); |
| 883 | 883 | |
| 884 | if (!has_flock_open_flags and flags.lock != .none) { | |
| 884 | if (have_flock and !has_flock_open_flags and flags.lock != .none) { | |
| 885 | 885 | // TODO: integrate async I/O |
| 886 | 886 | const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0; |
| 887 | 887 | try posix.flock(fd, switch (flags.lock) { |
| ... | ... | @@ -1029,7 +1029,7 @@ pub fn createFileZ(self: Dir, sub_path_c: [*:0]const u8, flags: File.CreateFlags |
| 1029 | 1029 | const fd = try posix.openatZ(self.fd, sub_path_c, os_flags, flags.mode); |
| 1030 | 1030 | errdefer posix.close(fd); |
| 1031 | 1031 | |
| 1032 | if (!has_flock_open_flags and flags.lock != .none) { | |
| 1032 | if (have_flock and !has_flock_open_flags and flags.lock != .none) { | |
| 1033 | 1033 | // TODO: integrate async I/O |
| 1034 | 1034 | const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0; |
| 1035 | 1035 | try posix.flock(fd, switch (flags.lock) { |
| ... | ... | @@ -2702,3 +2702,4 @@ const Allocator = std.mem.Allocator; |
| 2702 | 2702 | const assert = std.debug.assert; |
| 2703 | 2703 | const windows = std.os.windows; |
| 2704 | 2704 | const native_os = builtin.os.tag; |
| 2705 | const have_flock = @TypeOf(posix.system.flock) != void; |
lib/std/os/linux.zig-1| ... | ... | @@ -69,7 +69,6 @@ pub const Elf_Symndx = arch_bits.Elf_Symndx; |
| 69 | 69 | pub const F = arch_bits.F; |
| 70 | 70 | pub const Flock = arch_bits.Flock; |
| 71 | 71 | pub const HWCAP = arch_bits.HWCAP; |
| 72 | pub const LOCK = arch_bits.LOCK; | |
| 73 | 72 | pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT; |
| 74 | 73 | pub const REG = arch_bits.REG; |
| 75 | 74 | pub const SC = arch_bits.SC; |
lib/std/os/linux/arm-eabi.zig-7| ... | ... | @@ -167,13 +167,6 @@ pub const F = struct { |
| 167 | 167 | pub const GETOWNER_UIDS = 17; |
| 168 | 168 | }; |
| 169 | 169 | |
| 170 | pub const LOCK = struct { | |
| 171 | pub const SH = 1; | |
| 172 | pub const EX = 2; | |
| 173 | pub const UN = 8; | |
| 174 | pub const NB = 4; | |
| 175 | }; | |
| 176 | ||
| 177 | 170 | pub const VDSO = struct { |
| 178 | 171 | pub const CGT_SYM = "__vdso_clock_gettime"; |
| 179 | 172 | pub const CGT_VER = "LINUX_2.6"; |
lib/std/os/linux/arm64.zig-7| ... | ... | @@ -149,13 +149,6 @@ pub const F = struct { |
| 149 | 149 | pub const GETOWNER_UIDS = 17; |
| 150 | 150 | }; |
| 151 | 151 | |
| 152 | pub const LOCK = struct { | |
| 153 | pub const SH = 1; | |
| 154 | pub const EX = 2; | |
| 155 | pub const UN = 8; | |
| 156 | pub const NB = 4; | |
| 157 | }; | |
| 158 | ||
| 159 | 152 | pub const VDSO = struct { |
| 160 | 153 | pub const CGT_SYM = "__kernel_clock_gettime"; |
| 161 | 154 | pub const CGT_VER = "LINUX_2.6.39"; |
lib/std/os/linux/mips.zig-7| ... | ... | @@ -239,13 +239,6 @@ pub const F = struct { |
| 239 | 239 | pub const GETOWNER_UIDS = 17; |
| 240 | 240 | }; |
| 241 | 241 | |
| 242 | pub const LOCK = struct { | |
| 243 | pub const SH = 1; | |
| 244 | pub const EX = 2; | |
| 245 | pub const UN = 8; | |
| 246 | pub const NB = 4; | |
| 247 | }; | |
| 248 | ||
| 249 | 242 | pub const MMAP2_UNIT = 4096; |
| 250 | 243 | |
| 251 | 244 | pub const VDSO = struct { |
lib/std/os/linux/mips64.zig-7| ... | ... | @@ -224,13 +224,6 @@ pub const F = struct { |
| 224 | 224 | pub const GETOWNER_UIDS = 17; |
| 225 | 225 | }; |
| 226 | 226 | |
| 227 | pub const LOCK = struct { | |
| 228 | pub const SH = 1; | |
| 229 | pub const EX = 2; | |
| 230 | pub const UN = 8; | |
| 231 | pub const NB = 4; | |
| 232 | }; | |
| 233 | ||
| 234 | 227 | pub const MMAP2_UNIT = 4096; |
| 235 | 228 | |
| 236 | 229 | pub const VDSO = struct { |
lib/std/os/linux/powerpc.zig-7| ... | ... | @@ -168,13 +168,6 @@ pub const F = struct { |
| 168 | 168 | pub const UNLCK = 2; |
| 169 | 169 | }; |
| 170 | 170 | |
| 171 | pub const LOCK = struct { | |
| 172 | pub const SH = 1; | |
| 173 | pub const EX = 2; | |
| 174 | pub const UN = 8; | |
| 175 | pub const NB = 4; | |
| 176 | }; | |
| 177 | ||
| 178 | 171 | pub const VDSO = struct { |
| 179 | 172 | pub const CGT_SYM = "__kernel_clock_gettime"; |
| 180 | 173 | pub const CGT_VER = "LINUX_2.6.15"; |
lib/std/os/linux/powerpc64.zig-7| ... | ... | @@ -168,13 +168,6 @@ pub const F = struct { |
| 168 | 168 | pub const GETOWNER_UIDS = 17; |
| 169 | 169 | }; |
| 170 | 170 | |
| 171 | pub const LOCK = struct { | |
| 172 | pub const SH = 1; | |
| 173 | pub const EX = 2; | |
| 174 | pub const UN = 8; | |
| 175 | pub const NB = 4; | |
| 176 | }; | |
| 177 | ||
| 178 | 171 | pub const VDSO = struct { |
| 179 | 172 | pub const CGT_SYM = "__kernel_clock_gettime"; |
| 180 | 173 | pub const CGT_VER = "LINUX_2.6.15"; |
lib/std/os/linux/riscv64.zig-7| ... | ... | @@ -134,13 +134,6 @@ pub const F = struct { |
| 134 | 134 | pub const GETOWNER_UIDS = 17; |
| 135 | 135 | }; |
| 136 | 136 | |
| 137 | pub const LOCK = struct { | |
| 138 | pub const SH = 1; | |
| 139 | pub const EX = 2; | |
| 140 | pub const UN = 8; | |
| 141 | pub const NB = 4; | |
| 142 | }; | |
| 143 | ||
| 144 | 137 | pub const blksize_t = i32; |
| 145 | 138 | pub const nlink_t = u32; |
| 146 | 139 | pub const time_t = isize; |
lib/std/os/linux/sparc64.zig-7| ... | ... | @@ -218,13 +218,6 @@ pub const F = struct { |
| 218 | 218 | pub const GETOWNER_UIDS = 17; |
| 219 | 219 | }; |
| 220 | 220 | |
| 221 | pub const LOCK = struct { | |
| 222 | pub const SH = 1; | |
| 223 | pub const EX = 2; | |
| 224 | pub const NB = 4; | |
| 225 | pub const UN = 8; | |
| 226 | }; | |
| 227 | ||
| 228 | 221 | pub const VDSO = struct { |
| 229 | 222 | pub const CGT_SYM = "__vdso_clock_gettime"; |
| 230 | 223 | pub const CGT_VER = "LINUX_2.6"; |
lib/std/os/linux/x86.zig-7| ... | ... | @@ -181,13 +181,6 @@ pub const F = struct { |
| 181 | 181 | pub const UNLCK = 2; |
| 182 | 182 | }; |
| 183 | 183 | |
| 184 | pub const LOCK = struct { | |
| 185 | pub const SH = 1; | |
| 186 | pub const EX = 2; | |
| 187 | pub const NB = 4; | |
| 188 | pub const UN = 8; | |
| 189 | }; | |
| 190 | ||
| 191 | 184 | pub const MMAP2_UNIT = 4096; |
| 192 | 185 | |
| 193 | 186 | pub const VDSO = struct { |
lib/std/os/linux/x86_64.zig-7| ... | ... | @@ -195,13 +195,6 @@ pub const REG = struct { |
| 195 | 195 | pub const CR2 = 22; |
| 196 | 196 | }; |
| 197 | 197 | |
| 198 | pub const LOCK = struct { | |
| 199 | pub const SH = 1; | |
| 200 | pub const EX = 2; | |
| 201 | pub const NB = 4; | |
| 202 | pub const UN = 8; | |
| 203 | }; | |
| 204 | ||
| 205 | 198 | pub const Flock = extern struct { |
| 206 | 199 | type: i16, |
| 207 | 200 | whence: i16, |
lib/std/posix.zig+7-1| ... | ... | @@ -70,7 +70,6 @@ pub const IOV_MAX = system.IOV_MAX; |
| 70 | 70 | pub const IPPROTO = system.IPPROTO; |
| 71 | 71 | pub const KERN = system.KERN; |
| 72 | 72 | pub const Kevent = system.Kevent; |
| 73 | pub const LOCK = system.LOCK; | |
| 74 | 73 | pub const MADV = system.MADV; |
| 75 | 74 | pub const MAP = system.MAP; |
| 76 | 75 | pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN; |
| ... | ... | @@ -202,6 +201,13 @@ pub const winsize = extern struct { |
| 202 | 201 | ypixel: u16, |
| 203 | 202 | }; |
| 204 | 203 | |
| 204 | pub const LOCK = struct { | |
| 205 | pub const SH = 1; | |
| 206 | pub const EX = 2; | |
| 207 | pub const NB = 4; | |
| 208 | pub const UN = 8; | |
| 209 | }; | |
| 210 | ||
| 205 | 211 | pub const LOG = struct { |
| 206 | 212 | /// system is unusable |
| 207 | 213 | pub const EMERG = 0; |