2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996,1999 by Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include "port_before.h"
20 #include <arpa/nameser.h>
27 #include "port_after.h"
30 # define SPRINTF(x) strlen(sprintf/**/x)
32 # define SPRINTF(x) ((size_t)sprintf x)
37 static int fmt1(int t
, char s
, char **buf
, size_t *buflen
);
41 #define T(x) if ((x) < 0) return (-1); else (void)NULL
46 ns_format_ttl(u_long src
, char *dst
, size_t dstlen
) {
48 int secs
, mins
, hours
, days
, weeks
, x
;
51 secs
= src
% 60; src
/= 60;
52 mins
= src
% 60; src
/= 60;
53 hours
= src
% 24; src
/= 24;
54 days
= src
% 7; src
/= 7;
59 T(fmt1(weeks
, 'W', &dst
, &dstlen
));
63 T(fmt1(days
, 'D', &dst
, &dstlen
));
67 T(fmt1(hours
, 'H', &dst
, &dstlen
));
71 T(fmt1(mins
, 'M', &dst
, &dstlen
));
74 if (secs
|| !(weeks
|| days
|| hours
|| mins
)) {
75 T(fmt1(secs
, 'S', &dst
, &dstlen
));
82 for (p
= odst
; (ch
= *p
) != '\0'; p
++)
83 if (isascii(ch
) && isupper(ch
))
91 ns_parse_ttl(const char *src
, u_long
*dst
) {
93 int ch
, digits
, dirty
;
99 while ((ch
= *src
++) != '\0') {
100 if (!isascii(ch
) || !isprint(ch
))
122 default: goto einval
;
147 fmt1(int t
, char s
, char **buf
, size_t *buflen
) {
151 len
= SPRINTF((tmp
, "%d%c", t
, s
));
152 if (len
+ 1 > *buflen
)