Skip to content
Snippets Groups Projects
Commit bf13674e authored by jD91mZM2's avatar jD91mZM2
Browse files

Merge branch 'getpagesize_check' into 'master'

Use try_from in getpagesize(), add test

See merge request redox-os/relibc!225
parents 3be933ec 8b975877
No related branches found
No related tags found
1 merge request!225Use try_from in getpagesize(), add test
Pipeline #4979 failed
//! unistd implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/unistd.h.html //! unistd implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/unistd.h.html
use core::convert::TryFrom;
use core::{mem, ptr, slice}; use core::{mem, ptr, slice};
use alloc::collections::LinkedList; use alloc::collections::LinkedList;
...@@ -360,7 +361,21 @@ pub extern "C" fn getlogin_r(name: *mut c_char, namesize: size_t) -> c_int { ...@@ -360,7 +361,21 @@ pub extern "C" fn getlogin_r(name: *mut c_char, namesize: size_t) -> c_int {
#[no_mangle] #[no_mangle]
pub extern "C" fn getpagesize() -> c_int { pub extern "C" fn getpagesize() -> c_int {
sysconf(_SC_PAGESIZE) as 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
}
}
} }
// #[no_mangle] // #[no_mangle]
......
...@@ -114,6 +114,7 @@ NAMES=\ ...@@ -114,6 +114,7 @@ NAMES=\
unistd/getcwd \ unistd/getcwd \
unistd/gethostname \ unistd/gethostname \
unistd/getid \ unistd/getid \
unistd/getpagesize \
unistd/link \ unistd/link \
unistd/pathconf \ unistd/pathconf \
unistd/setid \ unistd/setid \
......
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#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));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment