MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sec2str

Function sec2str

tools/ndp/ndp.c:1432–1471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1430#endif /* SIOCSDEFIFACE_IN6 */
1431
1432static char *
1433sec2str(time_t total)
1434{
1435 static char result[256];
1436 int days, hours, mins, secs;
1437 int first = 1;
1438 char *p = result;
1439 char *ep = &result[sizeof(result)];
1440 int n;
1441
1442 days = total / 3600 / 24;
1443 hours = (total / 3600) % 24;
1444 mins = (total / 60) % 60;
1445 secs = total % 60;
1446
1447 if (days) {
1448 first = 0;
1449 n = snprintf(p, ep - p, "%dd", days);
1450 if (n < 0 || n >= ep - p)
1451 return "?";
1452 p += n;
1453 }
1454 if (!first || hours) {
1455 first = 0;
1456 n = snprintf(p, ep - p, "%dh", hours);
1457 if (n < 0 || n >= ep - p)
1458 return "?";
1459 p += n;
1460 }
1461 if (!first || mins) {
1462 first = 0;
1463 n = snprintf(p, ep - p, "%dm", mins);
1464 if (n < 0 || n >= ep - p)
1465 return "?";
1466 p += n;
1467 }
1468 snprintf(p, ep - p, "%ds", secs);
1469
1470 return(result);
1471}
1472
1473/*
1474 * Print the timestamp

Callers 3

dumpFunction · 0.70
rtrlistFunction · 0.70
plistFunction · 0.70

Calls 1

snprintfFunction · 0.85

Tested by

no test coverage detected