Panic when getpagesize() cannot succeed as specified

This commit is contained in:
Peter Limkilde Svendsen
2024-02-19 00:19:03 +00:00
committed by Jeremy Soller
parent 8313fc1c77
commit aea9e2b432
2 changed files with 6 additions and 20 deletions
+4 -15
View File
@@ -443,21 +443,10 @@ pub extern "C" fn getlogin_r(name: *mut c_char, namesize: size_t) -> c_int {
#[no_mangle]
pub extern "C" fn getpagesize() -> c_int {
match c_int::try_from(sysconf(_SC_PAGESIZE)) {
Ok(page_size) => page_size,
Err(_) => {
/* Behavior not specified by POSIX for this case. The -1
* value mimics sysconf()'s behavior, though.
*
* As specified for the limits.h header, the minimum
* acceptable value for {PAGESIZE} is 1. The -1 value thus
* cannot be mistaken for an acceptable value.
*
* POSIX does not specify any possible errors for this
* function, hence no errno setting. */
-1
}
}
// Panic if we can't uphold the required behavior (no errors are specified for this function)
Sys::getpagesize()
.try_into()
.expect("page size not representable as type `int`")
}
// #[no_mangle]
+2 -5
View File
@@ -5,10 +5,7 @@
#include "test_helpers.h"
int main(void) {
errno = 0;
int getpagesize_result = getpagesize();
int getpagesize_errno = errno;
printf("getpagesize(): %d, errno: %d = %s\n", getpagesize_result,
getpagesize_errno, strerror(getpagesize_errno));
printf("Page size: %d\n", getpagesize_result);
}