diff --git a/headers/posix/unistd.h b/headers/posix/unistd.h index 656b63b7fd..ad4186bce9 100644 --- a/headers/posix/unistd.h +++ b/headers/posix/unistd.h @@ -86,6 +86,21 @@ #define _SC_SEM_VALUE_MAX 29 #define _SC_SEMAPHORES 30 #define _SC_THREADS 31 +/* TODO: check and reorder */ +#define _SC_IOV_MAX 32 +#define _SC_UIO_MAXIOV _CS_IOV_MAX +#define _SC_NPROCESSORS_MAX 33 +#define _SC_NPROCESSORS_CONF 34 +#define _SC_NPROCESSORS_ONLN 35 +#define _SC_CPUID_MAX 36 +#define _SC_ATEXIT_MAX 37 +#define _SC_PASS_MAX 39 +#define _SC_PHYS_PAGES 40 +#define _SC_AVPHYS_PAGES 41 +#define _SC_PIPE 42 +#define _SC_SELECT 43 +#define _SC_POLL 44 + /* confstr() constants */ #define _CS_PATH 1 diff --git a/src/system/libroot/posix/unistd/conf.c b/src/system/libroot/posix/unistd/conf.c index 154c406ce8..6a34ed687f 100644 --- a/src/system/libroot/posix/unistd/conf.c +++ b/src/system/libroot/posix/unistd/conf.c @@ -20,6 +20,7 @@ #include #include +bool _kern_cpu_enabled(int cpu); int getdtablesize(void) @@ -35,6 +36,7 @@ getdtablesize(void) long sysconf(int name) { + int err; // TODO: This is about what BeOS does, better POSIX conformance would be nice, though switch (name) { @@ -72,6 +74,70 @@ sysconf(int name) return _POSIX_SEMAPHORES; case _SC_THREADS: return _POSIX_THREADS; + case _SC_IOV_MAX: + return IOV_MAX; + case _SC_NPROCESSORS_MAX: + return B_MAX_CPU_COUNT; + case _SC_NPROCESSORS_CONF: + { + system_info info; + err = get_system_info(&info); + if (err < B_OK) { + errno = err; + return -1; + } + return info.cpu_count; + } + case _SC_NPROCESSORS_ONLN: + { + system_info info; + int i; + int count = 0; + err = get_system_info(&info); + if (err < B_OK) { + errno = err; + return -1; + } + for (i = 0; i < info.cpu_count; i++) + if (_kern_cpu_enabled(i)) + count++; + return count; + } + case _SC_CPUID_MAX: + return B_MAX_CPU_COUNT - 1; + case _SC_ATEXIT_MAX: + return ATEXIT_MAX; + case _SC_PASS_MAX: + break; + //XXX:return PASS_MAX; + case _SC_PHYS_PAGES: + { + system_info info; + err = get_system_info(&info); + if (err < B_OK) { + errno = err; + return -1; + } + return info.max_pages; + } + case _SC_AVPHYS_PAGES: + { + system_info info; + err = get_system_info(&info); + if (err < B_OK) { + errno = err; + return -1; + } + return info.max_pages - info.used_pages; + } + /* + case _SC_PIPE: + return 1; + case _SC_SELECT: + return 1; + case _SC_POLL: + return 1; + */ } errno = EINVAL; @@ -158,7 +224,7 @@ __pathconf_common(struct statvfs *fs, struct stat *st, return 32; } // XXX: add fs ? add to statvfs/fs_info ? - return 64; + return FILESIZEBITS; } case _PC_SYMLINK_MAX: