]> pd.if.org Git - zpackage/blobdiff - lib/compress.c
let newpackage set additional fields
[zpackage] / lib / compress.c
index 5101688a9e83c433afc0554babcb2274b6a59b03..efbec3d94058e700fd84986fe32214bf54079dbb 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdlib.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -6,7 +7,6 @@
 
 #include <sys/mman.h>
 
-#include <sqlite3.h>
 #include "sha256.h"
 
 #include "lzma.h"
@@ -18,35 +18,26 @@ void *compresslzma(void *buf, size_t bufsize, size_t *len) {
        size_t outsize;
        void *outbuf;
        size_t outlen = 0;
+       int err = LZMA_OK;
 
        outsize = lzma_stream_buffer_bound(bufsize);
        outbuf = malloc(outsize);
        if (!outbuf) {
                *len = 0;
+               fprintf(stderr, "failed to malloc compression buffer\n");
                return NULL;
        }
        /* TODO adjust encoding level for size */
-       lzma_easy_buffer_encode(6, LZMA_CHECK_CRC64, NULL,
+       switch (err = lzma_easy_buffer_encode(6, LZMA_CHECK_CRC64, NULL,
                        buf, bufsize,
                        outbuf, &outlen, outsize
-                       );
+                       )) {
+               case LZMA_OK: break;
+               case LZMA_OPTIONS_ERROR: fprintf(stderr, "lzma options error\n");
+               default: fprintf(stderr, "lzma error %d\n", err);
+               return NULL;
+                        break;
+       }
        *len = outlen;
        return outbuf;
 }
-
-static int callback(void *NotUsed, int argc, char **argv, char **azColName){
-       int i;
-       for(i=0; i<argc; i++){
-               printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
-       }
-       printf("\n");
-       return 0;
-}
-
-static char *create_table = "create table if not exists files (hash text primary key, size integer, compression text, content blob)";
-
-struct dbh {
-       sqlite3 *db;
-       char *errmsg;
-       int rc;
-};