diff options
author | Hristo Venev <hristo@venev.name> | 2015-10-25 18:24:39 +0200 |
---|---|---|
committer | Hristo Venev <hristo@venev.name> | 2015-10-25 18:46:20 +0200 |
commit | 078efddd37c3d6e77525bb19eadfd159538df228 (patch) | |
tree | 4a1e3a8fea37124cf206ba9c7af37176806f7309 /src/basic/calendarspec.c | |
parent | 1e23792147b675cf6d3d7e85d02ba3d4dcc886c1 (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/calendarspec.c')
-rw-r--r-- | src/basic/calendarspec.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index 987ca81910..50328e4187 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -650,6 +650,7 @@ fail: int calendar_spec_from_string(const char *p, CalendarSpec **spec) { CalendarSpec *c; int r; + const char *utc; assert(p); assert(spec); @@ -661,9 +662,11 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { if (!c) return -ENOMEM; - c->utc = endswith_no_case(p, "UTC"); - if (c->utc) - p = strndupa(p, strlen(p) - strlen(" UTC")); + utc = endswith_no_case(p, " UTC"); + if (utc) { + c->utc = true; + p = strndupa(p, utc - p); + } if (strcaseeq(p, "minutely")) { r = const_chain(0, &c->second); |