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) {...@@ -204,6 +204,19 @@ pub const passwd = switch (native_os) {
204 shell: ?[*:0]const u8, // default shell204 shell: ?[*:0]const u8, // default shell
205 expire: time_t, // account expiration205 expire: time_t, // account expiration
206 },206 },
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 },
207 else => void,220 else => void,
208};221};
209222
...@@ -10271,9 +10284,13 @@ pub const fstatat = switch (native_os) {...@@ -10271,9 +10284,13 @@ pub const fstatat = switch (native_os) {
10271 },10284 },
10272 else => private.fstatat,10285 else => private.fstatat,
10273};10286};
1027410287pub extern "c" fn getpwent() ?*passwd;
10288pub extern "c" fn endpwent() void;
10289pub extern "c" fn setpwent() void;
10275pub extern "c" fn getpwnam(name: [*:0]const u8) ?*passwd;10290pub 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;
10276pub extern "c" fn getpwuid(uid: uid_t) ?*passwd;10292pub 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;
10277pub extern "c" fn getgrent() ?*group;10294pub extern "c" fn getgrent() ?*group;
10278pub extern "c" fn setgrent() void;10295pub extern "c" fn setgrent() void;
10279pub extern "c" fn endgrent() void;10296pub extern "c" fn endgrent() void;
...@@ -11009,11 +11026,7 @@ pub const bcrypt = openbsd.bcrypt;...@@ -11009,11 +11026,7 @@ pub const bcrypt = openbsd.bcrypt;
11009pub const bcrypt_checkpass = openbsd.bcrypt_checkpass;11026pub const bcrypt_checkpass = openbsd.bcrypt_checkpass;
11010pub const bcrypt_gensalt = openbsd.bcrypt_gensalt;11027pub const bcrypt_gensalt = openbsd.bcrypt_gensalt;
11011pub const bcrypt_newhash = openbsd.bcrypt_newhash;11028pub const bcrypt_newhash = openbsd.bcrypt_newhash;
11012pub const endpwent = openbsd.endpwent;
11013pub const getpwent = openbsd.getpwent;
11014pub const getpwnam_r = openbsd.getpwnam_r;
11015pub const getpwnam_shadow = openbsd.getpwnam_shadow;11029pub const getpwnam_shadow = openbsd.getpwnam_shadow;
11016pub const getpwuid_r = openbsd.getpwuid_r;
11017pub const getpwuid_shadow = openbsd.getpwuid_shadow;11030pub const getpwuid_shadow = openbsd.getpwuid_shadow;
11018pub const getthrid = openbsd.getthrid;11031pub const getthrid = openbsd.getthrid;
11019pub const login_cap_t = openbsd.login_cap_t;11032pub const login_cap_t = openbsd.login_cap_t;
...@@ -11030,7 +11043,6 @@ pub const pthread_spinlock_t = openbsd.pthread_spinlock_t;...@@ -11030,7 +11043,6 @@ pub const pthread_spinlock_t = openbsd.pthread_spinlock_t;
11030pub const pw_dup = openbsd.pw_dup;11043pub const pw_dup = openbsd.pw_dup;
11031pub const setclasscontext = openbsd.setclasscontext;11044pub const setclasscontext = openbsd.setclasscontext;
11032pub const setpassent = openbsd.setpassent;11045pub const setpassent = openbsd.setpassent;
11033pub const setpwent = openbsd.setpwent;
11034pub const setusercontext = openbsd.setusercontext;11046pub const setusercontext = openbsd.setusercontext;
11035pub const uid_from_user = openbsd.uid_from_user;11047pub const uid_from_user = openbsd.uid_from_user;
11036pub const unveil = openbsd.unveil;11048pub 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;...@@ -81,11 +81,6 @@ pub extern "c" fn auth_checknologin(lc: *login_cap_t) void;
8181
82pub extern "c" fn getpwuid_shadow(uid: uid_t) ?*passwd;82pub extern "c" fn getpwuid_shadow(uid: uid_t) ?*passwd;
83pub extern "c" fn getpwnam_shadow(name: [*:0]const u8) ?*passwd;83pub 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;
89pub extern "c" fn setpassent(stayopen: c_int) c_int;84pub extern "c" fn setpassent(stayopen: c_int) c_int;
90pub extern "c" fn uid_from_user(name: [*:0]const u8, uid: *uid_t) c_int;85pub extern "c" fn uid_from_user(name: [*:0]const u8, uid: *uid_t) c_int;
91pub extern "c" fn user_from_uid(uid: uid_t, noname: c_int) ?[*:0]const u8;86pub extern "c" fn user_from_uid(uid: uid_t, noname: c_int) ?[*:0]const u8;