source-date-epoch: make assumptions part of the code

so that it has a higher likelyhood of being documented
in the target codebase
parent 8b293758
Pipeline #48124 passed with stage
in 2 minutes and 18 seconds
...@@ -190,13 +190,15 @@ if (source_date_epoch) { ...@@ -190,13 +190,15 @@ if (source_date_epoch) {
build_time = gmtime(&now); build_time = gmtime(&now);
``` ```
If you want less verbose code and are happy with the assumption, that the variable will contain a correct, positive integer in the `time_t` range, you can use If you want less verbose code and are happy with the assumptions stated below, you can use
``` ```
#include <stdlib.h> #include <stdlib.h>
time_t now; time_t now;
char *source_date_epoch; char *source_date_epoch;
/* This assumes that the SOURCE_DATE_EPOCH environment variable will contain
a correct, positive integer in the time_t range */
if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL || if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL ||
(now = (time_t)strtoll(source_date_epoch, NULL, 10)) <= 0) (now = (time_t)strtoll(source_date_epoch, NULL, 10)) <= 0)
time(&now); time(&now);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment