aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fs/path.zig
AgeCommit message (Collapse)Author
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.
2021-05-08Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
Conflicts: * doc/langref.html.in * lib/std/enums.zig * lib/std/fmt.zig * lib/std/hash/auto_hash.zig * lib/std/math.zig * lib/std/mem.zig * lib/std/meta.zig * test/behavior/alignof.zig * test/behavior/bitcast.zig * test/behavior/bugs/1421.zig * test/behavior/cast.zig * test/behavior/ptrcast.zig * test/behavior/type_info.zig * test/behavior/vector.zig Master branch added `try` to a bunch of testing function calls, and some lines also had changed how to refer to the native architecture and other `@import("builtin")` stuff.
2021-05-08std: update usage of std.testingVeikka Tuominen
2021-04-15std: change `@import("builtin")` to `std.builtin`Andrew Kelley
2021-03-18std: Fix std.fs.path.joinZroot
2021-03-01std: Replace lastIndexOf with lastIndexOfScalarLemonBoy
This may work around the miscompilation in LLVM 12.
2021-03-01std: Add std.fs.path.joinZ (#7974)fancl20
* std: Add std.fs.path.joinZ * Merge std.fs.path.join and std.fs.path.joinZZ tests
2021-01-11update path.join to recognize any separators that isSep doesTravis
2020-12-31Year++Frank Denis
2020-12-11std.fs.path.extension: different behavior for ending dotAndrew Kelley
extension("a.") now returns "." instead of "". This matches both Python and Node.js standard library behavior as well as my personal opinion on how this function should be defined. Apologies for missing this in the code review.
2020-12-11std.fs.path.extension: add additional API guaranteeAndrew Kelley
Added: The returned slice is guaranteed to have its pointer within the start and end pointer address range of `path`, even if it is length zero.
2020-12-11Merge pull request #7098 from MasterQ32/std.fs.path.extensionAndrew Kelley
Implements std.fs.path.extension
2020-11-18Changes behaviour from std.fs.path.extension from returning `null` to ↵Felix (xq) Queißner
returning `""`.
2020-11-14Adapts to @andrewrk​s comment to include dot.Felix (xq) Queißner
2020-11-13std.fs.path.dirname: return null when input path is rootAndrew Kelley
This intentionally diverges from the unix dirname command, as well as Python and Node.js standard libraries, which all have this edge case return the input path, unmodified. This is a footgun, and nobody should have ever done it this way. Even the man page contradicts the behavior. It says: "strip last component from file name". Now consider, if you remove the last item from an array of length 1, then you have now an array of length 0. After you strip the last component, there should be no components remaining. Clearly, returning the input parameter unmodified in this case does not match the documented behavior. This is my justification for taking a stand on this API design. closes #6746 closes #6727 closes #6584 closes #6592 closes #6602
2020-11-13Makes @haze happy.Felix (xq) Queißner
2020-11-13Respects leading `.` and ignores it.Felix (xq) Queißner
2020-11-13Implements std.fs.path.extension.Felix (xq) Queißner
2020-08-20add license header to all std lib filesAndrew Kelley
add SPDX license identifier copyright ownership is zig contributors
2020-07-04std.mem.dupe is deprecated, move all references in stdjoachimschmidt557
Replaced all occurences of std.mem.dupe in stdlib with Allocator.dupe/std.mem.dupeZ -> Allocator.dupeZ
2020-06-09fix memory errorsJonathan Marler
2020-05-18Add/fix missing WASI functionality to pass libstd testsJakub Konka
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-01Merge branch 'windows-evented-io' of https://github.com/FireFox317/zig into ↵Andrew Kelley
FireFox317-windows-evented-io
2020-03-30std lib API deprecations for the upcoming 0.6.0 releaseAndrew Kelley
See #3811
2020-02-28introduce operating system version ranges as part of the targetAndrew Kelley
* 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-12Switch a bunch of FBA to use testing.allocatorBenjamin Feng
2020-02-05std: Rename isAbsoluteW to isAbsoluteWindowsWLemonBoy
2020-02-04std: Fix edge case in isAbsolute fn familyLemonBoy
* Empty strings are not considered absolute paths. * Refactor some common code. Closes #4382
2020-01-29Promoted "leak_count_allocator" to the main testing.allocatorBenjamin Feng
2020-01-29Create leak_count_allocatorBenjamin Feng
2020-01-29Move debug.global_allocator to testing.allocatorBenjamin Feng
2019-12-01Merge remote-tracking branch 'origin/master' into remove-array-type-coercionAndrew Kelley
2019-11-30move `std.fs.Dir.cwd` to `std.fs.cwd`Andrew Kelley
update to non-deprecated std.fs APIs throughout the codebase Related: #3811
2019-11-27remove type coercion from array values to referencesAndrew Kelley
* Implements #3768. This is a sweeping breaking change that requires many (trivial) edits to Zig source code. Array values no longer coerced to slices; however one may use `&` to obtain a reference to an array value, which may then be coerced to a slice. * Adds `IrInstruction::dump`, for debugging purposes. It's useful to call to inspect the instruction when debugging Zig IR. * Fixes bugs with result location semantics. See the new behavior test cases, and compile error test cases. * Fixes bugs with `@typeInfo` not properly resolving const values. * Behavior tests are passing but std lib tests are not yet. There is more work to do before merging this branch.
2019-11-21string literals are now null terminatedAndrew Kelley
this also deletes C string literals from the language, and then makes the std lib changes and compiler changes necessary to get the behavior tests and std lib tests passing again.
2019-11-06allow type coercion from *[0]T to E![]const TAndrew Kelley
This is an unambiguous, safe cast.
2019-10-29inline path separator looplukechampine