You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2026/10/21 02:54:20 UTC

(nuttx) 02/04: include/unistd.h: Define _POSIX_MONOTONIC_CLOCK and _POSIX_CLOCK_SELECTION.

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 85edf8c9877eb76468cc4435541c1c1e06cdf1c9
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Mon Oct 19 01:49:33 2026 +0200

    include/unistd.h: Define _POSIX_MONOTONIC_CLOCK and _POSIX_CLOCK_SELECTION.
    
    NuttX supports CLOCK_MONOTONIC, clock_nanosleep() and
    pthread_condattr_setclock().  sysconf(_SC_MONOTONIC_CLOCK) returns 1, and
    Documentation/standards/posix.rst marks both options as supported.  But
    <unistd.h> did not define the two option macros, so a program that
    checks them at compile time did not use the monotonic clock.  Also,
    sysconf(_SC_CLOCK_SELECTION) failed with ENOSYS.
    
    Define _POSIX_MONOTONIC_CLOCK and _POSIX_CLOCK_SELECTION to
    _POSIX_VERSION, as the other supported options.  sysconf() returns these
    values for _SC_MONOTONIC_CLOCK and _SC_CLOCK_SELECTION.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 include/unistd.h               | 2 ++
 libs/libc/unistd/lib_sysconf.c | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/unistd.h b/include/unistd.h
index 2a7b7c550fc..66cddf68d17 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -72,6 +72,8 @@
 #define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION
 #define _POSIX_MAPPED_FILES _POSIX_VERSION
 #define _POSIX_THREADS _POSIX_VERSION
+#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION
+#define _POSIX_CLOCK_SELECTION _POSIX_VERSION
 
 #ifdef CONFIG_FS_AIO
 #  define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION
diff --git a/libs/libc/unistd/lib_sysconf.c b/libs/libc/unistd/lib_sysconf.c
index 840279d5ad6..88d9faeb00a 100644
--- a/libs/libc/unistd/lib_sysconf.c
+++ b/libs/libc/unistd/lib_sysconf.c
@@ -270,7 +270,10 @@ long sysconf(int name)
         return CONFIG_SMP_NCPUS;
 
       case _SC_MONOTONIC_CLOCK:
-        return 1;
+        return _POSIX_MONOTONIC_CLOCK;
+
+      case _SC_CLOCK_SELECTION:
+        return _POSIX_CLOCK_SELECTION;
 
       case _SC_PAGESIZE:
         return DEFAULT_MM_PGSIZE;