Commit graph

71 commits

Author SHA1 Message Date
Andrew Kelley
3bf0ce65a5 fix miscellaneous compilation errors
- ILSEQ -> error.BadPathName
- implement dirStatPath for WASI
2025-10-29 06:20:50 -07:00
Andrew Kelley
f7bbcb4a4b fix miscellaneous compilation failures 2025-10-29 06:20:50 -07:00
Andrew Kelley
b1733b7bce std.Io: implement dirOpenFile 2025-10-29 06:20:49 -07:00
Andrew Kelley
8a1e6c8c39 std.Io: implement dirStatPath 2025-10-29 06:20:49 -07:00
Andrew Kelley
47aa5a70a5 std: updating to std.Io interface
got the build runner compiling
2025-10-29 06:20:48 -07:00
Andrew Kelley
0e9280ef1a std.Io: extract Dir to separate file 2025-10-29 06:20:48 -07:00
Alex Rønne Petersen
dba1bf9353 remove all Oracle Solaris support
There is no straightforward way for the Zig team to access the Solaris system
headers; to do this, one has to create an Oracle account, accept their EULA to
download the installer ISO, and finally install it on a machine or VM. We do not
have to jump through hoops like this for any other OS that we support, and no
one on the team has expressed willingness to do it.

As a result, we cannot audit any Solaris contributions to std.c or other
similarly sensitive parts of the standard library. The best we would be able to
do is assume that Solaris and illumos are 100% compatible with no way to verify
that assumption. But at that point, the solaris and illumos OS tags would be
functionally identical anyway.

For Solaris especially, any contributions that involve APIs introduced after the
OS was made closed-source would also be inherently more risky than equivalent
contributions for other proprietary OSs due to the case of Google LLC v. Oracle
America, Inc., wherein Oracle clearly demonstrated its willingness to pursue
legal action against entities that merely copy API declarations.

Finally, Oracle laid off most of the Solaris team in 2017; the OS has been in
maintenance mode since, presumably to be retired completely sometime in the 2030s.

For these reasons, this commit removes all Oracle Solaris support.

Anyone who still wishes to use Zig on Solaris can try their luck by simply using
illumos instead of solaris in target triples - chances are it'll work. But there
will be no effort from the Zig team to support this use case; we recommend that
people move to illumos instead.
2025-10-27 07:35:38 -07:00
usebeforefree
62e3d46287 replaced https://simonsapin.github.io/wtf-8/ with https://wtf-8.codeberg.page/ 2025-10-10 23:53:00 +02:00
Ryan Liptak
d629a146f5 Dir.realpathW: remove redundant buffer/copy
This same change was applied in 69007f0961 but accidentally reverted in 7bf740ee71
2025-10-10 12:13:35 -07:00
Michael Pfaff
7bf740ee71 Deprecate old realpathW correctly
- Rename modified `realpathW` to `realpathW2`
- Re-add original `realpathW`
- Add deprecation notice to `realpathW`
2025-10-08 17:07:38 -07:00
Michael Pfaff
a7dfc6470f Reuse pathname_w buffer as out_buffer when calling realpathW 2025-10-08 17:07:38 -07:00
Michael Pfaff
2886a8bf45 Improve documentation on Dir.realpathW 2025-10-08 17:07:38 -07:00
Michael Pfaff
f2227ae677 Return WTF16LE encoded path from realpathW 2025-10-08 17:07:38 -07:00
Ryan Liptak
894a991714 Add depth function to Walker.Entry
This enables depth-related use cases without any dependency on the Walker's internal stack which doesn't always pertain to the actual depth of the current entry (i.e. recursing into a directory immediately affects the stack).
2025-10-03 16:29:09 -07:00
Henry Kupty
df394faf77 feat: Reintroduce depth
Some decision-making might depend on the level of the traversal, so
it makes sense to expose depth here since it's stable, and not in the
automatic walker where it's not.
2025-10-03 16:29:08 -07:00
Ryan Liptak
760127a760 Add SelectiveWalker/walkSelectively and implement Walker in terms of it
This is a breaking change, since the fields of Walker have changed. The function APIs are unchanged, though.
2025-10-03 16:29:08 -07:00
Andrew Kelley
9a0970a12b rework std.Io.Writer.Allocating to support runtime-known alignment
Also, breaking API changes to:
* std.fs.Dir.readFileAlloc
* std.fs.Dir.readFileAllocOptions
2025-08-30 00:48:50 -07:00
Alex Rønne Petersen
77c09d16f9 std.fs.Dir: fix updateFile() to flush the file before updating its times
AtomicFile.finish() calls flush() which renders any previous updateTimes() calls
useless. Regression introduced in f2a3ac7c05.

