From: Arran Cudbard-Bell Date: Wed, 25 Aug 2021 02:37:00 +0000 (-0500) Subject: Correct uses of fr_time_from_utc X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f7fd74eebf42148b62388001ad3a5c4affd23747;p=thirdparty%2Ffreeradius-server.git Correct uses of fr_time_from_utc --- diff --git a/src/lib/util/misc.c b/src/lib/util/misc.c index dcdf73d1c3e..fc0ebb168a0 100644 --- a/src/lib/util/misc.c +++ b/src/lib/util/misc.c @@ -578,7 +578,7 @@ static int get_part(char **str, int *date, int min, int max, char term, char con int fr_unix_time_from_str(fr_unix_time_t *date, char const *date_str, fr_time_res_t hint) { int i; - time_t t; + fr_unix_time_t t; struct tm *tm, s_tm; char buf[64]; char *p; @@ -712,11 +712,6 @@ int fr_unix_time_from_str(fr_unix_time_t *date, char const *date_str, fr_time_re done: t = fr_time_from_utc(tm); - if (t == (time_t) -1) { - fr_strerror_printf("Failed calling system function to parse time - %s", - fr_syserror(errno)); - return -1; - } /* * Add in the time zone offset, which the posix @@ -901,15 +896,7 @@ int fr_unix_time_from_str(fr_unix_time_t *date, char const *date_str, fr_time_re tm->tm_min = atoi(f[1]); } - /* - * Returns -1 on failure. - */ t = fr_time_from_utc(tm); - if (t == (time_t) -1) { - fr_strerror_printf("Failed calling system function to parse time - %s", - fr_syserror(errno)); - return -1; - } /* * Get the UTC time, and manually add in the offset from GMT. diff --git a/src/lib/util/time.c b/src/lib/util/time.c index 6f96f518d06..47e158f1963 100644 --- a/src/lib/util/time.c +++ b/src/lib/util/time.c @@ -539,7 +539,7 @@ void fr_time_elapsed_fprint(FILE *fp, fr_time_elapsed_t const *elapsed, char con /* * Based on https://blog.reverberate.org/2020/05/12/optimizing-date-algorithms.html */ -time_t fr_time_from_utc(struct tm *tm) +fr_unix_time_t fr_time_from_utc(struct tm *tm) { static const uint16_t month_yday[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; diff --git a/src/lib/util/time.h b/src/lib/util/time.h index a58f01a4019..705b12e5cf1 100644 --- a/src/lib/util/time.h +++ b/src/lib/util/time.h @@ -354,7 +354,7 @@ size_t fr_time_strftime_utc(fr_sbuff_t *out, fr_time_t time, char const *fmt) void fr_time_elapsed_update(fr_time_elapsed_t *elapsed, fr_time_t start, fr_time_t end) CC_HINT(nonnull); void fr_time_elapsed_fprint(FILE *fp, fr_time_elapsed_t const *elapsed, char const *prefix, int tabs) CC_HINT(nonnull(1,2)); -time_t fr_time_from_utc(struct tm *tm) CC_HINT(nonnull); +fr_unix_time_t fr_time_from_utc(struct tm *tm) CC_HINT(nonnull); #ifdef __cplusplus }