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 af54865 commit 3df8435
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/unix/solarish/compat.rs
@@ -1,7 +1,6 @@
// Common functions that are unfortunately missing on illumos and
// Solaris, but often needed by other crates.

use core::convert::TryInto;
use unix::solarish::*;

const PTEM: &[u8] = b"ptem\0";
Expand Down Expand Up @@ -177,13 +176,18 @@ pub unsafe fn getpwent_r(
buflen: ::size_t,
result: *mut *mut passwd,
) -> ::c_int {
let res = native_getpwent_r(pwd, buf, buflen.try_into().unwrap());
if res.is_null() {
-1
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 {
*result = res;
0
}
};
*::___errno() = old_errno;

ret
}

pub unsafe fn getgrent_r(
Expand All @@ -192,11 +196,16 @@ pub unsafe fn getgrent_r(
buflen: ::size_t,
result: *mut *mut ::group,
) -> ::c_int {
let res = native_getgrent_r(grp, buf, buflen.try_into().unwrap());
if res.is_null() {
-1
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 {
*result = res;
0
}
};
*::___errno() = old_errno;

ret
}

0 comments on commit 3df8435

Please sign in to comment.