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

Function out_epoch_sec

src/stat.c:728–831  ·  view source on GitHub ↗

Output the number of seconds since the Epoch, using a format that acts like printf's %f format. */

Source from the content-addressed store, hash-verified

726/* Output the number of seconds since the Epoch, using a format that
727 acts like printf's %f format. */
728static void
729out_epoch_sec (char *pformat, size_t prefix_len,
730 struct timespec arg)
731{
732 char *dot = memchr (pformat, '.', prefix_len);
733 size_t sec_prefix_len = prefix_len;
734 int width = 0;
735 int precision = 0;
736 bool frac_left_adjust = false;
737
738 if (dot)
739 {
740 sec_prefix_len = dot - pformat;
741 pformat[prefix_len] = '\0';
742
743 if (c_isdigit (dot[1]))
744 {
745 long int lprec = strtol (dot + 1, NULL, 10);
746 precision = (lprec <= INT_MAX ? lprec : INT_MAX);
747 }
748 else
749 {
750 precision = 9;
751 }
752
753 if (precision && c_isdigit (dot[-1]))
754 {
755 /* If a nontrivial width is given, subtract the width of the
756 decimal point and PRECISION digits that will be output
757 later. */
758 char *p = dot;
759 *dot = '\0';
760
761 do
762 --p;
763 while (c_isdigit (p[-1]));
764
765 long int lwidth = strtol (p, NULL, 10);
766 width = (lwidth <= INT_MAX ? lwidth : INT_MAX);
767 if (1 < width)
768 {
769 p += (*p == '0');
770 sec_prefix_len = p - pformat;
771 int w_d = (decimal_point_len < width
772 ? width - decimal_point_len
773 : 0);
774 if (1 < w_d)
775 {
776 int w = w_d - precision;
777 if (1 < w)
778 {
779 char *dst = pformat;
780 for (char const *src = dst; src < p; src++)
781 {
782 if (*src == '-')
783 frac_left_adjust = true;
784 else
785 *dst++ = *src;

Callers 1

print_statFunction · 0.85

Calls 3

out_minus_zeroFunction · 0.85
out_intFunction · 0.85
out_uintFunction · 0.85

Tested by

no test coverage detected