Document more consise C code for parsing SDE

and document that stdlib.h is required for getenv
parent b7a0beef
...@@ -154,6 +154,7 @@ endif () ...@@ -154,6 +154,7 @@ endif ()
``` ```
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h>
struct tm *build_time; struct tm *build_time;
time_t now; time_t now;
...@@ -189,6 +190,18 @@ if (source_date_epoch) { ...@@ -189,6 +190,18 @@ if (source_date_epoch) {
build_time = gmtime(&now); build_time = gmtime(&now);
``` ```
If you want less verbose code and are happy with the assumtion, that the variable will contain a correct, positive integer in the `time_t` range, you can use
```
#include <stdlib.h>
time_t now;
char *source_date_epoch;
if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL ||
(now = (time_t)strtoll(source_date_epoch, NULL, 10)) <= 0)
time(&now);
```
### C++ ### C++
``` ```
......
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