this repo has no description

Fix crash with --long on macos

It turns out macOS does several things that go against the assumptions currently built into lsr:

1. The `/etc/passwd` file has an extensive comment at the top of the file; several lines starting with `#`.
2. macOS (and apparently [some other operating systems](https://community.unix.com/t/negative-uid-gid-i-can-see-em-but-what-the-hell-do-they-mean/139505)) allow negative `uid`s and `gid`s.

So, the changes here:

1. Allow for comments in `/etc/passwd`; and
2. Use `i33` instead of `u32`, `posix.uid_t` and `posix.gid_t` when parsing and using `uid`s and `gid`s.

authored by reykjalin.org and committed by

Tangled 87b0c6bd 3b2ea6d0

+16 -4
+16 -4
src/main.zig
··· 636 636 }; 637 637 638 638 const User = struct { 639 - uid: posix.uid_t, 639 + uid: if (builtin.os.tag == .macos) i33 else posix.uid_t, 640 640 name: []const u8, 641 641 642 642 fn lessThan(_: void, lhs: User, rhs: User) bool { ··· 645 645 }; 646 646 647 647 const Group = struct { 648 - gid: posix.gid_t, 648 + gid: if (builtin.os.tag == .macos) i33 else posix.gid_t, 649 649 name: []const u8, 650 650 651 651 fn lessThan(_: void, lhs: Group, rhs: Group) bool { ··· 905 905 // <name>:<throwaway>:<uid><...garbage> 906 906 while (lines.next()) |line| { 907 907 if (line.len == 0) continue; 908 + if (std.mem.startsWith(u8, line, "#")) continue; 909 + 908 910 var iter = std.mem.splitScalar(u8, line, ':'); 909 911 const name = iter.first(); 910 912 _ = iter.next(); ··· 912 914 913 915 const user: User = .{ 914 916 .name = name, 915 - .uid = try std.fmt.parseInt(u32, uid, 10), 917 + .uid = try std.fmt.parseInt( 918 + if (builtin.os.tag == .macos) i33 else u32, 919 + uid, 920 + 10, 921 + ), 916 922 }; 917 923 918 924 cmd.users.appendAssumeCapacity(user); ··· 947 953 // <name>:<throwaway>:<uid><...garbage> 948 954 while (lines.next()) |line| { 949 955 if (line.len == 0) continue; 956 + if (std.mem.startsWith(u8, line, "#")) continue; 957 + 950 958 var iter = std.mem.splitScalar(u8, line, ':'); 951 959 const name = iter.first(); 952 960 _ = iter.next(); ··· 954 962 955 963 const group: Group = .{ 956 964 .name = name, 957 - .gid = try std.fmt.parseInt(u32, gid, 10), 965 + .gid = try std.fmt.parseInt( 966 + if (builtin.os.tag == .macos) i33 else u32, 967 + gid, 968 + 10, 969 + ), 958 970 }; 959 971 960 972 cmd.groups.appendAssumeCapacity(group);