home *** CD-ROM | disk | FTP | other *** search
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <stdio.h>
- #include <arpa/nameser.h>
- #include <arpa/inet.h>
- #include <resolv.h>
-
- static char nbuf[40];
- /*
- * Return a mnemonic for a time to live
- */
- char *
- P_time(value)
- u_long value;
- {
- int secs, mins, hours;
- register char *p;
-
- if (value == 0) {
- strcpy(nbuf, "0 secs");
- return(nbuf);
- }
-
- secs = value % 60;
- value /= 60;
- mins = value % 60;
- value /= 60;
- hours = value % 24;
- value /= 24;
-
- #define PLURALIZE(x) x, (x == 1) ? "" : "s"
- p = nbuf;
- if (value) {
- (void)sprintf(p, "%d day%s", PLURALIZE(value));
- while (*++p);
- }
- if (hours) {
- if (value)
- *p++ = ' ';
- (void)sprintf(p, "%d hour%s", PLURALIZE(hours));
- while (*++p);
- }
- if (mins) {
- if (value || hours)
- *p++ = ' ';
- (void)sprintf(p, "%d min%s", PLURALIZE(mins));
- while (*++p);
- }
- if (secs || ! (value || hours || mins)) {
- if (value || hours || mins)
- *p++ = ' ';
- (void)sprintf(p, "%d sec%s", PLURALIZE(secs));
- }
- return(nbuf);
- }
-