minor: DIFF determination
use gdiff on SunOS
This commit is contained in:
@@ -7,8 +7,15 @@
|
|||||||
# in the COPYING file in the root directory of this source tree).
|
# 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
|
DIFF ?= diff
|
||||||
|
endif
|
||||||
|
|
||||||
HARNESS_FILES=*.c
|
HARNESS_FILES=*.c
|
||||||
|
|
||||||
MULTITHREAD_LDFLAGS = -pthread
|
MULTITHREAD_LDFLAGS = -pthread
|
||||||
@@ -30,7 +37,7 @@ harness: $(HARNESS_FILES)
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
@$(RM) harness
|
@$(RM) harness
|
||||||
@$(RM) -rf harness.dSYM
|
@$(RM) -rf harness.dSYM # MacOS specific
|
||||||
|
|
||||||
test: harness
|
test: harness
|
||||||
#
|
#
|
||||||
@@ -46,7 +53,8 @@ test: harness
|
|||||||
# note : files are presented multiple for training, to reach minimum threshold
|
# note : files are presented multiple for training, to reach minimum threshold
|
||||||
@$(ZSTD) --train harness.c zstd_decompress.c zstd_decompress.h README.md \
|
@$(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
|
harness.c zstd_decompress.c zstd_decompress.h README.md \
|
||||||
|
-o dictionary
|
||||||
@$(ZSTD) -f README.md -D dictionary -o tmp.zst
|
@$(ZSTD) -f README.md -D dictionary -o tmp.zst
|
||||||
@./harness tmp.zst tmp dictionary
|
@./harness tmp.zst tmp dictionary
|
||||||
@$(DIFF) -s tmp README.md
|
@$(DIFF) -s tmp README.md
|
||||||
|
|||||||
@@ -25,15 +25,16 @@ u8 *input;
|
|||||||
u8 *output;
|
u8 *output;
|
||||||
u8 *dict;
|
u8 *dict;
|
||||||
|
|
||||||
size_t read_file(const char *path, u8 **ptr) {
|
static size_t read_file(const char *path, u8 **ptr)
|
||||||
FILE *f = fopen(path, "rb");
|
{
|
||||||
|
FILE* const f = fopen(path, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fprintf(stderr, "failed to open file %s \n", path);
|
fprintf(stderr, "failed to open file %s \n", path);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(f, 0L, SEEK_END);
|
fseek(f, 0L, SEEK_END);
|
||||||
size_t size = (size_t)ftell(f);
|
size_t const size = (size_t)ftell(f);
|
||||||
rewind(f);
|
rewind(f);
|
||||||
|
|
||||||
*ptr = malloc(size);
|
*ptr = malloc(size);
|
||||||
@@ -44,7 +45,7 @@ size_t read_file(const char *path, u8 **ptr) {
|
|||||||
|
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
while (!feof(f)) {
|
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)) {
|
if (ferror(f)) {
|
||||||
fprintf(stderr, "error while reading file %s \n", path);
|
fprintf(stderr, "error while reading file %s \n", path);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -57,17 +58,17 @@ size_t read_file(const char *path, u8 **ptr) {
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_file(const char *path, const u8 *ptr, size_t size) {
|
static void write_file(const char *path, const u8 *ptr, size_t size)
|
||||||
FILE *f = fopen(path, "wb");
|
{
|
||||||
|
FILE* const f = fopen(path, "wb");
|
||||||
|
|
||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
while (written < size) {
|
while (written < size) {
|
||||||
written += fwrite(&ptr[written], 1, size, f);
|
written += fwrite(ptr+written, 1, size, f);
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
fprintf(stderr, "error while writing file %s\n", path);
|
fprintf(stderr, "error while writing file %s\n", path);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
} }
|
||||||
}
|
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
@@ -80,7 +81,7 @@ int main(int argc, char **argv) {
|
|||||||
return 1;
|
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;
|
size_t dict_size = 0;
|
||||||
if (argc >= 4) {
|
if (argc >= 4) {
|
||||||
dict_size = read_file(argv[3], &dict);
|
dict_size = read_file(argv[3], &dict);
|
||||||
@@ -92,8 +93,8 @@ int main(int argc, char **argv) {
|
|||||||
fprintf(stderr, "WARNING: Compressed data does not contain "
|
fprintf(stderr, "WARNING: Compressed data does not contain "
|
||||||
"decompressed size, going to assume the compression "
|
"decompressed size, going to assume the compression "
|
||||||
"ratio is at most %d (decompressed size of at most "
|
"ratio is at most %d (decompressed size of at most "
|
||||||
"%zu)\n",
|
"%u) \n",
|
||||||
MAX_COMPRESSION_RATIO, decompressed_size);
|
MAX_COMPRESSION_RATIO, (unsigned)decompressed_size);
|
||||||
}
|
}
|
||||||
if (decompressed_size > MAX_OUTPUT_SIZE) {
|
if (decompressed_size > MAX_OUTPUT_SIZE) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@@ -122,4 +123,5 @@ int main(int argc, char **argv) {
|
|||||||
free(output);
|
free(output);
|
||||||
free(dict);
|
free(dict);
|
||||||
input = output = dict = NULL;
|
input = output = dict = NULL;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user