]> pd.if.org Git - zpackage/commitdiff
add error checking
authorNathan Wagner <nw@hydaspes.if.org>
Sat, 17 Sep 2016 07:01:17 +0000 (02:01 -0500)
committerNathan Wagner <nw@hydaspes.if.org>
Sat, 17 Sep 2016 07:22:45 +0000 (02:22 -0500)
lib/compress.c
lib/db.c

index 5101688a9e83c433afc0554babcb2274b6a59b03..2657f6be0e69aac41a83b35ed83649990ee9f1fc 100644 (file)
@@ -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,6 +53,7 @@ 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)";
+#endif
 
 struct dbh {
        sqlite3 *db;
index e09732e6b214b80ad2aaef9b8491add8bd5fa793..e275d9288e7d4ecd37769f24a514022bb9e078d1 100644 (file)
--- a/lib/db.c
+++ b/lib/db.c
@@ -24,7 +24,9 @@ static int callback(void *NotUsed, int argc, char **argv, char **azColName){
        return 0;
 }
 
+#if 0
 static char *create_table = "create table if not exists files (hash text primary key, size integer, compression text, content blob)";
+#endif
 
 struct dbh {
        sqlite3 *db;