size_t cSize;
void* const cBuff = loadFile_orDie(fname, &cSize);
unsigned long long const rSize = ZSTD_findDecompressedSize(cBuff, cSize);
- if (rSize==ZSTD_CONTENTSIZE_UNKNOWN) {
+ if (rSize==ZSTD_CONTENTSIZE_ERROR) {
+ fprintf(stderr, "%s : it was not compressed by zstd.\n", fname);
+ exit(5);
+ } else if (rSize==ZSTD_CONTENTSIZE_UNKNOWN) {
fprintf(stderr, "%s : original size unknown \n", fname);
exit(6);
}
+
void* const rBuff = malloc_orDie((size_t)rSize);
ZSTD_DCtx* const dctx = ZSTD_createDCtx();
struct stat st;
if (stat(filename, &st) == 0) return st.st_size;
/* error */
- printf("stat: %s : %s \n", filename, strerror(errno));
+ fprintf(stderr, "stat: %s : %s \n", filename, strerror(errno));
exit(1);
}
FILE* const inFile = fopen(filename, instruction);
if (inFile) return inFile;
/* error */
- printf("fopen: %s : %s \n", filename, strerror(errno));
+ fprintf(stderr, "fopen: %s : %s \n", filename, strerror(errno));
exit(2);
}
void* const buff = malloc(size);
if (buff) return buff;
/* error */
- printf("malloc: %s \n", strerror(errno));
+ fprintf(stderr, "malloc: %s \n", strerror(errno));
exit(3);
}
void* const buffer = malloc_orDie(buffSize);
size_t const readSize = fread(buffer, 1, buffSize, inFile);
if (readSize != (size_t)buffSize) {
- printf("fread: %s : %s \n", fileName, strerror(errno));
+ fprintf(stderr, "fread: %s : %s \n", fileName, strerror(errno));
exit(4);
}
fclose(inFile); /* can't fail (read only) */
size_t cSize;
void* const cBuff = loadFile_orDie(fname, &cSize);
unsigned long long const rSize = ZSTD_findDecompressedSize(cBuff, cSize);
- if (rSize==ZSTD_CONTENTSIZE_UNKNOWN) {
- printf("%s : original size unknown. Use streaming decompression instead. \n", fname);
+ if (rSize==ZSTD_CONTENTSIZE_ERROR) {
+ fprintf(stderr, "%s : it was not compressed by zstd.\n", fname);
exit(5);
+ } else if (rSize==ZSTD_CONTENTSIZE_UNKNOWN) {
+ fprintf(stderr,
+ "%s : original size unknown. Use streaming decompression instead.\n", fname);
+ exit(6);
}
+
void* const rBuff = malloc_orDie((size_t)rSize);
size_t const dSize = ZSTD_decompress(rBuff, rSize, cBuff, cSize);
if (dSize != rSize) {
- printf("error decoding %s : %s \n", fname, ZSTD_getErrorName(dSize));
+ fprintf(stderr, "error decoding %s : %s \n", fname, ZSTD_getErrorName(dSize));
exit(7);
}