Commit Graph

135 Commits

Author SHA1 Message Date
LeRoyce Pearson
ea32a7d2bc Fix compile errors about adding error.FileLocksNotSupported 2020-04-03 00:27:34 -06:00
LeRoyce Pearson
733f1c25bd Fix compile errors in stage2 2020-04-02 23:39:25 -06:00
LeRoyce Pearson
ea6525797d Use flock instead of fcntl to lock files
`flock` locks based on the file handle, instead of the process id.
This brings the file locking on unix based systems closer to file
locking on Windows.
2020-04-02 22:57:02 -06:00
LeRoyce Pearson
e7cf3f92a9 Add FileLocksNotSupported error to OpenError 2020-04-02 22:12:45 -06:00
LeRoyce Pearson
35c462caf0 Merge branch 'master' into feature-file-locks 2020-04-02 21:46:48 -06:00
Andrew Kelley
8bf7cffe29
slight modification of the semantics of std.os.getenvW
Now, this function first attempts a case-sensitive lookup.
If no match is found, and `key` is ASCII, then it attempts a
second case-insensitive lookup.

It is not planned to support full Unicode case-insensitivity
on Windows, and in fact relying on non-ASCII case-insensitive
environment variables is fundamentally problematic.
2020-04-02 15:04:42 -04:00
Ilmari Autio
ba1a8b64c4
make std.os.getenvW case insensitive
partially addresses #4603

Fixing std.process.getEnvMap is NOT included in this commit.
2020-04-02 13:01:32 -04:00
LemonBoy
4209ab90a8 std: Use the versioned libc symbols if needed
Many symbols on NetBSD and some on OSX require the definition of an
alias.
2020-04-01 12:23:18 +02:00
daurnimator
3cf302a71d
Tidy up some mem.spanZ use-sites now that null is accepted 2020-04-01 01:50:34 +11:00
daurnimator
63409cf422 std: linux syscall numbers are now an extensible enum 2020-03-31 10:16:20 -04:00
Andrew Kelley
9e7ae06249
std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
LeRoyce Pearson
c7f4e68464
Merge branch 'master' into feature-file-locks 2020-03-27 11:32:33 -06:00
LemonBoy
3ccf99c0bd std: Slim duplicate logic for some calls 2020-03-24 19:47:18 +01:00
LeRoyce Pearson
8bec1304c3 Fix compile error on windows 2020-03-23 22:34:00 -06:00
LemonBoy
761602e3e8 std: Use getdents on all the BSDs
* Use the correct versioned libc calls to avoid nasty surprises
2020-03-23 18:54:14 +01:00
LemonBoy
27344464ed std: Add missing C defines for NetBSD 2020-03-23 18:47:40 +01:00
LemonBoy
4843c3b4c3
std: Introduce fnctl wrapper 2020-03-18 13:45:52 -04:00
Jonathan Marler
7251eb1681 fix a couple sockfds to be fd_t rather than i32
Using i32 causes compile errors on Windows because it uses *c_void rather than i32 for it's fd_t type.
2020-03-17 12:46:07 -04:00
Andrew Kelley
a27a8561e9
adjust renameatW to always supply dest root dir
this fixes tests for wine
2020-03-15 17:26:29 -04:00
Andrew Kelley
e369789062 fix std.os.renameatW
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-15 15:47:42 -04:00
Andrew Kelley
701aaf0ddf
renameatW: handle more windows nt status codes 2020-03-15 14:46:09 -04:00
Andrew Kelley
66e76a0209
zig build system: correctly handle multiple output artifacts
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-13 21:22:08 -04:00
Andrew Kelley
a9297f2267
Merge pull request #4716 from LemonBoy/sys-misc
Introduce std.fs.file.setEndPos
2020-03-13 11:18:08 -04:00
LemonBoy
de53537f10 Add NtDll-based ftruncate implementation 2020-03-13 08:45:37 +01:00
Nick Erdmann
92beb13914 std/os/uefi: status reform 2020-03-12 23:23:12 +01:00
LemonBoy
bd0b51477a Address review comments 2020-03-12 19:40:42 +01: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
Andrew Kelley
ba0e3be5cf
(breaking) rework stream abstractions
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-10 15:32:32 -04:00
Ryan Liptak
9b1b44b41c Windows: Fix std.fs.realpath/os.realpathW for directories 2020-03-09 12:59:17 -04:00
Michael Dusan
d31b65e762 std: fix sendfile on macOS and FreeBSD
- fix std.os.sendfile/FreeBSD use correct in/out fd_t
- fix std.os.sendfile/macOS use correct in/out fd_t
- undo 1141bfb21b (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-05 20:46:28 -05:00
Andrew Kelley
1141bfb21b Darwin can return EBADF for sendfile on non-files 2020-03-03 16:52:32 -05: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
a19a30bb17
std: move null byte check into toPosixPath
Note that windows NT paths *can* contain nulls
2020-03-03 13:25:43 -05:00
daurnimator
bfc569bc98
std: add os.fstatat 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
daurnimator
88e27f01c8
std: add mkdirat 2020-03-03 13:25:40 -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
a66c72749a more macos fixes 2020-03-03 03:10:56 -05:00
Ryan Liptak
d7579a2fcb Fix std.os.unlinkatW for absolute paths
RootDirectory can't be set in ObjectAttributes if ObjectName is an absolute path.

Fixes #4606
2020-03-03 03:07:12 -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
Andrew Kelley
ef3d761da5
breaking: std.mem.len no longer takes a type argument
also update fmt code to use std.mem.span.
2020-03-01 13:21:39 -05:00
LemonBoy
84549b3955 target: Implement OS version detection for OSX
Closes #4583
2020-02-29 21:46:07 +01:00
Andrew Kelley
07f52119de
implement native OS version detection for linux 2020-02-28 14:51:56 -05:00
Andrew Kelley
87b9e744dd
update std lib to new Target API 2020-02-28 14:51:54 -05: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
1d06c82c3b
Merge pull request #4516 from xackus/remove-bytes-to-slice
remove @bytesToSlice, @sliceToBytes from the language
2020-02-24 13:51:47 -05: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
936d0b18b1
update std lib to integrate with libc for environ
closes #3511
2020-02-22 15:59:13 -05:00