131 P = strchr(str,
'P');
137 T = strchr(str,
'T');
138 X = strchr(str,
'Y');
140 duration->
years = (time_t) atoi(str+1);
144 X = strchr(str,
'M');
145 if (X && (!T || (
size_t) (X-P) < (
size_t) (T-P))) {
146 duration->
months = (time_t) atoi(str+1);
150 X = strchr(str,
'D');
152 duration->
days = (time_t) atoi(str+1);
160 X = strchr(str,
'H');
162 duration->
hours = (time_t) atoi(str+1);
166 X = strrchr(str,
'M');
167 if (X && T && (
size_t) (X-P) > (
size_t) (T-P)) {
168 duration->
minutes = (time_t) atoi(str+1);
172 X = strchr(str,
'S');
174 duration->
seconds = (time_t) atoi(str+1);
179 W = strchr(str,
'W');
185 duration->
weeks = (time_t) atoi(str+1);
196 static inline int dur_scan_print(
char **buf,
char *eob,
char c, time_t t)
199 int r = snprintf(*buf, eob - *buf,
"%u%c", (
unsigned)t, c);
200 if (r < 0 || (*buf += r) >= eob)
216 char buf[300] =
"P0D", *eob = buf +
sizeof(buf), *p = buf + 1;
221 if (dur_scan_print(&p, eob,
'Y', d->
years)
222 || dur_scan_print(&p, eob,
'M', d->
months)
223 || dur_scan_print(&p, eob,
'W', d->
weeks)
224 || dur_scan_print(&p, eob,
'D', d->
days))
232 if (dur_scan_print(&p, eob,
'H', d->
hours)
233 || dur_scan_print(&p, eob,
'M', d->
minutes)
234 || dur_scan_print(&p, eob,
'S', d->
seconds))
252 period += (duration->
minutes)*60;
253 period += (duration->
hours)*3600;
254 period += (duration->
days)*86400;
255 period += (duration->
weeks)*86400*7;
256 period += (duration->
months)*86400*31;
257 period += (duration->
years)*86400*365;
time_t ldns_duration2time(const ldns_duration_type *duration)
Convert a duration to a time.
void ldns_duration_cleanup(ldns_duration_type *duration)
Clean up duration.
char * ldns_duration2string(const ldns_duration_type *d)
Convert a duration to a string.
ldns_duration_type * ldns_duration_create_from_string(const char *str)
Create a duration from string.
int ldns_duration_compare(const ldns_duration_type *d1, const ldns_duration_type *d2)
Compare durations.
ldns_duration_type * ldns_duration_create(void)
This file is copied from the OpenDNSSEC source repository and only slightly adapted to make it fit.