Skip to content

Commit 9bb656b

Browse files
committed
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)
1 parent c5b7ae0 commit 9bb656b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/shared/calendarspec.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,8 @@ static int find_next(const CalendarSpec *spec, struct tm *tm, usec_t *usec) {
11931193
int tm_usec;
11941194
int r;
11951195

1196+
/* Returns -ENOENT if the expression is not going to elapse anymore */
1197+
11961198
assert(spec);
11971199
assert(tm);
11981200

@@ -1285,14 +1287,13 @@ static int find_next(const CalendarSpec *spec, struct tm *tm, usec_t *usec) {
12851287
}
12861288
}
12871289

1288-
static int calendar_spec_next_usec_impl(const CalendarSpec *spec, usec_t usec, usec_t *next) {
1290+
static int calendar_spec_next_usec_impl(const CalendarSpec *spec, usec_t usec, usec_t *ret_next) {
12891291
struct tm tm;
12901292
time_t t;
12911293
int r;
12921294
usec_t tm_usec;
12931295

12941296
assert(spec);
1295-
assert(next);
12961297

12971298
if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
12981299
return -EINVAL;
@@ -1310,7 +1311,9 @@ static int calendar_spec_next_usec_impl(const CalendarSpec *spec, usec_t usec, u
13101311
if (t < 0)
13111312
return -EINVAL;
13121313

1313-
*next = (usec_t) t * USEC_PER_SEC + tm_usec;
1314+
if (ret_next)
1315+
*ret_next = (usec_t) t * USEC_PER_SEC + tm_usec;
1316+
13141317
return 0;
13151318
}
13161319

@@ -1319,12 +1322,14 @@ typedef struct SpecNextResult {
13191322
int return_value;
13201323
} SpecNextResult;
13211324

1322-
int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *next) {
1325+
int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *ret_next) {
13231326
SpecNextResult *shared, tmp;
13241327
int r;
13251328

1329+
assert(spec);
1330+
13261331
if (isempty(spec->timezone))
1327-
return calendar_spec_next_usec_impl(spec, usec, next);
1332+
return calendar_spec_next_usec_impl(spec, usec, ret_next);
13281333

13291334
shared = mmap(NULL, sizeof *shared, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
13301335
if (shared == MAP_FAILED)
@@ -1352,8 +1357,8 @@ int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *next)
13521357
if (munmap(shared, sizeof *shared) < 0)
13531358
return negative_errno();
13541359

1355-
if (tmp.return_value == 0)
1356-
*next = tmp.next;
1360+
if (tmp.return_value == 0 && ret_next)
1361+
*ret_next = tmp.next;
13571362

13581363
return tmp.return_value;
13591364
}

0 commit comments

Comments
 (0)