diff --git a/include/sys/types.h b/include/sys/types.h index e35f48aaa54e40c96f107919ce8fd7673a8818b9..270a43e46afb73d8f90d32fa302b77632deac22b 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -31,11 +31,4 @@ typedef unsigned long u_long, ulong; typedef long long quad_t; typedef unsigned long long u_quad_t; -#ifdef __linux__ -#define _SC_PAGE_SIZE 30 -#endif -#ifdef __redox__ -#define _SC_PAGE_SIZE 8 -#endif - #endif /* _SYS_TYPES_H */ diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index e0ee2e88f7919f0172e29488b9a79edb772e3083..0b0ac1af4bf8c6fe827bff0a83838b89e0d01bf6 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -15,10 +15,12 @@ use platform::{Pal, Sys}; pub use self::brk::*; pub use self::getopt::*; pub use self::pathconf::*; +pub use self::sysconf::*; mod brk; mod getopt; mod pathconf; +mod sysconf; pub const F_OK: c_int = 0; pub const R_OK: c_int = 4; @@ -559,11 +561,6 @@ pub extern "C" fn sync() { unimplemented!(); } -// #[no_mangle] -pub extern "C" fn sysconf(name: c_int) -> c_long { - unimplemented!(); -} - // #[no_mangle] pub extern "C" fn tcgetpgrp() -> pid_t { unimplemented!(); diff --git a/src/header/unistd/sysconf.rs b/src/header/unistd/sysconf.rs new file mode 100644 index 0000000000000000000000000000000000000000..8ce05f53ff7a82c6bb22769cb2da0c68a75c29df --- /dev/null +++ b/src/header/unistd/sysconf.rs @@ -0,0 +1,50 @@ +use header::errno; +use platform; +use platform::types::*; + +// POSIX.1 { +pub const _SC_ARG_MAX: c_int = 0; +pub const _SC_CHILD_MAX: c_int = 1; +pub const _SC_CLK_TCK: c_int = 2; +pub const _SC_NGROUPS_MAX: c_int = 3; +pub const _SC_OPEN_MAX: c_int = 4; +pub const _SC_STREAM_MAX: c_int = 5; +pub const _SC_TZNAME_MAX: c_int = 6; +// ... +pub const _SC_VERSION: c_int = 29; +pub const _SC_PAGESIZE: c_int = 30; +// ... +pub const _SC_RE_DUP_MAX: c_int = 44; +// ... +pub const _SC_LOGIN_NAME_MAX: c_int = 71; +pub const _SC_TTY_NAME_MAX: c_int = 72; +// ... +pub const _SC_SYMLOOP_MAX: c_int = 173; +// ... +pub const _SC_HOST_NAME_MAX: c_int = 180; +// } POSIX.1 + +#[no_mangle] +pub extern "C" fn sysconf(name: c_int) -> c_long { + //TODO: Real values + match name { + _SC_ARG_MAX => 4096, + _SC_CHILD_MAX => 65536, + _SC_CLK_TCK => 100, + _SC_NGROUPS_MAX => 65536, + _SC_OPEN_MAX => 1024, + _SC_STREAM_MAX => 16, + _SC_TZNAME_MAX => -1, + _SC_VERSION => 200809, + _SC_PAGESIZE => 4096, + _SC_RE_DUP_MAX => 32767, + _SC_LOGIN_NAME_MAX => 256, + _SC_TTY_NAME_MAX => 32, + _SC_SYMLOOP_MAX => -1, + _SC_HOST_NAME_MAX => 64, + _ => { + unsafe { platform::errno = errno::EINVAL; } + -1 + } + } +} diff --git a/tests/unistd/sysconf.c b/tests/unistd/sysconf.c new file mode 100644 index 0000000000000000000000000000000000000000..aa4bf4882f86304dba26f06d086771f88ffd4173 --- /dev/null +++ b/tests/unistd/sysconf.c @@ -0,0 +1,26 @@ +#include <errno.h> +#include <stdio.h> +#include <unistd.h> + +#define SC(N) { \ + errno = 0; \ + printf("%s (%d): %ld (%d)\n", #N, _SC_ ## N, sysconf(_SC_ ## N), errno); \ +} + +int main(){ + SC(ARG_MAX); + SC(CHILD_MAX); + SC(CLK_TCK); + SC(NGROUPS_MAX); + SC(OPEN_MAX); + SC(STREAM_MAX); + SC(TZNAME_MAX); + SC(VERSION); + SC(PAGESIZE); + SC(RE_DUP_MAX); + SC(LOGIN_NAME_MAX); + SC(TTY_NAME_MAX); + SC(SYMLOOP_MAX); + SC(HOST_NAME_MAX); + return 0; +}