Closes #24927.
2025-08-23 12:32:14 -07:00
Andrew Kelley
f2a3ac7c05 std.fs.File: delete writeFileAll and friends
please use File.Writer for these use cases

also breaking API changes to std.fs.AtomicFile
2025-07-21 12:32:37 -07:00
Linus Groh
eb37552536 Remove numerous things deprecated during the 0.14 release cycle
Basically everything that has a direct replacement or no uses left.

Notable omissions:

- std.ArrayHashMap: Too much fallout, needs a separate cleanup.
- std.debug.runtime_safety: Too much fallout.
- std.heap.GeneralPurposeAllocator: Lots of references to it remain, not
  a simple find and replace as "debug allocator" is not equivalent to
  "general purpose allocator".
- std.io.Reader: Is being reworked at the moment.
- std.unicode.utf8Decode(): No replacement, needs a new API first.
- Manifest backwards compat options: Removal would break test data used
  by TestFetchBuilder.
- panic handler needs to be a namespace: Many tests still rely on it
  being a function, needs a separate cleanup.
2025-07-11 08:17:43 +02:00
Jacob Young
16d78bc0c0 Build: add install commands to --verbose output 2025-06-19 11:45:06 -04:00
Elaine Gibson
7f73187004 std.fs.Dir: haiku fixes 2025-06-05 13:45:52 +01:00
Alex Rønne Petersen
adc4418bae std.fs.Dir.Iterator: Address a couple of alignment TODOs. 2025-06-05 07:17:40 +02:00
Michael Pfaff
69007f0961 Calculate WTF-8 length before converting instead of converting into an intermediate buffer on the stack 2025-04-26 14:31:28 +02:00
Chris Boesch
206bd1ced8
Merge pull request #23268 from chrboesch/i19875
std.posix: Added 'error.ProcessNotFound' where necessary
2025-04-14 22:20:44 +02:00
Andrew Kelley
f32a5d349d std: eradicate u29 and embrace std.mem.Alignment 2025-04-13 02:20:32 -04:00
Pat Tullmann
14c046fc07 lib/std: PermissionDenied/AccessDenied cleanup and fallout
This PR consistently maps .ACCES into AccessDenied and .PERM into
PermissionDenied.  AccessDenied is returned if the file mode bit
(user/group/other rwx bits) disallow access (errno was `EACCES`).
PermissionDenied is returned if something else denies access (errno was
`EPERM`) (immutable bit, SELinux, capabilities, etc).  This somewhat
subtle distinction is a POSIX thing.

Most of the change is updating std.posix Error Sets to contain both
errors, and then propagating the pair up through caller Error Sets.

Fixes #16782
2025-03-24 16:20:45 +01:00
Pat Tullmann
f304d8e50a windows: Use AccessDenied for ACCESS_DENIED on Windows
Windows defines an `ACCESS_DENIED` error code.  There is no
PERMISSION_DENIED (or its equivalent) which seems to only exist on POSIX
systems.  Fix a couple Windows calls code to return `error.AccessDenied`
for `ACCESS_DENIED` and to stop mapping AccessDenied into
PermissionDenied.
2025-03-24 16:20:45 +01:00
Alex Rønne Petersen
481b7bf3f0
std.Target: Remove functions that just wrap component functions.
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look
at multiple components of the target. But functions like isWasm(), isDarwin(),
isGnu(), etc only exist to save 4-8 characters. I don't think this is a good
enough reason to keep them, especially given that:

