#include "util.h"
#include "time-util.h"
+#include "path-util.h"
#include "strv.h"
usec_t now(clockid_t clock_id) {
return timespec_load(&ts);
}
+/// UNNEEDED by elogind
+#if 0
+nsec_t now_nsec(clockid_t clock_id) {
+ struct timespec ts;
+
+ assert_se(clock_gettime(clock_id, &ts) == 0);
+
+ return timespec_load_nsec(&ts);
+}
+#endif // 0
+
dual_timestamp* dual_timestamp_get(dual_timestamp *ts) {
assert(ts);
return ts;
}
+/// UNNEEDED by elogind
+#if 0
dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) {
int64_t delta;
assert(ts);
return ts;
}
+dual_timestamp* dual_timestamp_from_boottime_or_monotonic(dual_timestamp *ts, usec_t u) {
+ int64_t delta;
+
+ if (u == USEC_INFINITY) {
+ ts->realtime = ts->monotonic = USEC_INFINITY;
+ return ts;
+ }
+ ts->realtime = now(CLOCK_REALTIME);
+ ts->monotonic = now(CLOCK_MONOTONIC);
+
+ delta = (int64_t) now(clock_boottime_or_monotonic()) - (int64_t) u;
+
+ if ((int64_t) ts->realtime > delta)
+ ts->realtime -= delta;
+ else
+ ts->realtime = 0;
+
+ if ((int64_t) ts->monotonic > delta)
+ ts->monotonic -= delta;
+ else
+ ts->monotonic = 0;
+
+ return ts;
+}
+#endif // 0
+
usec_t timespec_load(const struct timespec *ts) {
assert(ts);
(usec_t) ts->tv_nsec / NSEC_PER_USEC;
}
+nsec_t timespec_load_nsec(const struct timespec *ts) {
+ assert(ts);
+
+ if (ts->tv_sec == (time_t) -1 &&
+ ts->tv_nsec == (long) -1)
+ return NSEC_INFINITY;
+
+ return
+ (nsec_t) ts->tv_sec * NSEC_PER_SEC +
+ (nsec_t) ts->tv_nsec;
+}
+
struct timespec *timespec_store(struct timespec *ts, usec_t u) {
assert(ts);
return format_timestamp_internal_us(buf, l, t, false);
}
+/// UNNEEDED by elogind
+#if 0
char *format_timestamp_us_utc(char *buf, size_t l, usec_t t) {
return format_timestamp_internal_us(buf, l, t, true);
}
+#endif // 0
char *format_timestamp_relative(char *buf, size_t l, usec_t t) {
const char *s;
return buf;
}
+/// UNNEEDED by elogind
+#if 0
void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) {
assert(f);
return 0;
}
-/// UNNEEDED by elogind
-#if 0
int parse_timestamp(const char *t, usec_t *usec) {
static const struct {
const char *name;
return 0;
}
+/// UNNEEDED by elogind
+#if 0
int parse_nsec(const char *t, nsec_t *nsec) {
static const struct {
const char *suffix;
return 0;
}
-/// UNNEEDED by elogind
-#if 0
bool ntp_synced(void) {
struct timex txc = {};
const char *p, *t;
struct stat st;
- if (!name || *name == 0 || *name == '/')
+ if (isempty(name))
+ return false;
+
+ if (name[0] == '/')
return false;
for (p = name; *p; p++) {
return true;
}
-#endif // 0
clockid_t clock_boottime_or_monotonic(void) {
static clockid_t clock = -1;
return clock;
}
+
+int get_timezone(char **tz) {
+ _cleanup_free_ char *t = NULL;
+ const char *e;
+ char *z;
+ int r;
+
+ r = readlink_malloc("/etc/localtime", &t);
+ if (r < 0)
+ return r; /* returns EINVAL if not a symlink */
+
+ e = path_startswith(t, "/usr/share/zoneinfo/");
+ if (!e)
+ e = path_startswith(t, "../usr/share/zoneinfo/");
+ if (!e)
+ return -EINVAL;
+
+ if (!timezone_is_valid(e))
+ return -EINVAL;
+
+ z = strdup(e);
+ if (!z)
+ return -ENOMEM;
+
+ *tz = z;
+ return 0;
+}
+#endif // 0