Skip to content

Commit

Permalink
adopt the get[pw/gr]ent_r def used by FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC committed Oct 3, 2022
1 parent 198beb0 commit 265b2dd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
40 changes: 40 additions & 0 deletions src/unix/solarish/compat.rs
Expand Up @@ -169,3 +169,43 @@ pub unsafe fn forkpty(

0
}

pub unsafe fn getpwent_r(
pwd: *mut passwd,
buf: *mut ::c_char,
buflen: ::size_t,
result: *mut *mut passwd,
) -> ::c_int {
let old_errno = *::___errno();
*::___errno() = 0;
*result = native_getpwent_r(pwd, buf, buflen.min(::c_int::MAX as ::size_t) as ::c_int);

let ret = if (*result).is_null() {
*::___errno()
} else {
0
};
*::___errno() = old_errno;

ret
}

pub unsafe fn getgrent_r(
grp: *mut ::group,
buf: *mut ::c_char,
buflen: ::size_t,
result: *mut *mut ::group,
) -> ::c_int {
let old_errno = *::___errno();
*::___errno() = 0;
*result = native_getgrent_r(grp, buf, buflen.min(::c_int::MAX as ::size_t) as ::c_int);

let ret = if (*result).is_null() {
*::___errno()
} else {
0
};
*::___errno() = old_errno;

ret
}
18 changes: 4 additions & 14 deletions src/unix/solarish/mod.rs
Expand Up @@ -3016,24 +3016,14 @@ extern "C" {
) -> ::c_int;
#[cfg_attr(
any(target_os = "solaris", target_os = "illumos"),
link_name = "__posix_getpwent_r"
link_name = "getpwent_r"
)]
pub fn getpwent_r(
pwd: *mut passwd,
buf: *mut ::c_char,
buflen: ::size_t,
result: *mut *mut passwd,
) -> ::c_int;
fn native_getpwent_r(pwd: *mut passwd, buf: *mut ::c_char, buflen: ::c_int) -> *mut passwd;
#[cfg_attr(
any(target_os = "solaris", target_os = "illumos"),
link_name = "__posix_getgrent_r"
link_name = "getgrent_r"
)]
pub fn getgrent_r(
grp: *mut ::group,
buf: *mut ::c_char,
buflen: ::size_t,
result: *mut *mut ::group,
) -> ::c_int;
fn native_getgrent_r(grp: *mut ::group, buf: *mut ::c_char, buflen: ::c_int) -> *mut ::group;
#[cfg_attr(
any(target_os = "solaris", target_os = "illumos"),
link_name = "__posix_sigwait"
Expand Down

0 comments on commit 265b2dd

Please sign in to comment.