<pre style='margin:0'>
Christopher Nielsen (mascguy) pushed a commit to branch master
in repository macports-legacy-support.

</pre>
<p><a href="https://github.com/macports/macports-legacy-support/commit/bb525c162848832be90e015038abbd05571c8241">https://github.com/macports/macports-legacy-support/commit/bb525c162848832be90e015038abbd05571c8241</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit bb525c162848832be90e015038abbd05571c8241
</span>Author: Kirill A. Korinsky <kirill@korins.ky>
AuthorDate: Tue Jun 6 00:27:59 2023 +0200

<span style='display:block; white-space:pre;color:#404040;'>    time.c: fix CLOCK_MONOTONIC
</span>---
 src/time.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/time.c b/src/time.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 7e47d47..0b49b96 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/time.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/time.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -20,6 +20,7 @@
</span> #if __MP_LEGACY_SUPPORT_GETTIME__
 
 #include <sys/time.h>
<span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <sys/sysctl.h>
</span> #include <mach/mach_time.h>
 
 #define BILLION  1000000000L
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -38,7 +39,24 @@ int clock_gettime( clockid_t clk_id, struct timespec *ts )
</span>       ts->tv_sec  = tv.tv_sec;
       ts->tv_nsec = tv.tv_usec * 1000;
     }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    else if ( CLOCK_MONOTONIC == clk_id || CLOCK_MONOTONIC_RAW == clk_id )
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    else if ( CLOCK_MONOTONIC == clk_id )
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      struct timeval boottime;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      size_t boottime_len = sizeof(boottime);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      ret = sysctlbyname("kern.boottime", &boottime, &boottime_len, NULL, 0);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      if (ret == -1)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        boottime.tv_sec = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        boottime.tv_usec = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      struct timeval tv;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      ret = gettimeofday(&tv, NULL);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      timersub(&tv, &boottime, &tv);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      ts->tv_sec  = tv.tv_sec;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      ts->tv_nsec = tv.tv_usec * 1000;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+      ret = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    else if ( CLOCK_MONOTONIC_RAW == clk_id )
</span>     {
       static mach_timebase_info_data_t timebase;
       if ( 0 == timebase.numer || 0 == timebase.denom ) {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -46,9 +64,6 @@ int clock_gettime( clockid_t clk_id, struct timespec *ts )
</span>         if ( kr != KERN_SUCCESS ) { return kr; }
       }
       uint64_t tdiff =  mach_absolute_time() * ( timebase.numer / timebase.denom );
<span style='display:block; white-space:pre;background:#ffe0e0;'>-      if ( CLOCK_MONOTONIC == clk_id ) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        tdiff = THOUSAND * ( tdiff / THOUSAND );
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-      }
</span>       ts->tv_sec  = tdiff / BILLION;
       ts->tv_nsec = tdiff % BILLION;
       ret = 0;
</pre><pre style='margin:0'>

</pre>