Commit Graph

293 Commits (5f7b97e84c7e2bc7682510e97996ad30147026d0)

Author SHA1 Message Date
Loris Cro 59ecdaea12 preadv
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:04:43 +02:00
Loris Cro bd9f2369d5 pread
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:04:05 +02:00
Loris Cro bc35435ca6 readv
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:03:12 +02:00
Loris Cro 08364ac773 read
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:00:55 +02:00
Loris Cro 730428bfd6 connect
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 21:56:27 +02:00
Loris Cro e85c89630e accept
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 21:56:27 +02:00
Ryan Liptak fbde15fdf4 Fix compile error in os.renameatW
Introduced in 5e3fa0e94f

Whoops!
2020-09-17 18:49:06 -04: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
LemonBoy 5e50d145d9 std: Limit the read/write size on Darwin
It turns out that the kernel won't read or write more than 0x7fffffff
bytes in a single call, failing with EINVAL when trying to do so.

Adjust the limit and curse whoever is responsible for this.

Closes #6332
2020-09-13 16:31:21 -04:00
Isaac Freund 744b73ab46
std: add prctl wrapper to std.os 2020-09-11 22:32:23 +02:00
Isaac Freund bb9773f695 std: fix errorset of std.os.seteuid/setegid 2020-09-10 15:41:21 -04: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 f5b9e445aa Handle some WSA errors 2020-09-09 18:55:45 +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 857613fb65 add unreachable 2020-09-08 12:16:03 +02:00
Bas van den Berg 9094d6cbb8 fix identation with zig-fmt 2020-09-08 12:15:44 +02:00
Bas 4a6ca735d9
Merge branch 'master' into improve-windows-networking 2020-09-08 11:56:59 +02:00
Veikka Tuominen 41bbadbb9a
Merge pull request #6246 from Vexu/field
Remove deprecated fields on `type`
2020-09-05 13:58:02 +03:00
Andrew Kelley 1034459170
Merge pull request #6243 from ifreund/uid-gid-cleanup
std: clean up usage of uid_t/gid_t, add seteuid/setegid to std.os
2020-09-03 18:05:59 -04:00
Andrew Kelley 39a80cf59e
Merge pull request #6238 from Aransentin/master
Add the "sync" family of functions
2020-09-03 14:07:36 -04:00
Kenta Iwasaki 50e3906951
os: return error.SocketNotListening for EINVAL on accept (#6226) 2020-09-03 13:57:08 -04:00
Vexu 1df0f3ac24
update uses of deprecated type field access 2020-09-03 18:10:40 +03:00
Isaac Freund d0d6647fdb
std: add seteuid/setegid to std.os
Currently these are only implemented for linux.
2020-09-03 15:22:43 +02:00
Isaac Freund e8a2aecd2f
std: fix linux uid_t, use uid_t/gid_t in std.os
- correct uid_t from i32 to u32 on linux
- define uid_t and gid_t for OSes missing definitions
- use uid_t/gid_t instead of plain u32s throughout std.os
2020-09-03 15:08:37 +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
Aransentin 25f6663304 Add the sync functions 2020-09-02 22:16:40 +00: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
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 b1c7334355
Merge pull request #5745 from lun-4/ebadf-error
map EBADF to error values for read and write
2020-08-19 23:46:22 -04:00
Andrew Kelley ae2c88754d std: signalfd: fix the types of things; add test 2020-08-17 16:19:57 -07:00
Luna 2deb07a001 rename signalfd4 to signalfd 2020-08-17 16:05:35 -07:00
Jakub Konka 3e2e6baee5 Add std.os.getFdPath and std.fs.Dir.realpath
`std.os.getFdPath` is very platform-specific and can be used to query
the OS for a canonical path to a file handle. Currently supported hosts
are Linux, macOS and Windows.

`std.fs.Dir.realpath` (and null-terminated, plus WTF16 versions) are
similar to `std.os.realpath`, however, they resolve a path wrt to this
`Dir` instance.

If the input pathname argument turns out to be an absolute path, this
function reverts to calling `realpath` on that pathname completely
ignoring this `Dir`.
2020-08-13 07:08:39 +02:00
Maciej Walczak 6febe7e977
copy_file_range linux syscall (#6010) 2020-08-11 15:49:43 -04: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 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
Jakub Konka 4b0ab0c186
Apply suggestions from code review
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-08-02 19:36:49 +02: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 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
luna a6626802f9
Add signalfd support (#5322)
* add signalfd_siginfo to linux bits

* Cast sigaddset's shift value to u5

* linux: add signalfd4

* os: add signalfd
2020-07-22 17:26:27 -04:00
Jakub Konka aa6fcaf76f Add missing cross-platform Dir.readLink fns 2020-07-22 08:51:23 +02:00
Jakub Konka 3d41d3fb6e Draft out ReadLinkW using NT primitives 2020-07-22 08:51:23 +02:00
Jakub Konka 2c9c13f624 Add various build fixes
Fix WASI build, fix atomicSymlink by using `cwd().symLink`, add
`Dir.symLink` on supported targets.
2020-07-22 08:51:22 +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 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 cc9c5c5b0e Handle relative/absolute symlinks; add more tests 2020-07-22 08:51:22 +02:00
Jakub Konka 30f1176a54 Add SymlinkFlags needed to create symlinks to dirs on Win 2020-07-22 08:51:22 +02:00
Jakub Konka 99e3e29e2e Refactor 2020-07-22 08:51:22 +02:00
Jakub Konka c47cb8d09f Fix unlinkatW to allow file symlink deletion on Windows 2020-07-22 08:51:22 +02:00
Jakub Konka ae8abedbed Use NtCreateFile to get handle to reparse point 2020-07-22 08:51:22 +02:00
Jakub Konka d17c9b3591 Fix incorrect byte format of REPARSE_DATA_BUFFER struct 2020-07-22 08:51:22 +02:00
Jakub Konka 9b00dc941b Use windows.CreateFileW to open the reparse point 2020-07-22 08:51:22 +02:00
Jakub Konka 49b5815364 Add windows.ReadLink similar to OpenFile but for reparse points only 2020-07-22 08:51:22 +02:00
Jakub Konka 92d11fd4e9 Debug readlinkW using OpenFile 2020-07-22 08:51:22 +02:00
Jakub Konka 791795a63a Finish symlink implementation on Windows 2020-07-22 08:51:22 +02:00
Jakub Konka 515c663cd6 Add readlink smoke test 2020-07-22 08:51:22 +02:00
Jakub Konka cc83d92b0b Start drafting out os.readlink on Windows 2020-07-22 08:51:22 +02:00
Vexu e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
luna e2cfc65909
Merge branch 'master' into ebadf-error 2020-07-02 00:49:56 -03:00
Jakub Konka 8306826d53 Map ENOTCAPABLE into error.AccessDenied instead of error.NotCapable
This is direct result of review comments left by andrewrk and
daurnimator. It makes sense to map `ENOTCAPABLE` into a more generic
`error.AccessDenied`.
2020-06-30 18:21:38 +02:00
Jakub Konka 5bc99dd7e8 Fix more compilation errors 2020-06-29 21:42:11 +02:00
Luna 3f5b2d6c51 std.os: map EBADF to errors on WASI read/write syscalls 2020-06-29 16:23:58 -03:00
Jakub Konka b96882c57a Fix compilation errors 2020-06-29 18:09:22 +02:00
Jakub Konka bf8bf528c6 Handle ENOTCAPABLE in WASI
This commit adds `error.NotCapable` enum value and makes sure that
every applicable WASI syscall that can return `ENOTCAPABLE` errno
remaps it to `error.NotCapable.
2020-06-29 17:10:01 +02:00
Luna f47c6d3c6b std.os: make EBADF return error for read and write 2020-06-28 18:40:43 -03:00
Jakub Konka d40e367b73 Reformat using if-else where appropriate 2020-06-24 21:00:21 +02:00
Jakub Konka be78b7b648 Implement fstatat targeting WASI
Also, add more informative `@compileError` in a few `std.os` functions
that would otherwise yield a cryptic compile error when targeting
WASI. Finally, enhance docs in a few places and add test case for
`fstatat`.
2020-06-24 21:00:21 +02:00
Jakub Konka c950f0c6c3 Enhance std.os.readlinkat coverage
Adds Windows stub (still needs to be implemented on Windows),
adds WASI implementation, adds unit test testing basic chain of
ops: create file -> symlink -> readlink.
2020-06-22 09:40:06 +02:00
Jakub Konka 64078ca924 Enhance std.os.symlinkat coverage
Fixes `std.os.symlinkat` compile errors, adds Windows stub (still
needs to be implemented), adds WASI implementation.
2020-06-22 09:14:51 +02:00
Ryan Liptak f7b6957fb4 Windows: Fix std.fs.Dir.deleteDir() deleting files
Would previously delete files, now correctly returns error.NotDir. Fixes #5536
2020-06-04 22:51:58 -04:00
Andrew Kelley 7fd937fef4 cleanups
* improve docs
 * add TODO comments for things that don't have open issues
 * remove redundant namespacing of struct fields
 * guard against ioctl returning EINTR
 * remove the general std.os.ioctl function in favor of the specific
   ioctl_SIOCGIFINDEX function. This allows us to have a more precise
   error set, and more type-safe API.
2020-06-02 15:28:46 -04:00
Luna 6623efd7d4 Change ioctl's request type to i32 2020-06-02 14:56:19 -04:00
Luna 7c71054286 Replace syscall3 to os.ioctl 2020-06-02 14:56:19 -04:00
Luna c8468bed42 Add std.os.ioctl 2020-06-02 14:56:19 -04:00
Andrew Kelley c6764fd254
Merge pull request #5475 from marler8997/windowsDns
support name resolution on windows
2020-06-01 15:33:05 -04:00
Jonathan Marler 58fb5b29b6 more windows network fixes
* support posix SOCK_NONBLOCK and SOCK_CLOEXEC flags on windows
* fix bugs in os.socket and os.connect to return at the correct place
2020-05-31 10:07:51 -06:00
Jonathan Marler 2eaab1e65e more windows network support, including dns 2020-05-29 22:38:48 -06:00
Jonathan S 631633b252 Document and reduce usage of MAX_PATH_BYTES, lifting arbitrary buffer size requirements 2020-05-29 18:23:06 -04:00
Andrew Kelley 53d011fa1a (breaking) std.time fixups and API changes
Remove the constants that assume a base unit in favor of explicit
x_per_y constants.

nanosecond calendar timestamps now use i128 for the type. This affects
fs.File.Stat, std.time.nanoTimestamp, and fs.File.updateTimes.

calendar timestamps are now signed, because the value can be less than
the epoch (the user can set their computer time to whatever they wish).

implement std.os.clock_gettime for Windows when clock id is
CLOCK_CALENDAR.
2020-05-24 21:40:08 -04:00
Jakub Konka fae4af9e1c Make mode_t a 0-byte type in WASI 2020-05-18 17:09:52 +02:00
Jakub Konka d43c08a3e5 Add/fix missing WASI functionality to pass libstd tests
This rather large commit adds/fixes missing WASI functionality
in `libstd` needed to pass the `libstd` tests. As such, now by
default tests targeting `wasm32-wasi` target are enabled in
`test/tests.zig` module. However, they can be disabled by passing
the `-Dskip-wasi=true` flag when invoking the `zig build test`
command. When the flag is set to `false`, i.e., when WASI tests are
included, `wasmtime` with `--dir=.` is used as the default testing
command.

Since the majority of `libstd` tests were relying on `fs.cwd()`
call to get current working directory handle wrapped in `Dir`
struct, in order to make the tests WASI-friendly, `fs.cwd()`
call was replaced with `testing.getTestDir()` function which
resolved to either `fs.cwd()` for non-WASI targets, or tries to
fetch the preopen list from the WASI runtime and extract a
preopen for '.' path.

The summary of changes introduced by this commit:
* implement `Dir.makeDir` and `Dir.openDir` targeting WASI
* implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI
* fix `os.close` and map errors in `unlinkat`
* move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi`
  to `std.os` module
* implement `lseek_{SET, CUR, END}` targeting WASI
* implement `futimens` targeting WASI
* implement `ftruncate` targeting WASI
* implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI
* make sure ANSI escape codes are _not_ used in stderr or stdout
  in WASI, as WASI always sanitizes stderr, and sanitizes stdout if
  fd is a TTY
* fix specifying WASI rights when opening/creating files/dirs
* tweak `AtomicFile` to be WASI-compatible
* implement `os.renameatWasi` for WASI-compliant `os.renameat` function
* implement sleep() targeting WASI
* fix `process.getEnvMap` targeting WASI
2020-05-18 16:09:49 +02:00
Loris Cro 35a59b5b0f remove readable check when opening a socket connection 2020-05-07 13:41:17 -04:00
Andrew Kelley b13a02ed1a avoid unnecessary fcntl syscalls when setting socket flags 2020-05-05 12:50:50 -04:00
Andrew Kelley 0a2104689b fix incorrect flags being set in os.setSockFlags
fixes networking stuff on darwin
2020-05-05 12:45:39 -04:00
Jonathan Marler 75b699b2c6 os.zig: add ETIMEDOUT error case to read function
According to documentation ETIMEDOUT (110) is a valid error code for the read function.  I just had my long-running  (been running for about 7 weeks) network program crash because it did not handle the ETIMEDOUT error code from "read".
2020-05-04 13:48:34 -04:00
Cato 9b788b765c Pass filtered_sock_type to system.socket. Cover PermissionDenied error 2020-05-03 15:35:36 -04:00
Andrew Kelley 8a8beefa36 solve the problem with Darwin shims in std.os instead
* implement SOCK_NONBLOCK and SOCK_CLOEXEC Darwin shims in std.os
 * revert changes to std.net
 * remove os.accept and rename os.accept4 to os.accept
2020-05-02 17:36:28 -04:00
Cato 07bee9da42 Fixed Darwin-incompatible socket flags and unavailable system calls 2020-05-02 16:37:39 -04:00
Andrew Kelley 7998e2b0f4 Merge remote-tracking branch 'origin/master' into FireFox317-windows-evented-io 2020-05-02 14:16:59 -04:00
Chris Heyes 8ebcca6734
Get evented io code paths to build on macOS (#5233)
* Get evented io code paths to build on macOS
* Use mode_t instead of usize where appropriate
2020-05-02 14:14:46 -04:00
Andrew Kelley 5656f5090d fs.File: improve handling async I/O on Windows
Before it was possible for .intended_io_mode = .blocking,
.capable_io_mode = .evented, and then the implementation would put a
request on the fs thread, which is the wrong behavior. Now it always
calls the appropriate WriteFile/ReadFile function, passing the intended
io mode directly as a parameter.

This makes the behavior tests pass on Windows with --test-evented-io.
2020-05-02 14:09:17 -04:00
Andrew Kelley 43f7856bac fix regressions in windows std lib tests 2020-05-02 01:25:22 -04:00
Andrew Kelley 2272a07ca0 std.event.Loop: promote the fs thread to be available for all OS's 2020-05-02 00:41:19 -04:00
Andrew Kelley 45bce27b8f cleanup and fixes. behavior tests passing with evented I/O 2020-05-01 23:17:28 -04:00
Andrew Kelley 988031c07c Merge branch 'windows-evented-io' of https://github.com/FireFox317/zig into FireFox317-windows-evented-io 2020-05-01 19:02:16 -04:00
nia 14a954f350 Add arc4random_buf() in NetBSD libc, use it to implement getrandom() 2020-05-01 17:22:27 +01:00
Tadeo Kondrak 350b2adacd
std.meta.IntType -> std.meta.Int 2020-04-28 19:11:31 -06:00