Commit Graph

1874 Commits

Author SHA1 Message Date
Benjamin Feng c11d1055b8 Integrated outstreams with new formatter 2020-03-12 10:26:28 -05:00
LemonBoy 11df0d0cf8 std: Add setEndPos to fs.file
Allow the user to shrink/grow the file size as needed.
2020-03-12 09:43:45 +01:00
LemonBoy 89d7fc773d std: Fix pwrite invocation on 32bit architectures 2020-03-12 09:43:45 +01:00
Heppokoyuki 3f1c8e3d58 fix bug 2020-03-12 00:29:30 -04:00
Andrew Kelley 3ded862cdf Merge pull request #4713 from Heppokoyuki/uefi-file-protocols
UEFI library improvements
2020-03-11 21:44:50 -04:00
Andrew Kelley 06d2f53ece windows: detect HANDLE_EOF in ReadFile 2020-03-11 17:39:53 -04:00
Andrew Kelley d96b6c0d9f fix footguns in File readAll functions 2020-03-11 13:06:30 -04:00
Heppokoyuki 58941927c4 refactor 2020-03-12 00:24:00 +09:00
Heppokoyuki 02ba1d8fe1 add file protocols 2020-03-12 00:24:00 +09:00
Andrew Kelley 18f1fef142 update standard library to new I/O streams API 2020-03-10 18:44:30 -04:00
LemonBoy 3e93dce0a1 std: Fix detection of Linux kernel version 2020-03-10 12:55:35 -04:00
daurnimator 648f94c027 std: add some definitions for netlink sockets 2020-03-09 13:02:38 -04:00
LeRoyce Pearson 25d9ab95dd Use os.ino_t for everything
Also, define ino_t for windows
2020-03-08 21:52:36 -06:00
LeRoyce Pearson cb84875eed Define ino_t for systems not yet defining it
Also, use ino_t instead of u64 in fs.File.INode
2020-03-08 18:31:18 -06:00
Andrew Kelley 6ac76bc25e add missing errors to std.os.windows.CreateDirectoryError 2020-03-07 19:13:21 -05:00
Andrew Kelley 7df9169081 Merge pull request #4651 from LemonBoy/fix-4645
std: Nicer way to access the PEB
2020-03-06 17:33:05 -05:00
Andrew Kelley 3163a16617 ?HMODULE instead of HMODULE 2020-03-06 16:57:59 -05:00
LemonBoy 2e04b61275 std: Work around unexported NtCurrentTeb
Apparently NtCurrentTeb is only exported for i386 and some other
platforms but not for x86_64 nor AArch64. Let's go with the flow and
provide our own NtCurrentTeb like the Windows headers do.

Thank you Microsoft.
2020-03-06 09:17:14 +01:00
LemonBoy b9a1d67637 std: Nicer way to access the PEB
Use the NtCurrentTeb API instead of using some inline asm, this is much
nicer and also more portable.

Closes #4645
2020-03-06 09:06:26 +01:00
Andrew Kelley 4a67dd04c9 breaking changes to std.fs, std.os
* improve `std.fs.AtomicFile` to use sendfile()
   - also fix AtomicFile cleanup not destroying tmp files under some
     error conditions
 * improve `std.fs.updateFile` to take advantage of the new `makePath`
   which no longer needs an Allocator.
 * rename std.fs.makeDir to std.fs.makeDirAbsolute
 * rename std.fs.Dir.makeDirC to std.fs.Dir.makeDirZ
 * add std.fs.Dir.makeDirW and provide Windows implementation of
   std.os.mkdirat. std.os.windows.CreateDirectory is now implemented
   by calling ntdll, supports an optional root directory handle,
   and returns an open directory handle. Its error set has a few more
   errors in it.
 * rename std.fs.Dir.changeTo to std.fs.Dir.setAsCwd
 * fix std.fs.File.writevAll and related functions when len 0 iovecs
   supplied.
 * introduce `std.fs.File.writeFileAll`, exposing a convenient
   cross-platform API on top of sendfile().
 * `NoDevice` added to std.os.MakeDirError error set.
 * std.os.fchdir gets a smaller error set.
 * std.os.windows.CloseHandle is implemented with ntdll call rather than
   kernel32.
