From 977f04a2b11e9b46b3d43d62b904378159c64987 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 27 Jun 2020 00:08:59 +0800 Subject: [PATCH] libc: sysconf support _SC_NPROCESSORS_CONF/_SC_NPROCESSORS_ONLN specified here: https://www.man7.org/linux/man-pages/man3/sysconf.3.html Signed-off-by: Xiang Xiao Change-Id: I87fba8476221797e59c69c1953974bebc8d0d7b3 --- include/unistd.h | 3 +++ libs/libc/unistd/lib_sysconf.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/include/unistd.h b/include/unistd.h index 1e3351ef35..1e29d2ae3b 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -255,6 +255,9 @@ #define _SC_XOPEN_UNIX 0x0079 #define _SC_XOPEN_VERSION 0x007a +#define _SC_NPROCESSORS_CONF 0x007b +#define _SC_NPROCESSORS_ONLN 0x007c + /* The following symbolic constants must be defined for file streams: */ #define STDERR_FILENO 2 /* File number of stderr */ diff --git a/libs/libc/unistd/lib_sysconf.c b/libs/libc/unistd/lib_sysconf.c index c27acf740e..6da23940f9 100644 --- a/libs/libc/unistd/lib_sysconf.c +++ b/libs/libc/unistd/lib_sysconf.c @@ -233,6 +233,14 @@ long sysconf(int name) return 0; #endif + case _SC_NPROCESSORS_CONF: + case _SC_NPROCESSORS_ONLN: +#ifdef CONFIG_SMP_NCPUS + return CONFIG_SMP_NCPUS; +#else + return 1; +#endif + default: #if 0 /* Assume valid but not implemented for the time being */ errcode = EINVAL;