/* * Derived from bind8 ns_format_ttl(). */ isc_result_t dns_ttl_totext(isc_uint32_t src, isc_boolean_t verbose, isc_buffer_t *target) { unsigned secs, mins, hours, days, weeks, x; secs = src % 60; src /= 60; mins = src % 60; src /= 60; hours = src % 24; src /= 24; days = src % 7; src /= 7; weeks = src; src = 0; x = 0; if (weeks != 0) { RETERR(ttlfmt(weeks, "week", verbose, ISC_TF(x > 0), target)); x++; } if (days != 0) { RETERR(ttlfmt(days, "day", verbose, ISC_TF(x > 0), target)); x++; } if (hours != 0) { RETERR(ttlfmt(hours, "hour", verbose, ISC_TF(x > 0), target)); x++; } if (mins != 0) { RETERR(ttlfmt(mins, "minute", verbose, ISC_TF(x > 0), target)); x++; } if (secs != 0 || (weeks == 0 && days == 0 && hours == 0 && mins == 0)) { RETERR(ttlfmt(secs, "second", verbose, ISC_TF(x > 0), target)); x++; } INSIST (x > 0); /* * If only a single unit letter is printed, print it * in upper case. (Why? Because BIND 8 does that. * Presumably it has a reason.) */ if (x == 1 && !verbose) { isc_region_t region; /* * The unit letter is the last character in the * used region of the buffer. * * toupper() does not need its argument to be masked of cast * here because region.base is type unsigned char *. */ isc_buffer_usedregion(target, ®ion); region.base[region.length - 1] = toupper(region.base[region.length - 1]); } return (ISC_R_SUCCESS); }
/* * Derived from bind8 ns_format_ttl(). */ isc_result_t dns_ttl_totext(isc_uint32_t src, isc_boolean_t verbose, isc_buffer_t *target) { unsigned secs, mins, hours, days, weeks, x; secs = src % 60; src /= 60; mins = src % 60; src /= 60; hours = src % 24; src /= 24; days = src % 7; src /= 7; weeks = src; src = 0; POST(src); x = 0; if (weeks != 0) { RETERR(ttlfmt(weeks, "week", verbose, ISC_TF(x > 0), target)); x++; } if (days != 0) { RETERR(ttlfmt(days, "day", verbose, ISC_TF(x > 0), target)); x++; } if (hours != 0) { RETERR(ttlfmt(hours, "hour", verbose, ISC_TF(x > 0), target)); x++; } if (mins != 0) { RETERR(ttlfmt(mins, "minute", verbose, ISC_TF(x > 0), target)); x++; } if (secs != 0 || (weeks == 0 && days == 0 && hours == 0 && mins == 0)) { RETERR(ttlfmt(secs, "second", verbose, ISC_TF(x > 0), target)); x++; } INSIST (x > 0); return (ISC_R_SUCCESS); }