From: Yann Collet Date: Thu, 17 Oct 2019 21:03:20 +0000 (-0700) Subject: minor: DIFF determination X-Git-Tag: v1.4.4~1^2~23^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfd829f2544a1518a896ed474408575461453a5b;p=thirdparty%2Fzstd.git minor: DIFF determination use gdiff on SunOS --- diff --git a/doc/educational_decoder/Makefile b/doc/educational_decoder/Makefile index a7dc21307..704f86766 100644 --- a/doc/educational_decoder/Makefile +++ b/doc/educational_decoder/Makefile @@ -7,8 +7,15 @@ # in the COPYING file in the root directory of this source tree). # ################################################################ -ZSTD ?= zstd # requires zstd installation on local system +ZSTD ?= zstd # note: requires zstd installation on local system + +UNAME?= $(shell uname) +ifeq ($(UNAME), SunOS) +DIFF ?= gdiff +else DIFF ?= diff +endif + HARNESS_FILES=*.c MULTITHREAD_LDFLAGS = -pthread @@ -30,7 +37,7 @@ harness: $(HARNESS_FILES) clean: @$(RM) harness - @$(RM) -rf harness.dSYM + @$(RM) -rf harness.dSYM # MacOS specific test: harness # @@ -46,7 +53,8 @@ test: harness # note : files are presented multiple for training, to reach minimum threshold @$(ZSTD) --train harness.c zstd_decompress.c zstd_decompress.h README.md \ harness.c zstd_decompress.c zstd_decompress.h README.md \ - harness.c zstd_decompress.c zstd_decompress.h README.md + harness.c zstd_decompress.c zstd_decompress.h README.md \ + -o dictionary @$(ZSTD) -f README.md -D dictionary -o tmp.zst @./harness tmp.zst tmp dictionary @$(DIFF) -s tmp README.md diff --git a/doc/educational_decoder/harness.c b/doc/educational_decoder/harness.c index 36f3967a9..df4c0af94 100644 --- a/doc/educational_decoder/harness.c +++ b/doc/educational_decoder/harness.c @@ -25,28 +25,29 @@ u8 *input; u8 *output; u8 *dict; -size_t read_file(const char *path, u8 **ptr) { - FILE *f = fopen(path, "rb"); +static size_t read_file(const char *path, u8 **ptr) +{ + FILE* const f = fopen(path, "rb"); if (!f) { - fprintf(stderr, "failed to open file %s\n", path); + fprintf(stderr, "failed to open file %s \n", path); exit(1); } fseek(f, 0L, SEEK_END); - size_t size = (size_t)ftell(f); + size_t const size = (size_t)ftell(f); rewind(f); *ptr = malloc(size); if (!ptr) { - fprintf(stderr, "failed to allocate memory to hold %s\n", path); + fprintf(stderr, "failed to allocate memory to hold %s \n", path); exit(1); } size_t pos = 0; while (!feof(f)) { - size_t read = fread(&(*ptr)[pos], 1, size, f); + size_t const read = fread(*ptr + pos, 1, size, f); if (ferror(f)) { - fprintf(stderr, "error while reading file %s\n", path); + fprintf(stderr, "error while reading file %s \n", path); exit(1); } pos += read; @@ -57,30 +58,30 @@ size_t read_file(const char *path, u8 **ptr) { return pos; } -void write_file(const char *path, const u8 *ptr, size_t size) { - FILE *f = fopen(path, "wb"); +static void write_file(const char *path, const u8 *ptr, size_t size) +{ + FILE* const f = fopen(path, "wb"); size_t written = 0; while (written < size) { - written += fwrite(&ptr[written], 1, size, f); + written += fwrite(ptr+written, 1, size, f); if (ferror(f)) { fprintf(stderr, "error while writing file %s\n", path); exit(1); - } - } + } } fclose(f); } int main(int argc, char **argv) { if (argc < 3) { - fprintf(stderr, "usage: %s [dictionary]\n", + fprintf(stderr, "usage: %s [dictionary] \n", argv[0]); return 1; } - size_t input_size = read_file(argv[1], &input); + size_t const input_size = read_file(argv[1], &input); size_t dict_size = 0; if (argc >= 4) { dict_size = read_file(argv[3], &dict); @@ -92,17 +93,17 @@ int main(int argc, char **argv) { fprintf(stderr, "WARNING: Compressed data does not contain " "decompressed size, going to assume the compression " "ratio is at most %d (decompressed size of at most " - "%zu)\n", - MAX_COMPRESSION_RATIO, decompressed_size); + "%u) \n", + MAX_COMPRESSION_RATIO, (unsigned)decompressed_size); } if (decompressed_size > MAX_OUTPUT_SIZE) { fprintf(stderr, - "Required output size too large for this implementation\n"); + "Required output size too large for this implementation \n"); return 1; } output = malloc(decompressed_size); if (!output) { - fprintf(stderr, "failed to allocate memory\n"); + fprintf(stderr, "failed to allocate memory \n"); return 1; } @@ -122,4 +123,5 @@ int main(int argc, char **argv) { free(output); free(dict); input = output = dict = NULL; + return 0; }