summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-03 09:19:58 +0000
committerbors <bors@rust-lang.org>2022-11-03 09:19:58 +0000
commit1ca1c4167ad6b5dc6e6a424378e88874f5970f9d (patch)
tree0f4cb0de116fd0f6f3049b1ba5bc24257ffe781e /src
parent875f3a69b10c3f59b51ecb152ac7a56c21050354 (diff)
parent8a914ca06587ecf74420f16448b8f4b32e8653d1 (diff)
downloadrust-libc-1ca1c4167ad6b5dc6e6a424378e88874f5970f9d.tar.gz
Auto merge of #2914 - SteveLauC:Wrong-getpwent_r-definition-on-solarish-os, r=JohnTitor
fix wrong definitions of getpwent_r and getgrent_r on solarish os Closes #2908 * [man page for `getpwent_r`](https://illumos.org/man/3C/getpwnam) * [man page for `getgrent_r`](https://illumos.org/man/3C/getgrnam) You may find the definitions for `getpwnam_r/getpwuid_r/getgrnam_r/getgruid_r` exposed by `libc` are also wrong: ```c struct passwd *getpwnam_r(const char *name, struct passwd *pwd, char *buffer, int buflen); ``` ```rust pub fn getpwnam_r( name: *const ::c_char, pwd: *mut passwd, buf: *mut ::c_cha buflen: ::size_t, result: *mut *mut passwd, ) -> ::c_int; ``` But actually they are **correct** as there are the POSIX-conforming definitions (see `Standard conforming` section of above man pages): ``` Standard conforming cc [ flag...] file... -D_POSIX_PTHREAD_SEMANTICS [ library... ] int getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result); int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result); ``` `getpwent_r/getgrent_r` don't get lucky, they do not have the POSIX-conforming alternatives. To double check this, I searched its [source code](https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/port/gen/getpwnam_r.c): ```shell $ rg "__posix_getpwnam_r" port/mapfile-vers 1582: __posix_getpwnam_r; port/gen/getpwnam_r.c 152:__posix_getpwnam_r(const char *name, struct passwd *pwd, char *buffer, $ rg "__posix_getpwent_r" $ ```
Diffstat (limited to 'src')
-rw-r--r--src/unix/solarish/compat.rs49
-rw-r--r--src/unix/solarish/mod.rs18
2 files changed, 53 insertions, 14 deletions
diff --git a/src/unix/solarish/compat.rs b/src/unix/solarish/compat.rs
index 4a232f0d83..cbf955a31e 100644
--- a/src/unix/solarish/compat.rs
+++ b/src/unix/solarish/compat.rs
@@ -1,6 +1,7 @@
// Common functions that are unfortunately missing on illumos and
// Solaris, but often needed by other crates.
+use core::cmp::min;
use unix::solarish::*;
const PTEM: &[u8] = b"ptem\0";
@@ -169,3 +170,51 @@ 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,
+ min(buflen, ::c_int::max_value() 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,
+ min(buflen, ::c_int::max_value() as ::size_t) as ::c_int,
+ );
+
+ let ret = if (*result).is_null() {
+ *::___errno()
+ } else {
+ 0
+ };
+ *::___errno() = old_errno;
+
+ ret
+}
diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs
index d01deefbf3..6b0557d359 100644
--- a/src/unix/solarish/mod.rs
+++ b/src/unix/solarish/mod.rs
@@ -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"