refactor: rename all 'allocator' args to 'gpa'

This commit is contained in:
utox39
2026-02-15 17:59:21 +01:00
parent 739b8d49f0
commit 1949f607a1
16 changed files with 181 additions and 182 deletions

View File

@@ -16,18 +16,18 @@ pub const KernelInfo = struct {
};
/// Returns the hostname.
pub fn getHostname(allocator: std.mem.Allocator) ![]u8 {
pub fn getHostname(gpa: std.mem.Allocator) ![]u8 {
var buf: [std.posix.HOST_NAME_MAX]u8 = undefined;
const hostnameEnv = try std.posix.gethostname(&buf);
const hostname = try allocator.dupe(u8, hostnameEnv);
const hostname = try gpa.dupe(u8, hostnameEnv);
return hostname;
}
pub fn getLocale(allocator: std.mem.Allocator, environ: std.process.Environ) ![]u8 {
const locale = std.process.Environ.getAlloc(environ, allocator, "LANG") catch |err| if (err == error.EnvironmentVariableNotFound) {
return allocator.dupe(u8, "Unknown");
pub fn getLocale(gpa: std.mem.Allocator, environ: std.process.Environ) ![]u8 {
const locale = std.process.Environ.getAlloc(environ, gpa, "LANG") catch |err| if (err == error.EnvironmentVariableNotFound) {
return gpa.dupe(u8, "Unknown");
} else return err;
return locale;
}
@@ -71,7 +71,7 @@ pub fn getSystemUptime(io: std.Io) !SystemUptime {
};
}
pub fn getKernelInfo(allocator: std.mem.Allocator) !KernelInfo {
pub fn getKernelInfo(gpa: std.mem.Allocator) !KernelInfo {
var size: usize = 0;
// --- KERNEL NAME ---
@@ -80,8 +80,8 @@ pub fn getKernelInfo(allocator: std.mem.Allocator) !KernelInfo {
return error.FailedToGetKernelNameSize;
}
const kernel_type: []u8 = try allocator.alloc(u8, size - 1);
errdefer allocator.free(kernel_type);
const kernel_type: []u8 = try gpa.alloc(u8, size - 1);
errdefer gpa.free(kernel_type);
// Second call to sysctlbyname to get the kernel name
if (c_sysctl.sysctlbyname("kern.ostype", kernel_type.ptr, &size, null, 0) != 0) {
@@ -94,8 +94,8 @@ pub fn getKernelInfo(allocator: std.mem.Allocator) !KernelInfo {
return error.FailedToGetKernelReleaseSize;
}
const os_release: []u8 = try allocator.alloc(u8, size - 1);
errdefer allocator.free(os_release);
const os_release: []u8 = try gpa.alloc(u8, size - 1);
errdefer gpa.free(os_release);
// Second call to sysctlbyname to get the kernel release
if (c_sysctl.sysctlbyname("kern.osrelease", os_release.ptr, &size, null, 0) != 0) {
@@ -108,7 +108,7 @@ pub fn getKernelInfo(allocator: std.mem.Allocator) !KernelInfo {
};
}
pub fn getOsInfo(allocator: std.mem.Allocator) ![]u8 {
pub fn getOsInfo(gpa: std.mem.Allocator) ![]u8 {
var size: usize = 0;
// First call to sysctlbyname to get the size of the string
@@ -116,20 +116,20 @@ pub fn getOsInfo(allocator: std.mem.Allocator) ![]u8 {
return error.FailedToGetCpuNameSize;
}
const os_version: []u8 = try allocator.alloc(u8, size - 1);
defer allocator.free(os_version);
const os_version: []u8 = try gpa.alloc(u8, size - 1);
defer gpa.free(os_version);
// Second call to sysctlbyname to get the os version
if (c_sysctl.sysctlbyname("kern.osproductversion", os_version.ptr, &size, null, 0) != 0) {
return error.FailedToGetOsVersion;
}
const os_info = try std.fmt.allocPrint(allocator, "macOS {s}", .{os_version});
const os_info = try std.fmt.allocPrint(gpa, "macOS {s}", .{os_version});
return os_info;
}
pub fn getWindowManagerInfo(allocator: std.mem.Allocator) ![]const u8 {
pub fn getWindowManagerInfo(gpa: std.mem.Allocator) ![]const u8 {
var name = [_]c_int{ c_sysctl.CTL_KERN, c_sysctl.KERN_PROC, c_sysctl.KERN_PROC_ALL };
var size: usize = 0;
@@ -138,8 +138,8 @@ pub fn getWindowManagerInfo(allocator: std.mem.Allocator) ![]const u8 {
return error.SysctlFailed;
}
const buffer: []u8 = try allocator.alloc(u8, size);
defer allocator.free(buffer);
const buffer: []u8 = try gpa.alloc(u8, size);
defer gpa.free(buffer);
// Second call to retrieve process data
if (c_sysctl.sysctl(&name, name.len, buffer.ptr, &size, null, 0) != 0) {
@@ -173,8 +173,8 @@ pub fn getWindowManagerInfo(allocator: std.mem.Allocator) ![]const u8 {
var pathbuf: [c_libproc.PROC_PIDPATHINFO_MAXSIZE]u8 = undefined;
// c_libproc.proc_pidpath saves the process name in `pathbuf` and returns the len
const path_len = @as(usize, @intCast(c_libproc.proc_pidpath(pid, &pathbuf, pathbuf.len)));
const proc_pathname = if (path_len > 0) try allocator.dupe(u8, pathbuf[0..@intCast(path_len)]) else try allocator.dupe(u8, "unknown");
defer allocator.free(proc_pathname);
const proc_pathname = if (path_len > 0) try gpa.dupe(u8, pathbuf[0..@intCast(path_len)]) else try gpa.dupe(u8, "unknown");
defer gpa.free(proc_pathname);
inline for (supported_wms) |wm| {
if (std.ascii.endsWithIgnoreCase(proc_pathname, wm)) {
@@ -183,7 +183,7 @@ pub fn getWindowManagerInfo(allocator: std.mem.Allocator) ![]const u8 {
else
proc_pathname;
break :outer try allocator.dupe(u8, basename);
break :outer try gpa.dupe(u8, basename);
}
}
}
@@ -191,5 +191,5 @@ pub fn getWindowManagerInfo(allocator: std.mem.Allocator) ![]const u8 {
break :outer null;
};
return wm_name orelse allocator.dupe(u8, "Quartz Compositor");
return wm_name orelse gpa.dupe(u8, "Quartz Compositor");
}