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

Function init_header

src/pr.c:1646–1692  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1644 FILENAME for reading. */
1645
1646static void
1647init_header (char const *filename, int desc)
1648{
1649 char *buf = NULL;
1650 struct stat st;
1651 struct timespec t;
1652 int ns;
1653 struct tm tm;
1654
1655 /* If parallel files or standard input, use current date. */
1656 if (streq (filename, "-"))
1657 desc = -1;
1658 if (0 <= desc && fstat (desc, &st) == 0)
1659 t = get_stat_mtime (&st);
1660 else
1661 {
1662 static struct timespec timespec;
1663 if (! timespec.tv_sec)
1664 gettime (&timespec);
1665 t = timespec;
1666 }
1667
1668 ns = t.tv_nsec;
1669 if (localtime_rz (localtz, &t.tv_sec, &tm))
1670 {
1671 ptrdiff_t len = nstrftime (NULL, MIN (PTRDIFF_MAX, SIZE_MAX),
1672 date_format, &tm, localtz, ns);
1673 if (0 <= len)
1674 {
1675 buf = ximalloc (len + 1);
1676 nstrftime (buf, len + 1, date_format, &tm, localtz, ns);
1677 }
1678 }
1679 if (!buf)
1680 {
1681 char secbuf[INT_BUFSIZE_BOUND (intmax_t)];
1682 buf = xmalloc (sizeof secbuf + MAX (10, INT_BUFSIZE_BOUND (int)));
1683 sprintf (buf, "%s.%09d", timetostr (t.tv_sec, secbuf), ns);
1684 }
1685
1686 free (date_text);
1687 date_text = buf;
1688 file_text = custom_header ? custom_header : desc < 0 ? "" : filename;
1689 header_width_available = (chars_per_line
1690 - mbswidth (date_text, 0)
1691 - mbswidth (file_text, 0));
1692}
1693
1694/* Set things up for printing a page
1695

Callers 1

init_fpsFunction · 0.85

Calls 1

timetostrFunction · 0.85

Tested by

no test coverage detected