2020-03-03 15:23:27 -05:00
daurnimator 1ca5f06762 Update callers of fs.makePath 2020-03-03 13:25:43 -05:00
daurnimator 627618a38d std: add Dir.changeDir as wrapper around fchdir 2020-03-03 13:25:43 -05:00
Andrew Kelley 582db68a15 remove superfluous comptime keyword 2020-03-03 12:01:17 -05:00
LemonBoy a6fb6dcfc9 linux: Correct pread64 syscall for ARM/MIPS
Closes #4615
2020-03-03 11:59:16 -05:00
Andrew Kelley 226b801830 Merge pull request #4612 from ziglang/os-read-write-sendfile
std.os read/write functions + sendfile
2020-03-03 10:15:37 -05:00
Andrew Kelley 9d6cc75ce3 disable sendfile test on mips 2020-03-03 09:49:46 -05:00
Alexandros Naskos 7559418305 Added comment justifying wrapping operations 2020-03-03 12:41:11 +02:00
Andrew Kelley 859fc856d3 fix macosx and freebsd build failures 2020-03-03 02:57:11 -05:00
Andrew Kelley c81345c8ae breaking: std.os read/write functions + sendfile
* rework os.sendfile and add macosx support, and a fallback
   implementation for any OS.
 * fix sendto compile error
 * std.os write functions support partial writes. closes #3443.
 * std.os pread / pwrite functions can now return `error.Unseekable`.
 * std.fs.File read/write functions now have readAll/writeAll variants
   which loop to complete operations even when partial reads/writes
   happen.
 * Audit std.os read/write functions with respect to Linux returning
   EINVAL for lengths greater than 0x7fff0000.
 * std.os read/write shim functions do not unnecessarily loop. Since
   partial reads/writes are part of the API, the caller will be forced
   to loop anyway, and so that would just be code bloat.
 * Improve doc comments
 * Add a non-trivial test for std.os.sendfile
 * Fix std.os.pread on 32 bit Linux
 * Add missing SYS_sendfile bit on aarch64
2020-03-03 02:25:26 -05:00
Terin Stock bd287dd194 std: implement sendfile on linux
This changset adds a `sendfile(2)` syscall bindings to the linux bits
component. Where available, the `sendfile64(2)` syscall will be
transparently called.

A wrapping function has also been added to the std.os to transform
errno returns to Zig errors.

Change-Id: I86769fc4382c0771e3656e7b21137bafd99a4411
2020-03-02 12:54:50 -05:00
Alexandros Naskos a48cd1cf58 Allow wrapping in VDSO lookup 2020-03-02 11:44:21 +02:00
Andrew Kelley ae99fabfe4 Merge pull request #4585 from LemonBoy/fix-4581
target: Implement OS version detection for Windows
2020-03-01 02:53:51 -05:00
daurnimator d0c22619f5 Complete windows PEB_LDR_DATA definition 2020-03-01 02:10:29 +11:00
daurnimator 513076ee9c Fill out PEB definition 2020-03-01 00:12:08 +11:00
LemonBoy f072b0c056 target: Implement OS version detection for Windows
Closes #4581
2020-02-29 12:02:40 +01:00
Andrew Kelley 4616af0ca4 introduce operating system version ranges as part of the target
* re-introduce `std.build.Target` which is distinct from `std.Target`.
   `std.build.Target` wraps `std.Target` so that it can be annotated as
   "the native target" or an explicitly specified target.
 * `std.Target.Os` is moved to `std.Target.Os.Tag`. The former is now a
   struct which has the tag as well as version range information.
 * `std.elf` gains some more ELF header constants.
 * `std.Target.parse` gains the ability to parse operating system
   version ranges as well as glibc version.
 * Added `std.Target.isGnuLibC()`.
 * self-hosted dynamic linker detection and glibc version detection.
   This also adds the improved logic using `/usr/bin/env` rather than
   invoking the system C compiler to find the dynamic linker when zig
   is statically linked. Related: #2084
   Note: this `/usr/bin/env` code is work-in-progress.
 * `-target-glibc` CLI option is removed in favor of the new `-target`
   syntax. Example: `-target x86_64-linux-gnu.2.27`

closes #1907
2020-02-28 14:51:53 -05:00
Vexu 538d9a5dd8 remove uses of @ArgType and @IntType 2020-02-24 23:39:03 +02:00
Andrew Kelley cfffb9c5e9 improve handling of environment variables on Windows
std.os.getenv and std.os.getenvZ have nice compile errors when not linking
libc and using Windows.

