121 Commits

Author SHA1 Message Date
Lee Cannon
64feae3ac3 Move utf8->utf16 up one level into os.zig 2020-11-18 15:37:44 +01:00
Lee Cannon
32c998e03c Switch to RtlSetCurrentDirectory_U 2020-11-18 15:37:44 +01:00
Lee Cannon
80b1e82b1b Implement chdir and chdirZ for Windows 2020-11-18 15:37:44 +01:00
LemonBoy
36c869dc14 std: Make windows.ReadFile allow short reads
Make it behave like the read() wrapper for unix systems.
Reading the whole buffer breaks some use-cases like buffered readers
over sockets.

Closes #7121
2020-11-16 13:35:06 -08:00
Andrew Kelley
569f7ce49e Merge branch 'improve-windows-networking'
of https://github.com/BarabasGitHub/zig into
BarabasGitHub-improve-windows-networking

Conflicts:
 lib/std/os.zig

This commit resolves conflicts with the changes to std.os which removed
the EAGAIN error handling interactions with the event loop. The solution
to the conflict was to apply EAGAIN => return error.WouldBlock into the
improved windows networking branch.
2020-10-22 16:59:15 -07:00
Andrew Kelley
fe117d9961
Merge pull request #6250 from ziglang/stage2-zig-cc
move `zig cc`, `zig translate-c`, `zig libc`, main(), and linking from stage1 to stage2
2020-09-30 04:28:19 -04:00
Ryan Liptak
254ee89def Windows: Handle ACCESS_DENIED in DeviceIoControl
This was causing the Dir.readLink test to fail for me locally with error.Unexpected NTSTATUS=0xc0000022. Not sure if PRIVILEGE_NOT_HELD is actually possible or not.
2020-09-29 20:54:45 -04:00
Andrew Kelley
af64fd2f42 Merge remote-tracking branch 'origin/master' into stage2-zig-cc
This merges in the revert that fixes the broken Windows build of master
branch.
2020-09-29 17:26:09 -07:00
Jakub Konka
bb636cb3bf Revert "Fix for Windows: std.os.windows.DeleteFile()" 2020-09-29 19:35:44 -04:00
Andrew Kelley
750b00c642 Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-29 00:27:48 -07:00
Suirad
43cd9eb110 Add clarification comment 2020-09-25 18:11:31 -05:00
Suirad
f78652484a Stdlib fix for os.windows.deleteFile to fail with
a proper error when attempting to delete a directory that isnt empty
2020-09-25 18:09:05 -05:00
Andrew Kelley
0c70bb4fce Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-21 21:16:46 -07:00
Ryan Liptak
5e3fa0e94f Add rename to std.fs API
- Moves fs.rename functions to fs.renameAbsolute to match other functions outside of fs.Dir
- Adds fs.Dir.rename that takes two paths relative to the given Dir
- Adds fs.rename that takes two separate Dir's that the given paths are relative to (for renaming across directories without having to make the second path relative to a single directory)
- Fixes FileNotFound error return in std.os.windows.MoveFileExW
- Returns error.RenameAcrossMountPoints from renameatW
  + Matches the RenameAcrossMountPoints error return in renameatWasi/renameatZ
