summaryrefslogtreecommitdiff
path: root/corelib/ncbitime.c
diff options
context:
space:
mode:
Diffstat (limited to 'corelib/ncbitime.c')
-rw-r--r--corelib/ncbitime.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/corelib/ncbitime.c b/corelib/ncbitime.c
index 9c6ac630..f8964054 100644
--- a/corelib/ncbitime.c
+++ b/corelib/ncbitime.c
@@ -77,6 +77,7 @@
#include <ncbi.h>
#include <ncbithr.h>
#include <ncbiwin.h>
+#include <stdlib.h>
#ifdef OS_UNIX
#include <sys/times.h>
@@ -108,8 +109,18 @@ NLM_EXTERN time_t LIBCALL Nlm_GetSecs (void)
*****************************************************************************/
NLM_EXTERN Nlm_Boolean LIBCALL Nlm_GetDayTime (Nlm_DayTimePtr dtp)
{
+ /* This function honors the SOURCE_DATE_EPOCH specificatin
+ (https://reproducible-builds.org/specs/source-date-epoch/) */
+ const char *sde = getenv("SOURCE_DATE_EPOCH");
#if (defined(SOLARIS_THREADS_AVAIL) || defined(POSIX_THREADS_AVAIL) || defined(WIN32)) && !defined(OS_UNIX_DARWIN)
- time_t t = time( NULL );
+ time_t t;
+ if (sde) {
+ t = strtoul(sde, NULL, 0);
+ if (t == 0)
+ return FALSE;
+ } else {
+ t = time( NULL );
+ }
#ifdef WIN32
static TNlmMutex localtime_lock;
if (NlmMutexLockEx( &localtime_lock ) != 0)
@@ -125,7 +136,13 @@ NLM_EXTERN Nlm_Boolean LIBCALL Nlm_GetDayTime (Nlm_DayTimePtr dtp)
time_t ltime;
struct tm *dt;
Nlm_MemFill ((Nlm_VoidPtr) dtp, 0, sizeof(Nlm_DayTime));
- time(&ltime);
+ if (sde) {
+ ltime = strtoul(sde, NULL, 0);
+ if (ltime == 0)
+ return FALSE;
+ } else {
+ time(&ltime);
+ }
if ((dt = localtime (&ltime)) != NULL)
{
Nlm_MemCopy ((Nlm_VoidPtr) dtp, (Nlm_VoidPtr) dt, sizeof (struct tm));