]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/time-util.c
util-lib: move a number of fs operations into fs-util.[ch]
[thirdparty/systemd.git] / src / basic / time-util.c
index d4e0914b27a9030ed8184fc19a71e26df6317d49..867e7b2430a72da0ed2698a8cd5b1976d0ce1fb7 100644 (file)
 ***/
 
 #include <string.h>
-#include <sys/timex.h>
 #include <sys/timerfd.h>
+#include <sys/timex.h>
 
-#include "util.h"
-#include "time-util.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "fs-util.h"
 #include "path-util.h"
+#include "string-util.h"
 #include "strv.h"
+#include "time-util.h"
+#include "util.h"
 
 usec_t now(clockid_t clock_id) {
         struct timespec ts;
@@ -477,7 +481,7 @@ int parse_timestamp(const char *t, usec_t *usec) {
         };
 
         const char *k;
-        bool utc;
+        const char *utc;
         struct tm tm, copy;
         time_t x;
         usec_t x_usec, plus = 0, minus = 0, ret;
@@ -527,8 +531,8 @@ int parse_timestamp(const char *t, usec_t *usec) {
 
                 goto finish;
 
-        } else if (endswith(t, " ago")) {
-                t = strndupa(t, strlen(t) - strlen(" ago"));
+        } else if ((k = endswith(t, " ago"))) {
+                t = strndupa(t, k - t);
 
                 r = parse_sec(t, &minus);
                 if (r < 0)
@@ -536,8 +540,8 @@ int parse_timestamp(const char *t, usec_t *usec) {
 
                 goto finish;
 
-        } else if (endswith(t, " left")) {
-                t = strndupa(t, strlen(t) - strlen(" left"));
+        } else if ((k = endswith(t, " left"))) {
+                t = strndupa(t, k - t);
 
                 r = parse_sec(t, &plus);
                 if (r < 0)
@@ -548,7 +552,7 @@ int parse_timestamp(const char *t, usec_t *usec) {
 
         utc = endswith_no_case(t, " UTC");
         if (utc)
-                t = strndupa(t, strlen(t) - strlen(" UTC"));
+                t = strndupa(t, utc - t);
 
         x = ret / USEC_PER_SEC;
         x_usec = 0;