Skip to content

Commit

Permalink
unix: abort on clock_gettime() error (libuv#3898)
Browse files Browse the repository at this point in the history
Per standard libuv operating procedures, abort on unexpected failure.
Don't silently ignore the error and return garbage.
  • Loading branch information
bnoordhuis authored Feb 1, 2023
1 parent 42cc412 commit be2ddac
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/unix/posix-hrtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
#include "internal.h"

#include <stdint.h>
#include <stdlib.h>
#include <time.h>

#undef NANOSEC
#define NANOSEC ((uint64_t) 1e9)

uint64_t uv__hrtime(uv_clocktype_t type) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
struct timespec t;

if (clock_gettime(CLOCK_MONOTONIC, &t))
abort();

return t.tv_sec * (uint64_t) 1e9 + t.tv_nsec;
}

0 comments on commit be2ddac

Please sign in to comment.