Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mx_util: Add mx_clock_getboottime
Add function to return seconds from CLOCK_BOOTTIME. This clock is
strictly monotonic and can be used if values are not communicated to
other systems and are not kept accross reboots.
  • Loading branch information
donald committed Aug 24, 2021
1 parent 3225c82 commit fa07d90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion mx_util.c
Expand Up @@ -10,7 +10,7 @@
#include <unistd.h>

#include <ctype.h>

#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/vfs.h>
Expand Down Expand Up @@ -1305,3 +1305,12 @@ unsigned long mx_df(const char *path) {
}
return s.f_bavail*s.f_frsize;
}

time_t mx_clock_boottime() {
struct timespec ts;
int res = clock_gettime(CLOCK_BOOTTIME, &ts);
if (res != 0) {
perror("clock_gettime");
}
return (ts.tv_sec);
}
2 changes: 1 addition & 1 deletion mx_util.h
Expand Up @@ -179,5 +179,5 @@ void _mx_sort_linked_list(void **list, int (*cmp)(void *o1,void *o2), void ** (*
#define mx_sort_linked_list(list,cmp,getnextptr) _mx_sort_linked_list((void **)(list),(int (*)(void *,void *))(cmp),(void ** (*)(void *))(getnextptr))

unsigned long mx_df(const char *path);

time_t mx_clock_boottime();
#endif

0 comments on commit fa07d90

Please sign in to comment.