unix: abort on clock_gettime() error (#3898)
Per standard libuv operating procedures, abort on unexpected failure. Don't silently ignore the error and return garbage.
This commit is contained in:
parent
42cc412c4a
commit
be2ddacb90
@ -23,13 +23,14 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#undef NANOSEC
|
|
||||||
#define NANOSEC ((uint64_t) 1e9)
|
|
||||||
|
|
||||||
uint64_t uv__hrtime(uv_clocktype_t type) {
|
uint64_t uv__hrtime(uv_clocktype_t type) {
|
||||||
struct timespec ts;
|
struct timespec t;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
||||||
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
|
if (clock_gettime(CLOCK_MONOTONIC, &t))
|
||||||
|
abort();
|
||||||
|
|
||||||
|
return t.tv_sec * (uint64_t) 1e9 + t.tv_nsec;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user