From fa8f8088233327eef83f0d5b3e3256067b398f80 Mon Sep 17 00:00:00 2001 From: Cameron Nemo Date: Sun, 13 Jan 2019 12:32:41 -0800 Subject: [PATCH] scdoc: do not use a GNU-extension for parsing --- srcpkgs/scdoc/patches/musl.patch | 90 ++++++++++++++++++++++++++++++++ srcpkgs/scdoc/template | 2 +- 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 srcpkgs/scdoc/patches/musl.patch diff --git a/srcpkgs/scdoc/patches/musl.patch b/srcpkgs/scdoc/patches/musl.patch new file mode 100644 index 00000000000..88f4430fa4d --- /dev/null +++ b/srcpkgs/scdoc/patches/musl.patch @@ -0,0 +1,90 @@ +From 599a615cb84799e1a50764ebecb27b459f629a3f Mon Sep 17 00:00:00 2001 +From: Silvan Jegen +Date: Wed, 2 Jan 2019 01:01:49 +0100 +Subject: [PATCH] Don't use a GNU-extension for $SOURCE_DATE_EPOCH parsing + +Code gratefully copied from the link below. + +https://reproducible-builds.org/docs/source-date-epoch/#c +--- + src/main.c | 44 +++++++++++++++++++++++++++++++++----------- + 1 file changed, 33 insertions(+), 11 deletions(-) + +diff --git a/src/main.c b/src/main.c +index 645d521..eab674e 100644 +--- src/main.c ++++ src/main.c +@@ -1,6 +1,8 @@ + #define _XOPEN_SOURCE 600 + #include + #include ++#include ++#include + #include + #include + #include +@@ -11,6 +13,7 @@ + #include "util.h" + + char *strstr(const char *haystack, const char *needle); ++char *strerror(int errnum); + + static int parse_section(struct parser *p) { + str_t *section = str_create(); +@@ -67,23 +70,42 @@ static void parse_preamble(struct parser *p) { + str_t *extras[2] = { NULL }; + int section = -1; + uint32_t ch; ++ time_t date_time; + char date[256]; + char *source_date_epoch = getenv("SOURCE_DATE_EPOCH"); + if (source_date_epoch != NULL) { +- struct tm source_date_epoch_tm; +- char *ret = strptime(source_date_epoch, "%s", &source_date_epoch_tm); +- if (ret == NULL || *ret != '\0') { +- fprintf(stderr, +- "Error: $SOURCE_DATE_EPOCH is set but malformed.\n"); +- exit(1); ++ unsigned long long epoch; ++ char *endptr; ++ errno = 0; ++ epoch = strtoull(source_date_epoch, &endptr, 10); ++ if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0)) ++ || (errno != 0 && epoch == 0)) { ++ fprintf(stderr, "$SOURCE_DATE_EPOCH: strtoull: %s\n", ++ strerror(errno)); ++ exit(EXIT_FAILURE); + } +- strftime(date, sizeof(date), "%F", &source_date_epoch_tm); ++ if (endptr == source_date_epoch) { ++ fprintf(stderr, "$SOURCE_DATE_EPOCH: No digits were found: %s\n", ++ endptr); ++ exit(EXIT_FAILURE); ++ } ++ if (*endptr != '\0') { ++ fprintf(stderr, "$SOURCE_DATE_EPOCH: Trailing garbage: %s\n", ++ endptr); ++ exit(EXIT_FAILURE); ++ } ++ if (epoch > ULONG_MAX) { ++ fprintf(stderr, "$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); ++ } ++ date_time = epoch; + } else { +- time_t now; +- time(&now); +- struct tm *now_tm = localtime(&now); +- strftime(date, sizeof(date), "%F", now_tm); ++ date_time = time(NULL); + } ++ struct tm *date_tm = localtime(&date_time); ++ strftime(date, sizeof(date), "%F", date_tm); + while ((ch = parser_getch(p)) != UTF8_INVALID) { + if ((ch < 0x80 && isalnum(ch)) || ch == '_' || ch == '-' || ch == '.') { + int ret = str_append_ch(name, ch); +-- +2.18.1 + diff --git a/srcpkgs/scdoc/template b/srcpkgs/scdoc/template index e02a1ca89f9..f03b3886558 100644 --- a/srcpkgs/scdoc/template +++ b/srcpkgs/scdoc/template @@ -1,7 +1,7 @@ # Template file for 'scdoc' pkgname=scdoc version=1.6.0 -revision=1 +revision=2 build_style=gnu-makefile short_desc="Tool for generating roff manual pages" maintainer="Julio Galvan "