authorgravatar for dalal.chinmay.0101@gmail.comChinmay Dalal <dalal.chinmay.0101@gmail.com> 2025-07-31 20:52:56+05:30
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-08-01 04:34:45+02:00
loga2d21d63270ebb5eec0d437f7726c261455da66b
treefa268a946085dd214aa63e29454c9119e486b0c5
parent0294e91451ba8fb06a40cbd0d3da80e2792f5923

enable pwd.h functions for other OSes

also add the layout of `struct passwd` for DragonflyBSD and FreeBSD: - https://github.com/DragonFlyBSD/DragonFlyBSD/blob/c267aac0072dae6cf4ae874605f3f0659a2fc820/include/pwd.h#L112 - https://cgit.freebsd.org/src/tree/include/pwd.h?id=d66f9c86fa3fd8d8f0a56ea96b03ca11f2fac1fb#n114

2 files changed, 18 insertions(+), 11 deletions(-)

lib/std/c.zig+18-6
......@@ -204,6 +204,19 @@ pub const passwd = switch (native_os) {
204204 shell: ?[*:0]const u8, // default shell
205205 expire: time_t, // account expiration
206206 },
207 .dragonfly, .freebsd => extern struct {
208 name: ?[*:0]const u8, // user name
209 passwd: ?[*:0]const u8, // encrypted password
210 uid: uid_t, // user uid
211 gid: gid_t, // user gid
212 change: time_t, // password change time
213 class: ?[*:0]const u8, // user access class
214 gecos: ?[*:0]const u8, // Honeywell login info
215 dir: ?[*:0]const u8, // home directory
216 shell: ?[*:0]const u8, // default shell
217 expire: time_t, // account expiration
218 fields: c_int, // internal
219 },
207220 else => void,
208221};
209222
......@@ -10271,9 +10284,13 @@ pub const fstatat = switch (native_os) {
1027110284 },
1027210285 else => private.fstatat,
1027310286};
10274
10287pub extern "c" fn getpwent() ?*passwd;
10288pub extern "c" fn endpwent() void;
10289pub extern "c" fn setpwent() void;
1027510290pub extern "c" fn getpwnam(name: [*:0]const u8) ?*passwd;
10291pub extern "c" fn getpwnam_r(name: [*:0]const u8, pwd: *passwd, buf: [*]u8, buflen: usize, result: *?*passwd) c_int;
1027610292pub extern "c" fn getpwuid(uid: uid_t) ?*passwd;
10293pub extern "c" fn getpwuid_r(uid: uid_t, pwd: *passwd, buf: [*]u8, buflen: usize, result: *?*passwd) c_int;
1027710294pub extern "c" fn getgrent() ?*group;
1027810295pub extern "c" fn setgrent() void;
1027910296pub extern "c" fn endgrent() void;
......@@ -11009,11 +11026,7 @@ pub const bcrypt = openbsd.bcrypt;
1100911026pub const bcrypt_checkpass = openbsd.bcrypt_checkpass;
1101011027pub const bcrypt_gensalt = openbsd.bcrypt_gensalt;
1101111028pub const bcrypt_newhash = openbsd.bcrypt_newhash;
11012pub const endpwent = openbsd.endpwent;
11013pub const getpwent = openbsd.getpwent;
11014pub const getpwnam_r = openbsd.getpwnam_r;
1101511029pub const getpwnam_shadow = openbsd.getpwnam_shadow;
11016pub const getpwuid_r = openbsd.getpwuid_r;
1101711030pub const getpwuid_shadow = openbsd.getpwuid_shadow;
1101811031pub const getthrid = openbsd.getthrid;
1101911032pub const login_cap_t = openbsd.login_cap_t;
......@@ -11030,7 +11043,6 @@ pub const pthread_spinlock_t = openbsd.pthread_spinlock_t;
1103011043pub const pw_dup = openbsd.pw_dup;
1103111044pub const setclasscontext = openbsd.setclasscontext;
1103211045pub const setpassent = openbsd.setpassent;
11033pub const setpwent = openbsd.setpwent;
1103411046pub const setusercontext = openbsd.setusercontext;
1103511047pub const uid_from_user = openbsd.uid_from_user;
1103611048pub const unveil = openbsd.unveil;
lib/std/c/openbsd.zig-5
......@@ -81,11 +81,6 @@ pub extern "c" fn auth_checknologin(lc: *login_cap_t) void;
8181
8282pub extern "c" fn getpwuid_shadow(uid: uid_t) ?*passwd;
8383pub extern "c" fn getpwnam_shadow(name: [*:0]const u8) ?*passwd;
84pub extern "c" fn getpwnam_r(name: [*:0]const u8, pw: *passwd, buf: [*]u8, buflen: usize, pwretp: *?*passwd) c_int;
85pub extern "c" fn getpwuid_r(uid: uid_t, pw: *passwd, buf: [*]u8, buflen: usize, pwretp: *?*passwd) c_int;
86pub extern "c" fn getpwent() ?*passwd;
87pub extern "c" fn setpwent() void;
88pub extern "c" fn endpwent() void;
8984pub extern "c" fn setpassent(stayopen: c_int) c_int;
9085pub extern "c" fn uid_from_user(name: [*:0]const u8, uid: *uid_t) c_int;
9186pub extern "c" fn user_from_uid(uid: uid_t, noname: c_int) ?[*:0]const u8;