mirror of
https://github.com/ziglang/zig.git
synced 2024-11-14 16:13:24 +00:00
rename "posix" to "bits"
This commit is contained in:
parent
17b0166e00
commit
3d61e42282
@ -474,10 +474,7 @@ set(ZIG_STD_FILES
|
||||
"c/linux.zig"
|
||||
"c/netbsd.zig"
|
||||
"c/windows.zig"
|
||||
"c/posix.zig"
|
||||
"c/posix/darwin.zig"
|
||||
"c/posix/freebsd.zig"
|
||||
"c/posix/windows.zig"
|
||||
"child_process.zig"
|
||||
"coff.zig"
|
||||
"crypto.zig"
|
||||
"crypto/blake2.zig"
|
||||
@ -491,8 +488,8 @@ set(ZIG_STD_FILES
|
||||
"crypto/x25519.zig"
|
||||
"cstr.zig"
|
||||
"debug.zig"
|
||||
"debug/leb128.zig"
|
||||
"debug/failing_allocator.zig"
|
||||
"debug/leb128.zig"
|
||||
"dwarf.zig"
|
||||
"dynamic_library.zig"
|
||||
"elf.zig"
|
||||
@ -513,6 +510,10 @@ set(ZIG_STD_FILES
|
||||
"fmt/errol/enum3.zig"
|
||||
"fmt/errol/lookup.zig"
|
||||
"fmt/parse_float.zig"
|
||||
"fs.zig"
|
||||
"fs/file.zig"
|
||||
"fs/get_app_data_dir.zig"
|
||||
"fs/path.zig"
|
||||
"hash.zig"
|
||||
"hash/adler.zig"
|
||||
"hash/crc.zig"
|
||||
@ -521,8 +522,8 @@ set(ZIG_STD_FILES
|
||||
"hash_map.zig"
|
||||
"heap.zig"
|
||||
"io.zig"
|
||||
"io/seekable_stream.zig"
|
||||
"io/c_out_stream.zig"
|
||||
"io/seekable_stream.zig"
|
||||
"json.zig"
|
||||
"lazy_init.zig"
|
||||
"linked_list.zig"
|
||||
@ -604,46 +605,40 @@ set(ZIG_STD_FILES
|
||||
"mutex.zig"
|
||||
"net.zig"
|
||||
"os.zig"
|
||||
"os/child_process.zig"
|
||||
"os/bits.zig"
|
||||
"os/bits/darwin.zig"
|
||||
"os/bits/freebsd.zig"
|
||||
"os/bits/linux.zig"
|
||||
"os/bits/linux/arm64.zig"
|
||||
"os/bits/linux/errno.zig"
|
||||
"os/bits/linux/x86_64.zig"
|
||||
"os/bits/netbsd.zig"
|
||||
"os/bits/wasi.zig"
|
||||
"os/bits/windows.zig"
|
||||
"os/darwin.zig"
|
||||
"os/darwin/errno.zig"
|
||||
"os/epoch.zig"
|
||||
"os/file.zig"
|
||||
"os/freebsd.zig"
|
||||
"os/freebsd/errno.zig"
|
||||
"os/get_app_data_dir.zig"
|
||||
"os/get_user_id.zig"
|
||||
"os/linux.zig"
|
||||
"os/linux/arm64.zig"
|
||||
"os/linux/errno.zig"
|
||||
"os/linux/posix.zig"
|
||||
"os/linux/posix/arm64.zig"
|
||||
"os/linux/posix/x86_64.zig"
|
||||
"os/linux/sys.zig"
|
||||
"os/linux/tls.zig"
|
||||
"os/linux/vdso.zig"
|
||||
"os/linux/x86_64.zig"
|
||||
"os/netbsd.zig"
|
||||
"os/netbsd/errno.zig"
|
||||
"os/path.zig"
|
||||
"os/posix.zig"
|
||||
"os/time.zig"
|
||||
"os/uefi.zig"
|
||||
"os/wasi.zig"
|
||||
"os/wasi/posix.zig"
|
||||
"os/windows.zig"
|
||||
"os/windows/advapi32.zig"
|
||||
"os/windows/errno.zig"
|
||||
"os/windows/error.zig"
|
||||
"os/windows/kernel32.zig"
|
||||
"os/windows/ntdll.zig"
|
||||
"os/windows/ole32.zig"
|
||||
"os/windows/shell32.zig"
|
||||
"os/windows/util.zig"
|
||||
"os/zen.zig"
|
||||
"packed_int_array.zig"
|
||||
"pdb.zig"
|
||||
"priority_queue.zig"
|
||||
"process.zig"
|
||||
"rand.zig"
|
||||
"rand/ziggurat.zig"
|
||||
"rb.zig"
|
||||
@ -655,17 +650,18 @@ set(ZIG_STD_FILES
|
||||
"special/build_runner.zig"
|
||||
"special/c.zig"
|
||||
"special/compiler_rt.zig"
|
||||
"special/compiler_rt/stack_probe.zig"
|
||||
"special/compiler_rt/arm/aeabi_fcmp.zig"
|
||||
"special/compiler_rt/arm/aeabi_dcmp.zig"
|
||||
"special/compiler_rt/addXf3.zig"
|
||||
"special/compiler_rt/arm/aeabi_dcmp.zig"
|
||||
"special/compiler_rt/arm/aeabi_fcmp.zig"
|
||||
"special/compiler_rt/ashlti3.zig"
|
||||
"special/compiler_rt/ashrti3.zig"
|
||||
"special/compiler_rt/aulldiv.zig"
|
||||
"special/compiler_rt/aullrem.zig"
|
||||
"special/compiler_rt/comparetf2.zig"
|
||||
"special/compiler_rt/comparedf2.zig"
|
||||
"special/compiler_rt/comparesf2.zig"
|
||||
"special/compiler_rt/divsf3.zig"
|
||||
"special/compiler_rt/comparetf2.zig"
|
||||
"special/compiler_rt/divdf3.zig"
|
||||
"special/compiler_rt/divsf3.zig"
|
||||
"special/compiler_rt/divti3.zig"
|
||||
"special/compiler_rt/extendXfYf2.zig"
|
||||
"special/compiler_rt/fixdfdi.zig"
|
||||
@ -690,26 +686,25 @@ set(ZIG_STD_FILES
|
||||
"special/compiler_rt/fixunstfti.zig"
|
||||
"special/compiler_rt/floatdidf.zig"
|
||||
"special/compiler_rt/floatsiXf.zig"
|
||||
"special/compiler_rt/floatunsidf.zig"
|
||||
"special/compiler_rt/floattidf.zig"
|
||||
"special/compiler_rt/floattisf.zig"
|
||||
"special/compiler_rt/floattitf.zig"
|
||||
"special/compiler_rt/floatundidf.zig"
|
||||
"special/compiler_rt/floatunditf.zig"
|
||||
"special/compiler_rt/floatunsidf.zig"
|
||||
"special/compiler_rt/floatunsitf.zig"
|
||||
"special/compiler_rt/floatuntidf.zig"
|
||||
"special/compiler_rt/floatuntisf.zig"
|
||||
"special/compiler_rt/floatuntitf.zig"
|
||||
"special/compiler_rt/lshrti3.zig"
|
||||
"special/compiler_rt/modti3.zig"
|
||||
"special/compiler_rt/mulXf3.zig"
|
||||
"special/compiler_rt/muloti4.zig"
|
||||
"special/compiler_rt/mulodi4.zig"
|
||||
"special/compiler_rt/muloti4.zig"
|
||||
"special/compiler_rt/multi3.zig"
|
||||
"special/compiler_rt/ashlti3.zig"
|
||||
"special/compiler_rt/ashrti3.zig"
|
||||
"special/compiler_rt/lshrti3.zig"
|
||||
"special/compiler_rt/negXf2.zig"
|
||||
"special/compiler_rt/popcountdi2.zig"
|
||||
"special/compiler_rt/stack_probe.zig"
|
||||
"special/compiler_rt/truncXfYf2.zig"
|
||||
"special/compiler_rt/udivmod.zig"
|
||||
"special/compiler_rt/udivmoddi4.zig"
|
||||
@ -726,6 +721,8 @@ set(ZIG_STD_FILES
|
||||
"statically_initialized_mutex.zig"
|
||||
"std.zig"
|
||||
"testing.zig"
|
||||
"thread.zig"
|
||||
"time.zig"
|
||||
"unicode.zig"
|
||||
"valgrind.zig"
|
||||
"valgrind/callgrind.zig"
|
||||
|
@ -1,10 +1,9 @@
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub const posix = @import("c/posix.zig");
|
||||
pub use posix;
|
||||
pub use @import("os/bits.zig");
|
||||
|
||||
pub use switch (builtin.os) {
|
||||
.linux => @import("os/linux/posix.zig"),
|
||||
.linux => @import("c/linux.zig"),
|
||||
.windows => @import("c/windows.zig"),
|
||||
.macosx, .ios, .tvos, .watchos => @import("c/darwin.zig"),
|
||||
.freebsd => @import("c/freebsd.zig"),
|
||||
|
@ -1,17 +1,12 @@
|
||||
const linux = @import("../os/linux.zig");
|
||||
pub use @import("../os/linux/errno.zig");
|
||||
const std = @import("../std.zig");
|
||||
use std.c;
|
||||
|
||||
pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int;
|
||||
extern "c" fn __errno_location() *c_int;
|
||||
pub const _errno = __errno_location;
|
||||
|
||||
pub const pthread_attr_t = extern struct {
|
||||
__size: [56]u8,
|
||||
__align: c_long,
|
||||
};
|
||||
|
||||
/// See std.elf for constants for this
|
||||
pub extern fn getauxval(__type: c_ulong) c_ulong;
|
||||
|
||||
pub const dl_iterate_phdr_callback = extern fn (info: *linux.dl_phdr_info, size: usize, data: ?*c_void) c_int;
|
||||
pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
|
||||
pub extern fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Declarations that are intended to be imported into the POSIX namespace.
|
||||
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub use switch (builtin.os) {
|
||||
.windows => @import("posix/windows.zig"),
|
||||
.macosx, .ios, .tvos, .watchos => @import("posix/darwin.zig"),
|
||||
.freebsd => @import("posix/freebsd.zig"),
|
||||
.netbsd => @import("posix/netbsd.zig"),
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
pub const fd_t = c_int;
|
||||
pub const pid_t = c_int;
|
||||
pub const pthread_t = *@OpaqueType();
|
||||
pub const FILE = @OpaqueType();
|
||||
|
||||
pub const iovec = extern struct {
|
||||
iov_base: [*]u8,
|
||||
iov_len: usize,
|
||||
};
|
||||
|
||||
pub const iovec_const = extern struct {
|
||||
iov_base: [*]const u8,
|
||||
iov_len: usize,
|
||||
};
|
@ -19,7 +19,7 @@ const builtin = @import("builtin");
|
||||
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
|
||||
|
||||
comptime {
|
||||
assert(@import("std") == std); // You have to run the std lib tests with --override-std-dir
|
||||
assert(@import("std") == std); // std lib tests require --override-std-dir
|
||||
}
|
||||
|
||||
pub const darwin = @import("os/darwin.zig");
|
||||
@ -43,6 +43,8 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) {
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
pub use @import("os/bits.zig");
|
||||
|
||||
/// See also `getenv`.
|
||||
pub var environ: [][*]u8 = undefined;
|
||||
|
||||
|
27
std/os/bits.zig
Normal file
27
std/os/bits.zig
Normal file
@ -0,0 +1,27 @@
|
||||
// Platform-dependent types and values that are used along with OS-specific APIs.
|
||||
// These are imported into `std.c`, `std.os`, and `std.os.linux`.
|
||||
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub use switch (builtin.os) {
|
||||
.macosx, .ios, .tvos, .watchos => @import("bits/darwin.zig"),
|
||||
.freebsd => @import("bits/freebsd.zig"),
|
||||
.linux => @import("bits/linux.zig"),
|
||||
.netbsd => @import("bits/netbsd.zig"),
|
||||
.wasi => @import("bits/wasi.zig"),
|
||||
.windows => @import("bits/windows.zig"),
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
pub const pthread_t = *@OpaqueType();
|
||||
pub const FILE = @OpaqueType();
|
||||
|
||||
pub const iovec = extern struct {
|
||||
iov_base: [*]u8,
|
||||
iov_len: usize,
|
||||
};
|
||||
|
||||
pub const iovec_const = extern struct {
|
||||
iov_base: [*]const u8,
|
||||
iov_len: usize,
|
||||
};
|
@ -1,6 +1,9 @@
|
||||
const std = @import("../std.zig");
|
||||
const std = @import("../../std.zig");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
pub const fd_t = c_int;
|
||||
pub const pid_t = c_int;
|
||||
|
||||
pub fn sigaction(sig: u5, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
|
||||
assert(sig != SIGKILL);
|
||||
assert(sig != SIGSTOP);
|
@ -1,4 +1,5 @@
|
||||
const std = @import("../std.zig");
|
||||
pub const fd_t = c_int;
|
||||
pub const pid_t = c_int;
|
||||
|
||||
/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
|
||||
pub const Kevent = extern struct {
|
@ -1,10 +1,7 @@
|
||||
// Declarations that are intended to be imported into the POSIX namespace.
|
||||
// This includes Linux-only APIs.
|
||||
|
||||
pub use @import("errno.zig");
|
||||
pub use switch (builtin.arch) {
|
||||
.x86_64 => @import("posix/x86_64.zig"),
|
||||
.aarch64 => @import("posix/arm64.zig"),
|
||||
.x86_64 => @import("linux/x86_64.zig"),
|
||||
.aarch64 => @import("linux/arm64.zig"),
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
@ -915,3 +912,8 @@ pub const dl_phdr_info = extern struct {
|
||||
dlpi_phdr: [*]elf.Phdr,
|
||||
dlpi_phnum: u16,
|
||||
};
|
||||
|
||||
pub const pthread_attr_t = extern struct {
|
||||
__size: [56]u8,
|
||||
__align: c_long,
|
||||
};
|
@ -1,6 +1,9 @@
|
||||
const std = @import("../../std.zig");
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub const fd_t = c_int;
|
||||
pub const pid_t = c_int;
|
||||
|
||||
/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
|
||||
pub const Kevent = extern struct {
|
||||
ident: usize,
|
@ -1,3 +1,8 @@
|
||||
use @import("../windows.zig");
|
||||
|
||||
pub const fd_t = HANDLE;
|
||||
pub const pid_t = HANDLE;
|
||||
|
||||
pub const EPERM = 1;
|
||||
pub const ENOENT = 2;
|
||||
pub const ESRCH = 3;
|
@ -4,7 +4,7 @@ pub const is_the_target = builtin.os == .linux;
|
||||
pub const sys = @import("linux/sys.zig");
|
||||
pub use if (builtin.link_libc) std.c else sys;
|
||||
|
||||
test "import" {
|
||||
test "" {
|
||||
if (is_the_target) {
|
||||
_ = @import("linux/test.zig");
|
||||
}
|
||||
|
@ -17,8 +17,7 @@ pub use switch (builtin.arch) {
|
||||
.aarch64 => @import("arm64.zig"),
|
||||
else => struct {},
|
||||
};
|
||||
pub const posix = @import("posix.zig");
|
||||
pub use posix;
|
||||
pub use @import("../bits.zig");
|
||||
|
||||
/// See `std.os.posix.getauxval`.
|
||||
pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
|
||||
|
@ -1,11 +1,11 @@
|
||||
// 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 builtin = @import("builtin");
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
pub const is_the_target = @import("builtin").os == .wasi;
|
||||
pub const posix = @import("wasi/posix.zig");
|
||||
pub use posix;
|
||||
pub const is_the_target = builtin.os == .wasi;
|
||||
pub use @import("bits/wasi.zig");
|
||||
|
||||
comptime {
|
||||
assert(@alignOf(i8) == 1);
|
||||
|
@ -1,12 +1,14 @@
|
||||
// This file contains the types and constants of the Windows API,
|
||||
// as well as the Windows-equivalent of "Zig-flavored POSIX" API layer.
|
||||
// This file contains thin wrappers around Windows-specific APIs, with these
|
||||
// specific goals in mind:
|
||||
// * Convert "errno"-style error codes into Zig errors.
|
||||
// * When null-terminated or UTF16LE byte buffers are required, provide APIs which accept
|
||||
// slices as well as APIs which accept null-terminated UTF16LE byte buffers.
|
||||
|
||||
const std = @import("../std.zig");
|
||||
const assert = std.debug.assert;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub const is_the_target = builtin.os == .windows;
|
||||
pub const posix = if (builtin.link_libc) struct {} else @import("windows/posix.zig");
|
||||
pub use posix;
|
||||
|
||||
pub const advapi32 = @import("windows/advapi32.zig");
|
||||
pub const kernel32 = @import("windows/kernel32.zig");
|
||||
@ -565,7 +567,7 @@ pub fn CreateFile(
|
||||
share_mode: DWORD,
|
||||
creation_disposition: DWORD,
|
||||
flags_and_attrs: DWORD,
|
||||
) CreateFileError!fd_t {
|
||||
) CreateFileError!HANDLE {
|
||||
const file_path_w = try sliceToPrefixedFileW(file_path);
|
||||
return CreateFileW(&file_path_w, desired_access, share_mode, creation_disposition, flags_and_attrs);
|
||||
}
|
||||
@ -934,7 +936,7 @@ pub const GetStdHandleError = error{
|
||||
Unexpected,
|
||||
};
|
||||
|
||||
pub fn GetStdHandle(handle_id: DWORD) GetStdHandleError!fd_t {
|
||||
pub fn GetStdHandle(handle_id: DWORD) GetStdHandleError!HANDLE {
|
||||
const handle = kernel32.GetStdHandle(handle_id) orelse return error.NoStandardHandleAttached;
|
||||
if (handle == INVALID_HANDLE_VALUE) {
|
||||
switch (kernel32.GetLastError()) {
|
||||
|
@ -1,6 +0,0 @@
|
||||
// Declarations that are intended to be imported into the POSIX namespace,
|
||||
// when not linking libc.
|
||||
const std = @import("../../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub const fd_t = std.os.windows.HANDLE;
|
@ -80,7 +80,7 @@ pub const STDOUT_FILENO = 1;
|
||||
pub const STDERR_FILENO = 2;
|
||||
|
||||
// FIXME: let's borrow Linux's error numbers for now.
|
||||
use @import("linux/errno.zig");
|
||||
use @import("../bits/linux/errno.zig");
|
||||
// Get the errno from a syscall return value, or 0 for no error.
|
||||
pub fn getErrno(r: usize) usize {
|
||||
const signed_r = @bitCast(isize, r);
|
||||
|
Loading…
Reference in New Issue
Block a user