]> pd.if.org Git - zpackage/blobdiff - lib/compress.c
separate zpm library database create and open
[zpackage] / lib / compress.c
index 5101688a9e83c433afc0554babcb2274b6a59b03..72fe159d2d6bb7edfdaecda4dee70643258a62eb 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,22 +18,31 @@ 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;
 }
 
+#if 0
 static int callback(void *NotUsed, int argc, char **argv, char **azColName){
        int i;
        for(i=0; i<argc; i++){
@@ -44,9 +53,4 @@ static int callback(void *NotUsed, int argc, char **argv, char **azColName){
 }
 
 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;
-};
+#endif