| 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,9 +4,6 @@ const c = @This(); |
| 4 | const maxInt = std.math.maxInt; | 4 | const maxInt = std.math.maxInt; |
| 5 | const assert = std.debug.assert; | 5 | const assert = std.debug.assert; |
| 6 | const page_size = std.mem.page_size; | 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 | const native_abi = builtin.abi; | 7 | const native_abi = builtin.abi; |
| 11 | const native_arch = builtin.cpu.arch; | 8 | const native_arch = builtin.cpu.arch; |
| 12 | const native_os = builtin.os.tag; | 9 | const native_os = builtin.os.tag; |
| ... | @@ -23,6 +20,14 @@ const dragonfly = @import("c/dragonfly.zig"); | ... | @@ -23,6 +20,14 @@ const dragonfly = @import("c/dragonfly.zig"); |
| 23 | const haiku = @import("c/haiku.zig"); | 20 | const haiku = @import("c/haiku.zig"); |
| 24 | const openbsd = @import("c/openbsd.zig"); | 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 | /// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address | 31 | /// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address |
| 27 | /// of the mach header in a Mach-O executable file type. It does not appear in | 32 | /// of the mach header in a Mach-O executable file type. It does not appear in |
| 28 | /// any file type other than a MH_EXECUTE file type. The type of the symbol is | 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,16 +1335,6 @@ pub const KERN = switch (native_os) { |
| 1330 | }, | 1335 | }, |
| 1331 | else => void, | 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 | pub const MADV = switch (native_os) { | 1338 | pub const MADV = switch (native_os) { |
| 1344 | .linux => linux.MADV, | 1339 | .linux => linux.MADV, |
| 1345 | .emscripten => emscripten.MADV, | 1340 | .emscripten => emscripten.MADV, |
| ... | @@ -9032,6 +9027,11 @@ pub const sf_hdtr = switch (native_os) { | ... | @@ -9032,6 +9027,11 @@ pub const sf_hdtr = switch (native_os) { |
| 9032 | else => void, | 9027 | else => void, |
| 9033 | }; | 9028 | }; |
| 9034 | 9029 | ||
| 9030 | pub const flock = switch (native_os) { | ||
| 9031 | .windows, .wasi => {}, | ||
| 9032 | else => private.flock, | ||
| 9033 | }; | ||
| 9034 | |||
| 9035 | pub extern "c" var environ: [*:null]?[*:0]u8; | 9035 | pub extern "c" var environ: [*:null]?[*:0]u8; |
| 9036 | 9036 | ||
| 9037 | pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE; | 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,7 +9116,6 @@ pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*u |
| 9116 | pub extern "c" fn tcgetattr(fd: fd_t, termios_p: *termios) c_int; | 9116 | pub extern "c" fn tcgetattr(fd: fd_t, termios_p: *termios) c_int; |
| 9117 | pub extern "c" fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) c_int; | 9117 | pub extern "c" fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) c_int; |
| 9118 | pub extern "c" fn fcntl(fd: fd_t, cmd: c_int, ...) c_int; | 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 | pub extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int; | 9119 | pub extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int; |
| 9121 | pub extern "c" fn uname(buf: *utsname) c_int; | 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,6 +9395,9 @@ pub extern "c" fn pthread_getthreadid_np() c_int; |
| 9396 | pub extern "c" fn pthread_set_name_np(thread: pthread_t, name: [*:0]const u8) void; | 9395 | pub extern "c" fn pthread_set_name_np(thread: pthread_t, name: [*:0]const u8) void; |
| 9397 | pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usize) void; | 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 | pub const AF_SUN = solaris.AF_SUN; | 9401 | pub const AF_SUN = solaris.AF_SUN; |
| 9400 | pub const AT_SUN = solaris.AT_SUN; | 9402 | pub const AT_SUN = solaris.AT_SUN; |
| 9401 | pub const FILE_EVENT = solaris.FILE_EVENT; | 9403 | pub const FILE_EVENT = solaris.FILE_EVENT; |
| ... | @@ -9675,6 +9677,7 @@ const private = struct { | ... | @@ -9675,6 +9677,7 @@ const private = struct { |
| 9675 | extern "c" fn clock_getres(clk_id: clockid_t, tp: *timespec) c_int; | 9677 | extern "c" fn clock_getres(clk_id: clockid_t, tp: *timespec) c_int; |
| 9676 | extern "c" fn clock_gettime(clk_id: clockid_t, tp: *timespec) c_int; | 9678 | extern "c" fn clock_gettime(clk_id: clockid_t, tp: *timespec) c_int; |
| 9677 | 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; | 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 | extern "c" fn fork() c_int; | 9681 | extern "c" fn fork() c_int; |
| 9679 | extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int; | 9682 | extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int; |
| 9680 | extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int; | 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,7 +881,7 @@ pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File |
| 881 | const fd = try posix.openatZ(self.fd, sub_path, os_flags, 0); | 881 | const fd = try posix.openatZ(self.fd, sub_path, os_flags, 0); |
| 882 | errdefer posix.close(fd); | 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 | // TODO: integrate async I/O | 885 | // TODO: integrate async I/O |
| 886 | const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0; | 886 | const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0; |
| 887 | try posix.flock(fd, switch (flags.lock) { | 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,7 +1029,7 @@ pub fn createFileZ(self: Dir, sub_path_c: [*:0]const u8, flags: File.CreateFlags |
| 1029 | const fd = try posix.openatZ(self.fd, sub_path_c, os_flags, flags.mode); | 1029 | const fd = try posix.openatZ(self.fd, sub_path_c, os_flags, flags.mode); |
| 1030 | errdefer posix.close(fd); | 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 | // TODO: integrate async I/O | 1033 | // TODO: integrate async I/O |
| 1034 | const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0; | 1034 | const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0; |
| 1035 | try posix.flock(fd, switch (flags.lock) { | 1035 | try posix.flock(fd, switch (flags.lock) { |
| ... | @@ -2702,3 +2702,4 @@ const Allocator = std.mem.Allocator; | ... | @@ -2702,3 +2702,4 @@ const Allocator = std.mem.Allocator; |
| 2702 | const assert = std.debug.assert; | 2702 | const assert = std.debug.assert; |
| 2703 | const windows = std.os.windows; | 2703 | const windows = std.os.windows; |
| 2704 | const native_os = builtin.os.tag; | 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,7 +69,6 @@ pub const Elf_Symndx = arch_bits.Elf_Symndx; |
| 69 | pub const F = arch_bits.F; | 69 | pub const F = arch_bits.F; |
| 70 | pub const Flock = arch_bits.Flock; | 70 | pub const Flock = arch_bits.Flock; |
| 71 | pub const HWCAP = arch_bits.HWCAP; | 71 | pub const HWCAP = arch_bits.HWCAP; |
| 72 | pub const LOCK = arch_bits.LOCK; | ||
| 73 | pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT; | 72 | pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT; |
| 74 | pub const REG = arch_bits.REG; | 73 | pub const REG = arch_bits.REG; |
| 75 | pub const SC = arch_bits.SC; | 74 | pub const SC = arch_bits.SC; |
lib/std/os/linux/arm-eabi.zig-7| ... | @@ -167,13 +167,6 @@ pub const F = struct { | ... | @@ -167,13 +167,6 @@ pub const F = struct { |
| 167 | pub const GETOWNER_UIDS = 17; | 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 | pub const VDSO = struct { | 170 | pub const VDSO = struct { |
| 178 | pub const CGT_SYM = "__vdso_clock_gettime"; | 171 | pub const CGT_SYM = "__vdso_clock_gettime"; |
| 179 | pub const CGT_VER = "LINUX_2.6"; | 172 | pub const CGT_VER = "LINUX_2.6"; |
lib/std/os/linux/arm64.zig-7| ... | @@ -149,13 +149,6 @@ pub const F = struct { | ... | @@ -149,13 +149,6 @@ pub const F = struct { |
| 149 | pub const GETOWNER_UIDS = 17; | 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 | pub const VDSO = struct { | 152 | pub const VDSO = struct { |
| 160 | pub const CGT_SYM = "__kernel_clock_gettime"; | 153 | pub const CGT_SYM = "__kernel_clock_gettime"; |
| 161 | pub const CGT_VER = "LINUX_2.6.39"; | 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,13 +239,6 @@ pub const F = struct { |
| 239 | pub const GETOWNER_UIDS = 17; | 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 | pub const MMAP2_UNIT = 4096; | 242 | pub const MMAP2_UNIT = 4096; |
| 250 | 243 | ||
| 251 | pub const VDSO = struct { | 244 | pub const VDSO = struct { |
lib/std/os/linux/mips64.zig-7| ... | @@ -224,13 +224,6 @@ pub const F = struct { | ... | @@ -224,13 +224,6 @@ pub const F = struct { |
| 224 | pub const GETOWNER_UIDS = 17; | 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 | pub const MMAP2_UNIT = 4096; | 227 | pub const MMAP2_UNIT = 4096; |
| 235 | 228 | ||
| 236 | pub const VDSO = struct { | 229 | pub const VDSO = struct { |
lib/std/os/linux/powerpc.zig-7| ... | @@ -168,13 +168,6 @@ pub const F = struct { | ... | @@ -168,13 +168,6 @@ pub const F = struct { |
| 168 | pub const UNLCK = 2; | 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 | pub const VDSO = struct { | 171 | pub const VDSO = struct { |
| 179 | pub const CGT_SYM = "__kernel_clock_gettime"; | 172 | pub const CGT_SYM = "__kernel_clock_gettime"; |
| 180 | pub const CGT_VER = "LINUX_2.6.15"; | 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,13 +168,6 @@ pub const F = struct { |
| 168 | pub const GETOWNER_UIDS = 17; | 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 | pub const VDSO = struct { | 171 | pub const VDSO = struct { |
| 179 | pub const CGT_SYM = "__kernel_clock_gettime"; | 172 | pub const CGT_SYM = "__kernel_clock_gettime"; |
| 180 | pub const CGT_VER = "LINUX_2.6.15"; | 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,13 +134,6 @@ pub const F = struct { |
| 134 | pub const GETOWNER_UIDS = 17; | 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 | pub const blksize_t = i32; | 137 | pub const blksize_t = i32; |
| 145 | pub const nlink_t = u32; | 138 | pub const nlink_t = u32; |
| 146 | pub const time_t = isize; | 139 | pub const time_t = isize; |
lib/std/os/linux/sparc64.zig-7| ... | @@ -218,13 +218,6 @@ pub const F = struct { | ... | @@ -218,13 +218,6 @@ pub const F = struct { |
| 218 | pub const GETOWNER_UIDS = 17; | 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 | pub const VDSO = struct { | 221 | pub const VDSO = struct { |
| 229 | pub const CGT_SYM = "__vdso_clock_gettime"; | 222 | pub const CGT_SYM = "__vdso_clock_gettime"; |
| 230 | pub const CGT_VER = "LINUX_2.6"; | 223 | pub const CGT_VER = "LINUX_2.6"; |
lib/std/os/linux/x86.zig-7| ... | @@ -181,13 +181,6 @@ pub const F = struct { | ... | @@ -181,13 +181,6 @@ pub const F = struct { |
| 181 | pub const UNLCK = 2; | 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 | pub const MMAP2_UNIT = 4096; | 184 | pub const MMAP2_UNIT = 4096; |
| 192 | 185 | ||
| 193 | pub const VDSO = struct { | 186 | pub const VDSO = struct { |
lib/std/os/linux/x86_64.zig-7| ... | @@ -195,13 +195,6 @@ pub const REG = struct { | ... | @@ -195,13 +195,6 @@ pub const REG = struct { |
| 195 | pub const CR2 = 22; | 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 | pub const Flock = extern struct { | 198 | pub const Flock = extern struct { |
| 206 | type: i16, | 199 | type: i16, |
| 207 | whence: i16, | 200 | whence: i16, |
lib/std/posix.zig+7-1| ... | @@ -70,7 +70,6 @@ pub const IOV_MAX = system.IOV_MAX; | ... | @@ -70,7 +70,6 @@ pub const IOV_MAX = system.IOV_MAX; |
| 70 | pub const IPPROTO = system.IPPROTO; | 70 | pub const IPPROTO = system.IPPROTO; |
| 71 | pub const KERN = system.KERN; | 71 | pub const KERN = system.KERN; |
| 72 | pub const Kevent = system.Kevent; | 72 | pub const Kevent = system.Kevent; |
| 73 | pub const LOCK = system.LOCK; | ||
| 74 | pub const MADV = system.MADV; | 73 | pub const MADV = system.MADV; |
| 75 | pub const MAP = system.MAP; | 74 | pub const MAP = system.MAP; |
| 76 | pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN; | 75 | pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN; |
| ... | @@ -202,6 +201,13 @@ pub const winsize = extern struct { | ... | @@ -202,6 +201,13 @@ pub const winsize = extern struct { |
| 202 | ypixel: u16, | 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 | pub const LOG = struct { | 211 | pub const LOG = struct { |
| 206 | /// system is unusable | 212 | /// system is unusable |
| 207 | pub const EMERG = 0; | 213 | pub const EMERG = 0; |