aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fs/path.zig
AgeCommit message (Collapse)Author
2025-10-29std.Io.Threaded: implement dirAccess for WindowsAndrew Kelley
2025-10-26fix `std.fs.path.resolveWindows` on UNC paths with mixed path separatorsTechatrix
2025-10-10replaced https://simonsapin.github.io/wtf-8/ with https://wtf-8.codeberg.page/usebeforefree
2025-08-31std.fmt: delete deprecated APIsAndrew Kelley
std.fmt.Formatter -> std.fmt.Alt std.fmt.format -> std.Io.Writer.print
2025-08-29std.Io: delete GenericReaderAndrew Kelley
and delete deprecated alias std.io
2025-08-11std.ArrayList: make unmanaged the defaultAndrew Kelley
2025-07-11std: rename `io` to `Io` in preparationAndrew Kelley
This commit is non-breaking. std.io is deprecated in favor of std.Io, in preparation for that namespace becoming an interface.
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-06-19Build: add install commands to `--verbose` outputJacob Young
2025-01-25std: add `fs.path.fmtJoin`mlugg
This allows joining paths without allocating using a `Writer`.
2025-01-21Revert "Merge pull request #21540 from BratishkaErik/search-env-in-path"Andrew Kelley
It caused an assertion failure when building Zig from source. This reverts commit 0595feb34128db22fbebea843af929de3ede8190, reversing changes made to 744771d3303e122474a72c8a94b14fe1e9fb480c. closes #22566 closes #22568
2025-01-20std.fs.path.joinSepMaybeZ: replace while-loops with for-loopsEric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-03-21std: promote tests to doctestsAndrew Kelley
Now these show up as "example usage" in generated documentation.
2024-02-24Add std.fs.path.fmtAsUtf8Lossy/fmtWtf16LeAsUtf8LossyRyan Liptak
2024-02-24Fix handling of Windows (WTF-16) and WASI (UTF-8) pathsRyan Liptak
Windows paths now use WTF-16 <-> WTF-8 conversion everywhere, which is lossless. Previously, conversion of ill-formed UTF-16 paths would either fail or invoke illegal behavior. WASI paths must be valid UTF-8, and the relevant function calls have been updated to handle the possibility of failure due to paths not being encoded/encodable as valid UTF-8. Closes #18694 Closes #1774 Closes #2565
2023-10-31std.builtin.Endian: make the tags lower caseAndrew Kelley
Let's take this breaking change opportunity to fix the style of this enum.
2023-10-18path.ComponentIterator: Add peekNext and peekPrevious functionsRyan Liptak
2023-10-08std.fs.path.resolve: add test cases for empty stringAndrew Kelley
Since I'm about to rely on this behavior.
2023-07-27Add fs.path.ComponentIterator and use it in Dir.makePathRyan Liptak
Before this commit, there were three issues with the makePath implementation: 1. The component iteration did not 'collapse' consecutive path separators; instead, it would treat `a/b//c` as `a/b//c`, `a/b/`, `a/b`, and `a`. 2. Trailing path separators led to redundant `makeDir` calls, e.g. with the path `a/b/` (if `a` doesn't exist), it would try to create `a/b/`, then try `a/b`, then try `a`, then try `a/b`, and finally try `a/b/` again. 3. The iteration did not treat the root of a path specially, so on Windows it could attempt to make a directory with a path like `X:` for something like `X:\a\b\c` if the `X:\` drive doesn't exist. This didn't lead to any problems that I could find, but there's no reason to try to make a drive letter as a directory (or any other root path). This commit fixes all three issues by introducing a ComponentIterator that is root-aware and handles both sequential path separators and trailing path separators and uses it in `Dir.makePath`. This reduces the number of `makeDir` calls for paths where (1) the root of the path doesn't exist, (2) there are consecutive path separators, or (3) there are trailing path separators As an example, here are the makeDir calls that would have been made before this commit when calling `makePath` for a relative path like `a/b//c//` (where the full path needs to be created): a/b//c// a/b//c/ a/b//c a/b/ a/b a a/b a/b/ a/b//c a/b//c/ a/b//c// And after this commit: a/b//c a/b a a/b a/b//c
2023-06-30fs.path: Fix Windows path component comparison being ASCII-onlyRyan Liptak
We can use eqlIgnoreCaseUtf8 to get Unicode-aware Windows-compliant case insensitive path component comparison
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-05-13Update all std.mem.tokenize calls to their appropriate functionRyan Liptak
Everywhere that can now use `tokenizeScalar` should get a nice little performance boost.
2023-04-30std: fix a bunch of typosLinus Groh
The majority of these are in comments, some in doc comments which might affect the generated documentation, and a few in parameter names - nothing that should be breaking, however.
2023-04-28update codebase to use `@memset` and `@memcpy`Andrew Kelley
2023-04-23Improvements to docs and textzooster
* docs(std.math): elaborate on difference between absCast and absInt * docs(std.rand.Random.weightedIndex): elaborate on likelihood I think this makes it easier to understand. * langref: add small reminder * docs(std.fs.path.extension): brevity * docs(std.bit_set.StaticBitSet): mention the specific types * std.debug.TTY: explain what purpose this struct serves This should also make it clearer that this struct is not supposed to provide unrelated terminal manipulation functionality such as setting the cursor position or something because terminals are complicated and we should keep this struct simple and focused on debugging. * langref(package listing): brevity * langref: explain what exactly `threadlocal` causes to happen * std.array_list: link between swapRemove and orderedRemove Maybe this can serve as a TLDR and make it easier to decide. * PrefetchOptions.locality: clarify docs that this is a range This confused me previously and I thought I can only use either 0 or 3. * fix typos and more * std.builtin.CallingConvention: document some CCs * langref: explain possibly cryptic names I think it helps knowing what exactly these acronyms (@clz and @ctz) and abbreviations (@popCount) mean. * variadic function error: add missing preposition * std.fmt.format docs: nicely hyphenate * help menu: say what to optimize for I think this is slightly more specific than just calling it "optimizations". These are speed optimizations. I used the word "performance" here.
2023-04-05std: fix memory bugsJacob Young
This fixes logged errors during CI based on the new GPA checks.
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2023-01-05Fix cache-dir specified on the command line (#14076)pluick
The resolvePosix and resolveWindows routines changed behaviour in an earlier commit so that the return value is not always an absolute path. That caused the relativePosix and relativeWindows to return a relative path that is not correct. The change in behaviour mentioned above would cause a local cache-dir to be created in the wrong directory when --cache-dir was specified for a build.
2023-01-03docs: Clarify that std.fs.path.resolve doesn't resolve relative path toSizhe Zhao
absolute path
2022-11-29std.mem.Allocator: allow shrink to failAndrew Kelley
closes #13535
2022-11-28CLI: more careful resolution of pathsAndrew Kelley
In general, we prefer compiler code to use relative paths based on open directory handles because this is the most portable. However, sometimes absolute paths are used, and sometimes relative paths are used that go up a directory. The recent improvements in 81d2135ca6ebd71b8c121a19957c8fbf7f87125b regressed the use case when an absolute path is used for the zig lib directory mixed with a relative path used for the root source file. This could happen when, for example, running the standard library tests, like this: stage3/bin/zig test ../lib/std/std.zig This happened because the zig lib dir was inferred to be an absolute directory based on the zig executable directory, while the root source file was detected as a relative path. There was no common prefix and so it was not determined that the std.zig file was inside the lib directory. This commit adds a function for resolving paths that preserves relative path names while allowing absolute paths, and converting relative upwards paths (e.g. "../foo") to absolute paths. This restores the previous functionality while remaining compatible with systems such as WASI that cannot deal with absolute paths.
2022-11-22std.fs.path.resolve: eliminate getcwd() syscallAndrew Kelley
This is a breaking change to the API. Instead of the first path implicitly being the current working directory, it now asserts that the number of paths passed is greater than zero. Importantly, it never calls getcwd(); instead, it can possibly return ".", or a series of "../". This changes the error set to only be `error{OutOfMemory}`. closes #13613
2022-10-24std.fs.path: add stem()r00ster91
2022-10-24docs(std.fs.path.extension): correct arrow alignmentr00ster91
2022-09-23use `std.ascii` instead of defining ascii functions in `std.fs.path`noiryuh
2022-09-22Fix docstring for std.fs.path.extensionEvin Yulo
2022-08-22Sema: fix parameter of type 'T' must be comptime errorVeikka Tuominen
Closes #12519 Closes #12505
2022-04-16stdlib std.os: Improve wasi-libc parity for WASI CWD emulationCody Tapscott
Two major changes here: 1. We store the CWD as a simple `[]const u8` and lookup Preopens for every absolute or CWD-referenced file operation, based on the Preopen with the longest match (i.e. most specific path) 2. Preorders are normalized to POSIX absolute paths at init time. Behavior depends on the "cwd_root" parameter of `initPreopensWasi`: `cwd_root` is used for any Preopens that start with "." For example: "./foo/bar" - inits to -> "{cwd_root}/foo/bar" "foo/bar" - inits to -> "/foo/bar" "/foo/bar" - inits to -> "/foo/bar" `cwd_root` must be an absolute path. Using "/" as `cwd_root` gives behavior similar to wasi-libc.
2022-03-03stdlib WASI: Add realpath() support for non-absolute PreopensCody Tapscott
2022-03-03stdlib: Add emulated CWD to std.os for WASI targetsCody Tapscott
This adds a special CWD file descriptor, AT.FDCWD (-2), to refer to the current working directory. The `*at(...)` functions look for this and resolve relative paths against the stored CWD. Absolute paths are dynamically matched against the stored Preopens. "os.initPreopensWasi()" must be called before std.os functions will resolve relative or absolute paths correctly. This is asserted at runtime. Support has been added for: `open`, `rename`, `mkdir`, `rmdir`, `chdir`, `fchdir`, `link`, `symlink`, `unlink`, `readlink`, `fstatat`, `access`, and `faccessat`. This also includes limited support for `getcwd()` and `realpath()`. These return an error if the CWD does not correspond to a Preopen with an absolute path. They also do not currently expand symlinks.
2022-01-11std.fs.path: revert recent public API changeAndrew Kelley
41fd343508880ffdfbc83c7b053237da09199f02 made a breaking change to the public API; this commit reverts the API changes but keeps the improved logic.
2022-01-11std: fix path joining on UEFIfifty-six
UEFI uses `\` for paths exclusively. This changes std.fs.path to use `\` for UEFI path joining. Also adds a few tests regarding it, specifically in making sure double-separators do not result from path joining, as the UEFI spec says to convert any that result from joining into single separators (UEFI Spec Version 2.7, pg. 448).
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-11-04std: Fix path resolution on WindowsLemonBoy
GetCurrentDirectory returns a path with a trailing slash iff the cwd is a root directory, making the code in `resolveWindows` return an invalid path with two consecutive slashes. Closes #10093
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-08-06Update all usages of mem.split/mem.tokenize for generic versionRyan Liptak
2021-07-28Skip empty strings in std.fs.path.join functionAustin Clements
2021-06-21fix code broken from previous commitJacob G-W
2021-05-17std: update regarding std.builtin reorganizationAndrew Kelley
There are also some regressed std.fmt tests here and I haven't figured out what's wrong yet.