]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - cmd/zstd/enzstd.c
Unify copyright comment format
[tofuproxy.git] / cmd / zstd / enzstd.c
index 63e557414cd20327dcf83e0d41771e024216770f..6ffae275a4ae9b05a002da342cce9453ecdaa028 100644 (file)
@@ -1,24 +1,21 @@
-/*
-enzstd -- .warc.zst compressor
-Copyright (C) 2021-2023 Sergey Matveev <stargrave@stargrave.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+// enzstd -- .warc.zst compressor
+// Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/endian.h>
 
 #include <zstd.h>
 
@@ -48,19 +45,19 @@ main(int argc, char **argv)
         return EXIT_FAILURE;
     }
 
-    char *src      = NULL;
-    char *dst      = NULL;
-    int rc         = EXIT_FAILURE;
+    unsigned char *src = NULL;
+    unsigned char *dst = NULL;
+    int rc = EXIT_FAILURE;
     size_t srcSize = 8;
-    src            = malloc(srcSize);
+    src = malloc(srcSize);
     if (src == NULL) {
         fprintf(stderr, "can not allocate memory: %zu\n", srcSize);
         goto Exit;
     }
-    size_t dstSize     = 0;
+    size_t dstSize = 0;
     size_t srcWantSize = 0;
     size_t dstWantSize = 0;
-    size_t n           = 0;
+    size_t n = 0;
     for (;;) {
         n = fread(src, 1, 8, stdin);
         if (n < 8) {
@@ -70,11 +67,14 @@ main(int argc, char **argv)
             perror("can not fread(stdin)");
             goto Exit;
         }
-        srcWantSize = (size_t)be64dec(src);
+        srcWantSize = ((uint64_t)(src[0]) << 56) | ((uint64_t)(src[1]) << 48) |
+                      ((uint64_t)(src[2]) << 40) | ((uint64_t)(src[3]) << 32) |
+                      ((uint64_t)(src[4]) << 24) | ((uint64_t)(src[5]) << 16) |
+                      ((uint64_t)(src[6]) << 8) | (uint64_t)(src[7]);
         if (srcWantSize > srcSize) {
             free(src);
             srcSize = srcWantSize;
-            src     = malloc(srcSize);
+            src = malloc(srcSize);
             if (src == NULL) {
                 fprintf(stderr, "can not allocate memory: %zu\n", srcSize);
                 goto Exit;
@@ -89,7 +89,7 @@ main(int argc, char **argv)
         if (dstWantSize > dstSize) {
             free(dst);
             dstSize = dstWantSize;
-            dst     = malloc(dstSize);
+            dst = malloc(dstSize);
             if (dst == NULL) {
                 fprintf(stderr, "can not allocate memory: %zu\n", dstSize);
                 goto Exit;