std.os.getenvW is provided as a Windows-only API that does not require
an allocator. It uses the Process Environment Block.
std.process.getEnvVarOwned is improved to be a simple wrapper on top of
std.os.getenvW.

std.process.getEnvMap is improved to use the Process Environment Block
rather than calling GetEnvironmentVariableW.

std.zig.system.NativePaths uses process.getEnvVarOwned instead of
std.os.getenvZ, which works on Windows as well as POSIX.
2020-02-22 17:35:36 -05:00
Andrew Kelley 3c76e5e33d update tls in std lib for lack of sub-arch 2020-02-19 22:09:35 -05:00
Andrew Kelley b53afc510c update dl_iterate_phdr test case to new API 2020-02-17 17:22:32 -05:00
Andrew Kelley 8173fbfb66 implement os.faccessat for Windows 2020-02-16 17:10:43 -05:00
Andrew Kelley 4b02a39aa9 self-hosted libc detection
* libc_installation.cpp is deleted.
   src-self-hosted/libc_installation.zig is now used for both stage1 and
   stage2 compilers.
 * (breaking) move `std.fs.File.access` to `std.fs.Dir.access`. The API
   now encourages use with an open directory handle.
 * Add `std.os.faccessat` and related functions.
 * Deprecate the "C" suffix naming convention for null-terminated
   parameters. "C" should be used when it is related to libc. However
   null-terminated parameters often have to do with the native system
   ABI rather than libc. "Z" suffix is the new convention. For example,
   `std.os.openC` is deprecated in favor of `std.os.openZ`.
 * Add `std.mem.dupeZ` for using an allocator to copy memory and add a
   null terminator.
 * Remove dead struct field `std.ChildProcess.llnode`.
 * Introduce `std.event.Batch`. This API allows expressing concurrency
   without forcing code to be async. It requires no Allocator and does
   not introduce any failure conditions. However it is not thread-safe.
 * There is now an ongoing experiment to transition away from
   `std.event.Group` in favor of `std.event.Batch`.
 * `std.os.execvpeC` calls `getenvZ` rather than `getenv`. This is
   slightly more efficient on most systems, and works around a
   limitation of `getenv` lack of integration with libc.
 * (breaking) `std.os.AccessError` gains `FileBusy`, `SymLinkLoop`, and
   `ReadOnlyFileSystem`. Previously these error codes were all reported
   as `PermissionDenied`.
 * Add `std.Target.isDragonFlyBSD`.
 * stage2: access to the windows_sdk functions is done with a manually
   maintained .zig binding file instead of `@cImport`.
 * Update src-self-hosted/libc_installation.zig with all the
   improvements that stage1 has seen to src/libc_installation.cpp until
   now. In addition, it now takes advantage of Batch so that evented I/O
   mode takes advantage of concurrency, but it still works in blocking
   I/O mode, which is how it is used in stage1.
2020-02-16 13:25:30 -05:00
Andrew Kelley e8dfc5e7f6 Merge pull request #4442 from fengb/testing-allocator-calls
Migrate tests from FixedBufferAllocator to testing.allocator
2020-02-13 16:17:21 -05:00
LemonBoy f93c219f30 Minor changes for a test case 2020-02-13 12:13:56 +01:00
Benjamin Feng 699c50a375 Switch a bunch of FBA to use testing.allocator 2020-02-12 17:17:56 -06:00
Andrew Kelley 702398dd0e Revert "windows: remove the 'A' versions of psapi functions"
This reverts commit 1cdefeb10b.

See #4426
2020-02-10 12:30:20 -05:00
Andrew Kelley 1cdefeb10b windows: remove the 'A' versions of psapi functions
See #534
2020-02-10 12:03:11 -05:00
Andrew Kelley 014f66e6de Merge pull request #4404 from ziglang/async-std
a big step towards std lib integration with async I/O
2020-02-10 00:22:59 -05:00
LemonBoy a779450fef linux/i386: Make syscall6 more robust and correct
LLVM10 exposed a subtle flaw in the previous implementation that made
the mmap tests fail.
2020-02-07 22:13:05 +01:00
Andrew Kelley 7f4cce3345 add fcntl support on darwin 2020-02-07 12:11:15 -05:00