2020-09-17 17:22:26 -04:00
Andrew Kelley
f82b1831f7 std: handle sharing violation when deleting a file on windows 2020-09-15 15:24:13 -07:00
Bas van den Berg
127fa80090 implement poll for windows with WSAPoll (only available on vista and higher) 2020-09-10 20:20:27 +02:00
Bas van den Berg
44f877d18b change socklen_t to u32 and add appropriate casts when calling WSA 2020-09-08 12:24:39 +02:00
Bas van den Berg
0a40a61548 os.send(to) and os.recv(from) functions made to work on windows. 2020-09-03 13:23:48 +02:00
Bas van den Berg
d80554cedf Made some changes and additions to the networking to make it work on windows. 2020-09-02 23:53:29 +02:00
Sahnvour
ac85befbb4 handle lack of privilege to create symbolic links on windows 2020-08-30 06:52:53 +02:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Andrew Kelley
23c427b5fb windows: match the same error code for EBADF 2020-08-19 20:51:06 -07:00
StrangeBug
59711becc7 Add handler for INVALID_HANDLE to prevent infinite loop when stderr is not available. 2020-08-19 20:49:25 -07:00
Jakub Konka
901bf0a2e2 Convert prefix from u8 to u16 programmatically 2020-08-10 20:44:22 +02:00
Jakub Konka
73b9f65746 Validate DOS path before returning
And some other minor refactors which address more review comments.
2020-08-10 16:39:02 +02:00
Jakub Konka
cd8e6b66d0 Address some review comments 2020-08-09 10:47:52 +02:00
Jakub Konka
310aa87198 Fix alignment issue 2020-08-07 23:21:06 +02:00
Jakub Konka
bdda8fa7a8 Redo GetFinalPathNameByHandle using DeviceIoControl
This commit reimagines `std.os.windows.GetFinalPathNameByHandle`
using `DeviceIoControl` to query the OS mount manager for the DOS
(symlink) paths for the given NT volume name. In particular,
it uses `IOCTL_MOUNTMGR_QUERY_POINTS` ioctl opcode to query the
manager for the available moount points.
2020-08-07 11:33:05 +02:00
Jakub Konka
e8abfef2aa Add docs 2020-08-06 23:56:37 +02:00
Jakub Konka
2628a8846e Use NtQueryInformationFile unless unavailable
Favour newer API which uses `NtQueryInformationFile` with class flags
`FileNormalizedNameInformation` and `FileVolumeNameInformation`
instead of lower-level `NtQueryObject`. `NtQueryObject` is still
used as a fallback in case the former are unavailable.
2020-08-06 23:56:37 +02:00
Jakub Konka
747d46f22c Initial draft of GetFinalPathNameByHandle
This commit proposes an initial draft of `GetPathNameByHandle` function
which wraps NT syscalls and strives to emulate (currently only
partially) the `kernel32.GetFinalPathNameByHandleW` function.
2020-08-06 23:56:37 +02:00
Andrew Kelley
d159ba9295 zig fmt 2020-08-04 23:04:20 -07:00
Jakub Konka
4d9eff4bdb Add prelim openW and openatW
Added POSIX functions targeting Windows pass `open` and `openat`
smoke tests.
2020-07-31 16:41:25 +02:00
Jakub Konka
390194431e Use NtCreateFile directly in ReadLink
This shaves off one syscall (we use one instead of two if we were to
use `windows.OpenFile` wrapper). Clean up flag generation in `OpenFile`.
Hopefully, we're in a much better place to *almost* support `openW`
and `openatW`.
2020-07-31 16:32:21 +02:00
Jakub Konka
8981b18fee Move delete file logic into windows.DeleteFile fn
This way, we can remove more `kernel32` calls such as `RemoveDirectoryW`
or `DeleteFileW`, and use `std.os.windows.DeleteFile` instead which
is purely NT-based.
2020-07-31 16:31:51 +02:00
Jakub Konka
66bbe4ec4c Refactor internal Win routines to reuse OpenFile
This covers mainly `ReadLink` and `CreateSymolicLink` functions.
2020-07-31 16:31:44 +02:00
Jakub Konka
a89d5cfc3e Remove CreateDirectoryW and CreateFileW calls
Replace them with `std.os.windows.OpenFile` instead. To allow
creation/opening of directories, `std.os.windows.OpenFileOptions`
now features a `.expect_dir: bool` member which is meant to emualate
POSIX's `O_DIRECTORY` flag.
2020-07-31 16:31:23 +02:00
Jakub Konka
547e520359 Split DeviceIoControl path into two fn call paths
As discussed in the previous commit, it would be better to avoid
function pointers to syscalls and explicitly split the control
path into two function calls instead. This commit addresses that
for `std.os.windows.DeviceIoControl`.
2020-07-29 14:17:49 +02:00
Jakub Konka
4fdfaf69c8 Add Zig wrapper for kernel32.DeviceIoControl
This commit adds a Zig wrapper for `kernel32.DeviceIoControl` which
applies ReactOS logic for deciding whether to use
`ntdll.NtDeviceIoControlFile` or `ntdll.NtFsControlFile` based on the
value of passed `IO_CONTROL_CODE`. The decision logic is based on the
logic found in ReactOS found in the following [link].

Thanks to Daurnimator for finding this bit in ReactOS!

[link]: https://doxygen.reactos.org/d3/d74/deviceio_8c.html
2020-07-29 01:19:10 +00:00
Jakub Konka
f0ed2ed67f Replace DeviceIoControl with FsControlFile
This commit replaces `windows.DeviceIoControl` with
`windows.FsControlFile` which is a wrapper around the NT-based
syscall `ntdll.NtFsControlFile`.
2020-07-27 19:45:23 +00:00
Jakub Konka
3d41d3fb6e Draft out ReadLinkW using NT primitives 2020-07-22 08:51:23 +02:00
Jakub Konka
4887350bf4 Finish drafting CreateSymolicLink using NT calls 2020-07-22 08:51:23 +02:00
Jakub Konka
99f0e64fa0 Draft out dir symlinks branch 2020-07-22 08:51:23 +02:00
Jakub Konka
c53bcd027f Start drafting CreateSymbolicLink using ntdll syscalls 2020-07-22 08:51:23 +02:00
Jakub Konka
e0b77a6b77 Ensure Dir.deleteTree does not dereference symlinks
Otherwise, the behaviour can lead to unexpected results, resulting
in removing an entire tree that's not necessarily under the root.
Furthermore, this change is needed if are to properly handle dir
symlinks on Windows. Without explicitly requiring that a directory
or file is opened with `FILE_OPEN_REPARSE_POINT`, Windows automatically
dereferences all symlinks along the way. This commit adds another
option to `OpenDirOptions`, namely `.no_follow`, which defaults to
`false` and can be used to specifically open a directory symlink on
Windows or call `openat` with `O_NOFOLLOW` flag in POSIX.
2020-07-22 08:51:22 +02:00
Jakub Konka
3c8ceb674e Fix Windows build 2020-07-22 08:51:22 +02:00
Jakub Konka
fc7d87fef1 Move symlink to fs.symlinkAbsolute with SymlinkFlags
This way `std.fs.symlinkAbsolute` becomes cross-platform and we can
legally include `SymlinkFlags` as an argument that's only used on
Windows. Also, now `std.os.symlink` generates a compile error on
Windows with a message to instead use `std.os.windows.CreateSymbolicLink`.
Finally, this PR also reshuffles the tests between `std.os.test` and
`std.fs.test`.
2020-07-22 08:51:22 +02:00
Jakub Konka
22362568cf Refactor 2020-07-22 08:51:22 +02:00
Jakub Konka
3ab5e6b1a9 Ensure we use Win32 prefix in Win32 calls 2020-07-22 08:51:22 +02:00
Jakub Konka
99e3e29e2e Refactor 2020-07-22 08:51:22 +02:00