mirror of
https://github.com/ziglang/zig.git
synced 2025-01-10 12:11:33 +00:00
parent
df7aa9a4f0
commit
67726e36b0
@ -621,9 +621,9 @@ set(ZIG_STD_FILES
|
||||
"os/time.zig"
|
||||
"os/uefi.zig"
|
||||
"os/wasi.zig"
|
||||
"os/wasi/core.zig"
|
||||
"os/windows.zig"
|
||||
"os/windows/advapi32.zig"
|
||||
"os/windows/errno.zig"
|
||||
"os/windows/error.zig"
|
||||
"os/windows/kernel32.zig"
|
||||
"os/windows/ntdll.zig"
|
||||
|
@ -195,7 +195,7 @@ const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
// If this program is run without stdout attached, exit with an error.
|
||||
const stdout_file = try std.io.getStdOut();
|
||||
const stdout_file = try std.os.File.stdout();
|
||||
// If this program encounters pipe failure when printing to stdout, exit
|
||||
// with an error.
|
||||
try stdout_file.write("Hello, world!\n");
|
||||
|
@ -1,9 +1,5 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
// If this program is run without stdout attached, exit with an error.
|
||||
const stdout_file = try std.io.getStdOut();
|
||||
// If this program encounters pipe failure when printing to stdout, exit
|
||||
// with an error.
|
||||
try stdout_file.write("Hello, world!\n");
|
||||
pub fn main() void {
|
||||
std.debug.warn("Hello, world!\n");
|
||||
}
|
||||
|
@ -2,13 +2,9 @@ const c = @cImport({
|
||||
// See https://github.com/ziglang/zig/issues/515
|
||||
@cDefine("_NO_CRT_STDIO_INLINE", "1");
|
||||
@cInclude("stdio.h");
|
||||
@cInclude("string.h");
|
||||
});
|
||||
|
||||
const msg = c"Hello, world!\n";
|
||||
|
||||
export fn main(argc: c_int, argv: **u8) c_int {
|
||||
if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1;
|
||||
|
||||
export fn main(argc: c_int, argv: [*]?[*]u8) c_int {
|
||||
c.fprintf(c.stderr, c"Hello, world!\n");
|
||||
return 0;
|
||||
}
|
||||
|
22
std/c.zig
22
std/c.zig
@ -1,15 +1,24 @@
|
||||
const builtin = @import("builtin");
|
||||
const Os = builtin.Os;
|
||||
|
||||
pub const is_the_target = builtin.link_libc;
|
||||
|
||||
pub use switch (builtin.os) {
|
||||
Os.linux => @import("c/linux.zig"),
|
||||
Os.windows => @import("c/windows.zig"),
|
||||
Os.macosx, Os.ios => @import("c/darwin.zig"),
|
||||
Os.freebsd => @import("c/freebsd.zig"),
|
||||
Os.netbsd => @import("c/netbsd.zig"),
|
||||
.linux => @import("c/linux.zig"),
|
||||
.windows => @import("c/windows.zig"),
|
||||
.macosx, .ios, .tvos, .watchos => @import("c/darwin.zig"),
|
||||
.freebsd => @import("c/freebsd.zig"),
|
||||
.netbsd => @import("c/netbsd.zig"),
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
pub fn getErrno(rc: var) u12 {
|
||||
if (rc == -1) {
|
||||
return @intCast(u12, _errno().*);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265 on this whole file
|
||||
|
||||
pub const FILE = @OpaqueType();
|
||||
@ -56,6 +65,7 @@ pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
|
||||
pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
|
||||
pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
|
||||
pub extern "c" fn rmdir(path: [*]const u8) c_int;
|
||||
pub extern "c" fn getenv(name: [*]const u8) ?[*]u8;
|
||||
|
||||
pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?*c_void;
|
||||
pub extern "c" fn malloc(usize) ?*c_void;
|
||||
|
@ -89,14 +89,7 @@ pub const Server = struct {
|
||||
},
|
||||
};
|
||||
} else |err| switch (err) {
|
||||
error.ProcessFdQuotaExceeded => {
|
||||
errdefer os.emfile_promise_queue.remove(&self.waiting_for_emfile_node);
|
||||
suspend {
|
||||
self.waiting_for_emfile_node = PromiseNode.init(@handle());
|
||||
os.emfile_promise_queue.append(&self.waiting_for_emfile_node);
|
||||
}
|
||||
continue;
|
||||
},
|
||||
error.ProcessFdQuotaExceeded => @panic("TODO handle this error"),
|
||||
error.ConnectionAborted => continue,
|
||||
|
||||
error.FileDescriptorNotASocket => unreachable,
|
||||
|
17
std/io.zig
17
std/io.zig
@ -18,23 +18,6 @@ const testing = std.testing;
|
||||
const is_posix = builtin.os != builtin.Os.windows;
|
||||
const is_windows = builtin.os == builtin.Os.windows;
|
||||
|
||||
const GetStdIoErrs = os.WindowsGetStdHandleErrs;
|
||||
|
||||
pub fn getStdErr() GetStdIoErrs!File {
|
||||
const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_ERROR_HANDLE) else if (is_posix) os.posix.STDERR_FILENO else unreachable;
|
||||
return File.openHandle(handle);
|
||||
}
|
||||
|
||||
pub fn getStdOut() GetStdIoErrs!File {
|
||||
const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_OUTPUT_HANDLE) else if (is_posix) os.posix.STDOUT_FILENO else unreachable;
|
||||
return File.openHandle(handle);
|
||||
}
|
||||
|
||||
pub fn getStdIn() GetStdIoErrs!File {
|
||||
const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_INPUT_HANDLE) else if (is_posix) os.posix.STDIN_FILENO else unreachable;
|
||||
return File.openHandle(handle);
|
||||
}
|
||||
|
||||
pub const SeekableStream = @import("io/seekable_stream.zig").SeekableStream;
|
||||
pub const SliceSeekableInStream = @import("io/seekable_stream.zig").SliceSeekableInStream;
|
||||
pub const COutStream = @import("io/c_out_stream.zig").COutStream;
|
||||
|
1883
std/os.zig
1883
std/os.zig
File diff suppressed because it is too large
Load Diff
@ -415,7 +415,7 @@ pub const ChildProcess = struct {
|
||||
os.posix_setreuid(uid, uid) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||
}
|
||||
|
||||
os.posixExecve(self.argv, env_map, self.allocator) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||
os.posix.execve(self.allocator, self.argv, env_map) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||
}
|
||||
|
||||
// we are the parent
|
||||
|
@ -1,9 +1,16 @@
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("../std.zig");
|
||||
const c = std.c;
|
||||
const assert = std.debug.assert;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub use @import("darwin/errno.zig");
|
||||
pub const is_the_target = switch (builtin.os) {
|
||||
.ios, .macosx, .watchos, .tvos => true,
|
||||
else => false,
|
||||
};
|
||||
|
||||
pub const errno_codes = @import("darwin/errno.zig");
|
||||
pub use errno_codes;
|
||||
|
||||
pub const PATH_MAX = 1024;
|
||||
|
||||
|
@ -223,9 +223,18 @@ pub const File = struct {
|
||||
os.close(self.handle);
|
||||
}
|
||||
|
||||
/// Calls `os.isTty` on `self.handle`.
|
||||
/// Test whether the file refers to a terminal.
|
||||
/// See also `supportsAnsiEscapeCodes`.
|
||||
pub fn isTty(self: File) bool {
|
||||
return os.isTty(self.handle);
|
||||
return posix.isatty(self.handle);
|
||||
}
|
||||
|
||||
/// Test whether ANSI escape codes will be treated as such.
|
||||
pub fn supportsAnsiEscapeCodes(self: File) bool {
|
||||
if (windows.is_the_target) {
|
||||
return posix.isCygwinPty(self.handle);
|
||||
}
|
||||
return self.isTty();
|
||||
}
|
||||
|
||||
pub const SeekError = error{
|
||||
@ -389,43 +398,16 @@ pub const File = struct {
|
||||
}
|
||||
}
|
||||
|
||||
pub const ReadError = os.WindowsReadError || os.PosixReadError;
|
||||
pub const ReadError = posix.ReadError;
|
||||
|
||||
pub fn read(self: File, buffer: []u8) ReadError!usize {
|
||||
if (is_posix) {
|
||||
return os.posixRead(self.handle, buffer);
|
||||
} else if (is_windows) {
|
||||
var index: usize = 0;
|
||||
while (index < buffer.len) {
|
||||
const want_read_count = @intCast(windows.DWORD, math.min(windows.DWORD(maxInt(windows.DWORD)), buffer.len - index));
|
||||
var amt_read: windows.DWORD = undefined;
|
||||
if (windows.ReadFile(self.handle, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {
|
||||
const err = windows.GetLastError();
|
||||
return switch (err) {
|
||||
windows.ERROR.OPERATION_ABORTED => continue,
|
||||
windows.ERROR.BROKEN_PIPE => return index,
|
||||
else => os.unexpectedErrorWindows(err),
|
||||
};
|
||||
}
|
||||
if (amt_read == 0) return index;
|
||||
index += amt_read;
|
||||
}
|
||||
return index;
|
||||
} else {
|
||||
@compileError("Unsupported OS");
|
||||
}
|
||||
return posix.read(self.handle, buffer);
|
||||
}
|
||||
|
||||
pub const WriteError = os.WindowsWriteError || os.PosixWriteError;
|
||||
pub const WriteError = posix.WriteError;
|
||||
|
||||
pub fn write(self: File, bytes: []const u8) WriteError!void {
|
||||
if (is_posix) {
|
||||
try os.posixWrite(self.handle, bytes);
|
||||
} else if (is_windows) {
|
||||
try os.windowsWrite(self.handle, bytes);
|
||||
} else {
|
||||
@compileError("Unsupported OS");
|
||||
}
|
||||
return posix.write(self.handle, bytes);
|
||||
}
|
||||
|
||||
pub fn inStream(file: File) InStream {
|
||||
@ -509,4 +491,19 @@ pub const File = struct {
|
||||
return self.file.getPos();
|
||||
}
|
||||
};
|
||||
|
||||
pub fn stdout() !File {
|
||||
const handle = try posix.GetStdHandle(posix.STD_OUTPUT_HANDLE);
|
||||
return openHandle(handle);
|
||||
}
|
||||
|
||||
pub fn stderr() !File {
|
||||
const handle = try posix.GetStdHandle(posix.STD_ERROR_HANDLE);
|
||||
return openHandle(handle);
|
||||
}
|
||||
|
||||
pub fn stdin() !File {
|
||||
const handle = try posix.GetStdHandle(posix.STD_INPUT_HANDLE);
|
||||
return openHandle(handle);
|
||||
}
|
||||
};
|
||||
|
@ -12,7 +12,12 @@ pub use switch (builtin.arch) {
|
||||
builtin.Arch.aarch64 => @import("linux/arm64.zig"),
|
||||
else => @compileError("unsupported arch"),
|
||||
};
|
||||
pub use @import("linux/errno.zig");
|
||||
pub const is_the_target = builtin.os == .linux;
|
||||
pub const errno_codes = @import("linux/errno.zig");
|
||||
pub use errno_codes;
|
||||
|
||||
/// See `std.os.posix.getauxval`.
|
||||
pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
|
||||
|
||||
pub const PATH_MAX = 4096;
|
||||
pub const IOV_MAX = 1024;
|
||||
@ -697,9 +702,9 @@ pub const winsize = extern struct {
|
||||
};
|
||||
|
||||
/// Get the errno from a syscall return value, or 0 for no error.
|
||||
pub fn getErrno(r: usize) usize {
|
||||
pub fn getErrno(r: usize) u12 {
|
||||
const signed_r = @bitCast(isize, r);
|
||||
return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
|
||||
return if (signed_r > -4096 and signed_r < 0) @intCast(u12, -signed_r) else 0;
|
||||
}
|
||||
|
||||
pub fn dup2(old: i32, new: i32) usize {
|
||||
@ -766,11 +771,6 @@ pub fn inotify_rm_watch(fd: i32, wd: i32) usize {
|
||||
return syscall2(SYS_inotify_rm_watch, @bitCast(usize, isize(fd)), @bitCast(usize, isize(wd)));
|
||||
}
|
||||
|
||||
pub fn isatty(fd: i32) bool {
|
||||
var wsz: winsize = undefined;
|
||||
return syscall3(SYS_ioctl, @bitCast(usize, isize(fd)), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
|
||||
return readlinkat(AT_FDCWD, path, buf_ptr, buf_len);
|
||||
@ -1137,15 +1137,6 @@ pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
|
||||
pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
|
||||
pub const empty_sigset = []usize{0} ** sigset_t.len;
|
||||
|
||||
pub fn raise(sig: i32) usize {
|
||||
var set: sigset_t = undefined;
|
||||
blockAppSignals(&set);
|
||||
const tid = syscall0(SYS_gettid);
|
||||
const ret = syscall2(SYS_tkill, tid, @bitCast(usize, isize(sig)));
|
||||
restoreSignals(&set);
|
||||
return ret;
|
||||
}
|
||||
|
||||
fn blockAllSignals(set: *sigset_t) void {
|
||||
_ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);
|
||||
}
|
||||
@ -1672,7 +1663,7 @@ pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_inf
|
||||
}
|
||||
|
||||
test "import" {
|
||||
if (builtin.os == builtin.Os.linux) {
|
||||
if (is_the_target) {
|
||||
_ = @import("linux/test.zig");
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ pub fn initTLS() void {
|
||||
var tls_phdr: ?*elf.Phdr = null;
|
||||
var img_base: usize = 0;
|
||||
|
||||
const auxv = std.os.linux_elf_aux_maybe.?;
|
||||
const auxv = std.os.linux.elf_aux_maybe.?;
|
||||
var at_phent: usize = undefined;
|
||||
var at_phnum: usize = undefined;
|
||||
var at_phdr: usize = undefined;
|
||||
|
2159
std/os/posix.zig
Normal file
2159
std/os/posix.zig
Normal file
File diff suppressed because it is too large
Load Diff
411
std/os/wasi.zig
411
std/os/wasi.zig
@ -1,42 +1,393 @@
|
||||
pub use @import("wasi/core.zig");
|
||||
// Based on https://github.com/CraneStation/wasi-sysroot/blob/wasi/libc-bottom-half/headers/public/wasi/core.h
|
||||
// and https://github.com/WebAssembly/WASI/blob/master/design/WASI-core.md
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
pub const is_the_target = @import("builtin").os == .wasi;
|
||||
|
||||
pub const STDIN_FILENO = 0;
|
||||
pub const STDOUT_FILENO = 1;
|
||||
pub const STDERR_FILENO = 2;
|
||||
|
||||
pub fn getErrno(r: usize) usize {
|
||||
const signed_r = @bitCast(isize, r);
|
||||
return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
|
||||
comptime {
|
||||
assert(@alignOf(i8) == 1);
|
||||
assert(@alignOf(u8) == 1);
|
||||
assert(@alignOf(i16) == 2);
|
||||
assert(@alignOf(u16) == 2);
|
||||
assert(@alignOf(i32) == 4);
|
||||
assert(@alignOf(u32) == 4);
|
||||
assert(@alignOf(i64) == 8);
|
||||
assert(@alignOf(u64) == 8);
|
||||
}
|
||||
|
||||
pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
|
||||
var nwritten: usize = undefined;
|
||||
pub const advice_t = u8;
|
||||
pub const ADVICE_NORMAL: advice_t = 0;
|
||||
pub const ADVICE_SEQUENTIAL: advice_t = 1;
|
||||
pub const ADVICE_RANDOM: advice_t = 2;
|
||||
pub const ADVICE_WILLNEED: advice_t = 3;
|
||||
pub const ADVICE_DONTNEED: advice_t = 4;
|
||||
pub const ADVICE_NOREUSE: advice_t = 5;
|
||||
|
||||
const ciovs = ciovec_t{
|
||||
.buf = buf,
|
||||
.buf_len = count,
|
||||
};
|
||||
pub const ciovec_t = extern struct {
|
||||
buf: [*]const u8,
|
||||
buf_len: usize,
|
||||
};
|
||||
|
||||
const err = fd_write(@bitCast(fd_t, isize(fd)), &ciovs, 1, &nwritten);
|
||||
if (err == ESUCCESS) {
|
||||
return nwritten;
|
||||
} else {
|
||||
return @bitCast(usize, -isize(err));
|
||||
}
|
||||
}
|
||||
pub const clockid_t = u32;
|
||||
pub const CLOCK_REALTIME: clockid_t = 0;
|
||||
pub const CLOCK_MONOTONIC: clockid_t = 1;
|
||||
pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;
|
||||
pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;
|
||||
|
||||
pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize {
|
||||
var nread: usize = undefined;
|
||||
pub const device_t = u64;
|
||||
|
||||
const iovs = iovec_t{
|
||||
.buf = buf,
|
||||
.buf_len = nbyte,
|
||||
};
|
||||
pub const dircookie_t = u64;
|
||||
pub const DIRCOOKIE_START: dircookie_t = 0;
|
||||
|
||||
const err = fd_read(@bitCast(fd_t, isize(fd)), &iovs, 1, &nread);
|
||||
if (err == ESUCCESS) {
|
||||
return nread;
|
||||
} else {
|
||||
return @bitCast(usize, -isize(err));
|
||||
}
|
||||
}
|
||||
pub const dirent_t = extern struct {
|
||||
d_next: dircookie_t,
|
||||
d_ino: inode_t,
|
||||
d_namlen: u32,
|
||||
d_type: filetype_t,
|
||||
};
|
||||
|
||||
pub const errno_t = u16;
|
||||
pub const ESUCCESS: errno_t = 0;
|
||||
pub const E2BIG: errno_t = 1;
|
||||
pub const EACCES: errno_t = 2;
|
||||
pub const EADDRINUSE: errno_t = 3;
|
||||
pub const EADDRNOTAVAIL: errno_t = 4;
|
||||
pub const EAFNOSUPPORT: errno_t = 5;
|
||||
pub const EAGAIN: errno_t = 6;
|
||||
pub const EALREADY: errno_t = 7;
|
||||
pub const EBADF: errno_t = 8;
|
||||
pub const EBADMSG: errno_t = 9;
|
||||
pub const EBUSY: errno_t = 10;
|
||||
pub const ECANCELED: errno_t = 11;
|
||||
pub const ECHILD: errno_t = 12;
|
||||
pub const ECONNABORTED: errno_t = 13;
|
||||
pub const ECONNREFUSED: errno_t = 14;
|
||||
pub const ECONNRESET: errno_t = 15;
|
||||
pub const EDEADLK: errno_t = 16;
|
||||
pub const EDESTADDRREQ: errno_t = 17;
|
||||
pub const EDOM: errno_t = 18;
|
||||
pub const EDQUOT: errno_t = 19;
|
||||
pub const EEXIST: errno_t = 20;
|
||||
pub const EFAULT: errno_t = 21;
|
||||
pub const EFBIG: errno_t = 22;
|
||||
pub const EHOSTUNREACH: errno_t = 23;
|
||||
pub const EIDRM: errno_t = 24;
|
||||
pub const EILSEQ: errno_t = 25;
|
||||
pub const EINPROGRESS: errno_t = 26;
|
||||
pub const EINTR: errno_t = 27;
|
||||
pub const EINVAL: errno_t = 28;
|
||||
pub const EIO: errno_t = 29;
|
||||
pub const EISCONN: errno_t = 30;
|
||||
pub const EISDIR: errno_t = 31;
|
||||
pub const ELOOP: errno_t = 32;
|
||||
pub const EMFILE: errno_t = 33;
|
||||
pub const EMLINK: errno_t = 34;
|
||||
pub const EMSGSIZE: errno_t = 35;
|
||||
pub const EMULTIHOP: errno_t = 36;
|
||||
pub const ENAMETOOLONG: errno_t = 37;
|
||||
pub const ENETDOWN: errno_t = 38;
|
||||
pub const ENETRESET: errno_t = 39;
|
||||
pub const ENETUNREACH: errno_t = 40;
|
||||
pub const ENFILE: errno_t = 41;
|
||||
pub const ENOBUFS: errno_t = 42;
|
||||
pub const ENODEV: errno_t = 43;
|
||||
pub const ENOENT: errno_t = 44;
|
||||
pub const ENOEXEC: errno_t = 45;
|
||||
pub const ENOLCK: errno_t = 46;
|
||||
pub const ENOLINK: errno_t = 47;
|
||||
pub const ENOMEM: errno_t = 48;
|
||||
pub const ENOMSG: errno_t = 49;
|
||||
pub const ENOPROTOOPT: errno_t = 50;
|
||||
pub const ENOSPC: errno_t = 51;
|
||||
pub const ENOSYS: errno_t = 52;
|
||||
pub const ENOTCONN: errno_t = 53;
|
||||
pub const ENOTDIR: errno_t = 54;
|
||||
pub const ENOTEMPTY: errno_t = 55;
|
||||
pub const ENOTRECOVERABLE: errno_t = 56;
|
||||
pub const ENOTSOCK: errno_t = 57;
|
||||
pub const ENOTSUP: errno_t = 58;
|
||||
pub const ENOTTY: errno_t = 59;
|
||||
pub const ENXIO: errno_t = 60;
|
||||
pub const EOVERFLOW: errno_t = 61;
|
||||
pub const EOWNERDEAD: errno_t = 62;
|
||||
pub const EPERM: errno_t = 63;
|
||||
pub const EPIPE: errno_t = 64;
|
||||
pub const EPROTO: errno_t = 65;
|
||||
pub const EPROTONOSUPPORT: errno_t = 66;
|
||||
pub const EPROTOTYPE: errno_t = 67;
|
||||
pub const ERANGE: errno_t = 68;
|
||||
pub const EROFS: errno_t = 69;
|
||||
pub const ESPIPE: errno_t = 70;
|
||||
pub const ESRCH: errno_t = 71;
|
||||
pub const ESTALE: errno_t = 72;
|
||||
pub const ETIMEDOUT: errno_t = 73;
|
||||
pub const ETXTBSY: errno_t = 74;
|
||||
pub const EXDEV: errno_t = 75;
|
||||
pub const ENOTCAPABLE: errno_t = 76;
|
||||
|
||||
pub const event_t = extern struct {
|
||||
userdata: userdata_t,
|
||||
@"error": errno_t,
|
||||
@"type": eventtype_t,
|
||||
u: extern union {
|
||||
fd_readwrite: extern struct {
|
||||
nbytes: filesize_t,
|
||||
flags: eventrwflags_t,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
pub const eventrwflags_t = u16;
|
||||
pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;
|
||||
|
||||
pub const eventtype_t = u8;
|
||||
pub const EVENTTYPE_CLOCK: eventtype_t = 0;
|
||||
pub const EVENTTYPE_FD_READ: eventtype_t = 1;
|
||||
pub const EVENTTYPE_FD_WRITE: eventtype_t = 2;
|
||||
|
||||
pub const exitcode_t = u32;
|
||||
|
||||
pub const fd_t = u32;
|
||||
|
||||
pub const fdflags_t = u16;
|
||||
pub const FDFLAG_APPEND: fdflags_t = 0x0001;
|
||||
pub const FDFLAG_DSYNC: fdflags_t = 0x0002;
|
||||
pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
|
||||
pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
|
||||
pub const FDFLAG_SYNC: fdflags_t = 0x0010;
|
||||
|
||||
const fdstat_t = extern struct {
|
||||
fs_filetype: filetype_t,
|
||||
fs_flags: fdflags_t,
|
||||
fs_rights_base: rights_t,
|
||||
fs_rights_inheriting: rights_t,
|
||||
};
|
||||
|
||||
pub const filedelta_t = i64;
|
||||
|
||||
pub const filesize_t = u64;
|
||||
|
||||
pub const filestat_t = extern struct {
|
||||
st_dev: device_t,
|
||||
st_ino: inode_t,
|
||||
st_filetype: filetype_t,
|
||||
st_nlink: linkcount_t,
|
||||
st_size: filesize_t,
|
||||
st_atim: timestamp_t,
|
||||
st_mtim: timestamp_t,
|
||||
st_ctim: timestamp_t,
|
||||
};
|
||||
|
||||
pub const filetype_t = u8;
|
||||
pub const FILETYPE_UNKNOWN: filetype_t = 0;
|
||||
pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1;
|
||||
pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2;
|
||||
pub const FILETYPE_DIRECTORY: filetype_t = 3;
|
||||
pub const FILETYPE_REGULAR_FILE: filetype_t = 4;
|
||||
pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5;
|
||||
pub const FILETYPE_SOCKET_STREAM: filetype_t = 6;
|
||||
pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7;
|
||||
|
||||
pub const fstflags_t = u16;
|
||||
pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001;
|
||||
pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002;
|
||||
pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004;
|
||||
pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
|
||||
|
||||
pub const inode_t = u64;
|
||||
|
||||
pub const iovec_t = extern struct {
|
||||
buf: [*]u8,
|
||||
buf_len: usize,
|
||||
};
|
||||
|
||||
pub const linkcount_t = u32;
|
||||
|
||||
pub const lookupflags_t = u32;
|
||||
pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001;
|
||||
|
||||
pub const oflags_t = u16;
|
||||
pub const O_CREAT: oflags_t = 0x0001;
|
||||
pub const O_DIRECTORY: oflags_t = 0x0002;
|
||||
pub const O_EXCL: oflags_t = 0x0004;
|
||||
pub const O_TRUNC: oflags_t = 0x0008;
|
||||
|
||||
pub const preopentype_t = u8;
|
||||
pub const PREOPENTYPE_DIR: preopentype_t = 0;
|
||||
|
||||
pub const prestat_t = extern struct {
|
||||
pr_type: preopentype_t,
|
||||
u: extern union {
|
||||
dir: extern struct {
|
||||
pr_name_len: usize,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
pub const riflags_t = u16;
|
||||
pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
|
||||
pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
|
||||
|
||||
pub const rights_t = u64;
|
||||
pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
|
||||
pub const RIGHT_FD_READ: rights_t = 0x0000000000000002;
|
||||
pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004;
|
||||
pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008;
|
||||
pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010;
|
||||
pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020;
|
||||
pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040;
|
||||
pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080;
|
||||
pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100;
|
||||
pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200;
|
||||
pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400;
|
||||
pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800;
|
||||
pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000;
|
||||
pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000;
|
||||
pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000;
|
||||
pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000;
|
||||
pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000;
|
||||
pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000;
|
||||
pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000;
|
||||
pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000;
|
||||
pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000;
|
||||
pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000;
|
||||
pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000;
|
||||
pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000;
|
||||
pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000;
|
||||
pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000;
|
||||
pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000;
|
||||
pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000;
|
||||
pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000;
|
||||
|
||||
pub const roflags_t = u16;
|
||||
pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
|
||||
|
||||
pub const sdflags_t = u8;
|
||||
pub const SHUT_RD: sdflags_t = 0x01;
|
||||
pub const SHUT_WR: sdflags_t = 0x02;
|
||||
|
||||
pub const siflags_t = u16;
|
||||
|
||||
pub const signal_t = u8;
|
||||
pub const SIGHUP: signal_t = 1;
|
||||
pub const SIGINT: signal_t = 2;
|
||||
pub const SIGQUIT: signal_t = 3;
|
||||
pub const SIGILL: signal_t = 4;
|
||||
pub const SIGTRAP: signal_t = 5;
|
||||
pub const SIGABRT: signal_t = 6;
|
||||
pub const SIGBUS: signal_t = 7;
|
||||
pub const SIGFPE: signal_t = 8;
|
||||
pub const SIGKILL: signal_t = 9;
|
||||
pub const SIGUSR1: signal_t = 10;
|
||||
pub const SIGSEGV: signal_t = 11;
|
||||
pub const SIGUSR2: signal_t = 12;
|
||||
pub const SIGPIPE: signal_t = 13;
|
||||
pub const SIGALRM: signal_t = 14;
|
||||
pub const SIGTERM: signal_t = 15;
|
||||
pub const SIGCHLD: signal_t = 16;
|
||||
pub const SIGCONT: signal_t = 17;
|
||||
pub const SIGSTOP: signal_t = 18;
|
||||
pub const SIGTSTP: signal_t = 19;
|
||||
pub const SIGTTIN: signal_t = 20;
|
||||
pub const SIGTTOU: signal_t = 21;
|
||||
pub const SIGURG: signal_t = 22;
|
||||
pub const SIGXCPU: signal_t = 23;
|
||||
pub const SIGXFSZ: signal_t = 24;
|
||||
pub const SIGVTALRM: signal_t = 25;
|
||||
pub const SIGPROF: signal_t = 26;
|
||||
pub const SIGWINCH: signal_t = 27;
|
||||
pub const SIGPOLL: signal_t = 28;
|
||||
pub const SIGPWR: signal_t = 29;
|
||||
pub const SIGSYS: signal_t = 30;
|
||||
|
||||
pub const subclockflags_t = u16;
|
||||
pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;
|
||||
|
||||
pub const subscription_t = extern struct {
|
||||
userdata: userdata_t,
|
||||
@"type": eventtype_t,
|
||||
u: extern union {
|
||||
clock: extern struct {
|
||||
identifier: userdata_t,
|
||||
clock_id: clockid_t,
|
||||
timeout: timestamp_t,
|
||||
precision: timestamp_t,
|
||||
flags: subclockflags_t,
|
||||
},
|
||||
fd_readwrite: extern struct {
|
||||
fd: fd_t,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
pub const timestamp_t = u64;
|
||||
|
||||
pub const userdata_t = u64;
|
||||
|
||||
pub const whence_t = u8;
|
||||
pub const WHENCE_CUR: whence_t = 0;
|
||||
pub const WHENCE_END: whence_t = 1;
|
||||
pub const WHENCE_SET: whence_t = 2;
|
||||
|
||||
pub extern "wasi_unstable" fn args_get(argv: [*][*]u8, argv_buf: [*]u8) errno_t;
|
||||
pub extern "wasi_unstable" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn clock_res_get(clock_id: clockid_t, resolution: *timestamp_t) errno_t;
|
||||
pub extern "wasi_unstable" fn clock_time_get(clock_id: clockid_t, precision: timestamp_t, timestamp: *timestamp_t) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn environ_get(environ: [*]?[*]u8, environ_buf: [*]u8) errno_t;
|
||||
pub extern "wasi_unstable" fn environ_sizes_get(environ_count: *usize, environ_buf_size: *usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn fd_advise(fd: fd_t, offset: filesize_t, len: filesize_t, advice: advice_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_allocate(fd: fd_t, offset: filesize_t, len: filesize_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_close(fd: fd_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_datasync(fd: fd_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_pread(fd: fd_t, iovs: [*]const iovec_t, iovs_len: usize, offset: filesize_t, nread: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_pwrite(fd: fd_t, iovs: [*]const ciovec_t, iovs_len: usize, offset: filesize_t, nwritten: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_read(fd: fd_t, iovs: [*]const iovec_t, iovs_len: usize, nread: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_readdir(fd: fd_t, buf: [*]u8, buf_len: usize, cookie: dircookie_t, bufused: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_renumber(from: fd_t, to: fd_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_seek(fd: fd_t, offset: filedelta_t, whence: whence_t, newoffset: *filesize_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_sync(fd: fd_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_tell(fd: fd_t, newoffset: *filesize_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_write(fd: fd_t, iovs: [*]const ciovec_t, iovs_len: usize, nwritten: *usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn fd_fdstat_get(fd: fd_t, buf: *fdstat_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_fdstat_set_flags(fd: fd_t, flags: fdflags_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_fdstat_set_rights(fd: fd_t, fs_rights_base: rights_t, fs_rights_inheriting: rights_t) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn fd_filestat_get(fd: fd_t, buf: *filestat_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_filestat_set_size(fd: fd_t, st_size: filesize_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_filestat_set_times(fd: fd_t, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags_t) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn fd_prestat_get(fd: fd_t, buf: *prestat_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_prestat_dir_name(fd: fd_t, path: [*]u8, path_len: usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn path_create_directory(fd: fd_t, path: [*]const u8, path_len: usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_filestat_get(fd: fd_t, flags: lookupflags_t, path: [*]const u8, path_len: usize, buf: *filestat_t) errno_t;
|
||||
pub extern "wasi_unstable" fn path_filestat_set_times(fd: fd_t, flags: lookupflags_t, path: [*]const u8, path_len: usize, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags_t) errno_t;
|
||||
pub extern "wasi_unstable" fn path_link(old_fd: fd_t, old_flags: lookupflags_t, old_path: [*]const u8, old_path_len: usize, new_fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_open(dirfd: fd_t, dirflags: lookupflags_t, path: [*]const u8, path_len: usize, oflags: oflags_t, fs_rights_base: rights_t, fs_rights_inheriting: rights_t, fs_flags: fdflags_t, fd: *fd_t) errno_t;
|
||||
pub extern "wasi_unstable" fn path_readlink(fd: fd_t, path: [*]const u8, path_len: usize, buf: [*]u8, buf_len: usize, bufused: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_remove_directory(fd: fd_t, path: [*]const u8, path_len: usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_rename(old_fd: fd_t, old_path: [*]const u8, old_path_len: usize, new_fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_symlink(old_path: [*]const u8, old_path_len: usize, fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_unlink_file(fd: fd_t, path: [*]const u8, path_len: usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn poll_oneoff(in: *const subscription_t, out: *event_t, nsubscriptions: usize, nevents: *usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn proc_exit(rval: exitcode_t) noreturn;
|
||||
pub extern "wasi_unstable" fn proc_raise(sig: signal_t) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn random_get(buf: [*]u8, buf_len: usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn sched_yield() errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn sock_recv(sock: fd_t, ri_data: *const iovec_t, ri_data_len: usize, ri_flags: riflags_t, ro_datalen: *usize, ro_flags: *roflags_t) errno_t;
|
||||
pub extern "wasi_unstable" fn sock_send(sock: fd_t, si_data: *const ciovec_t, si_data_len: usize, si_flags: siflags_t, so_datalen: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t;
|
||||
|
@ -1,374 +0,0 @@
|
||||
// Based on https://github.com/CraneStation/wasi-sysroot/blob/wasi/libc-bottom-half/headers/public/wasi/core.h
|
||||
// and https://github.com/WebAssembly/WASI/blob/master/design/WASI-core.md
|
||||
|
||||
pub const advice_t = u8;
|
||||
pub const ADVICE_NORMAL: advice_t = 0;
|
||||
pub const ADVICE_SEQUENTIAL: advice_t = 1;
|
||||
pub const ADVICE_RANDOM: advice_t = 2;
|
||||
pub const ADVICE_WILLNEED: advice_t = 3;
|
||||
pub const ADVICE_DONTNEED: advice_t = 4;
|
||||
pub const ADVICE_NOREUSE: advice_t = 5;
|
||||
|
||||
pub const ciovec_t = extern struct {
|
||||
buf: [*]const u8,
|
||||
buf_len: usize,
|
||||
};
|
||||
|
||||
pub const clockid_t = u32;
|
||||
pub const CLOCK_REALTIME: clockid_t = 0;
|
||||
pub const CLOCK_MONOTONIC: clockid_t = 1;
|
||||
pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;
|
||||
pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;
|
||||
|
||||
pub const device_t = u64;
|
||||
|
||||
pub const dircookie_t = u64;
|
||||
pub const DIRCOOKIE_START: dircookie_t = 0;
|
||||
|
||||
pub const dirent_t = extern struct {
|
||||
d_next: dircookie_t,
|
||||
d_ino: inode_t,
|
||||
d_namlen: u32,
|
||||
d_type: filetype_t,
|
||||
};
|
||||
|
||||
pub const errno_t = u16;
|
||||
pub const ESUCCESS: errno_t = 0;
|
||||
pub const E2BIG: errno_t = 1;
|
||||
pub const EACCES: errno_t = 2;
|
||||
pub const EADDRINUSE: errno_t = 3;
|
||||
pub const EADDRNOTAVAIL: errno_t = 4;
|
||||
pub const EAFNOSUPPORT: errno_t = 5;
|
||||
pub const EAGAIN: errno_t = 6;
|
||||
pub const EALREADY: errno_t = 7;
|
||||
pub const EBADF: errno_t = 8;
|
||||
pub const EBADMSG: errno_t = 9;
|
||||
pub const EBUSY: errno_t = 10;
|
||||
pub const ECANCELED: errno_t = 11;
|
||||
pub const ECHILD: errno_t = 12;
|
||||
pub const ECONNABORTED: errno_t = 13;
|
||||
pub const ECONNREFUSED: errno_t = 14;
|
||||
pub const ECONNRESET: errno_t = 15;
|
||||
pub const EDEADLK: errno_t = 16;
|
||||
pub const EDESTADDRREQ: errno_t = 17;
|
||||
pub const EDOM: errno_t = 18;
|
||||
pub const EDQUOT: errno_t = 19;
|
||||
pub const EEXIST: errno_t = 20;
|
||||
pub const EFAULT: errno_t = 21;
|
||||
pub const EFBIG: errno_t = 22;
|
||||
pub const EHOSTUNREACH: errno_t = 23;
|
||||
pub const EIDRM: errno_t = 24;
|
||||
pub const EILSEQ: errno_t = 25;
|
||||
pub const EINPROGRESS: errno_t = 26;
|
||||
pub const EINTR: errno_t = 27;
|
||||
pub const EINVAL: errno_t = 28;
|
||||
pub const EIO: errno_t = 29;
|
||||
pub const EISCONN: errno_t = 30;
|
||||
pub const EISDIR: errno_t = 31;
|
||||
pub const ELOOP: errno_t = 32;
|
||||
pub const EMFILE: errno_t = 33;
|
||||
pub const EMLINK: errno_t = 34;
|
||||
pub const EMSGSIZE: errno_t = 35;
|
||||
pub const EMULTIHOP: errno_t = 36;
|
||||
pub const ENAMETOOLONG: errno_t = 37;
|
||||
pub const ENETDOWN: errno_t = 38;
|
||||
pub const ENETRESET: errno_t = 39;
|
||||
pub const ENETUNREACH: errno_t = 40;
|
||||
pub const ENFILE: errno_t = 41;
|
||||
pub const ENOBUFS: errno_t = 42;
|
||||
pub const ENODEV: errno_t = 43;
|
||||
pub const ENOENT: errno_t = 44;
|
||||
pub const ENOEXEC: errno_t = 45;
|
||||
pub const ENOLCK: errno_t = 46;
|
||||
pub const ENOLINK: errno_t = 47;
|
||||
pub const ENOMEM: errno_t = 48;
|
||||
pub const ENOMSG: errno_t = 49;
|
||||
pub const ENOPROTOOPT: errno_t = 50;
|
||||
pub const ENOSPC: errno_t = 51;
|
||||
pub const ENOSYS: errno_t = 52;
|
||||
pub const ENOTCONN: errno_t = 53;
|
||||
pub const ENOTDIR: errno_t = 54;
|
||||
pub const ENOTEMPTY: errno_t = 55;
|
||||
pub const ENOTRECOVERABLE: errno_t = 56;
|
||||
pub const ENOTSOCK: errno_t = 57;
|
||||
pub const ENOTSUP: errno_t = 58;
|
||||
pub const ENOTTY: errno_t = 59;
|
||||
pub const ENXIO: errno_t = 60;
|
||||
pub const EOVERFLOW: errno_t = 61;
|
||||
pub const EOWNERDEAD: errno_t = 62;
|
||||
pub const EPERM: errno_t = 63;
|
||||
pub const EPIPE: errno_t = 64;
|
||||
pub const EPROTO: errno_t = 65;
|
||||
pub const EPROTONOSUPPORT: errno_t = 66;
|
||||
pub const EPROTOTYPE: errno_t = 67;
|
||||
pub const ERANGE: errno_t = 68;
|
||||
pub const EROFS: errno_t = 69;
|
||||
pub const ESPIPE: errno_t = 70;
|
||||
pub const ESRCH: errno_t = 71;
|
||||
pub const ESTALE: errno_t = 72;
|
||||
pub const ETIMEDOUT: errno_t = 73;
|
||||
pub const ETXTBSY: errno_t = 74;
|
||||
pub const EXDEV: errno_t = 75;
|
||||
pub const ENOTCAPABLE: errno_t = 76;
|
||||
|
||||
pub const event_t = extern struct {
|
||||
userdata: userdata_t,
|
||||
@"error": errno_t,
|
||||
@"type": eventtype_t,
|
||||
u: extern union {
|
||||
fd_readwrite: extern struct {
|
||||
nbytes: filesize_t,
|
||||
flags: eventrwflags_t,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
pub const eventrwflags_t = u16;
|
||||
pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;
|
||||
|
||||
pub const eventtype_t = u8;
|
||||
pub const EVENTTYPE_CLOCK: eventtype_t = 0;
|
||||
pub const EVENTTYPE_FD_READ: eventtype_t = 1;
|
||||
pub const EVENTTYPE_FD_WRITE: eventtype_t = 2;
|
||||
|
||||
pub const exitcode_t = u32;
|
||||
|
||||
pub const fd_t = u32;
|
||||
|
||||
pub const fdflags_t = u16;
|
||||
pub const FDFLAG_APPEND: fdflags_t = 0x0001;
|
||||
pub const FDFLAG_DSYNC: fdflags_t = 0x0002;
|
||||
pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
|
||||
pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
|
||||
pub const FDFLAG_SYNC: fdflags_t = 0x0010;
|
||||
|
||||
const fdstat_t = extern struct {
|
||||
fs_filetype: filetype_t,
|
||||
fs_flags: fdflags_t,
|
||||
fs_rights_base: rights_t,
|
||||
fs_rights_inheriting: rights_t,
|
||||
};
|
||||
|
||||
pub const filedelta_t = i64;
|
||||
|
||||
pub const filesize_t = u64;
|
||||
|
||||
pub const filestat_t = extern struct {
|
||||
st_dev: device_t,
|
||||
st_ino: inode_t,
|
||||
st_filetype: filetype_t,
|
||||
st_nlink: linkcount_t,
|
||||
st_size: filesize_t,
|
||||
st_atim: timestamp_t,
|
||||
st_mtim: timestamp_t,
|
||||
st_ctim: timestamp_t,
|
||||
};
|
||||
|
||||
pub const filetype_t = u8;
|
||||
pub const FILETYPE_UNKNOWN: filetype_t = 0;
|
||||
pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1;
|
||||
pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2;
|
||||
pub const FILETYPE_DIRECTORY: filetype_t = 3;
|
||||
pub const FILETYPE_REGULAR_FILE: filetype_t = 4;
|
||||
pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5;
|
||||
pub const FILETYPE_SOCKET_STREAM: filetype_t = 6;
|
||||
pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7;
|
||||
|
||||
pub const fstflags_t = u16;
|
||||
pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001;
|
||||
pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002;
|
||||
pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004;
|
||||
pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
|
||||
|
||||
pub const inode_t = u64;
|
||||
|
||||
pub const iovec_t = extern struct {
|
||||
buf: [*]u8,
|
||||
buf_len: usize,
|
||||
};
|
||||
|
||||
pub const linkcount_t = u32;
|
||||
|
||||
pub const lookupflags_t = u32;
|
||||
pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001;
|
||||
|
||||
pub const oflags_t = u16;
|
||||
pub const O_CREAT: oflags_t = 0x0001;
|
||||
pub const O_DIRECTORY: oflags_t = 0x0002;
|
||||
pub const O_EXCL: oflags_t = 0x0004;
|
||||
pub const O_TRUNC: oflags_t = 0x0008;
|
||||
|
||||
pub const preopentype_t = u8;
|
||||
pub const PREOPENTYPE_DIR: preopentype_t = 0;
|
||||
|
||||
pub const prestat_t = extern struct {
|
||||
pr_type: preopentype_t,
|
||||
u: extern union {
|
||||
dir: extern struct {
|
||||
pr_name_len: usize,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
pub const riflags_t = u16;
|
||||
pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
|
||||
pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
|
||||
|
||||
pub const rights_t = u64;
|
||||
pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
|
||||
pub const RIGHT_FD_READ: rights_t = 0x0000000000000002;
|
||||
pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004;
|
||||
pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008;
|
||||
pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010;
|
||||
pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020;
|
||||
pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040;
|
||||
pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080;
|
||||
pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100;
|
||||
pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200;
|
||||
pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400;
|
||||
pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800;
|
||||
pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000;
|
||||
pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000;
|
||||
pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000;
|
||||
pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000;
|
||||
pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000;
|
||||
pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000;
|
||||
pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000;
|
||||
pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000;
|
||||
pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000;
|
||||
pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000;
|
||||
pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000;
|
||||
pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000;
|
||||
pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000;
|
||||
pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000;
|
||||
pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000;
|
||||
pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000;
|
||||
pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000;
|
||||
|
||||
pub const roflags_t = u16;
|
||||
pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
|
||||
|
||||
pub const sdflags_t = u8;
|
||||
pub const SHUT_RD: sdflags_t = 0x01;
|
||||
pub const SHUT_WR: sdflags_t = 0x02;
|
||||
|
||||
pub const siflags_t = u16;
|
||||
|
||||
pub const signal_t = u8;
|
||||
pub const SIGHUP: signal_t = 1;
|
||||
pub const SIGINT: signal_t = 2;
|
||||
pub const SIGQUIT: signal_t = 3;
|
||||
pub const SIGILL: signal_t = 4;
|
||||
pub const SIGTRAP: signal_t = 5;
|
||||
pub const SIGABRT: signal_t = 6;
|
||||
pub const SIGBUS: signal_t = 7;
|
||||
pub const SIGFPE: signal_t = 8;
|
||||
pub const SIGKILL: signal_t = 9;
|
||||
pub const SIGUSR1: signal_t = 10;
|
||||
pub const SIGSEGV: signal_t = 11;
|
||||
pub const SIGUSR2: signal_t = 12;
|
||||
pub const SIGPIPE: signal_t = 13;
|
||||
pub const SIGALRM: signal_t = 14;
|
||||
pub const SIGTERM: signal_t = 15;
|
||||
pub const SIGCHLD: signal_t = 16;
|
||||
pub const SIGCONT: signal_t = 17;
|
||||
pub const SIGSTOP: signal_t = 18;
|
||||
pub const SIGTSTP: signal_t = 19;
|
||||
pub const SIGTTIN: signal_t = 20;
|
||||
pub const SIGTTOU: signal_t = 21;
|
||||
pub const SIGURG: signal_t = 22;
|
||||
pub const SIGXCPU: signal_t = 23;
|
||||
pub const SIGXFSZ: signal_t = 24;
|
||||
pub const SIGVTALRM: signal_t = 25;
|
||||
pub const SIGPROF: signal_t = 26;
|
||||
pub const SIGWINCH: signal_t = 27;
|
||||
pub const SIGPOLL: signal_t = 28;
|
||||
pub const SIGPWR: signal_t = 29;
|
||||
pub const SIGSYS: signal_t = 30;
|
||||
|
||||
pub const subclockflags_t = u16;
|
||||
pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;
|
||||
|
||||
pub const subscription_t = extern struct {
|
||||
userdata: userdata_t,
|
||||
@"type": eventtype_t,
|
||||
u: extern union {
|
||||
clock: extern struct {
|
||||
identifier: userdata_t,
|
||||
clock_id: clockid_t,
|
||||
timeout: timestamp_t,
|
||||
precision: timestamp_t,
|
||||
flags: subclockflags_t,
|
||||
},
|
||||
fd_readwrite: extern struct {
|
||||
fd: fd_t,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
pub const timestamp_t = u64;
|
||||
|
||||
pub const userdata_t = u64;
|
||||
|
||||
pub const whence_t = u8;
|
||||
pub const WHENCE_CUR: whence_t = 0;
|
||||
pub const WHENCE_END: whence_t = 1;
|
||||
pub const WHENCE_SET: whence_t = 2;
|
||||
|
||||
pub extern "wasi_unstable" fn args_get(argv: [*][*]u8, argv_buf: [*]u8) errno_t;
|
||||
pub extern "wasi_unstable" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn clock_res_get(clock_id: clockid_t, resolution: *timestamp_t) errno_t;
|
||||
pub extern "wasi_unstable" fn clock_time_get(clock_id: clockid_t, precision: timestamp_t, timestamp: *timestamp_t) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn environ_get(environ: [*]?[*]u8, environ_buf: [*]u8) errno_t;
|
||||
pub extern "wasi_unstable" fn environ_sizes_get(environ_count: *usize, environ_buf_size: *usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn fd_advise(fd: fd_t, offset: filesize_t, len: filesize_t, advice: advice_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_allocate(fd: fd_t, offset: filesize_t, len: filesize_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_close(fd: fd_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_datasync(fd: fd_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_pread(fd: fd_t, iovs: *const iovec_t, iovs_len: usize, offset: filesize_t, nread: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_pwrite(fd: fd_t, iovs: *const ciovec_t, iovs_len: usize, offset: filesize_t, nwritten: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_read(fd: fd_t, iovs: *const iovec_t, iovs_len: usize, nread: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_readdir(fd: fd_t, buf: [*]u8, buf_len: usize, cookie: dircookie_t, bufused: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_renumber(from: fd_t, to: fd_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_seek(fd: fd_t, offset: filedelta_t, whence: whence_t, newoffset: *filesize_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_sync(fd: fd_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_tell(fd: fd_t, newoffset: *filesize_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_write(fd: fd_t, iovs: *const ciovec_t, iovs_len: usize, nwritten: *usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn fd_fdstat_get(fd: fd_t, buf: *fdstat_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_fdstat_set_flags(fd: fd_t, flags: fdflags_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_fdstat_set_rights(fd: fd_t, fs_rights_base: rights_t, fs_rights_inheriting: rights_t) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn fd_filestat_get(fd: fd_t, buf: *filestat_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_filestat_set_size(fd: fd_t, st_size: filesize_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_filestat_set_times(fd: fd_t, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags_t) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn fd_prestat_get(fd: fd_t, buf: *prestat_t) errno_t;
|
||||
pub extern "wasi_unstable" fn fd_prestat_dir_name(fd: fd_t, path: [*]u8, path_len: usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn path_create_directory(fd: fd_t, path: [*]const u8, path_len: usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_filestat_get(fd: fd_t, flags: lookupflags_t, path: [*]const u8, path_len: usize, buf: *filestat_t) errno_t;
|
||||
pub extern "wasi_unstable" fn path_filestat_set_times(fd: fd_t, flags: lookupflags_t, path: [*]const u8, path_len: usize, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags_t) errno_t;
|
||||
pub extern "wasi_unstable" fn path_link(old_fd: fd_t, old_flags: lookupflags_t, old_path: [*]const u8, old_path_len: usize, new_fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_open(dirfd: fd_t, dirflags: lookupflags_t, path: [*]const u8, path_len: usize, oflags: oflags_t, fs_rights_base: rights_t, fs_rights_inheriting: rights_t, fs_flags: fdflags_t, fd: *fd_t) errno_t;
|
||||
pub extern "wasi_unstable" fn path_readlink(fd: fd_t, path: [*]const u8, path_len: usize, buf: [*]u8, buf_len: usize, bufused: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_remove_directory(fd: fd_t, path: [*]const u8, path_len: usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_rename(old_fd: fd_t, old_path: [*]const u8, old_path_len: usize, new_fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_symlink(old_path: [*]const u8, old_path_len: usize, fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t;
|
||||
pub extern "wasi_unstable" fn path_unlink_file(fd: fd_t, path: [*]const u8, path_len: usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn poll_oneoff(in: *const subscription_t, out: *event_t, nsubscriptions: usize, nevents: *usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn proc_exit(rval: exitcode_t) noreturn;
|
||||
pub extern "wasi_unstable" fn proc_raise(sig: signal_t) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn random_get(buf: [*]u8, buf_len: usize) errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn sched_yield() errno_t;
|
||||
|
||||
pub extern "wasi_unstable" fn sock_recv(sock: fd_t, ri_data: *const iovec_t, ri_data_len: usize, ri_flags: riflags_t, ro_datalen: *usize, ro_flags: *roflags_t) errno_t;
|
||||
pub extern "wasi_unstable" fn sock_send(sock: fd_t, si_data: *const ciovec_t, si_data_len: usize, si_flags: siflags_t, so_datalen: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t;
|
@ -2,6 +2,11 @@ const std = @import("../std.zig");
|
||||
const assert = std.debug.assert;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub const is_the_target = switch (builtin.os) {
|
||||
.windows => true,
|
||||
else => false,
|
||||
};
|
||||
|
||||
pub use @import("windows/advapi32.zig");
|
||||
pub use @import("windows/kernel32.zig");
|
||||
pub use @import("windows/ntdll.zig");
|
||||
@ -9,10 +14,13 @@ pub use @import("windows/ole32.zig");
|
||||
pub use @import("windows/shell32.zig");
|
||||
|
||||
test "import" {
|
||||
if (is_the_target) {
|
||||
_ = @import("windows/util.zig");
|
||||
}
|
||||
}
|
||||
|
||||
pub const ERROR = @import("windows/error.zig");
|
||||
pub const errno_codes = @import("windows/errno.zig");
|
||||
|
||||
pub const SHORT = c_short;
|
||||
pub const BOOL = c_int;
|
||||
|
1
std/os/windows/errno.zig
Normal file
1
std/os/windows/errno.zig
Normal file
@ -0,0 +1 @@
|
||||
// TODO get these values from msvcrt
|
@ -8,12 +8,6 @@ const mem = std.mem;
|
||||
const BufMap = std.BufMap;
|
||||
const cstr = std.cstr;
|
||||
|
||||
// > The maximum path of 32,767 characters is approximate, because the "\\?\"
|
||||
// > prefix may be expanded to a longer string by the system at run time, and
|
||||
// > this expansion applies to the total length.
|
||||
// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
|
||||
pub const PATH_MAX_WIDE = 32767;
|
||||
|
||||
pub const WaitError = error{
|
||||
WaitAbandoned,
|
||||
WaitTimeOut,
|
||||
@ -38,131 +32,6 @@ pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) Wa
|
||||
};
|
||||
}
|
||||
|
||||
pub fn windowsClose(handle: windows.HANDLE) void {
|
||||
assert(windows.CloseHandle(handle) != 0);
|
||||
}
|
||||
|
||||
pub const ReadError = error{
|
||||
OperationAborted,
|
||||
BrokenPipe,
|
||||
Unexpected,
|
||||
};
|
||||
|
||||
pub const WriteError = error{
|
||||
SystemResources,
|
||||
OperationAborted,
|
||||
BrokenPipe,
|
||||
|
||||
/// See https://github.com/ziglang/zig/issues/1396
|
||||
Unexpected,
|
||||
};
|
||||
|
||||
pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) WriteError!void {
|
||||
var bytes_written: windows.DWORD = undefined;
|
||||
if (windows.WriteFile(handle, bytes.ptr, @intCast(u32, bytes.len), &bytes_written, null) == 0) {
|
||||
const err = windows.GetLastError();
|
||||
return switch (err) {
|
||||
windows.ERROR.INVALID_USER_BUFFER => WriteError.SystemResources,
|
||||
windows.ERROR.NOT_ENOUGH_MEMORY => WriteError.SystemResources,
|
||||
windows.ERROR.OPERATION_ABORTED => WriteError.OperationAborted,
|
||||
windows.ERROR.NOT_ENOUGH_QUOTA => WriteError.SystemResources,
|
||||
windows.ERROR.IO_PENDING => unreachable,
|
||||
windows.ERROR.BROKEN_PIPE => WriteError.BrokenPipe,
|
||||
else => os.unexpectedErrorWindows(err),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn windowsIsTty(handle: windows.HANDLE) bool {
|
||||
if (windowsIsCygwinPty(handle))
|
||||
return true;
|
||||
|
||||
var out: windows.DWORD = undefined;
|
||||
return windows.GetConsoleMode(handle, &out) != 0;
|
||||
}
|
||||
|
||||
pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool {
|
||||
const size = @sizeOf(windows.FILE_NAME_INFO);
|
||||
var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);
|
||||
|
||||
if (windows.GetFileInformationByHandleEx(
|
||||
handle,
|
||||
windows.FileNameInfo,
|
||||
@ptrCast(*c_void, &name_info_bytes[0]),
|
||||
@intCast(u32, name_info_bytes.len),
|
||||
) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);
|
||||
const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)];
|
||||
const name_wide = @bytesToSlice(u16, name_bytes);
|
||||
return mem.indexOf(u16, name_wide, []u16{ 'm', 's', 'y', 's', '-' }) != null or
|
||||
mem.indexOf(u16, name_wide, []u16{ '-', 'p', 't', 'y' }) != null;
|
||||
}
|
||||
|
||||
pub const OpenError = error{
|
||||
SharingViolation,
|
||||
PathAlreadyExists,
|
||||
|
||||
/// When any of the path components can not be found or the file component can not
|
||||
/// be found. Some operating systems distinguish between path components not found and
|
||||
/// file components not found, but they are collapsed into FileNotFound to gain
|
||||
/// consistency across operating systems.
|
||||
FileNotFound,
|
||||
|
||||
AccessDenied,
|
||||
PipeBusy,
|
||||
NameTooLong,
|
||||
|
||||
/// On Windows, file paths must be valid Unicode.
|
||||
InvalidUtf8,
|
||||
|
||||
/// On Windows, file paths cannot contain these characters:
|
||||
/// '/', '*', '?', '"', '<', '>', '|'
|
||||
BadPathName,
|
||||
|
||||
/// See https://github.com/ziglang/zig/issues/1396
|
||||
Unexpected,
|
||||
};
|
||||
|
||||
pub fn windowsOpenW(
|
||||
file_path_w: [*]const u16,
|
||||
desired_access: windows.DWORD,
|
||||
share_mode: windows.DWORD,
|
||||
creation_disposition: windows.DWORD,
|
||||
flags_and_attrs: windows.DWORD,
|
||||
) OpenError!windows.HANDLE {
|
||||
const result = windows.CreateFileW(file_path_w, desired_access, share_mode, null, creation_disposition, flags_and_attrs, null);
|
||||
|
||||
if (result == windows.INVALID_HANDLE_VALUE) {
|
||||
const err = windows.GetLastError();
|
||||
switch (err) {
|
||||
windows.ERROR.SHARING_VIOLATION => return OpenError.SharingViolation,
|
||||
windows.ERROR.ALREADY_EXISTS => return OpenError.PathAlreadyExists,
|
||||
windows.ERROR.FILE_EXISTS => return OpenError.PathAlreadyExists,
|
||||
windows.ERROR.FILE_NOT_FOUND => return OpenError.FileNotFound,
|
||||
windows.ERROR.PATH_NOT_FOUND => return OpenError.FileNotFound,
|
||||
windows.ERROR.ACCESS_DENIED => return OpenError.AccessDenied,
|
||||
windows.ERROR.PIPE_BUSY => return OpenError.PipeBusy,
|
||||
else => return os.unexpectedErrorWindows(err),
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn windowsOpen(
|
||||
file_path: []const u8,
|
||||
desired_access: windows.DWORD,
|
||||
share_mode: windows.DWORD,
|
||||
creation_disposition: windows.DWORD,
|
||||
flags_and_attrs: windows.DWORD,
|
||||
) OpenError!windows.HANDLE {
|
||||
const file_path_w = try sliceToPrefixedFileW(file_path);
|
||||
return windowsOpenW(&file_path_w, desired_access, share_mode, creation_disposition, flags_and_attrs);
|
||||
}
|
||||
|
||||
/// Caller must free result.
|
||||
pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap) ![]u16 {
|
||||
// count bytes needed
|
||||
@ -278,39 +147,3 @@ pub fn windowsGetQueuedCompletionStatus(completion_port: windows.HANDLE, bytes_t
|
||||
}
|
||||
return WindowsWaitResult.Normal;
|
||||
}
|
||||
|
||||
pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {
|
||||
return sliceToPrefixedFileW(mem.toSliceConst(u8, s));
|
||||
}
|
||||
|
||||
pub fn sliceToPrefixedFileW(s: []const u8) ![PATH_MAX_WIDE + 1]u16 {
|
||||
return sliceToPrefixedSuffixedFileW(s, []u16{0});
|
||||
}
|
||||
|
||||
pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) ![PATH_MAX_WIDE + suffix.len]u16 {
|
||||
// TODO well defined copy elision
|
||||
var result: [PATH_MAX_WIDE + suffix.len]u16 = undefined;
|
||||
|
||||
// > File I/O functions in the Windows API convert "/" to "\" as part of
|
||||
// > converting the name to an NT-style name, except when using the "\\?\"
|
||||
// > prefix as detailed in the following sections.
|
||||
// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
|
||||
// Because we want the larger maximum path length for absolute paths, we
|
||||
// disallow forward slashes in zig std lib file functions on Windows.
|
||||
for (s) |byte| {
|
||||
switch (byte) {
|
||||
'/', '*', '?', '"', '<', '>', '|' => return error.BadPathName,
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
const start_index = if (mem.startsWith(u8, s, "\\\\") or !os.path.isAbsolute(s)) 0 else blk: {
|
||||
const prefix = []u16{ '\\', '\\', '?', '\\' };
|
||||
mem.copy(u16, result[0..], prefix);
|
||||
break :blk prefix.len;
|
||||
};
|
||||
const end_index = start_index + try std.unicode.utf8ToUtf16Le(result[start_index..], s);
|
||||
assert(end_index <= result.len);
|
||||
if (end_index + suffix.len > result.len) return error.NameTooLong;
|
||||
mem.copy(u16, result[end_index..], suffix);
|
||||
return result;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ fn posixCallMainAndExit() noreturn {
|
||||
if (builtin.os == builtin.Os.linux) {
|
||||
// Find the beginning of the auxiliary vector
|
||||
const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);
|
||||
std.os.linux_elf_aux_maybe = auxv;
|
||||
std.os.linux.elf_aux_maybe = auxv;
|
||||
// Initialize the TLS area
|
||||
std.os.linux.tls.initTLS();
|
||||
|
||||
@ -99,7 +99,7 @@ fn posixCallMainAndExit() noreturn {
|
||||
// and we want fewer call frames in stack traces.
|
||||
inline fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {
|
||||
std.os.ArgIteratorPosix.raw = argv[0..argc];
|
||||
std.os.posix_environ_raw = envp;
|
||||
std.os.posix.environ = envp;
|
||||
return callMain();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user