| 1644 | FILENAME for reading. */ |
| 1645 | |
| 1646 | static void |
| 1647 | init_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 (×pec); |
| 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 | |