return EXIT_FAILURE;
};
+ int rc = EXIT_FAILURE;
size_t srcSize = 8;
uint8_t *src = malloc(srcSize);
if (src == NULL) {
fprintf(stderr, "can not allocate memory: %zu\n", srcSize);
- return EXIT_FAILURE;
+ goto Exit;
};
size_t dstSize = 0;
uint8_t *dst = NULL;
break;
};
perror("can not fread(stdin)");
- return EXIT_FAILURE;
+ goto Exit;
};
srcWantSize = (size_t)be64dec(src);
if (srcWantSize > srcSize) {
src = malloc(srcSize);
if (src == NULL) {
fprintf(stderr, "can not allocate memory: %zu\n", srcSize);
- return EXIT_FAILURE;
+ goto Exit;
};
};
n = fread(src, 1, srcWantSize, stdin);
if (n < srcWantSize) {
fputs("insufficient data fed\n", stderr);
- return EXIT_FAILURE;
+ goto Exit;
};
dstWantSize = ZSTD_compressBound(srcWantSize);
if (dstWantSize > dstSize) {
dst = malloc(dstSize);
if (dst == NULL) {
fprintf(stderr, "can not allocate memory: %zu\n", dstSize);
- return EXIT_FAILURE;
+ goto Exit;
};
};
zCode = ZSTD_compress2(ctx, dst, dstSize, src, srcWantSize);
if (ZSTD_isError(zCode)) {
fprintf(stderr, "can not compress: %s\n", ZSTD_getErrorName(zCode));
- return EXIT_FAILURE;
+ goto Exit;
};
n = fwrite(dst, 1, zCode, stdout);
if (n < zCode) {
perror("can not fwrite(stdout)");
- return EXIT_FAILURE;
+ goto Exit;
};
};
+ rc = EXIT_SUCCESS;
+
+Exit:
free(dst);
free(src);
ZSTD_freeCCtx(ctx);
- return EXIT_SUCCESS;
+ return rc;
};