Conditionally import login_cap.h with pwd.h

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2024-08-05 15:16:58 +02:00
parent 2c428f5537
commit 5e85618730
2 changed files with 9 additions and 17 deletions

View File

@@ -35,18 +35,15 @@ pub const stdlib = @cImport({
pub const pwd = @cImport({
@cInclude("pwd.h");
// We include a FreeBSD-specific header here since login_cap.h references
// the passwd struct directly, so we can't import it separately'
if (builtin.os.tag == .freebsd) @cInclude("login_cap.h");
});
pub const grp = @cImport({
@cInclude("grp.h");
});
// FreeBSD-specific headers (except for pwd.h)
pub const logincap = @cImport({
@cInclude("pwd.h");
@cInclude("login_cap.h");
});
// BSD-specific headers
pub const kbio = @cImport({
@cInclude("sys/kbio.h");
@@ -61,11 +58,6 @@ pub const vt = @cImport({
@cInclude("sys/vt.h");
});
// On FreeBSD, login_cap.h references the passwd struct directly, so we must use logincap.passwd instead
pub const passwd = if (builtin.os.tag == .freebsd) logincap.passwd else pwd.passwd;
pub const endpwent = if (builtin.os.tag == .freebsd) logincap.endpwent else pwd.endpwent;
pub const getpwnam = if (builtin.os.tag == .freebsd) logincap.getpwnam else pwd.getpwnam;
// Used for getting & setting the lock state
const LedState = if (builtin.os.tag.isBSD()) c_int else c_char;
const get_led_state = if (builtin.os.tag.isBSD()) kbio.KDGETLED else kd.KDGKBLED;