summaryrefslogtreecommitdiff
path: root/src/basic/time-util.c
diff options
context:
space:
mode:
authorHristo Venev <hristo@venev.name>2015-10-25 18:24:39 +0200
committerHristo Venev <hristo@venev.name>2015-10-25 18:46:20 +0200
commit078efddd37c3d6e77525bb19eadfd159538df228 (patch)
tree4a1e3a8fea37124cf206ba9c7af37176806f7309 /src/basic/time-util.c
parent1e23792147b675cf6d3d7e85d02ba3d4dcc886c1 (diff)
basic: use the return value of endswith
It returns the position where the suffix begins, which can be used for strndup to extract the prefix without calling strlen.
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r--src/basic/time-util.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index d117380d52..b348ed4204 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -479,7 +479,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;
@@ -529,8 +529,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)
@@ -538,8 +538,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)
@@ -550,7 +550,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;