summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-04-25 13:21:54 +0200
committerLennart Poettering <lennart@poettering.net>2019-04-25 13:21:54 +0200
commit9bb656bd0cd9ca8d7c593c48d51c19d66557df53 (patch)
tree35328cd959f09b89ce12eca9ab693582e49f48bb
parentc5b7ae0edb4e32463b5326c973443a9bc6ae10e3 (diff)
downloadsystemd-9bb656bd0cd9ca8d7c593c48d51c19d66557df53.tar.gz
calendarspec: make return time value of calendar_spec_next_usec() optional
If noone is interested, there's no reason to return it. (Also document the ENOENT error code in a comment)
-rw-r--r--src/shared/calendarspec.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c
index 6e318fa265..4365dbaca8 100644
--- a/src/shared/calendarspec.c
+++ b/src/shared/calendarspec.c
@@ -1193,6 +1193,8 @@ static int find_next(const CalendarSpec *spec, struct tm *tm, usec_t *usec) {
int tm_usec;
int r;
+ /* Returns -ENOENT if the expression is not going to elapse anymore */
+
assert(spec);
assert(tm);
@@ -1285,14 +1287,13 @@ static int find_next(const CalendarSpec *spec, struct tm *tm, usec_t *usec) {
}
}
-static int calendar_spec_next_usec_impl(const CalendarSpec *spec, usec_t usec, usec_t *next) {
+static int calendar_spec_next_usec_impl(const CalendarSpec *spec, usec_t usec, usec_t *ret_next) {
struct tm tm;
time_t t;
int r;
usec_t tm_usec;
assert(spec);
- assert(next);
if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
return -EINVAL;
@@ -1310,7 +1311,9 @@ static int calendar_spec_next_usec_impl(const CalendarSpec *spec, usec_t usec, u
if (t < 0)
return -EINVAL;
- *next = (usec_t) t * USEC_PER_SEC + tm_usec;
+ if (ret_next)
+ *ret_next = (usec_t) t * USEC_PER_SEC + tm_usec;
+
return 0;
}
@@ -1319,12 +1322,14 @@ typedef struct SpecNextResult {
int return_value;
} SpecNextResult;
-int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *next) {
+int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *ret_next) {
SpecNextResult *shared, tmp;
int r;
+ assert(spec);
+
if (isempty(spec->timezone))
- return calendar_spec_next_usec_impl(spec, usec, next);
+ return calendar_spec_next_usec_impl(spec, usec, ret_next);
shared = mmap(NULL, sizeof *shared, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if (shared == MAP_FAILED)
@@ -1352,8 +1357,8 @@ int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *next)
if (munmap(shared, sizeof *shared) < 0)
return negative_errno();
- if (tmp.return_value == 0)
- *next = tmp.next;
+ if (tmp.return_value == 0 && ret_next)
+ *ret_next = tmp.next;
return tmp.return_value;
}