]> Sergey Matveev's repositories - tofuproxy.git/commitdiff
Get rid of endian.h dependency
authorSergey Matveev <stargrave@stargrave.org>
Sun, 19 Mar 2023 16:43:22 +0000 (19:43 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 19 Mar 2023 16:44:44 +0000 (19:44 +0300)
It is not POSIX. It is placed in different places in GNU and BSD systems.
Moreover not every system has leXXdec-style functions.

cmd/zstd/enzstd.c
cmd/zstd/unzstd.c

index 63e557414cd20327dcf83e0d41771e024216770f..6dbbe985a6367080b0384a4a89151e512210d78e 100644 (file)
@@ -18,7 +18,6 @@ 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>
 
@@ -70,7 +69,10 @@ 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;
index c87dcd6208c95982f0e7250da41b88859ba28590..823515c1f898585e4065a5d874cfe506f1748ecc 100644 (file)
@@ -23,7 +23,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/endian.h>
 
 #include <zstd.h>
 
@@ -34,6 +33,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <sysexits.h>
 #endif // __FreeBSD__
 
+static uint32_t
+le32dec(const char buf[4])
+{
+    return (uint32_t)(buf[3]) << 24 | (uint32_t)(buf[2]) << 16 |
+           (uint32_t)(buf[1]) << 8 | (uint32_t)(buf[0]);
+}
+
 int
 main(int argc, char **argv)
 {