Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building reproducible #1540

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion docs/scripts/insert_timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include "dawk.h"

int main(int argc, char **argv)
Expand All @@ -15,7 +18,35 @@ int main(int argc, char **argv)
char buf[64];
char const *version = "unknown";

time(&now);
char *source_date_epoch;
unsigned long long epoch;
char *endptr;

source_date_epoch = getenv("SOURCE_DATE_EPOCH");
if (source_date_epoch) {
errno = 0;
SiegeLord marked this conversation as resolved.
Show resolved Hide resolved
epoch = strtoull(source_date_epoch, &endptr, 10);
if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
|| (errno != 0 && epoch == 0)) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (endptr == source_date_epoch) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n", endptr);
exit(EXIT_FAILURE);
}
if (*endptr != '\0') {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n", endptr);
exit(EXIT_FAILURE);
}
if (epoch > ULONG_MAX) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to %lu but was found to be: %llu \n", ULONG_MAX, epoch);
exit(EXIT_FAILURE);
}
now = epoch;
} else {
now = time(NULL);
}
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S UTC", gmtime(&now));

if (argc > 1) {
Expand Down
12 changes: 10 additions & 2 deletions docs/scripts/scan_examples.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ typedef struct {
int index;
/* How many APIs are used in each example */
int count;
/* Store a pointer to the file string for comparison purposes */
char *filename;
} lookup_t;
static lookup_t *lookup;
static int compare(const void *pa, const void *pb) {
return ((const lookup_t *) pa)->count - ((const lookup_t *) pb)->count;
int val = ((const lookup_t *) pa)->count - ((const lookup_t *) pb)->count;

// if different count values, sort according to this.
if (val != 0) return val;

// But if the count value is the same, sort according to filename
return strcmp( (char*)((const lookup_t *) pa)->filename, (char*)((const lookup_t *) pb)->filename);
}

int main(int argc, char* argv[])
Expand All @@ -81,9 +89,9 @@ int main(int argc, char* argv[])
lookup = calloc(argc, sizeof(lookup_t));
for (j = 0; j < argc; ++j) {
lookup[j].index = j;
lookup[j].filename = argv[j];
}


for (j = 1; j < argc; ++j) {
d_open_input(argv[j]);
while (d_getline(line)) {
Expand Down