MCPcopy Create free account
hub / github.com/coreutils/coreutils / human_time

Function human_time

src/stat.c:644–668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

642}
643
644NODISCARD
645static char *
646human_time (struct timespec t)
647{
648 /* STR must be at least INT_BUFSIZE_BOUND (intmax_t) big, either
649 because localtime_rz fails, or because the time zone is truly
650 outlandish so that %z expands to a long string. */
651 static char str[INT_BUFSIZE_BOUND (intmax_t)
652 + INT_STRLEN_BOUND (int) /* YYYY */
653 + 1 /* because YYYY might equal INT_MAX + 1900 */
654 + sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +"];
655 static timezone_t tz;
656 if (!tz)
657 tz = tzalloc (getenv ("TZ"));
658 struct tm tm;
659 int ns = t.tv_nsec;
660 if (localtime_rz (tz, &t.tv_sec, &tm))
661 nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", &tm, tz, ns);
662 else
663 {
664 char secbuf[INT_BUFSIZE_BOUND (intmax_t)];
665 sprintf (str, "%s.%09d", timetostr (t.tv_sec, secbuf), ns);
666 }
667 return str;
668}
669
670/* PFORMAT points to a '%' followed by a prefix of a format, all of
671 size PREFIX_LEN. The flags allowed for this format are

Callers 1

print_statFunction · 0.85

Calls 1

timetostrFunction · 0.85

Tested by

no test coverage detected