]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - cmd/zstd/unzstd.c
uint8_t -> char
[tofuproxy.git] / cmd / zstd / unzstd.c
index ada11ea7494afcab042230ea8b5b0a147c6588c3..1e0c1cdff12165051f2d19cdc94345f51a77e14f 100644 (file)
@@ -27,18 +27,32 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <zstd.h>
 
+#ifdef __FreeBSD__
+#include "capsicum.c.in"
+#include <capsicum_helpers.h>
+#include <err.h>
+#include <sysexits.h>
+#endif // __FreeBSD__
+
 int
 main(int argc, char **argv)
 {
+    FILE *fdOff = fdopen(3, "wb");
+#ifdef __FreeBSD__
+    if ((fdOff != NULL) && (caph_limit_stream(3, CAPH_WRITE)) != 0) {
+        errx(EX_OSERR, "can not caph_limit_stream(3)");
+    };
+    capsicum_start();
+#endif // __FreeBSD__
+
     ZSTD_DCtx *ctx = ZSTD_createDCtx();
     if (ctx == NULL) {
         fputs("can not initialize ZSTD_DCtx\n", stderr);
         return 1;
     };
-    FILE *fdOff            = fdopen(3, "wb");
     int rc                 = EXIT_FAILURE;
-    uint8_t *bufIn         = NULL;
-    uint8_t *bufOut        = NULL;
+    char *bufIn            = NULL;
+    char *bufOut           = NULL;
     const size_t bufInSize = ZSTD_DStreamInSize();
     bufIn                  = malloc(bufInSize);
     if (bufIn == NULL) {
@@ -78,7 +92,7 @@ ReadAgain:
         if (n >= 8 && le32dec(bufIn) == 0x184D2A5D) {
             // dictionary frame
             size_t dictSize = (size_t)le32dec(bufIn + 4);
-            uint8_t *dict   = malloc(dictSize);
+            char *dict      = malloc(dictSize);
             if (dict == NULL) {
                 fprintf(stderr, "insufficient memory for dictionary: %zu\n", dictSize);
                 goto Exit;
@@ -120,7 +134,7 @@ ReadAgain:
                     free(dict);
                     goto Exit;
                 };
-                uint8_t *buf = malloc(bufSize);
+                char *buf = malloc(bufSize);
                 if (buf == NULL) {
                     fprintf(
                         stderr, "insufficient memory for dictionary: %llu\n", bufSize);