aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os.zig
AgeCommit message (Collapse)Author
2020-03-23Fix compile error on windowsLeRoyce Pearson
2020-03-23std: Use getdents on all the BSDsLemonBoy
* Use the correct versioned libc calls to avoid nasty surprises
2020-03-23std: Add missing C defines for NetBSDLemonBoy
2020-03-18std: Introduce fnctl wrapperLemonBoy
2020-03-17fix a couple sockfds to be fd_t rather than i32Jonathan Marler
Using i32 causes compile errors on Windows because it uses *c_void rather than i32 for it's fd_t type.
2020-03-15adjust renameatW to always supply dest root dirAndrew Kelley
this fixes tests for wine
2020-03-15fix std.os.renameatWAndrew Kelley
Ask for DELETE access when opening the source file. Additionally, when the source and dest dir are the same, pass null for RootDirectory.
2020-03-15renameatW: handle more windows nt status codesAndrew Kelley
2020-03-13zig build system: correctly handle multiple output artifactsAndrew Kelley
Previously the zig build system incorrectly assumed that the only build artifact was a binary. Now, when you enable the cache, only the output dir is printed to stdout, and the zig build system iterates over the files in that directory, copying them to the output directory. To support this change: * Add `std.os.renameat`, `std.os.renameatZ`, and `std.os.renameatW`. * Fix `std.os.linux.renameat` not compiling due to typos. * Deprecate `std.fs.updateFile` and `std.fs.updateFileMode`. * Add `std.fs.Dir.updateFile`, which supports using open directory handles for both the source and destination paths, as well as an options parameter which allows overriding the mode. * Update `std.fs.AtomicFile` to support operating based on an open directory handle. Instead of `std.fs.AtomicFile.init`, use `std.fs.Dir.atomicFile`. * `std.fs.AtomicFile` deinit() better handles the situation when the rename fails but the temporary file still exists, by still attempting to remove the temporary file. * `std.fs.Dir.openFileWindows` is moved to `std.os.windows.OpenFileW`. * `std.os.RenameError` gains the error codes `NoDevice`, `SharingViolation`, and `PipeBusy` which have been observed from Windows. Closes #4733
2020-03-13Merge pull request #4716 from LemonBoy/sys-miscAndrew Kelley
Introduce std.fs.file.setEndPos
2020-03-13Add NtDll-based ftruncate implementationLemonBoy
2020-03-12std/os/uefi: status reformNick Erdmann
2020-03-12Address review commentsLemonBoy
2020-03-12std: Add setEndPos to fs.fileLemonBoy
Allow the user to shrink/grow the file size as needed.
2020-03-10(breaking) rework stream abstractionsAndrew Kelley
The main goal here is to make the function pointers comptime, so that we don't have to do the crazy stuff with async function frames. Since InStream, OutStream, and SeekableStream are already generic across error sets, it's not really worse to make them generic across the vtable as well. See #764 for the open issue acknowledging that using generics for these abstractions is a design flaw. See #130 for the efforts to make these abstractions non-generic. This commit also changes the OutStream API so that `write` returns number of bytes written, and `writeAll` is the one that loops until the whole buffer is written.
2020-03-09Windows: Fix std.fs.realpath/os.realpathW for directoriesRyan Liptak
2020-03-05std: fix sendfile on macOS and FreeBSDMichael Dusan
- fix std.os.sendfile/FreeBSD use correct in/out fd_t - fix std.os.sendfile/macOS use correct in/out fd_t - undo 1141bfb21b82f8d3fc353e968a591f2ad9aaa571 (no longer needed) - fix c.freebsd.sendfile use off_t value - fix c.freebsd.sendfile decl correct in/out fd_t - fix c.darwin.sendfile decl correct in/out fd_t fix signature param names
2020-03-03Darwin can return EBADF for sendfile on non-filesAndrew Kelley
2020-03-03breaking changes to std.fs, std.osAndrew Kelley
* 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-03std: move null byte check into toPosixPathdaurnimator
Note that windows NT paths *can* contain nulls
2020-03-03std: add os.fstatatdaurnimator
2020-03-03std: add Dir.changeDir as wrapper around fchdirdaurnimator
2020-03-03std: add mkdiratdaurnimator
2020-03-03Merge pull request #4612 from ziglang/os-read-write-sendfileAndrew Kelley
std.os read/write functions + sendfile
2020-03-03more macos fixesAndrew Kelley
2020-03-03Fix std.os.unlinkatW for absolute pathsRyan Liptak
RootDirectory can't be set in ObjectAttributes if ObjectName is an absolute path. Fixes #4606
2020-03-03breaking: std.os read/write functions + sendfileAndrew Kelley
* 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-02std: implement sendfile on linuxTerin Stock
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-01breaking: std.mem.len no longer takes a type argumentAndrew Kelley
also update fmt code to use std.mem.span.
2020-02-29target: Implement OS version detection for OSXLemonBoy
Closes #4583
2020-02-28implement native OS version detection for linuxAndrew Kelley
2020-02-28update std lib to new Target APIAndrew Kelley
2020-02-28introduce operating system version ranges as part of the targetAndrew Kelley
* 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-24remove uses of `@ArgType` and `@IntType`Vexu
2020-02-24Merge pull request #4516 from xackus/remove-bytes-to-sliceAndrew Kelley
remove @bytesToSlice, @sliceToBytes from the language
2020-02-22improve handling of environment variables on WindowsAndrew Kelley
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-22update std lib to integrate with libc for environAndrew Kelley
closes #3511
2020-02-22std.os.execvpeZ_expandArg0: fix not restoring argv[0]Andrew Kelley
This function expands argv[0] into the absolute path resolved with PATH environment variable before making the execve syscall. However, in case the execve fails, e.g. with ENOENT, it did not restore argv to how it was before it was passed in. This resulted in the caller performing an invalid free. This commit also adds verbose debug info when native system C compiler detection fails. See #4521.
2020-02-21remove @bytesToSlice, @sliceToBytes from std libxackus
2020-02-17self-host dynamic linker detectionAndrew Kelley
2020-02-17expand argv[0] when spawning system C compilerAndrew Kelley
Some C compilers, such as Clang, are known to rely on argv[0] to find the path to their own executable, without even bothering to resolve PATH. This results in the message: error: unable to execute command: Executable "" doesn't exist! So we tell ChildProcess to expand argv[0] to the absolute path to give them a helping hand.
2020-02-16implement os.faccessat for WindowsAndrew Kelley
2020-02-16self-hosted libc detectionAndrew Kelley
* 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-10Merge pull request #4404 from ziglang/async-stdAndrew Kelley
a big step towards std lib integration with async I/O
2020-02-07add fcntl support on darwinAndrew Kelley
2020-02-07implement os.pipe2 for darwinAndrew Kelley
2020-02-06more std lib async I/O integrationAndrew Kelley
* `zig test` gainst `--test-evented-io` parameter and gains the ability to seamlessly run async tests. * `std.ChildProcess` opens its child process pipe with O_NONBLOCK when using evented I/O * `std.io.getStdErr()` gives a File that is blocking even in evented I/O mode. * Delete `std.event.fs`. The functionality is now merged into `std.fs` and async file system access (using a dedicated thread) is automatically handled. * `std.fs.File` can be configured to specify whether its handle is expected to block, and whether that is OK to block even when in async I/O mode. This makes async I/O work correctly for e.g. the file system as well as network. * `std.fs.File` has some deprecated functions removed. * Missing readv,writev,pread,pwrite,preadv,pwritev functions are added to `std.os` and `std.fs.File`. They are all integrated with async I/O. * `std.fs.Watch` is still bit rotted and needs to be audited in light of the new async/await syntax. * `std.io.OutStream` integrates with async I/O * linked list nodes in the std lib have default `null` values for `prev` and `next`. * Windows async I/O integration is enabled for reading/writing file handles. * Added `std.os.mode_t`. Integer sizes need to be audited. * Fixed #4403 which was causing compiler to crash. This is working towards: ./zig test ../test/stage1/behavior.zig --test-evented-io Which does not successfully build yet. I'd like to enable behavioral tests and std lib tests with --test-evented-io in the test matrix in the future, to prevent regressions.
2020-02-05std: improve non-libc dynamic library loadingAndrew Kelley
this is a cherry-pick of 5076f2d4f6918946616504d22907c9f80601caf8 from the llvm10 branch
2020-02-04Add basic linux termios implementationnofmal
2020-01-31Turn win32 errors into a non-exhaustive enumdaurnimator