]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
calendarspec: make return time value of calendar_spec_next_usec() optional
authorLennart Poettering <lennart@poettering.net>
Thu, 25 Apr 2019 11:21:54 +0000 (13:21 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 25 Apr 2019 11:21:54 +0000 (13:21 +0200)
If noone is interested, there's no reason to return it.

(Also document the ENOENT error code in a comment)

src/shared/calendarspec.c

index 6e318fa265fa24c5d67bfc73eb0726ba0d45128f..4365dbaca88c6c4f1da5bdbe366aa4f63795b621 100644 (file)
@@ -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;
 }