-static char *duration(time_t secs)
-{
- static char *buf = NULL;
- int p = 0;
-
- if (!buf) buf = calloc(64, 1);
-
- if (secs >= 86400)
- {
- int days = secs / 86400;
- p = sprintf(buf, "%d day%s, ", days, days > 1 ? "s" : "");
- secs %= 86400;
- }
-
- if (secs >= 3600)
- {
- int mins = secs / 60;
- int hrs = mins / 60;
-
- mins %= 60;
- sprintf(buf + p, "%d:%02d", hrs, mins);
- }
- else if (secs >= 60)
- {
- int mins = secs / 60;
- sprintf(buf + p, "%d min%s", mins, mins > 1 ? "s" : "");
- }
- else
- sprintf(buf, "%ld sec%s", secs, secs > 1 ? "s" : "");
-
- return buf;
-}
-