init: Move gettime() to util.c
Change-Id: I1df96964763f8baedbc1cea6875d3dfc5e48c065
diff --git a/init/util.c b/init/util.c
index 48f8d54..6f9a12e 100644
--- a/init/util.c
+++ b/init/util.c
@@ -21,6 +21,7 @@
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
+#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -280,3 +281,21 @@
}
return -1;
}
+
+/*
+ * gettime() - returns the time in seconds of the system's monotonic clock or
+ * zero on error.
+ */
+time_t gettime(void)
+{
+ struct timespec ts;
+ int ret;
+
+ ret = clock_gettime(CLOCK_MONOTONIC, &ts);
+ if (ret < 0) {
+ ERROR("clock_gettime(CLOCK_MONOTONIC) failed: %s\n", strerror(errno));
+ return 0;
+ }
+
+ return ts.tv_sec;
+}