diff options
| author | Ryan Liptak <squeek502@hotmail.com> | 2024-05-02 20:20:41 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-06-13 10:18:59 -0400 |
| commit | 76fb2b685b202ea665b850338e353c7816f5b2bb (patch) | |
| tree | 16b4b39db7541febd2b4bf92c041239bdd45f144 /lib/std/fs.zig | |
| parent | 4aa15440c7a12bcc6bc0cd589ade02295549d48c (diff) | |
| download | zig-76fb2b685b202ea665b850338e353c7816f5b2bb.tar.gz zig-76fb2b685b202ea665b850338e353c7816f5b2bb.zip | |
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/`
Diffstat (limited to 'lib/std/fs.zig')
| -rw-r--r-- | lib/std/fs.zig | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/lib/std/fs.zig b/lib/std/fs.zig index ee2cce1ef8..139660815a 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -35,8 +35,7 @@ pub const realpathW = posix.realpathW; pub const getAppDataDir = @import("fs/get_app_data_dir.zig").getAppDataDir; pub const GetAppDataDirError = @import("fs/get_app_data_dir.zig").GetAppDataDirError; -/// Deprecated: use `max_path_bytes`. -pub const MAX_PATH_BYTES = max_path_bytes; +pub const MAX_PATH_BYTES = @compileError("deprecated; renamed to max_path_bytes"); /// The maximum length of a file path that the operating system will accept. /// @@ -417,20 +416,20 @@ pub fn deleteTreeAbsolute(absolute_path: []const u8) !void { /// On Windows, `pathname` should be encoded as [WTF-8](https://simonsapin.github.io/wtf-8/). /// On WASI, `pathname` should be encoded as valid UTF-8. /// On other platforms, `pathname` is an opaque sequence of bytes with no particular encoding. -pub fn readLinkAbsolute(pathname: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { +pub fn readLinkAbsolute(pathname: []const u8, buffer: *[max_path_bytes]u8) ![]u8 { assert(path.isAbsolute(pathname)); return posix.readlink(pathname, buffer); } /// Windows-only. Same as `readlinkW`, except the path parameter is null-terminated, WTF16 /// encoded. -pub fn readlinkAbsoluteW(pathname_w: [*:0]const u16, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { +pub fn readlinkAbsoluteW(pathname_w: [*:0]const u16, buffer: *[max_path_bytes]u8) ![]u8 { assert(path.isAbsoluteWindowsW(pathname_w)); return posix.readlinkW(pathname_w, buffer); } /// Same as `readLink`, except the path parameter is null-terminated. -pub fn readLinkAbsoluteZ(pathname_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { +pub fn readLinkAbsoluteZ(pathname_c: [*:0]const u8, buffer: *[max_path_bytes]u8) ![]u8 { assert(path.isAbsoluteZ(pathname_c)); return posix.readlinkZ(pathname_c, buffer); } @@ -504,9 +503,9 @@ pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File { const prefixed_path_w = try windows.wToPrefixedFileW(null, image_path_name); return cwd().openFileW(prefixed_path_w.span(), flags); } - // Use of MAX_PATH_BYTES here is valid as the resulting path is immediately + // Use of max_path_bytes here is valid as the resulting path is immediately // opened with no modification. - var buf: [MAX_PATH_BYTES]u8 = undefined; + var buf: [max_path_bytes]u8 = undefined; const self_exe_path = try selfExePath(&buf); buf[self_exe_path.len] = 0; return openFileAbsoluteZ(buf[0..self_exe_path.len :0].ptr, flags); @@ -554,14 +553,14 @@ pub const SelfExePathError = error{ /// `selfExePath` except allocates the result on the heap. /// Caller owns returned memory. pub fn selfExePathAlloc(allocator: Allocator) ![]u8 { - // Use of MAX_PATH_BYTES here is justified as, at least on one tested Linux + // Use of max_path_bytes here is justified as, at least on one tested Linux // system, readlink will completely fail to return a result larger than // PATH_MAX even if given a sufficiently large buffer. This makes it // fundamentally impossible to get the selfExePath of a program running in // a very deeply nested directory chain in this way. // TODO(#4812): Investigate other systems and whether it is possible to get // this path by trying larger and larger buffers until one succeeds. - var buf: [MAX_PATH_BYTES]u8 = undefined; + var buf: [max_path_bytes]u8 = undefined; return allocator.dupe(u8, try selfExePath(&buf)); } @@ -581,12 +580,12 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { if (is_darwin) { // Note that _NSGetExecutablePath() will return "a path" to // the executable not a "real path" to the executable. - var symlink_path_buf: [MAX_PATH_BYTES:0]u8 = undefined; - var u32_len: u32 = MAX_PATH_BYTES + 1; // include the sentinel + var symlink_path_buf: [max_path_bytes:0]u8 = undefined; + var u32_len: u32 = max_path_bytes + 1; // include the sentinel const rc = std.c._NSGetExecutablePath(&symlink_path_buf, &u32_len); if (rc != 0) return error.NameTooLong; - var real_path_buf: [MAX_PATH_BYTES]u8 = undefined; + var real_path_buf: [max_path_bytes]u8 = undefined; const real_path = std.posix.realpathZ(&symlink_path_buf, &real_path_buf) catch |err| switch (err) { error.InvalidWtf8 => unreachable, // Windows-only error.NetworkNotFound => unreachable, // Windows-only @@ -634,7 +633,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { const argv0 = mem.span(std.os.argv[0]); if (mem.indexOf(u8, argv0, "/") != null) { // argv[0] is a path (relative or absolute): use realpath(3) directly - var real_path_buf: [MAX_PATH_BYTES]u8 = undefined; + var real_path_buf: [max_path_bytes]u8 = undefined; const real_path = posix.realpathZ(std.os.argv[0], &real_path_buf) catch |err| switch (err) { error.InvalidWtf8 => unreachable, // Windows-only error.NetworkNotFound => unreachable, // Windows-only @@ -650,13 +649,13 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { const PATH = posix.getenvZ("PATH") orelse return error.FileNotFound; var path_it = mem.tokenizeScalar(u8, PATH, path.delimiter); while (path_it.next()) |a_path| { - var resolved_path_buf: [MAX_PATH_BYTES - 1:0]u8 = undefined; + var resolved_path_buf: [max_path_bytes - 1:0]u8 = undefined; const resolved_path = std.fmt.bufPrintZ(&resolved_path_buf, "{s}/{s}", .{ a_path, std.os.argv[0], }) catch continue; - var real_path_buf: [MAX_PATH_BYTES]u8 = undefined; + var real_path_buf: [max_path_bytes]u8 = undefined; if (posix.realpathZ(resolved_path, &real_path_buf)) |real_path| { // found a file, and hope it is the right file if (real_path.len > out_buffer.len) @@ -689,14 +688,14 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { /// `selfExeDirPath` except allocates the result on the heap. /// Caller owns returned memory. pub fn selfExeDirPathAlloc(allocator: Allocator) ![]u8 { - // Use of MAX_PATH_BYTES here is justified as, at least on one tested Linux + // Use of max_path_bytes here is justified as, at least on one tested Linux // system, readlink will completely fail to return a result larger than // PATH_MAX even if given a sufficiently large buffer. This makes it // fundamentally impossible to get the selfExeDirPath of a program running // in a very deeply nested directory chain in this way. // TODO(#4812): Investigate other systems and whether it is possible to get // this path by trying larger and larger buffers until one succeeds. - var buf: [MAX_PATH_BYTES]u8 = undefined; + var buf: [max_path_bytes]u8 = undefined; return allocator.dupe(u8, try selfExeDirPath(&buf)); } @@ -716,13 +715,13 @@ pub fn selfExeDirPath(out_buffer: []u8) SelfExePathError![]const u8 { /// On other platforms, the result is an opaque sequence of bytes with no particular encoding. /// See also `Dir.realpath`. pub fn realpathAlloc(allocator: Allocator, pathname: []const u8) ![]u8 { - // Use of MAX_PATH_BYTES here is valid as the realpath function does not + // Use of max_path_bytes here is valid as the realpath function does not // have a variant that takes an arbitrary-size buffer. // TODO(#4812): Consider reimplementing realpath or using the POSIX.1-2008 // NULL out parameter (GNU's canonicalize_file_name) to handle overelong // paths. musl supports passing NULL but restricts the output to PATH_MAX // anyway. - var buf: [MAX_PATH_BYTES]u8 = undefined; + var buf: [max_path_bytes]u8 = undefined; return allocator.dupe(u8, try posix.realpath(pathname, &buf)); } |
