refactor(utils): move countEntries from macos utils in common utils

This commit is contained in:
utox39
2025-12-09 19:35:10 +01:00
parent a64db7a7d3
commit 6f4e4eb044
3 changed files with 15 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
const std = @import("std");
const utils = @import("utils.zig");
const utils = @import("../utils.zig");
pub fn getPackagesInfo(allocator: std.mem.Allocator) ![]const u8 {
var packages_info = std.array_list.Managed(u8).init(allocator);

View File

@@ -23,17 +23,3 @@ pub fn cfTypeRefToZigString(allocator: std.mem.Allocator, cf_type_ref: c_iokit.C
return allocator.realloc(buffer, actual_len);
}
pub fn countEntries(dir_path: []const u8) !usize {
var dir = try std.fs.openDirAbsolute(dir_path, .{ .iterate = true });
defer dir.close();
var count: usize = 0;
var iter = dir.iterate();
while (try iter.next()) |_| {
count += 1;
}
return count;
}

View File

@@ -125,3 +125,17 @@ pub fn readFile(allocator: std.mem.Allocator, file: std.fs.File, size: usize) ![
return allocator.dupe(u8, data);
}
pub fn countEntries(dir_path: []const u8) !usize {
var dir = try std.fs.openDirAbsolute(dir_path, .{ .iterate = true });
defer dir.close();
var count: usize = 0;
var iter = dir.iterate();
while (try iter.next()) |_| {
count += 1;
}
return count;
}