diff options
author | Nick Clifton <nickc@redhat.com> | 2023-09-26 14:07:23 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2023-09-26 14:07:23 +0100 |
commit | 6f56739807051e82a6327ff184b01be67be37670 (patch) | |
tree | de68ace335c036865cc3dda48f599baf25cc9383 /bfd/bfdio.c | |
parent | 0128542673364609a0b2e1d8a3f1896fc89584d2 (diff) | |
download | gdb-6f56739807051e82a6327ff184b01be67be37670.zip gdb-6f56739807051e82a6327ff184b01be67be37670.tar.gz gdb-6f56739807051e82a6327ff184b01be67be37670.tar.bz2 |
Allow the use of SOURCE_DATE_EPOCH in the timestamps for members of static archives.
(For some reason this commit was not applied at the time that the patch was approved).
Diffstat (limited to 'bfd/bfdio.c')
-rw-r--r-- | bfd/bfdio.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/bfd/bfdio.c b/bfd/bfdio.c index 457562f..7b8608b 100644 --- a/bfd/bfdio.c +++ b/bfd/bfdio.c @@ -828,3 +828,47 @@ const struct bfd_iovec _bfd_memory_iovec = &memory_bread, &memory_bwrite, &memory_btell, &memory_bseek, &memory_bclose, &memory_bflush, &memory_bstat, &memory_bmmap }; + +/* +FUNCTION + bfd_get_current_time + +SYNOPSIS + time_t bfd_get_current_time (time_t now); + +DESCRIPTION + Returns the current time. + + If the environment variable SOURCE_DATE_EPOCH is defined + then this is parsed and its value is returned. Otherwise + if the paramter NOW is non-zero, then that is returned. + Otherwise the result of the system call "time(NULL)" is + returned. +*/ + +time_t +bfd_get_current_time (time_t now) +{ + char *source_date_epoch; + unsigned long long epoch; + + /* FIXME: We could probably cache this lookup, + and the parsing of its value below. */ + source_date_epoch = getenv ("SOURCE_DATE_EPOCH"); + + if (source_date_epoch == NULL) + { + if (now) + return now; + return time (NULL); + } + + epoch = strtoull (source_date_epoch, NULL, 0); + + /* If epoch == 0 then something is wrong with SOURCE_DATE_EPOCH, + but we do not have an easy way to report it. Since the presence + of the environment variable implies that the user wants + deterministic behaviour we just accept the 0 value. */ + + return (time_t) epoch; +} |