2
0
Jeremy Soller 6 жил өмнө
parent
commit
434cad49ce

+ 0 - 7
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 */

+ 2 - 5
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!();

+ 50 - 0
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
+        }
+    }
+}

+ 26 - 0
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;
+}