The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
time.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: e045065dd754e50ea00e17b282bfb9634aabd1ad $
19 *
20 * @brief Platform independent time functions
21 * @file lib/util/time.c
22 *
23 * @copyright 2016-2019 Alan DeKok (aland@freeradius.org)
24 * @copyright 2019-2020 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
25 */
26RCSID("$Id: e045065dd754e50ea00e17b282bfb9634aabd1ad $")
27
28#include <freeradius-devel/autoconf.h>
29#include <freeradius-devel/util/time.h>
30#include <freeradius-devel/util/misc.h>
31
32int64_t const fr_time_multiplier_by_res[] = {
33 [FR_TIME_RES_NSEC] = 1,
38 [FR_TIME_RES_MIN] = (int64_t)NSEC * 60,
39 [FR_TIME_RES_HOUR] = (int64_t)NSEC * 3600,
40 [FR_TIME_RES_DAY] = (int64_t)NSEC * 86400,
41 [FR_TIME_RES_WEEK] = (int64_t)NSEC * 86400 * 7,
44};
45
47 { L("microseconds"), FR_TIME_RES_USEC },
48 { L("us"), FR_TIME_RES_USEC },
49
50 { L("nanoseconds"), FR_TIME_RES_NSEC },
51 { L("ns"), FR_TIME_RES_NSEC },
52
53 { L("milliseconds"), FR_TIME_RES_MSEC },
54 { L("ms"), FR_TIME_RES_MSEC },
55
56 { L("centiseconds"), FR_TIME_RES_CSEC },
57 { L("cs"), FR_TIME_RES_CSEC },
58
59 { L("seconds"), FR_TIME_RES_SEC },
60 { L("s"), FR_TIME_RES_SEC },
61
62 { L("minutes"), FR_TIME_RES_MIN },
63 { L("m"), FR_TIME_RES_MIN },
64
65 { L("hours"), FR_TIME_RES_HOUR },
66 { L("h"), FR_TIME_RES_HOUR },
67
68 { L("days"), FR_TIME_RES_DAY },
69 { L("d"), FR_TIME_RES_DAY },
70
71 { L("weeks"), FR_TIME_RES_WEEK },
72 { L("w"), FR_TIME_RES_WEEK },
73
74 /*
75 * These use special values FR_TIME_DUR_MONTH and FR_TIME_DUR_YEAR
76 */
77 { L("months"), FR_TIME_RES_MONTH },
78 { L("M"), FR_TIME_RES_MONTH },
79
80 { L("years"), FR_TIME_RES_YEAR },
81 { L("y"), FR_TIME_RES_YEAR },
82
83};
85
86int64_t fr_time_epoch; //!< monotonic clock at boot, i.e. our epoch
87_Atomic int64_t fr_time_monotonic_to_realtime; //!< difference between the two clocks
88
89static char const *tz_names[2] = { NULL, NULL }; //!< normal, DST, from localtime_r(), tm_zone
90static long gmtoff[2] = {0, 0}; //!< from localtime_r(), tm_gmtoff
91static bool isdst = false; //!< from localtime_r(), tm_is_dst
92
93
94/** Get a new fr_time_monotonic_to_realtime value
95 *
96 * Should be done regularly to adjust for changes in system time.
97 *
98 * @return
99 * - 0 on success.
100 * - -1 on failure.
101 */
103{
104 struct tm tm;
105 time_t now;
106
107 /*
108 * fr_time_monotonic_to_realtime is the difference in nano
109 *
110 * So to convert a realtime timeval to fr_time we just subtract fr_time_monotonic_to_realtime from the timeval,
111 * which leaves the number of nanoseconds elapsed since our epoch.
112 */
113 struct timespec ts_realtime, ts_monotime;
114
115 /*
116 * Call these consecutively to minimise drift...
117 */
118 if (clock_gettime(CLOCK_REALTIME, &ts_realtime) < 0) return -1;
119 if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts_monotime) < 0) return -1;
120
125
126 now = ts_realtime.tv_sec;
127
128 /*
129 * Get local time zone name, daylight savings, and GMT
130 * offsets.
131 */
132 (void) localtime_r(&now, &tm);
133
134 isdst = (tm.tm_isdst != 0);
135 tz_names[isdst] = tm.tm_zone;
136 gmtoff[isdst] = tm.tm_gmtoff * NSEC; /* they store seconds, we store nanoseconds */
137
138 return 0;
139}
140
141/** Initialize the local time.
142 *
143 * MUST be called when the program starts. MUST NOT be called after
144 * that.
145 *
146 * @return
147 * - <0 on error
148 * - 0 on success
149 */
151{
152 struct timespec ts;
153
154 tzset(); /* Populate timezone, daylight and tzname globals */
155
156 if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts) < 0) return -1;
158
159 return fr_time_sync();
160}
161
162/** Return time delta from the time zone.
163 *
164 * Returns the delta between UTC and the timezone specified by tz
165 *
166 * @param[in] tz time zone name
167 * @param[out] delta the time delta
168 * @return
169 * - 0 converted OK
170 * - <0 on error
171 *
172 * @note This function ONLY handles a limited number of time
173 * zones: local and gmt. It is impossible in general to parse
174 * arbitrary time zone strings, as there are duplicates.
175 */
177{
178 *delta = fr_time_delta_wrap(0);
179
180 if ((strcmp(tz, "UTC") == 0) ||
181 (strcmp(tz, "GMT") == 0)) {
182 return 0;
183 }
184
185 /*
186 * Our local time zone OR time zone with daylight savings.
187 */
188 if (tz_names[0] && (strcmp(tz, tz_names[0]) == 0)) {
189 *delta = fr_time_delta_wrap(gmtoff[0]);
190 return 0;
191 }
192
193 if (tz_names[1] && (strcmp(tz, tz_names[1]) == 0)) {
194 *delta = fr_time_delta_wrap(gmtoff[1]);
195 return 0;
196 }
197
198 return -1;
199}
200
201/** Create fr_time_delta_t from a string
202 *
203 * @param[out] out Where to write fr_time_delta_t
204 * @param[in] in String to parse.
205 * @param[in] hint scale for the parsing. Default is "seconds".
206 * @param[in] no_trailing asserts that there should be a terminal sequence
207 * after the time delta. Allows us to produce
208 * better errors.
209 * @param[in] tt terminal sequences.
210 * @return
211 * - >= 0 on success.
212 * - <0 on failure.
213 */
215 bool no_trailing, fr_sbuff_term_t const *tt)
216{
217 fr_sbuff_t our_in = FR_SBUFF(in);
218 int64_t integer; /* Whole units */
219 fr_time_res_t res;
220 bool negative;
222 bool overflow;
223 fr_time_delta_t delta; /* The delta we're building */
224 size_t match_len;
225
226 negative = fr_sbuff_is_char(&our_in, '-');
227
228 if (fr_sbuff_out(&sberr, &integer, &our_in) < 0) {
229 num_error:
230 fr_strerror_printf("Failed parsing time_delta: %s",
232 FR_SBUFF_ERROR_RETURN(&our_in);
233 }
235
236 /*
237 * We now determine which one of the three formats
238 * we accept the string is in.
239 *
240 * Either:
241 * - <integer>[<scale>]
242 * - <integer>.<fraction>[<scale>]
243 * - [hours:]minutes:seconds
244 */
245
246 /*
247 * We have a fractional component
248 *
249 * <integer>.<fraction>[<scale>]
250 */
251 if (fr_sbuff_next_if_char(&our_in, '.')) {
253 size_t f_len;
254 uint64_t f = 0; /* Fractional units */
255
256 /*
257 * Normalise as a positive integer
258 */
259 if (negative) integer = -(integer);
260
261 /*
262 * Mark the start of the fractional component
263 */
264 fr_sbuff_marker(&m_f, &our_in);
265
266 /*
267 * Leading zeros appear to mess up integer parsing
268 */
269 fr_sbuff_adv_past_zeros(&our_in, SIZE_MAX, tt);
270
271 if (fr_sbuff_out(&sberr, &f, &our_in) < 0) {
272 /*
273 * Crappy workaround for <num>.0
274 *
275 * Advancing past the leading zeros screws
276 * up the fractional parsing when the
277 * fraction is all zeros...
278 */
279 if ((sberr != FR_SBUFF_PARSE_ERROR_NOT_FOUND) || !fr_sbuff_is_char(&m_f, '0')) goto num_error;
280 }
281
282 f_len = fr_sbuff_behind(&m_f);
283 if (f_len > 9) {
284 fr_strerror_const("Too much precision for time_delta");
285 fr_sbuff_set(&our_in, fr_sbuff_current(&m_f) + 10);
286 FR_SBUFF_ERROR_RETURN(&our_in);
287 }
288
289 /*
290 * Convert to nanoseconds
291 *
292 * This can't overflow.
293 */
294 while (f_len < 9) {
295#ifdef STATIC_ANALYZER
296 // Coverity doesn't understand that the previous conditions prevent overflow.
297 if (f > UINT64_MAX / 10) break;
298#endif
299 f *= 10;
300 f_len++;
301 }
302
303 /*
304 * Look for a scale suffix
305 */
307
308 if (no_trailing && !fr_sbuff_is_terminal(&our_in, tt)) {
309 trailing_data:
310 /* Got a qualifier but there's stuff after */
311 if (res != FR_TIME_RES_INVALID) {
312 fr_strerror_const("Trailing data after time_delta");
313 FR_SBUFF_ERROR_RETURN(&our_in);
314 }
315
316 fr_strerror_const("Invalid precision qualifier for time_delta");
317 FR_SBUFF_ERROR_RETURN(&our_in);
318 }
319
320 /* Scale defaults to hint */
321 if (res == FR_TIME_RES_INVALID) res = hint;
322
323 /*
324 * Subseconds was parsed as if it was nanoseconds.
325 * But instead it may be something else, so it should
326 * be truncated.
327 *
328 * Note that this operation can't overflow.
329 */
331 f /= NSEC;
332
333 delta = fr_time_delta_from_integer(&overflow, integer, res);
334 if (overflow) {
335 overflow:
336 fr_strerror_printf("time_delta would %s", negative ? "underflow" : "overflow");
337 fr_sbuff_set_to_start(&our_in);
338 FR_SBUFF_ERROR_RETURN(&our_in);
339 }
340
341 {
342 int64_t tmp;
343
344 /*
345 * Add fractional and integral parts checking for overflow
346 */
347 if (!fr_add(&tmp, fr_time_delta_unwrap(delta), f)) goto overflow;
348
349 /*
350 * Flip the sign back to negative
351 */
352 if (negative) tmp = -(tmp);
353
354 *out = fr_time_delta_wrap(tmp);
355 }
356
357 FR_SBUFF_SET_RETURN(in, &our_in);
358 /*
359 * It's timestamp format
360 *
361 * [hours:]minutes:seconds
362 */
363 } else if (fr_sbuff_next_if_char(&our_in, ':')) {
364 uint64_t hours, minutes, seconds;
366
367 res = FR_TIME_RES_SEC;
368
369 fr_sbuff_marker(&m1, &our_in);
370
371 if (fr_sbuff_out(&sberr, &seconds, &our_in) < 0) goto num_error;
372
373 /*
374 * minutes:seconds
375 */
376 if (!fr_sbuff_next_if_char(&our_in, ':')) {
377 hours = 0;
378 minutes = negative ? -(integer) : integer;
379
380 if (minutes > UINT16_MAX) {
381 fr_strerror_printf("minutes component of time_delta is too large");
382 fr_sbuff_set_to_start(&our_in);
383 FR_SBUFF_ERROR_RETURN(&our_in);
384 }
385 /*
386 * hours:minutes:seconds
387 */
388 } else {
389 hours = negative ? -(integer) : integer;
390 minutes = seconds;
391
392 if (fr_sbuff_out(&sberr, &seconds, &our_in) < 0) goto num_error;
393
394 if (hours > UINT16_MAX) {
395 fr_strerror_printf("hours component of time_delta is too large");
396 fr_sbuff_set_to_start(&our_in);
397 FR_SBUFF_ERROR_RETURN(&our_in);
398 }
399
400 if (minutes > UINT16_MAX) {
401 fr_strerror_printf("minutes component of time_delta is too large");
403 }
404 }
405
406 if (no_trailing && !fr_sbuff_is_terminal(&our_in, tt)) goto trailing_data;
407
408 /*
409 * Add all the components together...
410 */
411 if (!fr_add(&integer, ((hours * 60) * 60) + (minutes * 60), seconds)) goto overflow;
412
413 /*
414 * Flip the sign back to negative
415 */
416 if (negative) integer = -(integer);
417
418 *out = fr_time_delta_from_sec(integer);
419 FR_SBUFF_SET_RETURN(in, &our_in);
420 /*
421 * Nothing fancy here it's just a time delta as an integer
422 *
423 * <integer>[<scale>]
424 */
425 } else {
426 if (no_trailing && !fr_sbuff_is_terminal(&our_in, tt)) goto trailing_data;
427
428 /* Scale defaults to hint */
429 if (res == FR_TIME_RES_INVALID) res = hint;
430
431 /* Do the scale conversion */
432 *out = fr_time_delta_from_integer(&overflow, integer, res);
433 if (overflow) goto overflow;
434
435 FR_SBUFF_SET_RETURN(in, &our_in);
436 }
437}
438
439/** Create fr_time_delta_t from a string
440 *
441 * @param[out] out Where to write fr_time_delta_t
442 * @param[in] in String to parse.
443 * @param[in] inlen Length of string.
444 * @param[in] hint scale for the parsing. Default is "seconds"
445 * @return
446 * - >0 on success.
447 * - <0 on failure.
448 */
450{
451 fr_slen_t slen;
452
453 slen = fr_time_delta_from_substr(out, &FR_SBUFF_IN(in, inlen), hint, true, NULL);
454 if (slen < 0) return slen;
455 if (slen != (fr_slen_t)inlen) {
456 fr_strerror_const("trailing data after time_delta"); /* Shouldn't happen with no_trailing */
457 return -(inlen + 1);
458 }
459 return slen;
460}
461
462/** Print fr_time_delta_t to a string with an appropriate suffix
463 *
464 * @param[out] out Where to write the string version of the time delta.
465 * @param[in] delta to print.
466 * @param[in] res to print resolution with.
467 * @param[in] is_unsigned whether the value should be printed unsigned.
468 * @return
469 * - >0 the number of bytes written to out.
470 * - <0 how many additional bytes would have been required.
471 */
473{
474 fr_sbuff_t our_out = FR_SBUFF(out);
475 char *q;
476 int64_t lhs = 0;
477 uint64_t rhs = 0;
478
479/*
480 * The % operator can return a _signed_ value. This macro is
481 * correct for both positive and negative inputs.
482 */
483#define MOD(a,b) (((a<0) ? (-a) : (a))%(b))
484
485 lhs = fr_time_delta_to_integer(delta, res);
487
488 if (!is_unsigned) {
489 /*
490 * 0 is unsigned, but we want to print
491 * "-0.1" if necessary.
492 */
493 if ((lhs == 0) && fr_time_delta_isneg(delta)) {
494 FR_SBUFF_IN_CHAR_RETURN(&our_out, '-');
495 }
496
497 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "%" PRIi64 ".%09" PRIu64, lhs, rhs);
498 } else {
499 if (fr_time_delta_isneg(delta)) lhs = rhs = 0;
500
501 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "%" PRIu64 ".%09" PRIu64, lhs, rhs);
502 }
503 q = fr_sbuff_current(&our_out) - 1;
504
505 /*
506 * Truncate trailing zeros.
507 */
508 while (*q == '0') *(q--) = '\0';
509
510 /*
511 * If there's nothing after the decimal point,
512 * truncate the decimal point. i.e. Don't print
513 * "5."
514 */
515 if (*q == '.') {
516 *q = '\0';
517 } else {
518 q++; /* to account for q-- above */
519 }
520
522}
523
524DIAG_OFF(format-nonliteral)
525/** Copy a time string (local timezone) to an sbuff
526 *
527 * @note This function will attempt to extend the sbuff by double the length of
528 * the fmt string. It is recommended to either pre-extend the sbuff before
529 * calling this function, or avoid using format specifiers that expand to
530 * character strings longer than 4 bytes.
531 *
532 * @param[in] out Where to write the formatted time string.
533 * @param[in] time Internal server time to convert to wallclock
534 * time and copy out as formatted string.
535 * @param[in] fmt Time format string.
536 * @return
537 * - >0 the number of bytes written to the sbuff.
538 * - 0 if there's insufficient space in the sbuff.
539 */
541{
542 struct tm tm;
543 time_t utime = fr_time_to_sec(time);
544 size_t len;
545
546 localtime_r(&utime, &tm);
547
548 len = strftime(fr_sbuff_current(out), fr_sbuff_extend_lowat(NULL, out, strlen(fmt) * 2), fmt, &tm);
549 if (len == 0) return 0;
550
551 return fr_sbuff_advance(out, len);
552}
553
554/** Copy a time string (UTC) to an sbuff
555 *
556 * @note This function will attempt to extend the sbuff by double the length of
557 * the fmt string. It is recommended to either pre-extend the sbuff before
558 * calling this function, or avoid using format specifiers that expand to
559 * character strings longer than 4 bytes.
560 *
561 * @param[in] out Where to write the formatted time string.
562 * @param[in] time Internal server time to convert to wallclock
563 * time and copy out as formatted string.
564 * @param[in] fmt Time format string.
565 * @return
566 * - >0 the number of bytes written to the sbuff.
567 * - 0 if there's insufficient space in the sbuff.
568 */
570{
571 struct tm tm;
572 time_t utime = fr_time_to_sec(time);
573 size_t len;
574
575 gmtime_r(&utime, &tm);
576
577 len = strftime(fr_sbuff_current(out), fr_sbuff_extend_lowat(NULL, out, strlen(fmt) * 2), fmt, &tm);
578 if (len == 0) return 0;
579
580 return fr_sbuff_advance(out, len);
581}
582DIAG_ON(format-nonliteral)
583
585{
586 fr_time_delta_t delay;
587
588 if (fr_time_gteq(start, end)) {
589 delay = fr_time_delta_wrap(0);
590 } else {
591 delay = fr_time_sub(end, start);
592 }
593
594 if (fr_time_delta_lt(delay, fr_time_delta_wrap(1000))) { /* microseconds */
595 elapsed->array[0]++;
596
597 } else if (fr_time_delta_lt(delay, fr_time_delta_wrap(10000))) {
598 elapsed->array[1]++;
599
600 } else if (fr_time_delta_lt(delay, fr_time_delta_wrap(100000))) {
601 elapsed->array[2]++;
602
603 } else if (fr_time_delta_lt(delay, fr_time_delta_wrap(1000000))) { /* milliseconds */
604 elapsed->array[3]++;
605
606 } else if (fr_time_delta_lt(delay, fr_time_delta_wrap(10000000))) {
607 elapsed->array[4]++;
608
609 } else if (fr_time_delta_lt(delay, fr_time_delta_wrap(100000000))) {
610 elapsed->array[5]++;
611
612 } else if (fr_time_delta_lt(delay, fr_time_delta_wrap(1000000000))) { /* seconds */
613 elapsed->array[6]++;
614
615 } else { /* tens of seconds or more */
616 elapsed->array[7]++;
617
618 }
619}
620
621static const char *names[8] = {
622 "1us", "10us", "100us",
623 "1ms", "10ms", "100ms",
624 "1s", "10s"
625};
626
627static char const *tab_string = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
628
629void fr_time_elapsed_fprint(FILE *fp, fr_time_elapsed_t const *elapsed, char const *prefix, int tab_offset)
630{
631 int i;
632 size_t prefix_len;
633
634 if (!prefix) prefix = "elapsed";
635
636 prefix_len = strlen(prefix);
637
638 for (i = 0; i < 8; i++) {
639 size_t len;
640
641 if (!elapsed->array[i]) continue;
642
643 len = prefix_len + 1 + strlen(names[i]);
644
645 if (len >= (size_t) (tab_offset * 8)) {
646 fprintf(fp, "%s.%s %" PRIu64 "\n",
647 prefix, names[i], elapsed->array[i]);
648
649 } else {
650 int tabs;
651
652 tabs = ((tab_offset * 8) - len);
653 if ((tabs & 0x07) != 0) tabs += 7;
654 tabs >>= 3;
655
656 fprintf(fp, "%s.%s%.*s%" PRIu64 "\n",
657 prefix, names[i], tabs, tab_string, elapsed->array[i]);
658 }
659 }
660}
661
662/*
663 * Based on https://blog.reverberate.org/2020/05/12/optimizing-date-algorithms.html
664 */
666{
667 static const uint16_t month_yday[12] = {0, 31, 59, 90, 120, 151,
668 181, 212, 243, 273, 304, 334};
669
670 uint32_t year_adj;
671 uint32_t febs;
672 uint32_t leap_days;
673 uint32_t days;
674
675 /* Prevent crash if tm->tm_mon is invalid - seen in clusterfuzz */
676 if (unlikely(tm->tm_mon >= (__typeof__(tm->tm_mon))NUM_ELEMENTS(month_yday))) return fr_unix_time_min();
677
678 if (unlikely(tm->tm_year > 10000)) return fr_unix_time_min();
679
680 year_adj = tm->tm_year + 4800 + 1900; /* Ensure positive year, multiple of 400. */
681 febs = year_adj - (tm->tm_mon < 2 ? 1 : 0); /* Februaries since base. tm_mon is 0 - 11 */
682 leap_days = 1 + (febs / 4) - (febs / 100) + (febs / 400);
683
684 days = 365 * year_adj + leap_days + month_yday[tm->tm_mon] + tm->tm_mday - 1;
685
686#define CHECK(_x, _max) if ((tm->tm_ ## _x < 0) || (tm->tm_ ## _x >= _max)) tm->tm_ ## _x = _max - 1
687
688 CHECK(sec, 60);
689 CHECK(min, 60);
690 CHECK(hour, 24);
691 CHECK(mday, 32);
692 CHECK(mon, 12);
693 CHECK(year, 3000);
694 CHECK(wday, 7);
695 CHECK(mon, 12);
696 CHECK(yday, 366);
697 /* don't check gmtoff, it can be negative */
698
699 /*
700 * 2472692 adjusts the days for Unix epoch. It is calculated as
701 * (365.2425 * (4800 + 1970))
702 *
703 * We REMOVE the time zone offset in order to get internal unix times in UTC.
704 */
705 return fr_unix_time_from_sec((((days - 2472692) * 86400) + (tm->tm_hour * 3600) +
706 (tm->tm_min * 60) + tm->tm_sec) - tm->tm_gmtoff);
707}
708
709/** Scale an input time to NSEC, clamping it at max / min.
710 *
711 * @param t input time / time delta
712 * @param hint time resolution hint
713 * @return
714 * - INT64_MIN on underflow
715 * - 0 on invalid hint
716 * - INT64_MAX on overflow
717 * - otherwise a valid number, multiplied by the relevant scale,
718 * so that the result is in nanoseconds.
719 */
720int64_t fr_time_scale(int64_t t, fr_time_res_t hint)
721{
722 int64_t scale;
723
724 switch (hint) {
725 case FR_TIME_RES_SEC:
726 scale = NSEC;
727 break;
728
729 case FR_TIME_RES_MSEC:
730 scale = 1000000;
731 break;
732
733 case FR_TIME_RES_USEC:
734 scale = 1000;
735 break;
736
737 case FR_TIME_RES_NSEC:
738 return t;
739
740 default:
741 return 0;
742 }
743
744 if (t < 0) {
745 if (t < (INT64_MIN / scale)) {
746 return INT64_MIN;
747 }
748 } else if (t > 0) {
749 if (t > (INT64_MAX / scale)) {
750 return INT64_MAX;
751 }
752 }
753
754 return t * scale;
755}
756
757
758/*
759 * Sort of strtok/strsep function.
760 */
761static char *mystrtok(char **ptr, char const *sep)
762{
763 char *res;
764
765 if (**ptr == '\0') return NULL;
766
767 while (**ptr && strchr(sep, **ptr)) (*ptr)++;
768
769 if (**ptr == '\0') return NULL;
770
771 res = *ptr;
772 while (**ptr && strchr(sep, **ptr) == NULL) (*ptr)++;
773
774 if (**ptr != '\0') *(*ptr)++ = '\0';
775
776 return res;
777}
778
779/*
780 * Helper function to get a 2-digit date. With a maximum value,
781 * and a terminating character.
782 */
783static int get_part(char **str, int *date, int min, int max, char term, char const *name)
784{
785 char *p = *str;
786
787 if (!isdigit((uint8_t) *p) || !isdigit((uint8_t) p[1])) return -1;
788 *date = (p[0] - '0') * 10 + (p[1] - '0');
789
790 if (*date < min) {
791 fr_strerror_printf("Invalid %s (too small)", name);
792 return -1;
793 }
794
795 if (*date > max) {
796 fr_strerror_printf("Invalid %s (too large)", name);
797 return -1;
798 }
799
800 p += 2;
801 if (!term) {
802 *str = p;
803 return 0;
804 }
805
806 if (*p != term) {
807 fr_strerror_printf("Expected '%c' after %s, got '%c'",
808 term, name, *p);
809 return -1;
810 }
811 p++;
812
813 *str = p;
814 return 0;
815}
816
817static char const *months[] = {
818 "jan", "feb", "mar", "apr", "may", "jun",
819 "jul", "aug", "sep", "oct", "nov", "dec" };
820
821
822/** Convert string in various formats to a fr_unix_time_t
823 *
824 * @param date_str input date string.
825 * @param date time_t to write result to.
826 * @param[in] hint scale for the parsing. Default is "seconds"
827 * @return
828 * - 0 on success.
829 * - -1 on failure.
830 */
831int fr_unix_time_from_str(fr_unix_time_t *date, char const *date_str, fr_time_res_t hint)
832{
833 int i;
834 int64_t tmp;
835 struct tm *tm, s_tm;
836 char buf[64];
837 char *p;
838 char *f[4];
839 char *tail = NULL;
840 unsigned long l;
841 fr_time_delta_t gmt_delta = fr_time_delta_wrap(0);
842
843 /*
844 * Test for unix timestamp, which is just a number and
845 * nothing else.
846 */
847 tmp = strtoul(date_str, &tail, 10);
848 if (*tail == '\0') {
849 *date = fr_unix_time_from_nsec(fr_time_scale(tmp, hint));
850 return 0;
851 }
852
853 tm = &s_tm;
854 memset(tm, 0, sizeof(*tm));
855 tm->tm_isdst = -1; /* don't know, and don't care about DST */
856
857 /*
858 * Check for RFC 3339 dates. Note that we only support
859 * dates in a ~1000 year period. If the server is being
860 * used after 3000AD, someone can patch it then.
861 *
862 * %Y-%m-%dT%H:%M:%S
863 * [.%d] sub-seconds
864 * Z | (+/-)%H:%M time zone offset
865 *
866 */
867 if ((tmp > 1900) && (tmp < 3000) && *tail == '-') {
868 unsigned long subseconds;
869 int tz, tz_hour, tz_min;
870
871 p = tail + 1;
872 s_tm.tm_year = tmp - 1900; /* 'struct tm' starts years in 1900 */
873
874 if (get_part(&p, &s_tm.tm_mon, 1, 12, '-', "month") < 0) return -1;
875 s_tm.tm_mon--; /* ISO is 1..12, where 'struct tm' is 0..11 */
876
877 if (get_part(&p, &s_tm.tm_mday, 1, 31, 'T', "day") < 0) return -1;
878 if (get_part(&p, &s_tm.tm_hour, 0, 23, ':', "hour") < 0) return -1;
879 if (get_part(&p, &s_tm.tm_min, 0, 59, ':', "minute") < 0) return -1;
880 if (get_part(&p, &s_tm.tm_sec, 0, 60, '\0', "seconds") < 0) return -1;
881
882 if (*p == '.') {
883 p++;
884 subseconds = strtoul(p, &tail, 10);
885 if (subseconds > NSEC) {
886 fr_strerror_const("Invalid nanosecond specifier");
887 return -1;
888 }
889
890 /*
891 * Scale subseconds to nanoseconds by how
892 * many digits were parsed/
893 */
894 if ((tail - p) < 9) {
895 for (i = 0; i < 9 - (tail -p); i++) {
896 subseconds *= 10;
897 }
898 }
899
900 p = tail;
901 } else {
902 subseconds = 0;
903 }
904
905 /*
906 * Time zone is GMT. Leave well enough
907 * alone.
908 */
909 if (*p == 'Z') {
910 if (p[1] != '\0') {
911 fr_strerror_printf("Unexpected text '%c' after time zone", p[1]);
912 return -1;
913 }
914 tz = 0;
915 goto done;
916 }
917
918 if ((*p != '+') && (*p != '-')) {
919 fr_strerror_printf("Invalid time zone specifier '%c'", *p);
920 return -1;
921 }
922 tail = p; /* remember sign for later */
923 p++;
924
925 if (get_part(&p, &tz_hour, 0, 23, ':', "hour in time zone") < 0) return -1;
926 if (get_part(&p, &tz_min, 0, 59, '\0', "minute in time zone") < 0) return -1;
927
928 if (*p != '\0') {
929 fr_strerror_printf("Unexpected text '%c' after time zone", *p);
930 return -1;
931 }
932
933 /*
934 * We set the time zone, but the timegm()
935 * function ignores it. Note also that mktime()
936 * ignores it too, and treats the time zone as
937 * local.
938 *
939 * We can't store this value in s_tm.gtmoff,
940 * because the timegm() function helpfully zeros
941 * it out.
942 *
943 * So insyead of using stupid C library
944 * functions, we just roll our own.
945 */
946 tz = tz_hour * 3600 + tz_min;
947 if (*tail == '-') tz *= -1;
948
949 done:
950 /*
951 * We REMOVE the time zone offset in order to get internal unix times in UTC.
952 */
953 tm->tm_gmtoff = -tz;
955 return 0;
956 }
957
958 /*
959 * Try to parse dates via locale-specific names,
960 * using the same format string as strftime().
961 *
962 * If that fails, then we fall back to our parsing
963 * routine, which is much more forgiving.
964 */
965
966#ifdef __APPLE__
967 /*
968 * OSX "man strptime" says it only accepts the local time zone, and GMT.
969 *
970 * However, when printing dates via strftime(), it prints
971 * "UTC" instead of "GMT". So... we have to fix it up
972 * for stupid nonsense.
973 */
974 {
975 char const *tz = strstr(date_str, "UTC");
976 if (tz) {
977 char *my_str;
978
979 my_str = talloc_strdup(NULL, date_str);
980 if (my_str) {
981 p = my_str + (tz - date_str);
982 memcpy(p, "GMT", 3);
983
984 p = strptime(my_str, "%b %e %Y %H:%M:%S %Z", tm);
985 if (p && (*p == '\0')) {
986 talloc_free(my_str);
987 *date = fr_unix_time_from_tm(tm);
988 return 0;
989 }
990 talloc_free(my_str);
991 }
992 }
993 }
994#endif
995
996 p = strptime(date_str, "%b %e %Y %H:%M:%S %Z", tm);
997 if (p && (*p == '\0')) {
998 *date = fr_unix_time_from_tm(tm);
999 return 0;
1000 }
1001
1002 strlcpy(buf, date_str, sizeof(buf));
1003
1004 p = buf;
1005 f[0] = mystrtok(&p, " \t");
1006 f[1] = mystrtok(&p, " \t");
1007 f[2] = mystrtok(&p, " \t");
1008 f[3] = mystrtok(&p, " \t"); /* may, or may not, be present */
1009 if (!f[0] || !f[1] || !f[2]) {
1010 fr_strerror_const("Too few fields");
1011 return -1;
1012 }
1013
1014 /*
1015 * Try to parse the time zone. If it's GMT / UTC or a
1016 * local time zone we're OK.
1017 *
1018 * Otherwise, ignore errors and assume GMT.
1019 */
1020 if (*p != '\0') {
1022 (void) fr_time_delta_from_time_zone(p, &gmt_delta);
1023 }
1024
1025 /*
1026 * The time has a colon, where nothing else does.
1027 * So if we find it, bubble it to the back of the list.
1028 */
1029 if (f[3]) {
1030 for (i = 0; i < 3; i++) {
1031 if (strchr(f[i], ':')) {
1032 p = f[3];
1033 f[3] = f[i];
1034 f[i] = p;
1035 break;
1036 }
1037 }
1038 }
1039
1040 /*
1041 * The month is text, which allows us to find it easily.
1042 */
1043 tm->tm_mon = 12;
1044 for (i = 0; i < 3; i++) {
1045 if (isalpha((uint8_t) *f[i])) {
1046 int j;
1047
1048 /*
1049 * Bubble the month to the front of the list
1050 */
1051 p = f[0];
1052 f[0] = f[i];
1053 f[i] = p;
1054
1055 for (j = 0; j < 12; j++) {
1056 if (strncasecmp(months[j], f[0], 3) == 0) {
1057 tm->tm_mon = j;
1058 break;
1059 }
1060 }
1061 }
1062 }
1063
1064 /* month not found? */
1065 if (tm->tm_mon == 12) {
1066 fr_strerror_const("No month found");
1067 return -1;
1068 }
1069
1070 /*
1071 * Check for invalid text, or invalid trailing text.
1072 */
1073 l = strtoul(f[1], &tail, 10);
1074 if ((l == ULONG_MAX) || (*tail != '\0')) {
1075 fr_strerror_const("Invalid year string");
1076 return -1;
1077 }
1078 tm->tm_year = l;
1079
1080 l = strtoul(f[2], &tail, 10);
1081 if ((l == ULONG_MAX) || (*tail != '\0')) {
1082 fr_strerror_const("Invalid day of month string");
1083 return -1;
1084 }
1085 tm->tm_mday = l;
1086
1087 if (tm->tm_year >= 1900) {
1088 tm->tm_year -= 1900;
1089
1090 } else {
1091 /*
1092 * We can't use 2-digit years any more, they make it
1093 * impossible to tell what's the day, and what's the year.
1094 */
1095 if (tm->tm_mday < 1900) {
1096 fr_strerror_const("Invalid year < 1900");
1097 return -1;
1098 }
1099
1100 /*
1101 * Swap the year and the day.
1102 */
1103 i = tm->tm_year;
1104 tm->tm_year = tm->tm_mday - 1900;
1105 tm->tm_mday = i;
1106 }
1107
1108 if (tm->tm_year > 10000) {
1109 fr_strerror_const("Invalid value for year");
1110 return -1;
1111 }
1112
1113 /*
1114 * If the day is out of range, die.
1115 */
1116 if ((tm->tm_mday < 1) || (tm->tm_mday > 31)) {
1117 fr_strerror_const("Invalid value for day of month");
1118 return -1;
1119 }
1120
1121 /*
1122 * There may be %H:%M:%S. Parse it in a hacky way.
1123 */
1124 if (f[3]) {
1125 f[0] = f[3]; /* HH */
1126 f[1] = strchr(f[0], ':'); /* find : separator */
1127 if (!f[1]) {
1128 fr_strerror_const("No ':' after hour");
1129 return -1;
1130 }
1131
1132 *(f[1]++) = '\0'; /* nuke it, and point to MM:SS */
1133
1134 f[2] = strchr(f[1], ':'); /* find : separator */
1135 if (f[2]) {
1136 *(f[2]++) = '\0'; /* nuke it, and point to SS */
1137 tm->tm_sec = atoi(f[2]);
1138 } /* else leave it as zero */
1139
1140 tm->tm_hour = atoi(f[0]);
1141 tm->tm_min = atoi(f[1]);
1142 }
1143
1144 *date = fr_unix_time_add(fr_unix_time_from_tm(tm), gmt_delta);
1145
1146 return 0;
1147}
1148
1149/** Convert unix time to string
1150 *
1151 * @param[out] out Where to write the string.
1152 * @param[in] time to convert.
1153 * @param[in] res What base resolution to print the time as.
1154 * @return
1155 * - 0 on success.
1156 * - -1 on failure.
1157 */
1159{
1160 fr_sbuff_t our_out = FR_SBUFF(out);
1161 int64_t subseconds;
1162 time_t t;
1163 struct tm s_tm;
1164 size_t len;
1165 char buf[128];
1166
1167 t = fr_unix_time_to_sec(time);
1168 if (utc) {
1169 (void) gmtime_r(&t, &s_tm);
1170 } else {
1171 (void) localtime_r(&t, &s_tm);
1172 }
1173
1174 len = strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", &s_tm);
1175 FR_SBUFF_IN_BSTRNCPY_RETURN(&our_out, buf, len);
1176 subseconds = fr_unix_time_unwrap(time) % NSEC;
1177
1178 /*
1179 * Use RFC 3339 format, which is a
1180 * profile of ISO8601. The ISO standard
1181 * allows a much more complex set of date
1182 * formats. The RFC is much stricter.
1183 */
1184 switch (res) {
1186 case FR_TIME_RES_YEAR:
1187 case FR_TIME_RES_MONTH:
1188 case FR_TIME_RES_WEEK:
1189 case FR_TIME_RES_DAY:
1190 case FR_TIME_RES_HOUR:
1191 case FR_TIME_RES_MIN:
1192 case FR_TIME_RES_SEC:
1193 break;
1194
1195 case FR_TIME_RES_CSEC:
1196 subseconds /= (NSEC / CSEC);
1197 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, ".%02" PRIi64, subseconds);
1198 break;
1199
1200 case FR_TIME_RES_MSEC:
1201 subseconds /= (NSEC / MSEC);
1202 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, ".%03" PRIi64, subseconds);
1203 break;
1204
1205 case FR_TIME_RES_USEC:
1206 subseconds /= (NSEC / USEC);
1207 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, ".%06" PRIi64, subseconds);
1208 break;
1209
1210 case FR_TIME_RES_NSEC:
1211 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, ".%09" PRIi64, subseconds);
1212 break;
1213 }
1214
1215 /*
1216 * And time zone.
1217 */
1218 if (s_tm.tm_gmtoff != 0) {
1219 int hours, minutes;
1220
1221 hours = s_tm.tm_gmtoff / 3600;
1222 minutes = (s_tm.tm_gmtoff / 60) % 60;
1223
1224 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "%+03d:%02u", hours, minutes);
1225 } else {
1226 FR_SBUFF_IN_CHAR_RETURN(&our_out, 'Z');
1227 }
1228
1229 FR_SBUFF_SET_RETURN(out, &our_out);
1230}
1231
1232/** Get the offset to gmt.
1233 *
1234 */
1239
1240/** Whether or not we're daylight savings.
1241 *
1242 */
1244{
1245 return isdst;
1246}
static int const char * fmt
Definition acutest.h:573
#define RCSID(id)
Definition build.h:483
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
#define DIAG_ON(_x)
Definition build.h:458
#define unlikely(_x)
Definition build.h:381
#define NUM_ELEMENTS(_t)
Definition build.h:337
#define DIAG_OFF(_x)
Definition build.h:457
static const char * tabs
Definition command.c:1581
static size_t min(size_t x, size_t y)
Definition dbuff.c:66
static fr_slen_t in
Definition dict.h:824
talloc_free(reap)
#define fr_add(_out, _a, _b)
Adds two integers.
Definition math.h:129
unsigned short uint16_t
unsigned int uint32_t
unsigned char uint8_t
ssize_t fr_slen_t
unsigned long int size_t
fr_sbuff_parse_error_t
@ FR_SBUFF_PARSE_ERROR_NOT_FOUND
String does not contain a token matching the output type.
#define fr_skip_whitespace(_p)
Skip whitespace ('\t', '\n', '\v', '\f', '\r', ' ')
Definition misc.h:59
int strncasecmp(char *s1, char *s2, int n)
Definition missing.c:36
struct tm * gmtime_r(time_t const *l_clock, struct tm *result)
Definition missing.c:201
struct tm * localtime_r(time_t const *l_clock, struct tm *result)
Definition missing.c:163
static bool done
Definition radclient.c:80
static char const * name
bool fr_sbuff_is_terminal(fr_sbuff_t *in, fr_sbuff_term_t const *tt)
Efficient terminal string search.
Definition sbuff.c:2152
fr_table_num_ordered_t const sbuff_parse_error_table[]
Definition sbuff.c:43
bool fr_sbuff_next_if_char(fr_sbuff_t *sbuff, char c)
Return true if the current char matches, and if it does, advance.
Definition sbuff.c:2088
#define fr_sbuff_out_by_longest_prefix(_match_len, _out, _table, _sbuff, _def)
#define fr_sbuff_adv_past_zeros(_sbuff, _len, _tt)
#define FR_SBUFF_IN_CHAR_RETURN(_sbuff,...)
#define fr_sbuff_set(_dst, _src)
#define FR_SBUFF_IN(_start, _len_or_end)
#define fr_sbuff_current(_sbuff_or_marker)
#define fr_sbuff_is_char(_sbuff_or_marker, _c)
#define FR_SBUFF_ERROR_RETURN(_sbuff_or_marker)
#define FR_SBUFF_SET_RETURN(_dst, _src)
#define FR_SBUFF_IN_SPRINTF_RETURN(...)
#define FR_SBUFF(_sbuff_or_marker)
#define FR_SBUFF_IN_BSTRNCPY_RETURN(...)
#define fr_sbuff_advance(_sbuff_or_marker, _len)
#define fr_sbuff_out(_err, _out, _in)
#define fr_sbuff_behind(_sbuff_or_marker)
#define fr_sbuff_extend_lowat(_status, _sbuff_or_marker, _lowat)
Set of terminal elements.
@ memory_order_release
Definition stdatomic.h:130
#define _Atomic(T)
Definition stdatomic.h:77
#define atomic_store_explicit(object, desired, order)
Definition stdatomic.h:314
size_t strlcpy(char *dst, char const *src, size_t siz)
Definition strlcpy.c:34
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:772
An element in an arbitrarily ordered array of name to num mappings.
Definition table.h:57
static char * mystrtok(char **ptr, char const *sep)
Definition time.c:761
void fr_time_elapsed_update(fr_time_elapsed_t *elapsed, fr_time_t start, fr_time_t end)
Definition time.c:584
fr_unix_time_t fr_unix_time_from_tm(struct tm *tm)
Definition time.c:665
static char const * tab_string
Definition time.c:627
static const char * names[8]
Definition time.c:621
int fr_time_sync(void)
Get a new fr_time_monotonic_to_realtime value.
Definition time.c:102
static int get_part(char **str, int *date, int min, int max, char term, char const *name)
Definition time.c:783
static long gmtoff[2]
from localtime_r(), tm_gmtoff
Definition time.c:90
fr_table_num_ordered_t const fr_time_precision_table[]
Definition time.c:46
size_t fr_time_strftime_local(fr_sbuff_t *out, fr_time_t time, char const *fmt)
Copy a time string (local timezone) to an sbuff.
Definition time.c:540
#define CHECK(_x, _max)
fr_slen_t fr_time_delta_from_substr(fr_time_delta_t *out, fr_sbuff_t *in, fr_time_res_t hint, bool no_trailing, fr_sbuff_term_t const *tt)
Create fr_time_delta_t from a string.
Definition time.c:214
int fr_time_delta_from_time_zone(char const *tz, fr_time_delta_t *delta)
Return time delta from the time zone.
Definition time.c:176
fr_slen_t fr_time_delta_from_str(fr_time_delta_t *out, char const *in, size_t inlen, fr_time_res_t hint)
Create fr_time_delta_t from a string.
Definition time.c:449
bool fr_time_is_dst(void)
Whether or not we're daylight savings.
Definition time.c:1243
void fr_time_elapsed_fprint(FILE *fp, fr_time_elapsed_t const *elapsed, char const *prefix, int tab_offset)
Definition time.c:629
_Atomic int64_t fr_time_monotonic_to_realtime
difference between the two clocks
Definition time.c:87
int fr_unix_time_from_str(fr_unix_time_t *date, char const *date_str, fr_time_res_t hint)
Convert string in various formats to a fr_unix_time_t.
Definition time.c:831
int64_t fr_time_scale(int64_t t, fr_time_res_t hint)
Scale an input time to NSEC, clamping it at max / min.
Definition time.c:720
#define MOD(a, b)
static char const * months[]
Definition time.c:817
fr_time_delta_t fr_time_gmtoff(void)
Get the offset to gmt.
Definition time.c:1235
fr_slen_t fr_time_delta_to_str(fr_sbuff_t *out, fr_time_delta_t delta, fr_time_res_t res, bool is_unsigned)
Print fr_time_delta_t to a string with an appropriate suffix.
Definition time.c:472
size_t fr_time_precision_table_len
Definition time.c:84
static char const * tz_names[2]
normal, DST, from localtime_r(), tm_zone
Definition time.c:89
int fr_time_start(void)
Initialize the local time.
Definition time.c:150
static bool isdst
from localtime_r(), tm_is_dst
Definition time.c:91
fr_slen_t fr_unix_time_to_str(fr_sbuff_t *out, fr_unix_time_t time, fr_time_res_t res, bool utc)
Convert unix time to string.
Definition time.c:1158
int64_t fr_time_epoch
monotonic clock at boot, i.e. our epoch
Definition time.c:86
size_t fr_time_strftime_utc(fr_sbuff_t *out, fr_time_t time, char const *fmt)
Copy a time string (UTC) to an sbuff.
Definition time.c:569
int64_t const fr_time_multiplier_by_res[]
Definition time.c:32
static fr_time_delta_t fr_time_delta_from_integer(bool *overflow, int64_t integer, fr_time_res_t res)
Definition time.h:548
#define MSEC
Definition time.h:381
static int64_t fr_time_delta_to_integer(fr_time_delta_t delta, fr_time_res_t res)
Definition time.h:627
static int64_t fr_time_to_sec(fr_time_t when)
Convert an fr_time_t (internal time) to number of sec since the unix epoch (wallclock time)
Definition time.h:731
#define fr_time_gteq(_a, _b)
Definition time.h:238
static fr_unix_time_t fr_unix_time_from_nsec(int64_t nsec)
Definition time.h:423
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
Definition time.h:154
#define fr_time_delta_isneg(_a)
Definition time.h:291
#define fr_time_delta_lt(_a, _b)
Definition time.h:285
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
static int64_t fr_unix_time_to_sec(fr_unix_time_t delta)
Definition time.h:506
#define fr_time_delta_wrap(_time)
Definition time.h:152
#define fr_unix_time_min()
Definition time.h:159
fr_time_res_t
The base resolution for print parse operations.
Definition time.h:48
@ FR_TIME_RES_MONTH
Definition time.h:55
@ FR_TIME_RES_MSEC
Definition time.h:58
@ FR_TIME_RES_WEEK
Definition time.h:54
@ FR_TIME_RES_MIN
Definition time.h:51
@ FR_TIME_RES_CSEC
Definition time.h:57
@ FR_TIME_RES_HOUR
Definition time.h:52
@ FR_TIME_RES_YEAR
Definition time.h:56
@ FR_TIME_RES_DAY
Definition time.h:53
@ FR_TIME_RES_NSEC
Definition time.h:60
@ FR_TIME_RES_USEC
Definition time.h:59
@ FR_TIME_RES_SEC
Definition time.h:50
@ FR_TIME_RES_INVALID
Definition time.h:49
static fr_unix_time_t fr_unix_time_from_sec(int64_t sec)
Definition time.h:449
#define NSEC
Definition time.h:379
static uint64_t fr_unix_time_unwrap(fr_unix_time_t time)
Definition time.h:161
#define CLOCK_MONOTONIC_RAW
Definition time.h:950
uint64_t array[8]
100ns to 100s
Definition time.h:376
#define USEC
Definition time.h:380
#define fr_time_sub(_a, _b)
Subtract one time from another.
Definition time.h:229
#define FR_TIME_DUR_MONTH
Definition time.h:394
#define CSEC
Definition time.h:382
#define fr_unix_time_add(_a, _b)
Add a time/time delta together.
Definition time.h:324
static fr_time_delta_t fr_time_delta_from_timespec(struct timespec const *ts)
Definition time.h:614
#define FR_TIME_DUR_YEAR
Definition time.h:393
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69
"Unix" time.
Definition time.h:95
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define fr_strerror_const(_msg)
Definition strerror.h:223
static size_t char fr_sbuff_t size_t inlen
Definition value.h:997
static size_t char ** out
Definition value.h:997