From 946d2a031634b81ee2728f61cd2d321fcab27c33 Mon Sep 17 00:00:00 2001 From: Eric Joldasov Date: Wed, 20 Mar 2024 22:51:30 +0500 Subject: [PATCH] src: update to standard library changes in Zig 0.12.0-dev.3385+3a836b480 * rearrangment of entries in `std.os` and `std.c`, `std.posix` finally extracted in https://github.com/ziglang/zig/pull/19354 . Signed-off-by: Eric Joldasov --- src/main.zig | 8 ++++---- src/scan.zig | 10 +++++----- src/ui.zig | 22 +++++++++++----------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main.zig b/src/main.zig index cd3e6d8..4ab196e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -365,7 +365,7 @@ fn spawnShell() void { else env.put("NCDU_LEVEL", "1") catch unreachable; - const shell = std.os.getenvZ("NCDU_SHELL") orelse std.os.getenvZ("SHELL") orelse "/bin/sh"; + const shell = std.posix.getenvZ("NCDU_SHELL") orelse std.posix.getenvZ("SHELL") orelse "/bin/sh"; var child = std.process.Child.init(&.{shell}, allocator); child.cwd = path.items; child.env_map = &env; @@ -433,7 +433,7 @@ pub fn main() void { config.thousands_sep = span; } } - if (std.os.getenvZ("NO_COLOR") == null) config.ui_color = .darkbg; + if (std.posix.getenvZ("NO_COLOR") == null) config.ui_color = .darkbg; const loadConf = blk: { var args = std.process.ArgIteratorPosix.init(); @@ -446,11 +446,11 @@ pub fn main() void { if (loadConf) { tryReadArgsFile("/etc/ncdu.conf"); - if (std.os.getenvZ("XDG_CONFIG_HOME")) |p| { + if (std.posix.getenvZ("XDG_CONFIG_HOME")) |p| { const path = std.fs.path.joinZ(allocator, &.{p, "ncdu", "config"}) catch unreachable; defer allocator.free(path); tryReadArgsFile(path); - } else if (std.os.getenvZ("HOME")) |p| { + } else if (std.posix.getenvZ("HOME")) |p| { const path = std.fs.path.joinZ(allocator, &.{p, ".config", "ncdu", "config"}) catch unreachable; defer allocator.free(path); tryReadArgsFile(path); diff --git a/src/scan.zig b/src/scan.zig index 4e7106b..07a2a3d 100644 --- a/src/scan.zig +++ b/src/scan.zig @@ -32,17 +32,17 @@ const Stat = struct { } fn read(parent: std.fs.Dir, name: [:0]const u8, follow: bool) !Stat { - const stat = try std.os.fstatatZ(parent.fd, name, if (follow) 0 else std.os.AT.SYMLINK_NOFOLLOW); + const stat = try std.posix.fstatatZ(parent.fd, name, if (follow) 0 else std.posix.AT.SYMLINK_NOFOLLOW); return Stat{ .blocks = clamp(Stat, .blocks, stat.blocks), .size = clamp(Stat, .size, stat.size), .dev = truncate(Stat, .dev, stat.dev), .ino = truncate(Stat, .ino, stat.ino), .nlink = clamp(Stat, .nlink, stat.nlink), - .hlinkc = stat.nlink > 1 and !std.os.system.S.ISDIR(stat.mode), - .dir = std.os.system.S.ISDIR(stat.mode), - .reg = std.os.system.S.ISREG(stat.mode), - .symlink = std.os.system.S.ISLNK(stat.mode), + .hlinkc = stat.nlink > 1 and !std.posix.S.ISDIR(stat.mode), + .dir = std.posix.S.ISDIR(stat.mode), + .reg = std.posix.S.ISREG(stat.mode), + .symlink = std.posix.S.ISLNK(stat.mode), .ext = .{ .mtime = clamp(model.Ext, .mtime, stat.mtime().tv_sec), .uid = truncate(model.Ext, .uid, stat.uid), diff --git a/src/ui.zig b/src/ui.zig index 3851ed8..59bae8f 100644 --- a/src/ui.zig +++ b/src/ui.zig @@ -343,7 +343,7 @@ pub fn init() void { clearScr(); if (main.config.nc_tty) { const tty = c.fopen("/dev/tty", "r+"); - if (tty == null) die("Error opening /dev/tty: {s}.\n", .{ c.strerror(@intFromEnum(std.c.getErrno(-1))) }); + if (tty == null) die("Error opening /dev/tty: {s}.\n", .{ c.strerror(@intFromEnum(std.posix.errno(-1))) }); const term = c.newterm(null, tty, tty); if (term == null) die("Error initializing ncurses.\n", .{}); _ = c.set_term(term); @@ -473,14 +473,14 @@ pub fn addnum(bg: Bg, v: u64) void { // Print a file mode, takes 10 columns pub fn addmode(mode: u32) void { - addch(switch (mode & std.os.S.IFMT) { - std.os.S.IFDIR => 'd', - std.os.S.IFREG => '-', - std.os.S.IFLNK => 'l', - std.os.S.IFIFO => 'p', - std.os.S.IFSOCK => 's', - std.os.S.IFCHR => 'c', - std.os.S.IFBLK => 'b', + addch(switch (mode & std.posix.S.IFMT) { + std.posix.S.IFDIR => 'd', + std.posix.S.IFREG => '-', + std.posix.S.IFLNK => 'l', + std.posix.S.IFIFO => 'p', + std.posix.S.IFSOCK => 's', + std.posix.S.IFCHR => 'c', + std.posix.S.IFBLK => 'b', else => '?' }); addch(if (mode & 0o400 > 0) 'r' else '-'); @@ -491,7 +491,7 @@ pub fn addmode(mode: u32) void { addch(if (mode & 0o2000 > 0) 's' else if (mode & 0o010 > 0) @as(u7, 'x') else '-'); addch(if (mode & 0o004 > 0) 'r' else '-'); addch(if (mode & 0o002 > 0) 'w' else '-'); - addch(if (mode & 0o1000 > 0) (if (std.os.S.ISDIR(mode)) @as(u7, 't') else 'T') else if (mode & 0o001 > 0) @as(u7, 'x') else '-'); + addch(if (mode & 0o1000 > 0) (if (std.posix.S.ISDIR(mode)) @as(u7, 't') else 'T') else if (mode & 0o001 > 0) @as(u7, 'x') else '-'); } // Print a timestamp, takes 25 columns @@ -592,5 +592,5 @@ pub fn getch(block: bool) i32 { return ch; } die("Error reading keyboard input, assuming TTY has been lost.\n(Potentially nonsensical error message: {s})\n", - .{ c.strerror(@intFromEnum(std.c.getErrno(-1))) }); + .{ c.strerror(@intFromEnum(std.posix.errno(-1))) }); }