* It's not immediately obvious to a reader whether target.isDarwin() means the
  same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar
  functions *do* look at multiple components.
* It's not clear where we would draw the line. The logical conclusion before
  this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(),
  Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand.
* It's nice to just have a single correct way of doing something.
2025-02-17 19:18:19 +01:00
Meghan Denny
9142482372
std.ArrayList: popOrNull() -> pop() [v2] (#22720) 2025-02-10 04:21:31 +00:00
Pat Tullmann
138d30bb47 wasi: fix wasm-wasi-musl constants
Zig's copy of the `SYMLINK_{NO,}FOLLOW` constants from wasi-musl was
wrong, as were the `IFIFO` and `IFSOCK` file type flags.  Fix these up,
and add comments pointing to exactly where they come from (as the
wasi-musl source has lots of unused, different definitions of these
constants).

Add tests for the Zig convention that WASM preopen 3 is the current
working directory.   This is true for WASM with or without libc.

Enable several fs and posix tests that are now passing (not necessarily
because of this change) on wasm targets.

Fixes #20890.
2025-02-09 09:08:11 +01:00
max
961fc0e140
std.fs.Dir: update deleteTree doc comment to match function signature (#22509)
the actual parameter name is `sub_path` which is also referenced in other
comments describing the fuction.
2025-01-16 20:11:42 +00:00
Justin Braben
4a2a0f50ca
fix compilation errors for fs and fs.Dir (#21643)
* fix compilation errors for fs and fs.Dir

* mem.span instead of mem.sliceTo

* Updating symLinkAbsoluteW function parameters

* Update with expected rename semantics
2024-10-17 01:08:58 +02:00
achan1989
b01a5c6bb7 Explain why POLL_FD_READWRITE is not dangerous at sites of use 2024-10-06 09:47:12 +01:00
achan1989
0d85284e4d Create/open file on WASI targets should have POLL_FD_READWRITE rights 2024-10-05 15:23:00 +02:00
Linus Groh
8588964972 Replace deprecated default initializations with decl literals 2024-09-12 16:01:23 +01:00
Andrew Kelley
12d0c9a2fc add std.fs.Dir.Handle
mirrors std.fs.File.Handle
2024-08-01 13:47:23 -07:00
Alex Rønne Petersen
13945548fc
std.fs: Rework to always use statx() instead of fstat()/fstatat() on Linux.
statx() is strictly superior to stat() and friends. We can do this because the
standard library declares Linux 4.19 to be the minimum version supported in
std.Target. This is also necessary on riscv32 where there is only statx().

While here, I improved std.fs.File.metadata() to gather as much information as
possible when calling statx() since that is the expectation from this particular
API.
2024-07-29 09:50:41 +02:00
Andrew Kelley
08e83fee57
Merge pull request #20297 from sno2/wtf8-conversion-buffer-overflows
std: fix buffer overflows from improper WTF encoding
2024-07-28 20:24:31 -07:00
Carter Snook
219acaa1d6 std.fs.Dir: Refactor atomicSymLink from std.fs
Deprecates std.fs.atomicSymLink and removes the allocator requirement
from the new std.fs.Dir.atomicSymLink. Replaces the two usages of this
within std.

I did not include the TODOs from the original code that were based
off of `switch (err) { ..., else => return err }` not having correct
inference that cases handled in `...` are impossible in the error
union return type because these are not specified in many places but
I can add them back if wanted.

Thank you @squeek502 for help with fixing buffer overflows!
2024-07-28 20:08:52 -07:00
Andrew Kelley
01337e2093 fix regression of flock being called on wasi targets
* common symbols are now public from std.c even if they live in
  std.posix
* LOCK is now one of the common symbols since it is the same on 100% of
  operating systems.
* flock is now void value on wasi and windows
* std.fs.Dir now uses flock being void as feature detection, avoiding
  trying to call it on wasi and windows
2024-07-19 11:35:22 -07:00
Andrew Kelley
e8c4e79499 std.c reorganization
It is now composed of these main sections:
* Declarations that are shared among all operating systems.
* Declarations that have the same name, but different type signatures
  depending on the operating system. Often multiple operating systems
  share the same type signatures however.
* Declarations that are specific to a single operating system.
  - These are imported one per line so you can see where they come from,
    protected by a comptime block to prevent accessing the wrong one.

Closes #19352 by changing the convention to making types `void` and
functions `{}`, so that it becomes possible to update `@hasDecl` sites
to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up
removing some duplicate logic and update some bitrotted feature
detection checks.

A handful of types have been modified to gain namespacing and type
safety. This is a breaking change.

Oh, and the last usage of `usingnamespace` site is eliminated.
2024-07-19 00:30:32 -07:00
Krzysztof Wolicki
0cc42d090f
std.fs.Dir: Rename OpenDirOptions to OpenOptions (#20542)
* std.fs.Dir: Rename OpenDirOptions to OpenOptions
https://ziglang.org/documentation/master/#Avoid-Redundant-Names-in-Fully-Qualified-Namespaces

* std.fs.Dir: Add deprecated alias `OpenDirOptions`
2024-07-09 13:36:38 -07:00
Michael Bradshaw
21cad3e09f Rename MAX_NAME_BYTES to max_name_bytes 2024-07-03 17:42:09 +01:00
Carter Snook
0b3508073c std: fix buffer overflows from improper WTF encoding
Closes #20288
2024-06-14 15:42:17 -05:00
Ryan Liptak
76fb2b685b std: Convert deprecated aliases to compile errors and fix usages
Deprecated aliases that are now compile errors:

- `std.fs.MAX_PATH_BYTES` (renamed to `std.fs.max_path_bytes`)
- `std.mem.tokenize` (split into `tokenizeAny`, `tokenizeSequence`, `tokenizeScalar`)
- `std.mem.split` (split into `splitSequence`, `splitAny`, `splitScalar`)
- `std.mem.splitBackwards` (split into `splitBackwardsSequence`, `splitBackwardsAny`, `splitBackwardsScalar`)
- `std.unicode`
  + `utf16leToUtf8Alloc`, `utf16leToUtf8AllocZ`, `utf16leToUtf8`, `fmtUtf16le` (all renamed to have capitalized `Le`)
  + `utf8ToUtf16LeWithNull` (renamed to `utf8ToUtf16LeAllocZ`)
- `std.zig.CrossTarget` (moved to `std.Target.Query`)

Deprecated `lib/std/std.zig` decls were deleted instead of made a `@compileError` because the `refAllDecls` in the test block would trigger the `@compileError`. The deleted top-level `std` namespaces are:

- `std.rand` (renamed to `std.Random`)
- `std.TailQueue` (renamed to `std.DoublyLinkedList`)
- `std.ChildProcess` (renamed/moved to `std.process.Child`)

This is not exhaustive. Deprecated aliases that I didn't touch:
  + `std.io.*`
  + `std.Build.*`
  + `std.builtin.Mode`
  + `std.zig.c_translation.CIntLiteralRadix`
  + anything in `src/`
2024-06-13 10:18:59 -04:00
Ryan Liptak
5490021ab7 Dir.makeOpenPathAccessMaskW: Fix leaking intermediate directory handles
Fixes a regression introduced in 67455c5e70. The `errdefer` cannot run since its not possible for an error to occur, and we don't want it to run on the last handle, so we move the closing back down to where it was before 67455c5e70.
2024-06-04 18:45:25 -07:00
Georgijs
084c2cd90f
windows: use permissive file share flags everywhere (#19505)
* use permissive file share flags everywhere

* remove file_share_delete from createnamedpipefile
2024-05-11 23:34:40 +02:00
Jacob Young
67455c5e70 fs: handle OBJECT_NAME_COLLISION in makeOpenPath
This fixes a race condition when two threads/processes try to
`makeOpenPath` the same path simultaneously.
2024-05-07 05:23:29 -04:00
Ryan Liptak
b86c4bde64 Rename Dir.writeFile2 -> Dir.writeFile and update all callsites
writeFile was deprecated in favor of writeFile2 in f645022d16. This commit renames writeFile2 to writeFile and makes writeFile2 a compile error.
2024-05-03 13:29:22 -07:00