LCOV - code coverage report
Current view: top level - libs/libgroff - curtime.cpp (source / functions) Hit Total Coverage
Test: GNU roff Lines: 5 15 33.3 %
Date: 2026-01-16 17:51:41 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright 2015-2020 Free Software Foundation, Inc.
       2             : 
       3             : This file is part of groff, the GNU roff typesetting system.
       4             : 
       5             : groff is free software; you can redistribute it and/or modify it under
       6             : the terms of the GNU General Public License as published by the Free
       7             : Software Foundation, either version 2 of the License, or
       8             : (at your option) any later version.
       9             : 
      10             : groff is distributed in the hope that it will be useful, but WITHOUT ANY
      11             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13             : for more details.
      14             : 
      15             : The GNU General Public License version 2 (GPL2) is available in the
      16             : internet at <http://www.gnu.org/licenses/gpl-2.0.txt>. */
      17             : 
      18             : #ifdef HAVE_CONFIG_H
      19             : #include <config.h>
      20             : #endif
      21             : 
      22             : #include <errno.h>
      23             : #include <limits.h>
      24             : #include <stdlib.h>
      25             : #include <string.h>
      26             : #include <time.h>
      27             : 
      28             : #include "lib.h"
      29             : 
      30             : #include "curtime.h"
      31             : #include "errarg.h"
      32             : #include "error.h"
      33             : 
      34        1513 : struct tm *current_time()
      35             : {
      36             : #ifdef LONG_FOR_TIME_T
      37             :   long
      38             : #else
      39             :   time_t
      40             : #endif
      41             :     t;
      42        1513 :   char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
      43             : 
      44        1513 :   if (source_date_epoch) {
      45           0 :     errno = 0;
      46             :     char *endptr;
      47           0 :     long epoch = strtol(source_date_epoch, &endptr, 10);
      48             : 
      49           0 :     if (errno == ERANGE)
      50           0 :       fatal("$SOURCE_DATE_EPOCH: strtol: %1", strerror(errno));
      51           0 :     if (endptr == source_date_epoch)
      52           0 :       fatal("$SOURCE_DATE_EPOCH: no digits found: '%1'", endptr);
      53           0 :     if (*endptr != '\0')
      54           0 :       fatal("$SOURCE_DATE_EPOCH: trailing garbage: '%1'", endptr);
      55           0 :     t = epoch;
      56           0 :     return gmtime(&t);
      57             :   } else {
      58        1513 :     t = time(0);
      59        1513 :     return localtime(&t);
      60             :   }
      61             : }

Generated by: LCOV version 1.14