X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fstaging%2Fmkresin.git;a=blobdiff_plain;f=tools%2Ffirmware-utils%2Fsrc%2Fmkdlinkfw-lib.c;h=b3f3f41348527f05e86509cedccb892149a974b2;hp=a661c0bc821fc132d847098ddba504a21aa05bbb;hb=0e78af22d95d91f7c2fdfc66fac993c6c5d349d8;hpb=f4aa9d8839958c39d24d7cca3d3215efad98a1e2 diff --git a/tools/firmware-utils/src/mkdlinkfw-lib.c b/tools/firmware-utils/src/mkdlinkfw-lib.c index a661c0bc82..b3f3f41348 100644 --- a/tools/firmware-utils/src/mkdlinkfw-lib.c +++ b/tools/firmware-utils/src/mkdlinkfw-lib.c @@ -34,9 +34,24 @@ extern char *progname; uint32_t jboot_timestamp(void) { - time_t rawtime; - time(&rawtime); - return (((uint32_t) rawtime) - TIMESTAMP_MAGIC) >> 2; + char *env = getenv("SOURCE_DATE_EPOCH"); + char *endptr = env; + time_t fixed_timestamp = -1; + errno = 0; + + if (env && *env) { + fixed_timestamp = strtoull(env, &endptr, 10); + + if (errno || (endptr && *endptr != '\0')) { + fprintf(stderr, "Invalid SOURCE_DATE_EPOCH"); + fixed_timestamp = -1; + } + } + + if (fixed_timestamp == -1) + time(&fixed_timestamp); + + return (((uint32_t) fixed_timestamp) - TIMESTAMP_MAGIC) >> 2; } uint16_t jboot_checksum(uint16_t start_val, uint16_t *data, int size) @@ -82,6 +97,7 @@ int read_to_buf(const struct file_info *fdata, char *buf) { FILE *f; int ret = EXIT_FAILURE; + size_t read; f = fopen(fdata->file_name, "r"); if (f == NULL) { @@ -89,9 +105,8 @@ int read_to_buf(const struct file_info *fdata, char *buf) goto out; } - errno = 0; - fread(buf, fdata->file_size, 1, f); - if (errno != 0) { + read = fread(buf, fdata->file_size, 1, f); + if (ferror(f) || read != 1) { ERRS("unable to read from file \"%s\"", fdata->file_name); goto out_close; }