diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-05-24 19:36:09 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-05-26 18:32:44 -0400 |
| commit | 3d61e4228298dcb973c13d8d6eba0bff36acf1ca (patch) | |
| tree | d20ca827bdbcfef862a3048df288e65c3971aab5 | |
| parent | 17b0166e004e81d9c433576f4c642e743fc527b7 (diff) | |
| download | zig-3d61e4228298dcb973c13d8d6eba0bff36acf1ca.tar.gz zig-3d61e4228298dcb973c13d8d6eba0bff36acf1ca.zip | |
rename "posix" to "bits"
| -rw-r--r-- | CMakeLists.txt | 63 | ||||
| -rw-r--r-- | std/c.zig | 5 | ||||
| -rw-r--r-- | std/c/linux.zig | 11 | ||||
| -rw-r--r-- | std/c/posix.zig | 26 | ||||
| -rw-r--r-- | std/os.zig | 4 | ||||
| -rw-r--r-- | std/os/bits.zig | 27 | ||||
| -rw-r--r-- | std/os/bits/darwin.zig (renamed from std/c/posix/darwin.zig) | 5 | ||||
| -rw-r--r-- | std/os/bits/freebsd.zig (renamed from std/c/posix/freebsd.zig) | 3 | ||||
| -rw-r--r-- | std/os/bits/linux.zig (renamed from std/os/linux/posix.zig) | 12 | ||||
| -rw-r--r-- | std/os/bits/linux/arm64.zig (renamed from std/os/linux/posix/arm64.zig) | 0 | ||||
| -rw-r--r-- | std/os/bits/linux/errno.zig (renamed from std/os/linux/errno.zig) | 0 | ||||
| -rw-r--r-- | std/os/bits/linux/x86_64.zig (renamed from std/os/linux/posix/x86_64.zig) | 0 | ||||
| -rw-r--r-- | std/os/bits/netbsd.zig (renamed from std/c/posix/netbsd.zig) | 3 | ||||
| -rw-r--r-- | std/os/bits/wasi.zig (renamed from std/os/wasi/posix.zig) | 0 | ||||
| -rw-r--r-- | std/os/bits/windows.zig (renamed from std/c/posix/windows.zig) | 5 | ||||
| -rw-r--r-- | std/os/linux.zig | 2 | ||||
| -rw-r--r-- | std/os/linux/sys.zig | 3 | ||||
| -rw-r--r-- | std/os/wasi.zig | 6 | ||||
| -rw-r--r-- | std/os/windows.zig | 14 | ||||
| -rw-r--r-- | std/os/windows/posix.zig | 6 | ||||
| -rw-r--r-- | std/os/zen.zig | 2 |
21 files changed, 100 insertions, 97 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c41b20569..1c7ceb88b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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"), diff --git a/std/c/linux.zig b/std/c/linux.zig index 48e359f361..388d8edab8 100644 --- a/std/c/linux.zig +++ b/std/c/linux.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; diff --git a/std/c/posix.zig b/std/c/posix.zig deleted file mode 100644 index 5e9ac2b9d8..0000000000 --- a/std/c/posix.zig +++ /dev/null @@ -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, -}; diff --git a/std/os.zig b/std/os.zig index a2fbca812b..5f6716e017 100644 --- a/std/os.zig +++ b/std/os.zig @@ -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; diff --git a/std/os/bits.zig b/std/os/bits.zig new file mode 100644 index 0000000000..7b87cc6e4d --- /dev/null +++ b/std/os/bits.zig @@ -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, +}; diff --git a/std/c/posix/darwin.zig b/std/os/bits/darwin.zig index a3c0e1e966..ed64a6426a 100644 --- a/std/c/posix/darwin.zig +++ b/std/os/bits/darwin.zig @@ -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); diff --git a/std/c/posix/freebsd.zig b/std/os/bits/freebsd.zig index 62ad55aa06..941181f221 100644 --- a/std/c/posix/freebsd.zig +++ b/std/os/bits/freebsd.zig @@ -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 { diff --git a/std/os/linux/posix.zig b/std/os/bits/linux.zig index 803f786045..40b554b27f 100644 --- a/std/os/linux/posix.zig +++ b/std/os/bits/linux.zig @@ -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, +}; diff --git a/std/os/linux/posix/arm64.zig b/std/os/bits/linux/arm64.zig index 8966df30d2..8966df30d2 100644 --- a/std/os/linux/posix/arm64.zig +++ b/std/os/bits/linux/arm64.zig diff --git a/std/os/linux/errno.zig b/std/os/bits/linux/errno.zig index 5ad8777f92..5ad8777f92 100644 --- a/std/os/linux/errno.zig +++ b/std/os/bits/linux/errno.zig diff --git a/std/os/linux/posix/x86_64.zig b/std/os/bits/linux/x86_64.zig index 12ac6b8d7a..12ac6b8d7a 100644 --- a/std/os/linux/posix/x86_64.zig +++ b/std/os/bits/linux/x86_64.zig diff --git a/std/c/posix/netbsd.zig b/std/os/bits/netbsd.zig index 0dc9267254..4a9cf0391c 100644 --- a/std/c/posix/netbsd.zig +++ b/std/os/bits/netbsd.zig @@ -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, diff --git a/std/os/wasi/posix.zig b/std/os/bits/wasi.zig index 4a8be6890a..4a8be6890a 100644 --- a/std/os/wasi/posix.zig +++ b/std/os/bits/wasi.zig diff --git a/std/c/posix/windows.zig b/std/os/bits/windows.zig index 6ce678af2b..d3558958ff 100644 --- a/std/c/posix/windows.zig +++ b/std/os/bits/windows.zig @@ -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; diff --git a/std/os/linux.zig b/std/os/linux.zig index 4a3cd59132..40e9fa5108 100644 --- a/std/os/linux.zig +++ b/std/os/linux.zig @@ -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"); } diff --git a/std/os/linux/sys.zig b/std/os/linux/sys.zig index a5939c579b..272124f06c 100644 --- a/std/os/linux/sys.zig +++ b/std/os/linux/sys.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; diff --git a/std/os/wasi.zig b/std/os/wasi.zig index e7f2212a3a..1ce0fe0c92 100644 --- a/std/os/wasi.zig +++ b/std/os/wasi.zig @@ -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); diff --git a/std/os/windows.zig b/std/os/windows.zig index d1b8c81ed9..70772ee807 100644 --- a/std/os/windows.zig +++ b/std/os/windows.zig @@ -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()) { diff --git a/std/os/windows/posix.zig b/std/os/windows/posix.zig deleted file mode 100644 index 0bec450bd8..0000000000 --- a/std/os/windows/posix.zig +++ /dev/null @@ -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; diff --git a/std/os/zen.zig b/std/os/zen.zig index 0564956b24..6931b07f78 100644 --- a/std/os/zen.zig +++ b/std/os/zen.zig @@ -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); |
