Convert from int with defined True/False to bool from stdbool.h
authorJonathan Dieter <jdieter@gmail.com>
Mon, 30 Jul 2018 16:57:46 +0000 (17:57 +0100)
committerJonathan Dieter <jdieter@gmail.com>
Mon, 30 Jul 2018 16:57:46 +0000 (17:57 +0100)
Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
26 files changed:
include/zck.h.in
src/lib/comp/comp.c
src/lib/comp/nocomp/nocomp.c
src/lib/comp/zstd/zstd.c
src/lib/compint.c
src/lib/dl/dl.c
src/lib/dl/multipart.c
src/lib/dl/range.c
src/lib/error.c
src/lib/hash/hash.c
src/lib/header.c
src/lib/index/index_common.c
src/lib/index/index_create.c
src/lib/index/index_read.c
src/lib/io.c
src/lib/log.c
src/lib/zck.c
src/lib/zck_private.h
src/unzck.c
src/util_common.c
src/zck.c
src/zck_delta_size.c
src/zck_dl.c
src/zck_read_header.c
test/empty.c
test/lib/util.c

index 557d2df38e9b37d9b935b06b032d304c4b147b39..e9f1a9cc063d3521b5b81744aeb7c1cc3b1154a5 100644 (file)
@@ -3,9 +3,6 @@
 
 #define ZCK_VERSION "@version@"
 
-#define True 1
-#define False 0
-
 typedef enum zck_hash {
     ZCK_HASH_SHA1,
     ZCK_HASH_SHA256,
@@ -62,7 +59,7 @@ typedef size_t (*zck_wcb)(void *ptr, size_t l, size_t c, void *dl_v);
 zckCtx *zck_create()
     __attribute__ ((warn_unused_result));
 /* Initialize zchunk for reading */
-int zck_init_read (zckCtx *zck, int src_fd)
+bool zck_init_read (zckCtx *zck, int src_fd)
     __attribute__ ((warn_unused_result));
 /* Decompress dst_size bytes from zchunk file to dst, while verifying hashes */
 ssize_t zck_read(zckCtx *zck, char *dst, size_t dst_size)
@@ -73,7 +70,7 @@ ssize_t zck_read(zckCtx *zck, char *dst, size_t dst_size)
  * Writing a zchunk file
  *******************************************************************/
 /* Initialize zchunk for writing */
-int zck_init_write (zckCtx *zck, int dst_fd)
+bool zck_init_write (zckCtx *zck, int dst_fd)
     __attribute__ ((warn_unused_result));
 /* Compress data src of size src_size, and write to zchunk file
  * Due to the nature of zchunk files and how they are built, no data will
@@ -90,7 +87,7 @@ ssize_t zck_end_chunk(zckCtx *zck)
  *******************************************************************/
 /* Close a zchunk file so it may no longer be read from or written to. The
  * context still contains information about the file */
-int zck_close(zckCtx *zck)
+bool zck_close(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 /* Free a zchunk context.  You must pass the address of the context, and the
  * context will automatically be set to NULL after it is freed */
@@ -101,11 +98,11 @@ void zck_free(zckCtx **zck);
  * Options
  *******************************************************************/
 /* Set string option */
-int zck_set_soption(zckCtx *zck, zck_soption option, const char *value,
-                    size_t length)
+bool zck_set_soption(zckCtx *zck, zck_soption option, const char *value,
+                     size_t length)
     __attribute__ ((warn_unused_result));
 /* Set integer option */
-int zck_set_ioption(zckCtx *zck, zck_ioption option, ssize_t value)
+bool zck_set_ioption(zckCtx *zck, zck_ioption option, ssize_t value)
     __attribute__ ((warn_unused_result));
 
 
@@ -121,11 +118,12 @@ void zck_set_log_fd(int fd);
 int zck_is_error(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 /* Get error message
- * Returns char* containing error message, or NULL if there isn't one */
+ * Returns char* containing error message.  char* will contain empty string if
+ * there is no error message */
 const char *zck_get_error(zckCtx *zck);
 /* Clear error message
  * Returns 1 if message was cleared, 0 if error is fatal and can't be cleared */
-int zck_clear_error(zckCtx *zck);
+bool zck_clear_error(zckCtx *zck);
 
 /*******************************************************************
  * Miscellaneous utilities
@@ -138,7 +136,8 @@ int zck_validate_checksums(zckCtx *zck)
  * Returns 0 for error, -1 for invalid checksum and 1 for valid checksum */
 int zck_validate_data_checksum(zckCtx *zck)
     __attribute__ ((warn_unused_result));
-/* Go through file and mark valid chunks as valid */
+/* Go through file and mark valid chunks as valid
+ * Returns 0 for error, -1 for invalid checksum and 1 for valid checksum */
 int zck_find_valid_chunks(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 
@@ -155,7 +154,7 @@ char *zck_get_range_char(zckCtx *zck, zckRange *range)
 int zck_get_fd(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 /* Set file descriptor attached to zchunk context */
-int zck_set_fd(zckCtx *zck, int fd)
+bool zck_set_fd(zckCtx *zck, int fd)
     __attribute__ ((warn_unused_result));
 
 /* Return number of missing chunks (-1 if error) */
@@ -211,16 +210,16 @@ const char *zck_comp_name_from_type(int comp_type)
  * Advanced zchunk reading functions
  *******************************************************************/
 /* Initialize zchunk for reading using advanced options */
-int zck_init_adv_read (zckCtx *zck, int src_fd)
+bool zck_init_adv_read (zckCtx *zck, int src_fd)
     __attribute__ ((warn_unused_result));
 /* Read zchunk lead */
-int zck_read_lead(zckCtx *zck)
+bool zck_read_lead(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 /* Read zchunk header */
-int zck_read_header(zckCtx *zck)
+bool zck_read_header(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 /* Validate lead */
-int zck_validate_lead(zckCtx *zck)
+bool zck_validate_lead(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 
 /*******************************************************************
@@ -251,7 +250,7 @@ int zck_get_chunk_valid(zckChunk *idx)
 char *zck_get_chunk_digest(zckChunk *item)
     __attribute__ ((warn_unused_result));
 /* Find out if two chunk digests are the same */
-int zck_compare_chunk_digest(zckChunk *a, zckChunk *b)
+bool zck_compare_chunk_digest(zckChunk *a, zckChunk *b)
     __attribute__ ((warn_unused_result));
 
 /*******************************************************************
@@ -283,7 +282,7 @@ const char *zck_hash_name_from_type(int hash_type)
  * Ranges
  *******************************************************************/
 /* Get any matching chunks from src and put them in the right place in tgt */
-int zck_copy_chunks(zckCtx *src, zckCtx *tgt)
+bool zck_copy_chunks(zckCtx *src, zckCtx *tgt)
     __attribute__ ((warn_unused_result));
 /* Free zckRange */
 void zck_range_free(zckRange **info);
@@ -312,12 +311,12 @@ void zck_dl_free(zckDL **dl);
 zckCtx *zck_dl_get_zck(zckDL *dl)
     __attribute__ ((warn_unused_result));
 /* Set zchunk context in download context */
-int zck_dl_set_zck(zckDL *dl, zckCtx *zck)
+bool zck_dl_set_zck(zckDL *dl, zckCtx *zck)
     __attribute__ ((warn_unused_result));
 /* Clear regex used for extracting download ranges from multipart download */
 void zck_dl_clear_regex(zckDL *dl);
 /* Download and process the header from url */
-int zck_dl_get_header(zckCtx *zck, zckDL *dl, char *url)
+bool zck_dl_get_header(zckCtx *zck, zckDL *dl, char *url)
     __attribute__ ((warn_unused_result));
 /* Get number of bytes downloaded using download context */
 ssize_t zck_dl_get_bytes_downloaded(zckDL *dl)
@@ -326,23 +325,23 @@ ssize_t zck_dl_get_bytes_downloaded(zckDL *dl)
 ssize_t zck_dl_get_bytes_uploaded(zckDL *dl)
     __attribute__ ((warn_unused_result));
 /* Set download ranges for zchunk download context */
-int zck_dl_set_range(zckDL *dl, zckRange *range)
+bool zck_dl_set_range(zckDL *dl, zckRange *range)
     __attribute__ ((warn_unused_result));
 /* Get download ranges from zchunk download context */
 zckRange *zck_dl_get_range(zckDL *dl)
     __attribute__ ((warn_unused_result));
 
 /* Set header callback function */
-int zck_dl_set_header_cb(zckDL *dl, zck_wcb func)
+bool zck_dl_set_header_cb(zckDL *dl, zck_wcb func)
     __attribute__ ((warn_unused_result));
 /* Set header userdata */
-int zck_dl_set_header_data(zckDL *dl, void *data)
+bool zck_dl_set_header_data(zckDL *dl, void *data)
     __attribute__ ((warn_unused_result));
 /* Set write callback function */
-int zck_dl_set_write_cb(zckDL *dl, zck_wcb func)
+bool zck_dl_set_write_cb(zckDL *dl, zck_wcb func)
     __attribute__ ((warn_unused_result));
 /* Set write userdata */
-int zck_dl_set_write_data(zckDL *dl, void *data)
+bool zck_dl_set_write_data(zckDL *dl, void *data)
     __attribute__ ((warn_unused_result));
 
 /* Write callback.  You *must* pass this and your initialized zchunk download
index 158b56510f8f8cf29b5579f33f8196a768bcf89a..d4a9b36d6da36dd864089f2c0adc3d56065afcd5 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <math.h>
 #include <zck.h>
@@ -55,7 +56,7 @@ static void update_buzhash_bits(zckCtx *zck) {
     zck->buzhash_bitmask = s;
 }
 
-static int set_comp_type(zckCtx *zck, ssize_t type) {
+static bool set_comp_type(zckCtx *zck, ssize_t type) {
     VALIDATE_BOOL(zck);
 
     zckComp *comp = &(zck->comp);
@@ -63,7 +64,7 @@ static int set_comp_type(zckCtx *zck, ssize_t type) {
     /* Cannot change compression type after compression has started */
     if(comp->started) {
         set_error(zck, "Unable to set compression type after initialization");
-        return False;
+        return false;
     }
 
     /* Set all values to 0 before setting compression type */
@@ -86,9 +87,9 @@ static int set_comp_type(zckCtx *zck, ssize_t type) {
     } else {
         set_error(zck, "Unsupported compression type: %s",
                   zck_comp_name_from_type(type));
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
 static size_t comp_read_from_dc(zckCtx *zck, zckComp *comp, char *dst,
@@ -108,8 +109,8 @@ static size_t comp_read_from_dc(zckCtx *zck, zckComp *comp, char *dst,
     return dl_size;
 }
 
-static int comp_add_to_data(zckCtx *zck, zckComp *comp, const char *src,
-                            size_t src_size) {
+static bool comp_add_to_data(zckCtx *zck, zckComp *comp, const char *src,
+                             size_t src_size) {
     VALIDATE_BOOL(zck);
     ALLOCD_BOOL(comp);
     ALLOCD_BOOL(src);
@@ -118,17 +119,17 @@ static int comp_add_to_data(zckCtx *zck, zckComp *comp, const char *src,
     if(comp->data == NULL) {
         set_fatal_error(zck, "Unable to reallocate %lu bytes",
                         comp->data_size + src_size);
-        return False;
+        return false;
     }
     zck_log(ZCK_LOG_DEBUG, "Adding %lu bytes to compressed buffer",
         src_size);
     memcpy(comp->data + comp->data_size, src, src_size);
     comp->data_size += src_size;
     comp->data_loc += src_size;
-    return True;
+    return true;
 }
 
-static ssize_t comp_end_dchunk(zckCtx *zck, int use_dict, size_t fd_size) {
+static ssize_t comp_end_dchunk(zckCtx *zck, bool use_dict, size_t fd_size) {
     VALIDATE_READ_INT(zck);
 
     ssize_t rb = zck->comp.end_dchunk(zck, &(zck->comp), use_dict, fd_size);
@@ -166,24 +167,24 @@ static ssize_t comp_write(zckCtx *zck, const char *src, const size_t src_size) {
     return src_size;
 }
 
-int comp_init(zckCtx *zck) {
+bool comp_init(zckCtx *zck) {
     VALIDATE_BOOL(zck);
 
     zckComp *comp = &(zck->comp);
 
     if(zck->comp.started) {
         set_error(zck, "Compression already initialized");
-        return False;
+        return false;
     }
     if((zck->comp.dict && zck->comp.dict_size == 0) ||
        (zck->comp.dict == NULL && zck->comp.dict_size > 0)) {
         set_error(zck, "Invalid dictionary configuration");
-        return False;
+        return false;
     }
     zck_log(ZCK_LOG_DEBUG, "Initializing %s compression",
             zck_comp_name_from_type(comp->type));
     if(!zck->comp.init(zck, &(zck->comp)))
-        return False;
+        return false;
     if(zck->mode == ZCK_MODE_WRITE) {
         if(zck->chunk_min_size == 0) {
             zck->chunk_min_size = CHUNK_DEFAULT_MIN;
@@ -222,47 +223,47 @@ int comp_init(zckCtx *zck) {
 
             if(zck->comp.compress(zck, comp, zck->comp.dict,
                                   zck->comp.dict_size, &dst, &dst_size, 0) < 0)
-                return False;
+                return false;
             zck->comp.dc_data_size = zck->comp.dict_size;
             if(!write_data(zck, zck->temp_fd, dst, dst_size)) {
                 free(dst);
-                return False;
+                return false;
             }
             if(!index_add_to_chunk(zck, dst, dst_size,
                                        zck->comp.dict_size)) {
                 free(dst);
-                return False;
+                return false;
             }
             free(dst);
             dst = NULL;
             dst_size = 0;
 
             if(!zck->comp.end_cchunk(zck, comp, &dst, &dst_size, 0))
-                return False;
+                return false;
             zck->comp.dc_data_size = 0;
             if(!write_data(zck, zck->temp_fd, dst, dst_size)) {
                 free(dst);
-                return False;
+                return false;
             }
             if(!index_add_to_chunk(zck, dst, dst_size, 0) ||
                !index_finish_chunk(zck)) {
                 free(dst);
-                return False;
+                return false;
             }
             free(dst);
         } else {
             if(!index_finish_chunk(zck))
-                return False;
+                return false;
         }
     }
     free(zck->comp.dict);
     zck->comp.dict = NULL;
     zck->comp.dict_size = 0;
-    zck->comp.started = True;
-    return True;
+    zck->comp.started = true;
+    return true;
 }
 
-int comp_reset(zckCtx *zck) {
+bool comp_reset(zckCtx *zck) {
     ALLOCD_BOOL(zck);
 
     zck->comp.started = 0;
@@ -273,11 +274,11 @@ int comp_reset(zckCtx *zck) {
         zck->comp.dc_data_size = 0;
     }
     if(zck->comp.close == NULL)
-        return True;
+        return true;
     return zck->comp.close(zck, &(zck->comp));
 }
 
-int comp_close(zckCtx *zck) {
+bool comp_close(zckCtx *zck) {
     ALLOCD_BOOL(zck);
 
     zck_log(ZCK_LOG_DEBUG, "Closing compression");
@@ -291,14 +292,14 @@ int comp_close(zckCtx *zck) {
     return comp_reset(zck);
 }
 
-int comp_ioption(zckCtx *zck, zck_ioption option, ssize_t value) {
+bool comp_ioption(zckCtx *zck, zck_ioption option, ssize_t value) {
     VALIDATE_BOOL(zck);
 
     /* Cannot change compression parameters after compression has started */
     if(zck && zck->comp.started) {
         set_error(zck,
                   "Unable to set compression parameters after initialization");
-        return False;
+        return false;
     }
     if(option == ZCK_COMP_TYPE) {
         return set_comp_type(zck, value);
@@ -313,37 +314,37 @@ int comp_ioption(zckCtx *zck, zck_ioption option, ssize_t value) {
             zck_log(ZCK_LOG_DEBUG, "Enabling automatic chunking");
             zck->manual_chunk = 0;
         }
-        return True;
+        return true;
 
     /* Minimum chunk size */
     } else if(option == ZCK_CHUNK_MIN) {
         VALIDATE_WRITE_BOOL(zck);
         if(value < 1) {
             set_error(zck, "Minimum chunk size must be > 0");
-            return False;
+            return false;
         }
         if(value > zck->chunk_max_size) {
             set_error(zck, "Minimum chunk size must be <= maximum chunk size");
-            return False;
+            return false;
         }
         zck->chunk_min_size = value;
         zck_log(ZCK_LOG_DEBUG, "Setting minimum chunk size to %li", value);
-        return True;
+        return true;
 
     /* Maximum chunk size */
     } else if(option == ZCK_CHUNK_MAX) {
         VALIDATE_WRITE_BOOL(zck);
         if(value < 1) {
             set_error(zck, "Maximum chunk size must be > 0");
-            return False;
+            return false;
         }
         if(value < zck->chunk_min_size) {
             set_error(zck, "Maximum chunk size must be >= minimum chunk size");
-            return False;
+            return false;
         }
         zck->chunk_max_size = value;
         zck_log(ZCK_LOG_DEBUG, "Setting maximum chunk size to %li", value);
-        return True;
+        return true;
 
     } else {
         if(zck && zck->comp.set_parameter)
@@ -351,20 +352,20 @@ int comp_ioption(zckCtx *zck, zck_ioption option, ssize_t value) {
 
         set_error(zck, "Unsupported compression parameter: %i",
                   option);
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
-int comp_soption(zckCtx *zck, zck_soption option, const void *value,
-                 size_t length) {
+bool comp_soption(zckCtx *zck, zck_soption option, const void *value,
+                  size_t length) {
     VALIDATE_BOOL(zck);
 
     /* Cannot change compression parameters after compression has started */
     if(zck && zck->comp.started) {
         set_error(zck,
                   "Unable to set compression parameters after initialization");
-        return False;
+        return false;
     }
     if(option == ZCK_COMP_DICT) {
         zck->comp.dict = (char *)value;
@@ -374,13 +375,13 @@ int comp_soption(zckCtx *zck, zck_soption option, const void *value,
             return zck->comp.set_parameter(zck, &(zck->comp), option, value);
 
         set_error(zck, "Unsupported compression parameter: %i", option);
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
-int comp_add_to_dc(zckCtx *zck, zckComp *comp, const char *src,
-                   size_t src_size) {
+bool comp_add_to_dc(zckCtx *zck, zckComp *comp, const char *src,
+                    size_t src_size) {
     VALIDATE_BOOL(zck);
     ALLOCD_BOOL(comp);
     ALLOCD_BOOL(src);
@@ -390,7 +391,7 @@ int comp_add_to_dc(zckCtx *zck, zckComp *comp, const char *src,
     if(temp == NULL) {
         set_fatal_error(zck, "Unable to allocate %lu bytes",
                         comp->dc_data_size - comp->dc_data_loc + src_size);
-        return False;
+        return false;
     }
     if(comp->dc_data_loc != 0)
         zck_log(ZCK_LOG_DEBUG, "Freeing %lu bytes from decompressed buffer",
@@ -407,10 +408,10 @@ int comp_add_to_dc(zckCtx *zck, zckComp *comp, const char *src,
     /* Copy new uncompressed data into comp */
     memcpy(comp->dc_data + comp->dc_data_size, src, src_size);
     comp->dc_data_size += src_size;
-    return True;
+    return true;
 }
 
-ssize_t comp_read(zckCtx *zck, char *dst, size_t dst_size, int use_dict) {
+ssize_t comp_read(zckCtx *zck, char *dst, size_t dst_size, bool use_dict) {
     VALIDATE_READ_INT(zck);
 
     if(!zck->comp.started) {
@@ -430,10 +431,10 @@ ssize_t comp_read(zckCtx *zck, char *dst, size_t dst_size, int use_dict) {
     char *src = zmalloc(dst_size - dc);
     if(src == NULL) {
         set_fatal_error(zck, "Unable to allocate %lu bytes", dst_size-dc);
-        return False;
+        return false;
     }
-    int finished_rd = False;
-    int finished_dc = False;
+    bool finished_rd = false;
+    bool finished_dc = false;
     zck_log(ZCK_LOG_DEBUG, "Trying to read %lu bytes", dst_size);
     while(dc < dst_size) {
         /* Get bytes from decompressed buffer */
@@ -486,14 +487,14 @@ ssize_t comp_read(zckCtx *zck, char *dst, size_t dst_size, int use_dict) {
             if(!comp_end_dchunk(zck, use_dict, zck->comp.data_idx->length))
                 return -1;
             if(zck->comp.data_idx == NULL)
-                zck->comp.data_eof = True;
+                zck->comp.data_eof = true;
             continue;
         }
 
         /* If we finished reading and we've reached here, we're done
          * decompressing */
         if(finished_rd) {
-            finished_dc = True;
+            finished_dc = true;
             continue;
         }
 
@@ -509,7 +510,7 @@ ssize_t comp_read(zckCtx *zck, char *dst, size_t dst_size, int use_dict) {
             goto read_error;
         if(rb < rs) {
             zck_log(ZCK_LOG_DDEBUG, "EOF");
-            finished_rd = True;
+            finished_rd = true;
         }
         if(!hash_update(zck, &(zck->check_full_hash), src, rb) ||
            !hash_update(zck, &(zck->check_chunk_hash), src, rb) ||
index 74eb26ebddb5fc2548ee7f397f307f94b2464f61..539b94b2dffd2a104e5289d878f41c975d79c55c 100644 (file)
 
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <zck.h>
 
 #include "zck_private.h"
 
-static int init(zckCtx *zck, zckComp *comp) {
+static bool init(zckCtx *zck, zckComp *comp) {
     VALIDATE_BOOL(zck);
     ALLOCD_BOOL(comp);
 
-    return True;
+    return true;
 }
 
 static ssize_t compress(zckCtx *zck, zckComp *comp, const char *src,
                         const size_t src_size, char **dst, size_t *dst_size,
-                        int use_dict) {
+                        bool use_dict) {
     VALIDATE_INT(zck);
     ALLOCD_INT(comp);
 
@@ -56,18 +57,18 @@ static ssize_t compress(zckCtx *zck, zckComp *comp, const char *src,
     return *dst_size;
 }
 
-static int end_cchunk(zckCtx *zck, zckComp *comp, char **dst, size_t *dst_size,
-                     int use_dict) {
+static bool end_cchunk(zckCtx *zck, zckComp *comp, char **dst, size_t *dst_size,
+                       bool use_dict) {
     VALIDATE_BOOL(zck);
     ALLOCD_BOOL(comp);
 
     *dst = NULL;
     *dst_size = 0;
 
-    return True;
+    return true;
 }
 
-static int decompress(zckCtx *zck, zckComp *comp, const int use_dict) {
+static bool decompress(zckCtx *zck, zckComp *comp, const bool use_dict) {
     VALIDATE_BOOL(zck);
     ALLOCD_BOOL(comp);
 
@@ -77,35 +78,35 @@ static int decompress(zckCtx *zck, zckComp *comp, const int use_dict) {
     comp->data_size = 0;
     if(!comp_add_to_dc(zck, comp, src, src_size)) {
         free(src);
-        return False;
+        return false;
     }
     free(src);
-    return True;
+    return true;
 }
 
-static int end_dchunk(zckCtx *zck, zckComp *comp, const int use_dict,
-                      const size_t fd_size) {
-    return True;
+static bool end_dchunk(zckCtx *zck, zckComp *comp, const bool use_dict,
+                       const size_t fd_size) {
+    return true;
 }
 
-static int close(zckCtx *zck, zckComp *comp) {
-    return True;
+static bool close(zckCtx *zck, zckComp *comp) {
+    return true;
 }
 
 /* Nocomp doesn't support any parameters, so return error if setting a parameter
  * was attempted */
-static int set_parameter(zckCtx *zck, zckComp *comp, int option,
-                         const void *value) {
+static bool set_parameter(zckCtx *zck, zckComp *comp, int option,
+                          const void *value) {
     set_error(zck, "Invalid compression parameter for ZCK_COMP_NONE");
-    return False;
+    return false;
 }
 
 /* No default parameters to set when there's no compression */
-static int set_default_parameters(zckCtx *zck, zckComp *comp) {
-    return True;
+static bool set_default_parameters(zckCtx *zck, zckComp *comp) {
+    return true;
 }
 
-int nocomp_setup(zckCtx *zck, zckComp *comp) {
+bool nocomp_setup(zckCtx *zck, zckComp *comp) {
     comp->init = init;
     comp->set_parameter = set_parameter;
     comp->compress = compress;
index e50f7cb23adeb02f1de6d0dc05ead63762c7bd37..94b4a55dd8ae61131999134c975ebd05c512fec3 100644 (file)
 
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <zstd.h>
 #include <zck.h>
 
 #include "zck_private.h"
 
-static int init(zckCtx *zck, zckComp *comp) {
+static bool init(zckCtx *zck, zckComp *comp) {
     VALIDATE_BOOL(zck);
     ALLOCD_BOOL(comp);
 
@@ -44,16 +45,16 @@ static int init(zckCtx *zck, zckComp *comp) {
         if(comp->cdict_ctx == NULL) {
             set_fatal_error(zck,
                             "Unable to create zstd compression dict context");
-            return False;
+            return false;
         }
         comp->ddict_ctx = ZSTD_createDDict(comp->dict, comp->dict_size);
         if(comp->ddict_ctx == NULL) {
             set_fatal_error(zck,
                             "Unable to create zstd decompression dict context");
-            return False;
+            return false;
         }
     }
-    return True;
+    return true;
 }
 
 /* The zstd compression format doesn't allow streaming compression with a dict
@@ -61,7 +62,7 @@ static int init(zckCtx *zck, zckComp *comp) {
  * compression where we buffer the data until the chunk ends. */
 static ssize_t compress(zckCtx *zck, zckComp *comp, const char *src,
                         const size_t src_size, char **dst, size_t *dst_size,
-                        int use_dict) {
+                        bool use_dict) {
     VALIDATE_INT(zck);
     ALLOCD_INT(comp);
 
@@ -77,8 +78,8 @@ static ssize_t compress(zckCtx *zck, zckComp *comp, const char *src,
     return 0;
 }
 
-static int end_cchunk(zckCtx *zck, zckComp *comp, char **dst, size_t *dst_size,
-                      int use_dict) {
+static bool end_cchunk(zckCtx *zck, zckComp *comp, char **dst, size_t *dst_size,
+                       bool use_dict) {
     VALIDATE_BOOL(zck);
     ALLOCD_BOOL(comp);
 
@@ -86,13 +87,13 @@ static int end_cchunk(zckCtx *zck, zckComp *comp, char **dst, size_t *dst_size,
     if(ZSTD_isError(max_size)) {
         set_fatal_error(zck, "zstd compression error: %s",
                         ZSTD_getErrorName(max_size));
-        return False;
+        return false;
     }
 
     *dst = zmalloc(max_size);
     if(dst == NULL) {
         set_fatal_error(zck, "Unable to allocate %lu bytes", max_size);
-        return False;
+        return false;
     }
 
     if(use_dict && comp->cdict_ctx) {
@@ -109,20 +110,20 @@ static int end_cchunk(zckCtx *zck, zckComp *comp, char **dst, size_t *dst_size,
     if(ZSTD_isError(*dst_size)) {
         set_fatal_error(zck, "zstd compression error: %s",
                         ZSTD_getErrorName(*dst_size));
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
-static int decompress(zckCtx *zck, zckComp *comp, const int use_dict) {
+static bool decompress(zckCtx *zck, zckComp *comp, const bool use_dict) {
     VALIDATE_BOOL(zck);
     ALLOCD_BOOL(comp);
 
-    return True;
+    return true;
 }
 
-static int end_dchunk(zckCtx *zck, zckComp *comp, const int use_dict,
-                      const size_t fd_size) {
+static bool end_dchunk(zckCtx *zck, zckComp *comp, const bool use_dict,
+                       const size_t fd_size) {
     VALIDATE_BOOL(zck);
     ALLOCD_BOOL(comp);
 
@@ -158,15 +159,15 @@ static int end_dchunk(zckCtx *zck, zckComp *comp, const int use_dict,
         goto decomp_error_2;
     free(dst);
     free(src);
-    return True;
+    return true;
 decomp_error_2:
     free(dst);
 decomp_error_1:
     free(src);
-    return False;
+    return false;
 }
 
-static int close(zckCtx *zck, zckComp *comp) {
+static bool close(zckCtx *zck, zckComp *comp) {
     if(comp->cdict_ctx) {
         ZSTD_freeCDict(comp->cdict_ctx);
         comp->cdict_ctx = NULL;
@@ -183,28 +184,28 @@ static int close(zckCtx *zck, zckComp *comp) {
         ZSTD_freeDCtx(comp->dctx);
         comp->dctx = NULL;
     }
-    return True;
+    return true;
 }
 
-static int set_parameter(zckCtx *zck, zckComp *comp, int option,
-                         const void *value) {
+static bool set_parameter(zckCtx *zck, zckComp *comp, int option,
+                          const void *value) {
     if(option == ZCK_ZSTD_COMP_LEVEL) {
         if(*(int*)value >= 0 && *(int*)value <= ZSTD_maxCLevel()) {
             comp->level = *(int*)value;
-            return True;
+            return true;
         }
     }
     set_error(zck, "Invalid compression parameter for ZCK_COMP_ZSTD");
-    return False;
+    return false;
 }
 
-static int set_default_parameters(zckCtx *zck, zckComp *comp) {
+static bool set_default_parameters(zckCtx *zck, zckComp *comp) {
     /* Set default compression level to 16 */
     int level=16;
     return set_parameter(zck, comp, ZCK_ZSTD_COMP_LEVEL, &level);
 }
 
-int zstd_setup(zckCtx *zck, zckComp *comp) {
+bool zstd_setup(zckCtx *zck, zckComp *comp) {
     comp->init = init;
     comp->set_parameter = set_parameter;
     comp->compress = compress;
index 519bdb870a1d8330e5d5c7721e900c2c92ba80b1..d3f491ead81b78d37f7761eafcbf6edadcaeaff7 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <zck.h>
 #include "zck_private.h"
 
@@ -50,12 +51,12 @@ int compint_to_size(zckCtx *zck, size_t *val, const char *compint,
     size_t old_val = 0;
     const unsigned char *i = (unsigned char *)compint;
     int count = 0;
-    int done = False;
-    while(True) {
+    bool done = false;
+    while(true) {
         size_t c = i[0];
         if(c >= 128) {
             c -= 128;
-            done = True;
+            done = true;
         }
         /* There *must* be a more elegant way of doing c * 128**count */
         for(int f=0; f<count; f++)
@@ -74,11 +75,11 @@ int compint_to_size(zckCtx *zck, size_t *val, const char *compint,
                 set_fatal_error(zck, "Number too large");
             *length -= count;
             *val = 0;
-            return False;
+            return false;
         }
         old_val = *val;
     }
-    return True;
+    return true;
 }
 
 int compint_from_int(zckCtx *zck, char *compint, int val, size_t *length) {
@@ -86,11 +87,11 @@ int compint_from_int(zckCtx *zck, char *compint, int val, size_t *length) {
 
     if(val < 0) {
         set_error(zck, "Unable to compress negative integers");
-        return False;
+        return false;
     }
 
     compint_from_size(compint, (size_t)val, length);
-    return True;
+    return true;
 }
 
 int compint_to_int(zckCtx *zck, int *val, const char *compint, size_t *length,
@@ -99,11 +100,11 @@ int compint_to_int(zckCtx *zck, int *val, const char *compint, size_t *length,
 
     size_t new = (size_t)*val;
     if(!compint_to_size(zck, &new, compint, length, max_length))
-        return False;
+        return false;
     *val = (int)new;
     if(*val < 0) {
         set_fatal_error(zck, "Overflow error: compressed int is negative");
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
index a82adb4a07d77b27848d0ac559a4c32048fda085..1bfc58c7565e98f0f0a75b90fc4e39c71f1fa8ed 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <curl/curl.h>
 #include <unistd.h>
@@ -58,24 +59,24 @@ static void clear_dl_regex(zckDL *dl) {
 }
 
 /* Write zeros to tgt->fd in location of tgt_idx */
-static int zero_chunk(zckCtx *tgt, zckChunk *tgt_idx) {
+static bool zero_chunk(zckCtx *tgt, zckChunk *tgt_idx) {
     char buf[BUF_SIZE] = {0};
     size_t to_read = tgt_idx->comp_length;
     if(!seek_data(tgt, tgt->data_offset + tgt_idx->start, SEEK_SET))
-        return False;
+        return false;
     while(to_read > 0) {
         int rb = BUF_SIZE;
         if(rb > to_read)
             rb = to_read;
         if(!write_data(tgt, tgt->fd, buf, rb))
-            return False;
+            return false;
         to_read -= rb;
     }
-    return True;
+    return true;
 }
 
 /* Check whether last downloaded chunk is valid and zero it out if it isn't */
-static int set_chunk_valid(zckDL *dl) {
+static bool set_chunk_valid(zckDL *dl) {
     ALLOCD_BOOL(dl);
     VALIDATE_BOOL(dl->zck);
 
@@ -83,14 +84,14 @@ static int set_chunk_valid(zckDL *dl) {
                                 dl->tgt_number);
     if(retval < 1) {
         if(!zero_chunk(dl->zck, dl->tgt_check))
-            return False;
+            return false;
         dl->tgt_check->valid = -1;
-        return False;
+        return false;
     } else {
         dl->tgt_check->valid = 1;
     }
     dl->tgt_check = NULL;
-    return True;
+    return true;
 }
 
 /* Write length or to end of current chunk, whichever comes first */
@@ -116,9 +117,9 @@ static int dl_write(zckDL *dl, const char *at, size_t length) {
 }
 
 /* Copy chunk identified by src_idx into location specified by tgt_idx */
-static int write_and_verify_chunk(zckCtx *src, zckCtx *tgt,
-                                  zckChunk *src_idx,
-                                  zckChunk *tgt_idx) {
+static bool write_and_verify_chunk(zckCtx *src, zckCtx *tgt,
+                                   zckChunk *src_idx,
+                                   zckChunk *tgt_idx) {
     VALIDATE_READ_BOOL(src);
     VALIDATE_READ_BOOL(tgt);
 
@@ -126,22 +127,22 @@ static int write_and_verify_chunk(zckCtx *src, zckCtx *tgt,
 
     size_t to_read = src_idx->comp_length;
     if(!seek_data(src, src->data_offset + src_idx->start, SEEK_SET))
-        return False;
+        return false;
     if(!seek_data(tgt, tgt->data_offset + tgt_idx->start, SEEK_SET))
-        return False;
+        return false;
     zckHash check_hash = {0};
     if(!hash_init(tgt, &check_hash, &(src->chunk_hash_type)))
-        return False;
+        return false;
     while(to_read > 0) {
         int rb = BUF_SIZE;
         if(rb > to_read)
             rb = to_read;
         if(!read_data(src, buf, rb))
-            return False;
+            return false;
         if(!hash_update(tgt, &check_hash, buf, rb))
-            return False;
+            return false;
         if(!write_data(tgt, tgt->fd, buf, rb))
-            return False;
+            return false;
         to_read -= rb;
     }
     char *digest = hash_finalize(tgt, &check_hash);
@@ -154,7 +155,7 @@ static int write_and_verify_chunk(zckCtx *src, zckCtx *tgt,
         zck_log(ZCK_LOG_WARNING, "Target hash: %s", pdigest);
         free(pdigest);
         if(!zero_chunk(tgt, tgt_idx))
-            return False;
+            return false;
         tgt_idx->valid = -1;
     } else {
         tgt_idx->valid = 1;
@@ -162,7 +163,7 @@ static int write_and_verify_chunk(zckCtx *src, zckCtx *tgt,
                 tgt_idx->comp_length, tgt_idx->start);
     }
     free(digest);
-    return True;
+    return true;
 }
 
 /* Split current read into the appropriate chunks and write appropriately */
@@ -189,7 +190,7 @@ int dl_write_range(zckDL *dl, const char *at, size_t length) {
     if(dl->write_in_chunk == 0) {
         /* Check whether we just finished downloading a chunk and verify it */
         if(dl->tgt_check && !set_chunk_valid(dl))
-            return False;
+            return false;
 
         for(zckChunk *chk = dl->range->index.first; chk; chk = chk->next) {
             if(dl->dl_chunk_data == chk->start) {
@@ -231,7 +232,10 @@ int dl_write_range(zckDL *dl, const char *at, size_t length) {
     return wb + wb2;
 }
 
-int PUBLIC zck_copy_chunks(zckCtx *src, zckCtx *tgt) {
+bool PUBLIC zck_copy_chunks(zckCtx *src, zckCtx *tgt) {
+    VALIDATE_READ_BOOL(src);
+    VALIDATE_READ_BOOL(tgt);
+
     zckIndex *tgt_info = &(tgt->index);
     zckIndex *src_info = &(src->index);
     zckChunk *tgt_idx = tgt_info->first;
@@ -243,7 +247,7 @@ int PUBLIC zck_copy_chunks(zckCtx *src, zckCtx *tgt) {
             continue;
         }
 
-        int found = False;
+        bool found = false;
         src_idx = src_info->first;
 
         while(src_idx) {
@@ -252,7 +256,7 @@ int PUBLIC zck_copy_chunks(zckCtx *src, zckCtx *tgt) {
                tgt_idx->digest_size == src_idx->digest_size &&
                memcmp(tgt_idx->digest, src_idx->digest,
                       tgt_idx->digest_size) == 0) {
-                found = True;
+                found = true;
                 break;
             }
             src_idx = src_idx->next;
@@ -262,7 +266,7 @@ int PUBLIC zck_copy_chunks(zckCtx *src, zckCtx *tgt) {
             write_and_verify_chunk(src, tgt, src_idx, tgt_idx);
         tgt_idx = tgt_idx->next;
     }
-    return True;
+    return true;
 }
 
 ssize_t PUBLIC zck_dl_get_bytes_downloaded(zckDL *dl) {
@@ -332,17 +336,17 @@ zckCtx PUBLIC *zck_dl_get_zck(zckDL *dl) {
     return dl->zck;
 }
 
-int PUBLIC zck_dl_set_zck(zckDL *dl, zckCtx *zck) {
+bool PUBLIC zck_dl_set_zck(zckDL *dl, zckCtx *zck) {
     ALLOCD_BOOL(dl);
 
     dl->zck = zck;
-    return True;
+    return true;
 }
-int PUBLIC zck_dl_set_range(zckDL *dl, zckRange *range) {
+bool PUBLIC zck_dl_set_range(zckDL *dl, zckRange *range) {
     ALLOCD_BOOL(dl);
 
     dl->range = range;
-    return True;
+    return true;
 }
 
 zckRange PUBLIC *zck_dl_get_range(zckDL *dl) {
@@ -351,32 +355,32 @@ zckRange PUBLIC *zck_dl_get_range(zckDL *dl) {
     return dl->range;
 }
 
-int PUBLIC zck_dl_set_header_cb(zckDL *dl, zck_wcb func) {
+bool PUBLIC zck_dl_set_header_cb(zckDL *dl, zck_wcb func) {
     ALLOCD_BOOL(dl);
 
     dl->header_cb = func;
-    return True;
+    return true;
 }
 
-int PUBLIC zck_dl_set_header_data(zckDL *dl, void *data) {
+bool PUBLIC zck_dl_set_header_data(zckDL *dl, void *data) {
     ALLOCD_BOOL(dl);
 
     dl->header_data = data;
-    return True;
+    return true;
 }
 
-int PUBLIC zck_dl_set_write_cb(zckDL *dl, zck_wcb func) {
+bool PUBLIC zck_dl_set_write_cb(zckDL *dl, zck_wcb func) {
     ALLOCD_BOOL(dl);
 
     dl->write_cb = func;
-    return True;
+    return true;
 }
 
-int PUBLIC zck_dl_set_write_data(zckDL *dl, void *data) {
+bool PUBLIC zck_dl_set_write_data(zckDL *dl, void *data) {
     ALLOCD_BOOL(dl);
 
     dl->write_data = data;
-    return True;
+    return true;
 }
 
 /*******************************************************************
@@ -395,7 +399,8 @@ size_t PUBLIC zck_header_cb(char *b, size_t l, size_t c, void *dl_v) {
     return c*l;
 }
 
-size_t PUBLIC zck_write_zck_header_cb(void *ptr, size_t l, size_t c, void *dl_v) {
+size_t PUBLIC zck_write_zck_header_cb(void *ptr, size_t l, size_t c,
+                                      void *dl_v) {
     ALLOCD_BOOL(dl_v);
     zckDL *dl = (zckDL*)dl_v;
 
index b0dcc0dea199427b271327dd677258d66e97699d..bd3c5aefcbe49b12709841e8e8310356349d6f22 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <stdio.h>
 #include <regex.h>
@@ -55,21 +56,21 @@ static char *add_boundary_to_regex(zckCtx *zck, const char *regex,
     return regex_b;
 }
 
-static int create_regex(zckCtx *zck, regex_t *reg, const char *regex) {
+static bool create_regex(zckCtx *zck, regex_t *reg, const char *regex) {
     VALIDATE_BOOL(zck);
 
     if(reg == NULL || regex == NULL) {
         set_error(zck, "Regular expression not initialized");
-        return False;
+        return false;
     }
     if(regcomp(reg, regex, REG_ICASE | REG_EXTENDED) != 0) {
         set_error(zck, "Unable to compile regular expression");
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
-static int gen_regex(zckDL *dl) {
+static bool gen_regex(zckDL *dl) {
     ALLOCD_BOOL(dl);
     VALIDATE_BOOL(dl->zck);
 
@@ -78,23 +79,23 @@ static int gen_regex(zckDL *dl) {
     char *end =  "\r\n--%s--\r\n\r";
     char *regex_n = add_boundary_to_regex(dl->zck, next, dl->boundary);
     if(regex_n == NULL)
-        return False;
+        return false;
     char *regex_e = add_boundary_to_regex(dl->zck, end, dl->boundary);
     if(regex_n == NULL)
-        return False;
+        return false;
     dl->dl_regex = zmalloc(sizeof(regex_t));
     if(!create_regex(dl->zck, dl->dl_regex, regex_n)) {
         free(regex_n);
-        return False;
+        return false;
     }
     free(regex_n);
     dl->end_regex = zmalloc(sizeof(regex_t));
     if(!create_regex(dl->zck, dl->end_regex, regex_e)) {
         free(regex_e);
-        return False;
+        return false;
     }
     free(regex_e);
-    return True;
+    return true;
 }
 
 void reset_mp(zckMP *mp) {
@@ -113,7 +114,7 @@ size_t multipart_extract(zckDL *dl, char *b, size_t l) {
         return 0;
     zckMP *mp = dl->mp;
     char *buf = b;
-    int alloc_buf = False;
+    bool alloc_buf = false;
 
     /* Add new data to stored buffer */
     if(mp->buffer) {
@@ -127,7 +128,7 @@ size_t multipart_extract(zckDL *dl, char *b, size_t l) {
         l = mp->buffer_len + l;
         mp->buffer = NULL;  // No need to free, buf holds realloc'd buffer
         mp->buffer_len = 0;
-        alloc_buf = True;
+        alloc_buf = true;
     }
 
     /* If regex hasn't been created, create it */
index bd0fc613ce6ef25d24c36cf11c5f99e97ecbadfb..18e9ec6c030ce3bc747620c9829c38a797e1dff2 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <math.h>
 #include <errno.h>
@@ -58,7 +59,7 @@ static zckRangeItem *range_insert_new(zckCtx *zck, zckRangeItem *prev,
     }
     if(add_index)
         if(!index_new_chunk(zck, &(info->index), idx->digest, idx->digest_size,
-                                end-start+1, end-start+1, False)) {
+                                end-start+1, end-start+1, false)) {
             free(new);
             return NULL;
         }
@@ -90,16 +91,16 @@ static void range_merge_combined(zckCtx *zck, zckRange *info) {
     }
 }
 
-static int range_add(zckRange *info, zckChunk *chk, zckCtx *zck) {
+static bool range_add(zckRange *info, zckChunk *chk, zckCtx *zck) {
     if(info == NULL || chk == NULL) {
         set_error(zck, "zckRange or zckChunk not allocated");
-        return False;
+        return false;
     }
     size_t header_len = 0;
-    int add_index = False;
+    bool add_index = false;
     if(zck) {
         header_len = zck_get_header_length(zck);
-        add_index = True;
+        add_index = true;
     }
 
     size_t start = chk->start + header_len;
@@ -113,31 +114,31 @@ static int range_add(zckRange *info, zckChunk *chk, zckCtx *zck) {
         } else if(start < ptr->start) {
             if(range_insert_new(zck, ptr->prev, ptr, start, end, info, chk,
                                 add_index) == NULL)
-                return False;
+                return false;
             if(info->first == ptr) {
                 info->first = ptr->prev;
             }
             info->count += 1;
             range_merge_combined(zck, info);
-            return True;
+            return true;
         } else { // start == ptr->start
             if(end > ptr->end)
                 ptr->end = end;
             info->count += 1;
             range_merge_combined(zck, info);
-            return True;
+            return true;
         }
     }
     /* We've only reached here if we should be last item */
     zckRangeItem *new = range_insert_new(zck, prev, NULL, start, end, info, chk,
                                          add_index);
     if(new == NULL)
-        return False;
+        return false;
     if(info->first == NULL)
         info->first = new;
     info->count += 1;
     range_merge_combined(zck, info);
-    return True;
+    return true;
 }
 
 void PUBLIC zck_range_free(zckRange **info) {
index 5bddc22f7e0b8a014e7f20519a46f8026611c66a..2bc572b3a440d3cf1737efd4e12e96a712ec372a 100644 (file)
@@ -28,6 +28,7 @@
 #include <assert.h>
 #include <string.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <zck.h>
 
 #include "zck_private.h"
@@ -88,12 +89,12 @@ const char PUBLIC *zck_get_error(zckCtx *zck) {
     return zck->msg;
 }
 
-int PUBLIC zck_clear_error(zckCtx *zck) {
+bool PUBLIC zck_clear_error(zckCtx *zck) {
     if(zck == NULL || zck->error_state > 1)
-        return False;
+        return false;
 
     free(zck->msg);
     zck->msg = NULL;
     zck->error_state = 0;
-    return True;
+    return true;
 }
index 2f4585206d1f401945aa96f26c036c4d15ebb737..9ce8c86eac301b413f9c71fd2177e79bffb37bdb 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <zck.h>
 
@@ -88,7 +89,7 @@ static int validate_checksums(zckCtx *zck, zck_log_type bad_checksums) {
         return 0;
 
     /* Check each chunk checksum */
-    int all_good = True;
+    bool all_good = true;
     int count = 0;
     for(zckChunk *idx = zck->index.first; idx; idx = idx->next, count++) {
         if(idx == zck->index.first && idx->length == 0) {
@@ -117,7 +118,7 @@ static int validate_checksums(zckCtx *zck, zck_log_type bad_checksums) {
             return 0;
         idx->valid = valid_chunk;
         if(all_good && valid_chunk != 1)
-            all_good = False;
+            all_good = false;
     }
     int valid_file = -1;
     if(all_good) {
@@ -151,10 +152,10 @@ char *get_digest_string(const char *digest, int size) {
     return str;
 }
 
-int hash_setup(zckCtx *zck, zckHashType *ht, int h) {
+bool hash_setup(zckCtx *zck, zckHashType *ht, int h) {
     if(!ht) {
         set_error(zck, "zckHashType is null");
-        return False;
+        return false;
     }
     if(h == ZCK_HASH_SHA1) {
         memset(ht, 0, sizeof(zckHashType));
@@ -162,14 +163,14 @@ int hash_setup(zckCtx *zck, zckHashType *ht, int h) {
         ht->digest_size = SHA1_DIGEST_LENGTH;
         zck_log(ZCK_LOG_DEBUG, "Setting up hash type %s",
                 zck_hash_name_from_type(ht->type));
-        return True;
+        return true;
     } else if(h == ZCK_HASH_SHA256) {
         memset(ht, 0, sizeof(zckHashType));
         ht->type = ZCK_HASH_SHA256;
         ht->digest_size = SHA256_DIGEST_SIZE;
         zck_log(ZCK_LOG_DEBUG, "Setting up hash type %s",
                 zck_hash_name_from_type(ht->type));
-        return True;
+        return true;
     } else if(h >= ZCK_HASH_SHA512 &&
               h <= ZCK_HASH_SHA512_128) {
         memset(ht, 0, sizeof(zckHashType));
@@ -180,10 +181,10 @@ int hash_setup(zckCtx *zck, zckHashType *ht, int h) {
             ht->digest_size = 16;
         zck_log(ZCK_LOG_DEBUG, "Setting up hash type %s",
                 zck_hash_name_from_type(ht->type));
-        return True;
+        return true;
     }
     set_error(zck, "Unsupported hash type: %s", zck_hash_name_from_type(h));
-    return False;
+    return false;
 }
 
 void hash_close(zckHash *hash) {
@@ -203,78 +204,78 @@ void hash_reset(zckHashType *ht) {
     return;
 }
 
-int hash_init(zckCtx *zck, zckHash *hash, zckHashType *hash_type) {
+bool hash_init(zckCtx *zck, zckHash *hash, zckHashType *hash_type) {
     hash_close(hash);
     if(hash == NULL || hash_type == NULL) {
         set_error(zck, "Either zckHash or zckHashType struct is null");
-        return False;
+        return false;
     }
     if(hash_type->type == ZCK_HASH_SHA1) {
         zck_log(ZCK_LOG_DDEBUG, "Initializing SHA-1 hash");
         hash->ctx = zmalloc(sizeof(SHA_CTX));
         hash->type = hash_type;
         if(hash->ctx == NULL)
-            return False;
+            return false;
         SHA1_Init((SHA_CTX *) hash->ctx);
-        return True;
+        return true;
     } else if(hash_type->type == ZCK_HASH_SHA256) {
         zck_log(ZCK_LOG_DDEBUG, "Initializing SHA-256 hash");
         hash->ctx = zmalloc(sizeof(SHA256_CTX));
         hash->type = hash_type;
         if(hash->ctx == NULL)
-            return False;
+            return false;
         SHA256_Init((SHA256_CTX *) hash->ctx);
-        return True;
+        return true;
     } else if(hash_type->type >= ZCK_HASH_SHA512 &&
               hash_type->type <= ZCK_HASH_SHA512_128) {
         zck_log(ZCK_LOG_DDEBUG, "Initializing SHA-512 hash");
         hash->ctx = zmalloc(sizeof(SHA512_CTX));
         hash->type = hash_type;
         if(hash->ctx == NULL)
-            return False;
+            return false;
         SHA512_Init((SHA512_CTX *) hash->ctx);
-        return True;
+        return true;
     }
     set_error(zck, "Unsupported hash type: %s",
               zck_hash_name_from_type(hash_type->type));
-    return False;
+    return false;
 }
 
-int hash_update(zckCtx *zck, zckHash *hash, const char *message,
+bool hash_update(zckCtx *zck, zckHash *hash, const char *message,
                 const size_t size) {
     if(message == NULL && size == 0)
-        return True;
+        return true;
     if(message == NULL) {
         set_error(zck,
                   "Hash data is supposed to have %lu bytes, but is NULL", size);
-        return False;
+        return false;
     }
     if(size == 0) {
         set_error(zck,
                   "Hash data is supposed to be 0-length, but is not NULL");
-        return False;
+        return false;
     }
     if(hash && hash->ctx && hash->type) {
         if(hash->type->type == ZCK_HASH_SHA1) {
             SHA1_Update((SHA_CTX *)hash->ctx, (const sha1_byte *)message, size);
-            return True;
+            return true;
         } else if(hash->type->type == ZCK_HASH_SHA256) {
             SHA256_Update((SHA256_CTX *)hash->ctx,
                           (const unsigned char *)message, size);
-            return True;
+            return true;
         } else if(hash->type->type >= ZCK_HASH_SHA512 &&
                   hash->type->type <= ZCK_HASH_SHA512_128) {
             SHA512_Update((SHA512_CTX *)hash->ctx,
                           (const unsigned char *)message, size);
-            return True;
+            return true;
         }
         set_error(zck, "Unsupported hash type: %s",
                   zck_hash_name_from_type(hash->type->type));
 
-        return False;
+        return false;
     }
     set_error(zck, "Hash hasn't been initialized");
-    return False;
+    return false;
 }
 
 char *hash_finalize(zckCtx *zck, zckHash *hash) {
@@ -306,23 +307,23 @@ char *hash_finalize(zckCtx *zck, zckHash *hash) {
     return NULL;
 }
 
-int set_full_hash_type(zckCtx *zck, int hash_type) {
+bool set_full_hash_type(zckCtx *zck, int hash_type) {
     VALIDATE_BOOL(zck);
 
     zck_log(ZCK_LOG_INFO, "Setting full hash to %s",
             zck_hash_name_from_type(hash_type));
     if(!hash_setup(zck, &(zck->hash_type), hash_type)) {
         set_error(zck, "Unable to set full hash");
-        return False;
+        return false;
     }
     if(!hash_init(zck, &(zck->full_hash), &(zck->hash_type))) {
         set_error(zck, "Unable initialize full hash");
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
-int set_chunk_hash_type(zckCtx *zck, int hash_type) {
+bool set_chunk_hash_type(zckCtx *zck, int hash_type) {
     VALIDATE_BOOL(zck);
 
     memset(&(zck->chunk_hash_type), 0, sizeof(zckHashType));
@@ -330,11 +331,11 @@ int set_chunk_hash_type(zckCtx *zck, int hash_type) {
             zck_hash_name_from_type(hash_type));
     if(!hash_setup(zck, &(zck->chunk_hash_type), hash_type)) {
         set_error(zck, "Unable to set chunk hash");
-        return False;
+        return false;
     }
     zck->index.hash_type = zck->chunk_hash_type.type;
     zck->index.digest_size = zck->chunk_hash_type.digest_size;
-    return True;
+    return true;
 }
 
 /* Validate chunk, returning -1 if checksum fails, 1 if good, 0 if error */
index 096855b0b1e93d07255ed67c618d360da4d37bb3..c98b6c37073e6139e496d1094892509fc8d36b1e 100644 (file)
 
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <unistd.h>
 #include <zck.h>
 
 #include "zck_private.h"
 
-static int check_flags(zckCtx *zck, size_t flags) {
+static bool check_flags(zckCtx *zck, size_t flags) {
     zck->has_streams = flags & 1;
     if(zck->has_streams) {
         set_fatal_error(zck,
                         "This version of zchunk doesn't support streams");
-        return False;
+        return false;
     }
     flags = flags & (SIZE_MAX - 1);
     if(flags != 0) {
         set_fatal_error(zck, "Unknown flags(s) set");
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
-static int read_header_from_file(zckCtx *zck) {
+static bool read_header_from_file(zckCtx *zck) {
     /* Allocate header and store any extra bytes at beginning of header */
     zck->header = realloc(zck->header, zck->lead_size + zck->header_length);
     if(zck->header == NULL) {
         set_fatal_error(zck, "Unable to reallocate %lu bytes",
                         zck->lead_size + zck->header_length);
-        return False;
+        return false;
     }
     zck->lead_string = zck->header;
     char *header = zck->header + zck->lead_size;
@@ -61,7 +62,7 @@ static int read_header_from_file(zckCtx *zck) {
 
     if(zck->header_length < zck->header_size - zck->lead_size) {
         set_fatal_error(zck, "Header size is too small for actual data");
-        return False;
+        return false;
     }
     if(zck->lead_size < zck->header_size)
         loaded = zck->header_size - zck->lead_size;
@@ -71,32 +72,32 @@ static int read_header_from_file(zckCtx *zck) {
             zck->header_length);
     if(loaded < zck->header_length) {
         if(!read_data(zck, header + loaded, zck->header_length - loaded))
-            return False;
+            return false;
         zck->header_size = zck->lead_size + zck->header_length;
     }
 
     if(!hash_init(zck, &(zck->check_full_hash), &(zck->hash_type)))
-        return False;
+        return false;
     if(!hash_update(zck, &(zck->check_full_hash), zck->header,
                     zck->hdr_digest_loc))
-        return False;
+        return false;
     if(!hash_update(zck, &(zck->check_full_hash), header, zck->header_length))
-        return False;
+        return false;
     int ret = validate_header(zck);
     if(ret < 1) {
         if(ret == -1)
             set_fatal_error(zck, "Header checksum failed verification");
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
-static int read_preface(zckCtx *zck) {
+static bool read_preface(zckCtx *zck) {
     VALIDATE_READ_BOOL(zck);
 
     if(zck->header_digest == NULL) {
         set_error(zck, "Reading preface before lead is read");
-        return False;
+        return false;
     }
 
     char *header = zck->header + zck->lead_size;
@@ -107,13 +108,13 @@ static int read_preface(zckCtx *zck) {
     zck_log(ZCK_LOG_DEBUG, "Reading data digest");
     if(length + zck->hash_type.digest_size > max_length) {
         set_fatal_error(zck, "Read past end of header");
-        return False;
+        return false;
     }
     zck->full_hash_digest = zmalloc(zck->hash_type.digest_size);
     if(!zck->full_hash_digest) {
         set_fatal_error(zck, "Unable to allocate %lu bytes",
                         zck->hash_type.digest_size);
-        return False;
+        return false;
     }
     memcpy(zck->full_hash_digest, header+length, zck->hash_type.digest_size);
     length += zck->hash_type.digest_size;
@@ -121,9 +122,9 @@ static int read_preface(zckCtx *zck) {
     /* Read flags */
     size_t flags = 0;
     if(!compint_to_size(zck, &flags, header+length, &length, max_length))
-        return False;
+        return false;
     if(!check_flags(zck, flags))
-        return False;
+        return false;
 
     /* Setup for reading compression type */
     zck_log(ZCK_LOG_DEBUG, "Reading compression type and index size");
@@ -131,28 +132,28 @@ static int read_preface(zckCtx *zck) {
 
     /* Read and initialize compression type */
     if(!compint_to_int(zck, &tmp, header+length, &length, max_length))
-        return False;
+        return false;
     if(!comp_ioption(zck, ZCK_COMP_TYPE, tmp))
-        return False;
+        return false;
     if(!comp_init(zck))
-        return False;
+        return false;
 
     /* Read and initialize index size */
     if(!compint_to_int(zck, &tmp, header+length, &length, max_length))
-        return False;
+        return false;
     zck->index_size = tmp;
 
     zck->preface_string = header;
     zck->preface_size = length;
-    return True;
+    return true;
 }
 
-static int read_index(zckCtx *zck) {
+static bool read_index(zckCtx *zck) {
     VALIDATE_READ_BOOL(zck);
 
     if(zck->preface_string == NULL) {
         set_error(zck, "Reading index before preface is read");
-        return False;
+        return false;
     }
 
     char *header = NULL;
@@ -160,23 +161,23 @@ static int read_index(zckCtx *zck) {
     if(zck->lead_size + zck->preface_size + zck->index_size >
        zck->header_size) {
         set_fatal_error(zck, "Read past end of header");
-        return False;
+        return false;
     }
     header = zck->header + zck->lead_size + zck->preface_size;
     int max_length = zck->header_size - (zck->lead_size + zck->preface_size);
     if(!index_read(zck, header, zck->index_size, max_length))
-        return False;
+        return false;
 
     zck->index_string = header;
-    return True;
+    return true;
 }
 
-static int read_sig(zckCtx *zck) {
+static bool read_sig(zckCtx *zck) {
     VALIDATE_READ_BOOL(zck);
 
     if(zck->index_string == NULL) {
         set_error(zck, "Reading signatures before index is read");
-        return False;
+        return false;
     }
 
     char *header = zck->header + zck->lead_size + zck->preface_size +
@@ -186,13 +187,13 @@ static int read_sig(zckCtx *zck) {
     size_t length = 0;
 
     if(!compint_to_int(zck, &(zck->sigs.count), header, &length, max_length))
-        return False;
+        return false;
 
     /* We don't actually support signatures yet, so bail if there is one */
     zck_log(ZCK_LOG_DEBUG, "Signature count: %i", zck->sigs.count);
     if(zck->sigs.count > 0) {
         set_fatal_error(zck, "Signatures aren't supported yet");
-        return False;
+        return false;
     }
 
     /* Set data_offset */
@@ -204,10 +205,10 @@ static int read_sig(zckCtx *zck) {
 
     zck->sig_size = length;
     zck->sig_string = header;
-    return True;
+    return true;
 }
 
-static int preface_create(zckCtx *zck) {
+static bool preface_create(zckCtx *zck) {
     VALIDATE_WRITE_BOOL(zck);
 
     int header_malloc = zck->hash_type.digest_size + 4 + 2*MAX_COMP_SIZE;
@@ -215,7 +216,7 @@ static int preface_create(zckCtx *zck) {
     char *header = zmalloc(header_malloc);
     if(header == NULL) {
         set_error(zck, "Unable to allocate %lu bytes", header_malloc);
-        return False;
+        return false;
     }
     size_t length = 0;
 
@@ -232,7 +233,7 @@ static int preface_create(zckCtx *zck) {
     /* Write out compression type and index size */
     if(!compint_from_int(zck, header+length, zck->comp.type, &length)) {
         free(header);
-        return False;
+        return false;
     }
     compint_from_size(header+length, zck->index_size, &length);
 
@@ -240,20 +241,20 @@ static int preface_create(zckCtx *zck) {
     header = realloc(header, length);
     if(header == NULL) {
         set_fatal_error(zck, "Unable to reallocate %lu bytes", length);
-        return False;
+        return false;
     }
 
     zck->preface_string = header;
     zck->preface_size = length;
     zck_log(ZCK_LOG_DEBUG, "Generated preface: %lu bytes", zck->preface_size);
-    return True;
+    return true;
 }
 
-static int sig_create(zckCtx *zck) {
+static bool sig_create(zckCtx *zck) {
     char *header = zmalloc(MAX_COMP_SIZE);
     if(header == NULL) {
         set_error(zck, "Unable to allocate %lu bytes", MAX_COMP_SIZE);
-        return False;
+        return false;
     }
     size_t length = 0;
 
@@ -262,7 +263,7 @@ static int sig_create(zckCtx *zck) {
     /* Write out signature count and signatures */
     if(!compint_from_int(zck, header+length, zck->sigs.count, &length)) {
         free(header);
-        return False;
+        return false;
     }
     for(int i=0; i<zck->sigs.count; i++) {
         // TODO: Add signatures
@@ -270,15 +271,15 @@ static int sig_create(zckCtx *zck) {
     zck->sig_string = header;
     zck->sig_size = length;
     zck_log(ZCK_LOG_DEBUG, "Generated signatures: %lu bytes", zck->sig_size);
-    return True;
+    return true;
 }
 
-static int lead_create(zckCtx *zck) {
+static bool lead_create(zckCtx *zck) {
     int phs = 5 + 2*MAX_COMP_SIZE + zck->hash_type.digest_size;
     char *header = zmalloc(phs);
     if(header == NULL) {
         set_error(zck, "Unable to allocate %lu bytes", phs);
-        return False;
+        return false;
     }
     size_t length = 0;
     memcpy(header, "\0ZCK1", 5);
@@ -296,16 +297,16 @@ static int lead_create(zckCtx *zck) {
     header = realloc(header, length);
     if(header == NULL) {
         set_fatal_error(zck, "Unable to reallocate %lu bytes", length);
-        return False;
+        return false;
     }
 
     zck->lead_string = header;
     zck->lead_size = length;
     zck_log(ZCK_LOG_DEBUG, "Generated lead: %lu bytes", zck->lead_size);
-    return True;
+    return true;
 }
 
-int header_create(zckCtx *zck) {
+bool header_create(zckCtx *zck) {
     VALIDATE_WRITE_BOOL(zck);
 
     /* Rebuild header without header hash */
@@ -316,19 +317,19 @@ int header_create(zckCtx *zck) {
 
     /* Generate index */
     if(!index_create(zck))
-        return False;
+        return false;
 
     /* Generate preface */
     if(!preface_create(zck))
-        return False;
+        return false;
 
     /* Rebuild signatures */
     if(!sig_create(zck))
-        return False;
+        return false;
 
     /* Rebuild pre-header */
     if(!lead_create(zck))
-        return False;
+        return false;
 
     /* Calculate data offset */
     zck->data_offset = zck->lead_size + zck->preface_size +
@@ -341,7 +342,7 @@ int header_create(zckCtx *zck) {
     if(zck->header == NULL) {
         set_fatal_error(zck, "Unable to allocate %lu bytes",
                         zck->data_offset);
-        return False;
+        return false;
     }
     size_t offs = 0;
     memcpy(zck->header + offs, zck->lead_string, zck->lead_size);
@@ -365,38 +366,38 @@ int header_create(zckCtx *zck) {
 
     /* Calculate hash of header */
     if(!hash_init(zck, &header_hash, &(zck->hash_type)))
-        return False;
+        return false;
     zck_log(ZCK_LOG_DEBUG, "Hashing lead");
     /* Hash lead up to header digest */
     if(!hash_update(zck, &header_hash, zck->lead_string,
                     zck->hdr_digest_loc))
-        return False;
+        return false;
     zck_log(ZCK_LOG_DEBUG, "Hashing the rest");
     /* Hash rest of header */
     if(!hash_update(zck, &header_hash, zck->preface_string, zck->header_length))
-        return False;
+        return false;
     zck->header_digest = hash_finalize(zck, &header_hash);
     if(zck->header_digest == NULL)
-        return False;
+        return false;
 
     /* Write digest to header */
     memcpy(zck->lead_string+zck->hdr_digest_loc, zck->header_digest,
            zck->hash_type.digest_size);
 
-    return True;
+    return true;
 }
 
-int write_header(zckCtx *zck) {
+bool write_header(zckCtx *zck) {
     VALIDATE_WRITE_BOOL(zck);
 
     zck_log(ZCK_LOG_DEBUG, "Writing header: %lu bytes",
             zck->lead_size);
     if(!write_data(zck, zck->fd, zck->header, zck->header_size))
-        return False;
-    return True;
+        return false;
+    return true;
 }
 
-static int read_lead(zckCtx *zck) {
+static bool read_lead(zckCtx *zck) {
     VALIDATE_READ_BOOL(zck);
 
     int lead = 5 + 2*MAX_COMP_SIZE;
@@ -404,17 +405,17 @@ static int read_lead(zckCtx *zck) {
     char *header = zmalloc(lead);
     if(header == NULL) {
         set_error(zck, "Unable to allocate %lu bytes", lead);
-        return False;
+        return false;
     }
     size_t length = 0;
 
     if(read_data(zck, header, lead) < lead)
-        return False;
+        return false;
 
     if(memcmp(header, "\0ZCK1", 5) != 0) {
         free(header);
         set_error(zck, "Invalid lead, perhaps this is not a zck file?");
-        return False;
+        return false;
     }
     length += 5;
 
@@ -422,17 +423,17 @@ static int read_lead(zckCtx *zck) {
     int hash_type = 0;
     if(!compint_to_int(zck, &hash_type, header+length, &length, lead)) {
         free(header);
-        return False;
+        return false;
     }
     if(zck->prep_hash_type > -1 && zck->prep_hash_type != hash_type) {
         free(header);
         set_error(zck, "Hash type (%i) doesn't match requested hash type "
                   "(%i)", hash_type, zck->prep_hash_type);
-        return False;
+        return false;
     }
     if(!hash_setup(zck, &(zck->hash_type), hash_type)) {
         free(header);
-        return False;
+        return false;
     }
     zck_log(ZCK_LOG_DEBUG, "Setting header and full digest hash type to %s",
             zck_hash_name_from_type(hash_type));
@@ -442,7 +443,7 @@ static int read_lead(zckCtx *zck) {
     if(!compint_to_size(zck, &header_length, header+length, &length, lead)) {
         free(header);
         hash_reset(&(zck->hash_type));
-        return False;
+        return false;
     }
     zck->header_length = header_length;
 
@@ -458,7 +459,7 @@ static int read_lead(zckCtx *zck) {
         hash_reset(&(zck->hash_type));
         set_fatal_error(zck, "Unable to re-allocate %lu bytes",
                         length + zck->hash_type.digest_size);
-        return False;
+        return false;
     }
     size_t to_read = 0;
     if(lead < length + zck->hash_type.digest_size)
@@ -468,7 +469,7 @@ static int read_lead(zckCtx *zck) {
         zck->header_length = 0;
         zck->hdr_digest_loc = 0;
         hash_reset(&(zck->hash_type));
-        return False;
+        return false;
     }
     lead += to_read;
 
@@ -485,7 +486,7 @@ static int read_lead(zckCtx *zck) {
                                     zck->hash_type.digest_size),
                   get_digest_string(header + length,
                                     zck->hash_type.digest_size));
-        return False;
+        return false;
     }
     zck->header_digest = zmalloc(zck->hash_type.digest_size);
     if(zck->header_digest == NULL) {
@@ -495,7 +496,7 @@ static int read_lead(zckCtx *zck) {
         hash_reset(&(zck->hash_type));
         set_error(zck, "Unable to allocate %lu bytes",
                   zck->hash_type.digest_size);
-        return False;
+        return false;
     }
     memcpy(zck->header_digest, header + length, zck->hash_type.digest_size);
     length += zck->hash_type.digest_size;
@@ -513,7 +514,7 @@ static int read_lead(zckCtx *zck) {
                   "Header length (%lu) doesn't match requested header length "
                   "(%lu)", zck->header_length + length,
                   zck->prep_hdr_size);
-        return False;
+        return false;
     }
     /* Store pre-header */
     zck->header = header;
@@ -521,21 +522,21 @@ static int read_lead(zckCtx *zck) {
     zck->lead_string = header;
     zck->lead_size = length;
     zck_log(ZCK_LOG_DEBUG, "Parsed lead: %lu bytes", length);
-    return True;
+    return true;
 }
 
-int PUBLIC zck_read_lead(zckCtx *zck) {
+bool PUBLIC zck_read_lead(zckCtx *zck) {
     VALIDATE_BOOL(zck);
 
     return read_lead(zck);
 }
 
-int PUBLIC zck_validate_lead(zckCtx *zck) {
+bool PUBLIC zck_validate_lead(zckCtx *zck) {
     VALIDATE_BOOL(zck);
 
     int retval = read_lead(zck);
     if(!zck_clear_error(zck))
-        return False;
+        return false;
     free(zck->header);
     free(zck->header_digest);
     zck->header = NULL;
@@ -548,22 +549,22 @@ int PUBLIC zck_validate_lead(zckCtx *zck) {
     zck->hdr_digest_loc = 0;
     hash_reset(&(zck->hash_type));
     if(!seek_data(zck, 0, SEEK_SET))
-        return False;
+        return false;
     return retval;
 }
 
-int PUBLIC zck_read_header(zckCtx *zck) {
+bool PUBLIC zck_read_header(zckCtx *zck) {
     VALIDATE_READ_BOOL(zck);
 
     if(!read_header_from_file(zck))
-        return False;
+        return false;
     if(!read_preface(zck))
-        return False;
+        return false;
     if(!read_index(zck))
-        return False;
+        return false;
     if(!read_sig(zck))
-        return False;
-    return True;
+        return false;
+    return true;
 }
 
 ssize_t PUBLIC zck_get_header_length(zckCtx *zck) {
index 6d0ee3c7f4bf119ae45cd1f5fe69db203106c245..89c9047b20b532712db6f43b8d49029fa46a8825 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <zck.h>
 
index 6b4af9358fba9f90caefde9529bfe33b90747758..b6bb783a169e418c2de2a3e11254380cfca38105 100644 (file)
 
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <zck.h>
 
 #include "zck_private.h"
 
-static int create_chunk(zckCtx *zck) {
+static bool create_chunk(zckCtx *zck) {
     VALIDATE_BOOL(zck);
 
     clear_work_index(zck);
@@ -39,15 +40,15 @@ static int create_chunk(zckCtx *zck) {
     if(zck->work_index_item == NULL) {
         set_error(zck, "Unable to allocate %lu bytes",
                   sizeof(zckChunk));
-        return False;
+        return false;
     }
     if(!hash_init(zck, &(zck->work_index_hash), &(zck->chunk_hash_type)))
-        return False;
-    return True;
+        return false;
+    return true;
 }
 
-static int finish_chunk(zckIndex *index, zckChunk *item, char *digest,
-                        int valid, zckCtx *zck) {
+static bool finish_chunk(zckIndex *index, zckChunk *item, char *digest,
+                        bool valid, zckCtx *zck) {
     VALIDATE_BOOL(zck);
     ALLOCD_BOOL(index);
     ALLOCD_BOOL(item);
@@ -55,7 +56,7 @@ static int finish_chunk(zckIndex *index, zckChunk *item, char *digest,
     item->digest = zmalloc(index->digest_size);
     if(item->digest == NULL) {
         set_error(zck, "Unable to allocate %lu bytes", index->digest_size);
-        return False;
+        return false;
     }
     if(digest) {
         memcpy(item->digest, digest, index->digest_size);
@@ -74,10 +75,10 @@ static int finish_chunk(zckIndex *index, zckChunk *item, char *digest,
     }
     index->count += 1;
     index->length += item->comp_length;
-    return True;
+    return true;
 }
 
-int index_create(zckCtx *zck) {
+bool index_create(zckCtx *zck) {
     VALIDATE_BOOL(zck);
 
     char *index;
@@ -87,7 +88,7 @@ int index_create(zckCtx *zck) {
 
     zck->full_hash_digest = hash_finalize(zck, &(zck->full_hash));
     if(zck->full_hash_digest == NULL)
-        return False;
+        return false;
 
     /* Set initial malloc size */
     index_malloc  = MAX_COMP_SIZE * 2;
@@ -125,30 +126,30 @@ int index_create(zckCtx *zck) {
     index = realloc(index, index_size);
     if(index == NULL) {
         set_fatal_error(zck, "Unable to reallocate %lu bytes", index_size);
-        return False;
+        return false;
     }
     zck->index_string = index;
     zck->index_size = index_size;
     zck_log(ZCK_LOG_DEBUG, "Generated index: %lu bytes", zck->index_size);
-    return True;
+    return true;
 }
 
-int index_new_chunk(zckCtx *zck, zckIndex *index, char *digest, int digest_size,
-                    size_t comp_size, size_t orig_size, int finished) {
+bool index_new_chunk(zckCtx *zck, zckIndex *index, char *digest, int digest_size,
+                    size_t comp_size, size_t orig_size, bool finished) {
     VALIDATE_BOOL(zck);
 
     if(index == NULL) {
         set_error(zck, "Invalid index");
-        return False;
+        return false;
     }
     if(digest_size == 0) {
         set_error(zck, "Digest size 0 too small");
-        return False;
+        return false;
     }
     zckChunk *chk = zmalloc(sizeof(zckChunk));
     if(chk == NULL) {
         set_error(zck, "Unable to allocate %lu bytes", sizeof(zckChunk));
-        return False;
+        return false;
     }
     index->digest_size = digest_size;
     chk->comp_length = comp_size;
@@ -156,31 +157,31 @@ int index_new_chunk(zckCtx *zck, zckIndex *index, char *digest, int digest_size,
     return finish_chunk(index, chk, digest, finished, zck);
 }
 
-int index_add_to_chunk(zckCtx *zck, char *data, size_t comp_size,
+bool index_add_to_chunk(zckCtx *zck, char *data, size_t comp_size,
                            size_t orig_size) {
     VALIDATE_BOOL(zck);
 
     if(zck->work_index_item == NULL && !create_chunk(zck))
-        return False;
+        return false;
 
     zck->work_index_item->length += orig_size;
     if(comp_size == 0)
-        return True;
+        return true;
 
     if(!hash_update(zck, &(zck->full_hash), data, comp_size))
-        return False;
+        return false;
     if(!hash_update(zck, &(zck->work_index_hash), data, comp_size))
-        return False;
+        return false;
 
     zck->work_index_item->comp_length += comp_size;
-    return True;
+    return true;
 }
 
-int index_finish_chunk(zckCtx *zck) {
+bool index_finish_chunk(zckCtx *zck) {
     VALIDATE_BOOL(zck);
 
     if(zck->work_index_item == NULL && !create_chunk(zck))
-        return False;
+        return false;
 
     char *digest = NULL;
     if(zck->work_index_item->length > 0) {
@@ -190,21 +191,21 @@ int index_finish_chunk(zckCtx *zck) {
             set_fatal_error(zck,
                             "Unable to calculate %s checksum for new chunk",
                             zck_hash_name_from_type(zck->index.hash_type));
-            return False;
+            return false;
         }
     } else {
         digest = zmalloc(zck->chunk_hash_type.digest_size);
         if(digest == NULL) {
             set_fatal_error(zck, "Unable to allocate %lu bytes",
                             zck->chunk_hash_type.digest_size);
-            return False;
+            return false;
         }
     }
-    if(!finish_chunk(&(zck->index), zck->work_index_item, digest, True, zck))
-        return False;
+    if(!finish_chunk(&(zck->index), zck->work_index_item, digest, true, zck))
+        return false;
 
     free(digest);
     zck->work_index_item = NULL;
     hash_close(&(zck->work_index_hash));
-    return True;
+    return true;
 }
index 8af45a149bbc2f08ba5622591a911224f1cf7d5e..29f109e3dd90d3753b7381e00f573684fbaaafb6 100644 (file)
 
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <endian.h>
 #include <zck.h>
 
 #include "zck_private.h"
 
-int index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
+bool index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
     VALIDATE_BOOL(zck);
     size_t length = 0;
 
@@ -40,11 +41,11 @@ int index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
     int hash_type;
     if(!compint_to_int(zck, &hash_type, data + length, &length, max_length)) {
         set_fatal_error(zck, "Unable to read hash type");
-        return False;
+        return false;
     }
     if(!set_chunk_hash_type(zck, hash_type)) {
         set_fatal_error(zck, "Unable to set chunk hash type");
-        return False;
+        return false;
     }
 
     /* Read number of index entries */
@@ -52,7 +53,7 @@ int index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
     if(!compint_to_size(zck, &index_count, data + length, &length,
                         max_length)) {
         set_fatal_error(zck, "Unable to read index count");
-        return False;
+        return false;
     }
     zck->index.count = index_count;
 
@@ -62,14 +63,14 @@ int index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
     while(length < size) {
         if(length + zck->index.digest_size > max_length) {
             set_fatal_error(zck, "Read past end of header");
-            return False;
+            return false;
         }
 
         zckChunk *new = zmalloc(sizeof(zckChunk));
         if(!new) {
             set_fatal_error(zck, "Unable to allocate %lu bytes",
                             sizeof(zckChunk));
-            return False;
+            return false;
         }
 
         /* Read index entry digest */
@@ -77,7 +78,7 @@ int index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
         if(!new->digest) {
             set_fatal_error(zck, "Unable to allocate %lu bytes",
                                  zck->index.digest_size);
-            return False;
+            return false;
         }
         memcpy(new->digest, data+length, zck->index.digest_size);
         new->digest_size = zck->index.digest_size;
@@ -89,7 +90,7 @@ int index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
                             max_length)) {
             set_fatal_error(zck, "Unable to read chunk %i compressed size",
                             count);
-            return False;
+            return false;
         }
         new->start = idx_loc;
         new->comp_length = chunk_length;
@@ -100,7 +101,7 @@ int index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
                             max_length)) {
             set_fatal_error(zck, "Unable to read chunk %i uncompressed size",
                             count);
-            return False;
+            return false;
         }
         new->length = chunk_length;
         new->zck = zck;
@@ -117,7 +118,7 @@ int index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
     }
     free(zck->index_string);
     zck->index_string = NULL;
-    return True;
+    return true;
 }
 
 ssize_t PUBLIC zck_get_chunk_count(zckCtx *zck) {
@@ -167,15 +168,15 @@ int PUBLIC zck_get_chunk_valid(zckChunk *idx) {
     return idx->valid;
 }
 
-int PUBLIC zck_compare_chunk_digest(zckChunk *a, zckChunk *b) {
+bool PUBLIC zck_compare_chunk_digest(zckChunk *a, zckChunk *b) {
     ALLOCD_BOOL(a);
     ALLOCD_BOOL(b);
 
     if(a->digest_size != b->digest_size)
-        return False;
+        return false;
     if(memcmp(a->digest, b->digest, a->digest_size) != 0)
-        return False;
-    return True;
+        return false;
+    return true;
 }
 
 int PUBLIC zck_missing_chunks(zckCtx *zck) {
index 0ae1692659b2e64175d82821b2e1813ca4da02b6..1b3e3b6dbb902d0d9d27c9586c5c455b6870566e 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
@@ -54,20 +55,20 @@ int write_data(zckCtx *zck, int fd, const char *data, size_t length) {
     VALIDATE_INT(zck);
 
     if(length == 0)
-        return True;
+        return true;
     if(data == NULL) {
         set_error(zck, "Unable to write from NULL data pointer");
-        return False;
+        return false;
     }
     ssize_t write_bytes = write(fd, data, length);
     if(write_bytes == -1) {
         set_error(zck, "Error write data: %s", strerror(errno));
-        return False;
+        return false;
     } else if(write_bytes != length) {
         set_fatal_error(zck, "Short write");
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
 int seek_data(zckCtx *zck, off_t offset, int whence) {
@@ -87,9 +88,9 @@ int seek_data(zckCtx *zck, off_t offset, int whence) {
         }
         set_error(zck, "Unable to seek to %lu %s: %s", offset, wh_str,
                   strerror(errno));
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
 ssize_t tell_data(zckCtx *zck) {
@@ -101,17 +102,17 @@ int chunks_from_temp(zckCtx *zck) {
     int read_count;
     char *data = zmalloc(BUF_SIZE);
     if(data == NULL)
-        return False;
+        return false;
 
     if(lseek(zck->temp_fd, 0, SEEK_SET) == -1)
-        return False;
+        return false;
 
     while((read_count = read(zck->temp_fd, data, BUF_SIZE)) > 0) {
         if(read_count == -1 || !write_data(zck, zck->fd, data, read_count)) {
             free(data);
-            return False;
+            return false;
         }
     }
     free(data);
-    return True;
+    return true;
 }
index e03d93a8f2b7bdd7ecfa8a587b2c99b45c27ce56..b6598d8d43792943ea27fe493561f67317fa72fe 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdio.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <stdarg.h>
 #include <unistd.h>
 #include <zck.h>
index 01d770651638f9963b97d0e894daa5fb1159c853..216a4c1ba18675b581f583cf8c5e25460f314c19 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -144,44 +145,44 @@ int get_tmp_fd(zckCtx *zck) {
     return temp_fd;
 }
 
-int import_dict(zckCtx *zck) {
+bool import_dict(zckCtx *zck) {
     VALIDATE_BOOL(zck);
 
     size_t size = zck->index.first->length;
 
     /* No dict */
     if(size == 0)
-        return True;
+        return true;
 
     zck_log(ZCK_LOG_DEBUG, "Reading compression dict");
     char *data = zmalloc(size);
     if(data == NULL) {
         set_error(zck, "Unable to allocate %lu bytes", size);
-        return False;
+        return false;
     }
     if(comp_read(zck, data, size, 0) != size) {
         set_error(zck, "Error reading compressed dict");
-        return False;
+        return false;
     }
     zck_log(ZCK_LOG_DEBUG, "Resetting compression");
     if(!comp_reset(zck))
-        return False;
+        return false;
     zck_log(ZCK_LOG_DEBUG, "Setting dict");
     if(!comp_soption(zck, ZCK_COMP_DICT, data, size))
-        return False;
+        return false;
     if(!comp_init(zck))
-        return False;
+        return false;
 
-    return True;
+    return true;
 }
 
-int PUBLIC zck_set_soption(zckCtx *zck, zck_soption option, const char *value,
-                           size_t length) {
+bool PUBLIC zck_set_soption(zckCtx *zck, zck_soption option, const char *value,
+                            size_t length) {
     VALIDATE_BOOL(zck);
     char *data = zmalloc(length);
     if(data == NULL) {
         set_error(zck, "Unable to allocate %lu bytes", length);
-        return False;
+        return false;
     }
     memcpy(data, value, length);
 
@@ -193,11 +194,11 @@ int PUBLIC zck_set_soption(zckCtx *zck, zck_soption option, const char *value,
             free(data);
             set_error(zck, "For validation, you must set the header hash type "
                            "*before* the header digest itself");
-            return False;
+            return false;
         }
         if(!hash_setup(zck, &chk_type, zck->prep_hash_type)) {
             free(data);
-            return False;
+            return false;
         }
         if(chk_type.digest_size*2 != length) {
             free(data);
@@ -205,7 +206,7 @@ int PUBLIC zck_set_soption(zckCtx *zck, zck_soption option, const char *value,
                                  "validation\n"
                                  "Expected: %lu\nProvided: %lu",
                                  chk_type.digest_size*2, length);
-            return False;
+            return false;
         }
         zck_log(ZCK_LOG_DEBUG, "Setting expected hash to (%s)%s",
                 zck_hash_name_from_type(zck->prep_hash_type), data);
@@ -221,12 +222,12 @@ int PUBLIC zck_set_soption(zckCtx *zck, zck_soption option, const char *value,
     } else {
         free(data);
         set_error(zck, "Unknown string option %i", option);
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
-int PUBLIC zck_set_ioption(zckCtx *zck, zck_ioption option, ssize_t value) {
+bool PUBLIC zck_set_ioption(zckCtx *zck, zck_ioption option, ssize_t value) {
     VALIDATE_BOOL(zck);
 
     /* Set hash type */
@@ -243,14 +244,14 @@ int PUBLIC zck_set_ioption(zckCtx *zck, zck_ioption option, ssize_t value) {
         if(value < 0) {
             set_error(zck, "Header hash type can't be less than zero: %li",
                       value);
-            return False;
+            return false;
         }
         /* Make sure that header hash type is set before the header digest,
          * otherwise we run the risk of a buffer overflow */
         if(zck->prep_digest != NULL) {
             set_error(zck, "For validation, you must set the header hash type "
                            "*before* the header digest itself");
-            return False;
+            return false;
         }
         zck->prep_hash_type = value;
     } else if(option == ZCK_VAL_HEADER_LENGTH) {
@@ -259,7 +260,7 @@ int PUBLIC zck_set_ioption(zckCtx *zck, zck_ioption option, ssize_t value) {
             set_error(zck,
                       "Header size validation can't be less than zero: %li",
                       value);
-            return False;
+            return false;
         }
         zck->prep_hdr_size = value;
 
@@ -267,7 +268,7 @@ int PUBLIC zck_set_ioption(zckCtx *zck, zck_ioption option, ssize_t value) {
     } else if(option < 100) {
         /* Currently no hash options other than setting hash type, so bail */
         set_error(zck, "Unknown option %lu", value);
-        return False;
+        return false;
 
     /* Compression options */
     } else if(option < 2000) {
@@ -277,37 +278,37 @@ int PUBLIC zck_set_ioption(zckCtx *zck, zck_ioption option, ssize_t value) {
     /* Unknown options */
     } else {
         set_error(zck, "Unknown integer option %i", option);
-        return False;
+        return false;
     }
-    return True;
+    return true;
 }
 
-int PUBLIC zck_close(zckCtx *zck) {
+bool PUBLIC zck_close(zckCtx *zck) {
     VALIDATE_BOOL(zck);
 
     if(zck->mode == ZCK_MODE_WRITE) {
         if(zck_end_chunk(zck) < 0)
-            return False;
+            return false;
         if(!header_create(zck))
-            return False;
+            return false;
         if(!write_header(zck))
-            return False;
+            return false;
         zck_log(ZCK_LOG_DEBUG, "Writing chunks");
         if(!chunks_from_temp(zck))
-            return False;
+            return false;
         zck_log(ZCK_LOG_DEBUG, "Finished writing file, cleaning up");
         if(!comp_close(zck))
-            return False;
+            return false;
         if(zck->temp_fd) {
             close(zck->temp_fd);
             zck->temp_fd = 0;
         }
     } else {
         if(validate_file(zck, ZCK_LOG_WARNING) < 1)
-            return False;
+            return false;
     }
 
-    return True;
+    return true;
 }
 
 void PUBLIC zck_free(zckCtx **zck) {
@@ -330,58 +331,58 @@ zckCtx PUBLIC *zck_create() {
     return zck;
 }
 
-int PUBLIC zck_init_adv_read (zckCtx *zck, int src_fd) {
+bool PUBLIC zck_init_adv_read (zckCtx *zck, int src_fd) {
     VALIDATE_BOOL(zck);
 
     zck->mode = ZCK_MODE_READ;
     zck->fd = src_fd;
-    return True;
+    return true;
 }
 
-int PUBLIC zck_init_read (zckCtx *zck, int src_fd) {
+bool PUBLIC zck_init_read (zckCtx *zck, int src_fd) {
     VALIDATE_BOOL(zck);
 
     if(!zck_init_adv_read(zck, src_fd)) {
         set_fatal_error(zck, "Unable to read file");
-        return False;
+        return false;
     }
 
     if(!zck_read_lead(zck)) {
         set_fatal_error(zck, "Unable to read lead");
-        return False;
+        return false;
     }
 
     if(!zck_read_header(zck)) {
         set_fatal_error(zck, "Unable to read header");
-        return False;
+        return false;
     }
 
-    return True;
+    return true;
 }
 
-int PUBLIC zck_init_write (zckCtx *zck, int dst_fd) {
+bool PUBLIC zck_init_write (zckCtx *zck, int dst_fd) {
     VALIDATE_BOOL(zck);
 
     zck->mode = ZCK_MODE_WRITE;
     zck->temp_fd = get_tmp_fd(zck);
     if(zck->temp_fd < 0)
-        return False;
+        return false;
 
     /* Set defaults */
 #ifdef ZCHUNK_ZSTD
     if(!zck_set_ioption(zck, ZCK_COMP_TYPE, ZCK_COMP_ZSTD))
-        return False;
+        return false;
 #else
     if(!zck_set_ioption(zck, ZCK_COMP_TYPE, ZCK_COMP_NONE))
-        return False;
+        return false;
 #endif
     if(!zck_set_ioption(zck, ZCK_HASH_FULL_TYPE, ZCK_HASH_SHA256))
-        return False;
+        return false;
     if(!zck_set_ioption(zck, ZCK_HASH_CHUNK_TYPE, ZCK_HASH_SHA512_128))
-        return False;
+        return false;
     zck->fd = dst_fd;
 
-    return True;
+    return true;
 }
 
 int PUBLIC zck_get_fd(zckCtx *zck) {
@@ -389,8 +390,8 @@ int PUBLIC zck_get_fd(zckCtx *zck) {
     return zck->fd;
 }
 
-int PUBLIC zck_set_fd(zckCtx *zck, int fd) {
+bool PUBLIC zck_set_fd(zckCtx *zck, int fd) {
     VALIDATE_BOOL(zck);
     zck->fd = fd;
-    return True;
+    return true;
 }
index de569c420d3dbb93be83a35a241aa4821e128759..2502c13081d7269484a7a5433f58c4c3d3664cc3 100644 (file)
@@ -2,6 +2,7 @@
 #define ZCK_PRIVATE_H
 #include <stdarg.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <stddef.h>
 #include <regex.h>
 #include "buzhash/buzhash.h"
@@ -30,7 +31,7 @@
 #define ALLOCD_BOOL(f)      if(!f) { \
                                 zck_log(ZCK_LOG_NONE, \
                                         "Object not initialized"); \
-                                return False; \
+                                return false; \
                             }
 #define ALLOCD_INT(f)       if(!f) { \
                                 zck_log(ZCK_LOG_NONE, \
@@ -43,7 +44,7 @@
                                 return NULL; \
                             }
 #define VALIDATE_BOOL(f)    ALLOCD_BOOL(f) \
-                            if((f)->error_state > 0) return False;
+                            if((f)->error_state > 0) return false;
 #define VALIDATE_INT(f)     ALLOCD_INT(f) \
                             if((f)->error_state > 0) return -1;
 #define VALIDATE_PTR(f)     ALLOCD_PTR(f) \
@@ -53,7 +54,7 @@
                                 if(f->mode != ZCK_MODE_READ) { \
                                     set_error(f, \
                                         "zckCtx not opened for reading"); \
-                                    return False; \
+                                    return false; \
                                 }
 #define VALIDATE_READ_INT(f)    VALIDATE_INT(f); \
                                 if(f->mode != ZCK_MODE_READ) { \
@@ -72,7 +73,7 @@
                                 if(f->mode != ZCK_MODE_WRITE) { \
                                     set_error(f, \
                                         "zckCtx not opened for writing"); \
-                                    return False; \
+                                    return false; \
                                 }
 #define VALIDATE_WRITE_INT(f)   VALIDATE_INT(f); \
                                 if(f->mode != ZCK_MODE_WRITE) { \
 typedef struct zckComp zckComp;
 typedef zckCtx zckCtx;
 
-typedef int (*finit)(zckCtx *zck, zckComp *comp);
-typedef int (*fparam)(zckCtx *zck,zckComp *comp, int option, const void *value);
-typedef int (*fccompend)(zckCtx *zck, zckComp *comp, char **dst,
-                         size_t *dst_size, int use_dict);
+typedef bool (*finit)(zckCtx *zck, zckComp *comp);
+typedef bool (*fparam)(zckCtx *zck,zckComp *comp, int option, const void *value);
+typedef bool (*fccompend)(zckCtx *zck, zckComp *comp, char **dst,
+                          size_t *dst_size, bool use_dict);
 typedef ssize_t (*fcomp)(zckCtx *zck, zckComp *comp, const char *src,
                          const size_t src_size, char **dst, size_t *dst_size,
-                         int use_dict);
-typedef int (*fdecomp)(zckCtx *zck, zckComp *comp, const int use_dict);
-typedef int (*fdcompend)(zckCtx *zck, zckComp *comp, const int use_dict,
-                         const size_t fd_size);
-typedef int (*fcclose)(zckCtx *zck, zckComp *comp);
+                         bool use_dict);
+typedef bool (*fdecomp)(zckCtx *zck, zckComp *comp, const bool use_dict);
+typedef bool (*fdcompend)(zckCtx *zck, zckComp *comp, const bool use_dict,
+                          const size_t fd_size);
+typedef bool (*fcclose)(zckCtx *zck, zckComp *comp);
 
 typedef enum zck_log_type zck_log_type;
 
@@ -290,17 +291,17 @@ typedef struct zckCtx {
 
 int get_tmp_fd()
     __attribute__ ((warn_unused_result));
-int import_dict(zckCtx *zck)
+bool import_dict(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 
 
 /* hash/hash.h */
-int hash_setup(zckCtx *zck, zckHashType *ht, int h)
+bool hash_setup(zckCtx *zck, zckHashType *ht, int h)
     __attribute__ ((warn_unused_result));
-int hash_init(zckCtx *zck, zckHash *hash, zckHashType *hash_type)
+bool hash_init(zckCtx *zck, zckHash *hash, zckHashType *hash_type)
     __attribute__ ((warn_unused_result));
-int hash_update(zckCtx *zck, zckHash *hash, const char *message,
-                const size_t size)
+bool hash_update(zckCtx *zck, zckHash *hash, const char *message,
+                 const size_t size)
     __attribute__ ((warn_unused_result));
 char *hash_finalize(zckCtx *zck, zckHash *hash)
     __attribute__ ((warn_unused_result));
@@ -315,9 +316,9 @@ int validate_current_chunk(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 int validate_header(zckCtx *zck)
     __attribute__ ((warn_unused_result));
-int set_full_hash_type(zckCtx *zck, int hash_type)
+bool set_full_hash_type(zckCtx *zck, int hash_type)
     __attribute__ ((warn_unused_result));
-int set_chunk_hash_type(zckCtx *zck, int hash_type)
+bool set_chunk_hash_type(zckCtx *zck, int hash_type)
     __attribute__ ((warn_unused_result));
 int get_max_hash_size()
     __attribute__ ((warn_unused_result));
@@ -326,22 +327,22 @@ char *get_digest_string(const char *digest, int size)
 
 
 /* index/index.c */
-int index_read(zckCtx *zck, char *data, size_t size, size_t max_length)
+bool index_read(zckCtx *zck, char *data, size_t size, size_t max_length)
     __attribute__ ((warn_unused_result));
-int index_create(zckCtx *zck)
+bool index_create(zckCtx *zck)
     __attribute__ ((warn_unused_result));
-int index_new_chunk(zckCtx *zck, zckIndex *index, char *digest, int digest_size,
-                    size_t comp_size, size_t orig_size, int valid)
+bool index_new_chunk(zckCtx *zck, zckIndex *index, char *digest, int digest_size,
+                     size_t comp_size, size_t orig_size, bool valid)
     __attribute__ ((warn_unused_result));
-int index_add_to_chunk(zckCtx *zck, char *data, size_t comp_size,
+bool index_add_to_chunk(zckCtx *zck, char *data, size_t comp_size,
                         size_t orig_size)
     __attribute__ ((warn_unused_result));
-int index_finish_chunk(zckCtx *zck)
+bool index_finish_chunk(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 void index_clean(zckIndex *index);
 void index_free(zckCtx *zck);
 void clear_work_index(zckCtx *zck);
-int write_index(zckCtx *zck)
+bool write_index(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 
 
@@ -358,26 +359,26 @@ int chunks_from_temp(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 
 /* header.c */
-int header_create(zckCtx *zck)
+bool header_create(zckCtx *zck)
     __attribute__ ((warn_unused_result));
-int write_header(zckCtx *zck)
+bool write_header(zckCtx *zck)
     __attribute__ ((warn_unused_result));
 
 /* comp/comp.c */
-int comp_init(zckCtx *zck)
+bool comp_init(zckCtx *zck)
     __attribute__ ((warn_unused_result));
-int comp_close(zckCtx *zck)
+bool comp_close(zckCtx *zck)
     __attribute__ ((warn_unused_result));
-int comp_reset(zckCtx *zck)
+bool comp_reset(zckCtx *zck)
     __attribute__ ((warn_unused_result));
-int comp_add_to_dc(zckCtx *zck, zckComp *comp, const char *src, size_t src_size)
+bool comp_add_to_dc(zckCtx *zck, zckComp *comp, const char *src, size_t src_size)
     __attribute__ ((warn_unused_result));
-ssize_t comp_read(zckCtx *zck, char *dst, size_t dst_size, int use_dict)
+ssize_t comp_read(zckCtx *zck, char *dst, size_t dst_size, bool use_dict)
     __attribute__ ((warn_unused_result));
-int comp_ioption(zckCtx *zck, zck_ioption option, ssize_t value)
+bool comp_ioption(zckCtx *zck, zck_ioption option, ssize_t value)
     __attribute__ ((warn_unused_result));
-int comp_soption(zckCtx *zck, zck_soption option, const void *value,
-                 size_t length)
+bool comp_soption(zckCtx *zck, zck_soption option, const void *value,
+                  size_t length)
     __attribute__ ((warn_unused_result));
 
 /* dl/range.c */
index efafb53623e90dfdde3c8762f6d9d9fa0710b326..dc15ba9dd4a09d5ca38c1d51da934a44391b979c 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -54,7 +55,7 @@ static struct argp_option options[] = {
 struct arguments {
   char *args[1];
   zck_log_type log_level;
-  int stdout;
+  bool stdout;
 };
 
 static error_t parse_opt (int key, char *arg, struct argp_state *state) {
@@ -67,7 +68,7 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
                 arguments->log_level = ZCK_LOG_DDEBUG;
             break;
         case 'c':
-            arguments->stdout = 1;
+            arguments->stdout = true;
             break;
         case 'V':
             version();
@@ -128,7 +129,7 @@ int main (int argc, char *argv[]) {
         }
     }
 
-    int good_exit = False;
+    bool good_exit = false;
 
     zckCtx *zck = zck_create();
     if(zck == NULL)
@@ -146,7 +147,7 @@ int main (int argc, char *argv[]) {
     }
 
     size_t total = 0;
-    while(True) {
+    while(true) {
         ssize_t read = zck_read(zck, data, BUF_SIZE);
         if(read < 0)
             goto error2;
@@ -162,7 +163,7 @@ int main (int argc, char *argv[]) {
         goto error2;
     if(arguments.log_level <= ZCK_LOG_INFO)
         printf("Decompressed %lu bytes\n", (unsigned long)total);
-    good_exit = True;
+    good_exit = true;
 error2:
     free(data);
     if(!good_exit)
index 9ef99707d7c0e0d3fa361d5c9c5b245ba4646442..dd7494696c800d1bd2275d5832fc6080bf83bc43 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdbool.h>
 #include <zck.h>
 
 #include "util_common.h"
index 77dc38294b239751bc19823cadbdc9f802bb0710..26487196aeee2f4afea643991f3a794c295c13ea 100644 (file)
--- a/src/zck.c
+++ b/src/zck.c
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -62,7 +63,7 @@ struct arguments {
   char *args[1];
   zck_log_type log_level;
   char *split_string;
-  int manual_chunk;
+  bool manual_chunk;
   char *output;
   char *dict;
 };
@@ -80,7 +81,7 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
             arguments->split_string = arg;
             break;
         case 'm':
-            arguments->manual_chunk = 1;
+            arguments->manual_chunk = true;
             break;
         case 'o':
             arguments->output = arg;
index ebf43e5b60a6f0dce93c3e3802ecd2c72842b289..962d34d047492a910c001e14903b81e809b13607 100644 (file)
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -157,11 +158,11 @@ int main (int argc, char *argv[]) {
     ssize_t matched_chunks = 0;
     for(tgt_idx = zck_get_first_chunk(zck_tgt); tgt_idx;
         tgt_idx = zck_get_next_chunk(tgt_idx)) {
-        int found = False;
+        bool found = false;
         for(src_idx = zck_get_first_chunk(zck_src); src_idx;
             src_idx = zck_get_next_chunk(src_idx)) {
             if(zck_compare_chunk_digest(tgt_idx, src_idx)) {
-                found = True;
+                found = true;
                 break;
             }
         }
index 93bdc5af84edc7bd9cdb0fb2f892e1d2af8f336f..5a2c03e360f456f6858facebe280cad63de8ae40 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
index 5f9e10182a532cc923958cb03cf390dc26d02c77..3239c2f73a2e378b8fa28c1588e185dbdd34ebf4 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -52,9 +53,9 @@ static struct argp_option options[] = {
 
 struct arguments {
   char *args[1];
-  int verify;
-  int quiet;
-  int show_chunks;
+  bool verify;
+  bool quiet;
+  bool show_chunks;
   zck_log_type log_level;
 };
 
@@ -68,16 +69,16 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
                 arguments->log_level = ZCK_LOG_DDEBUG;
             break;
         case 'c':
-            arguments->show_chunks = True;
+            arguments->show_chunks = true;
             break;
         case 'q':
-            arguments->quiet = True;
+            arguments->quiet = true;
             break;
         case 'V':
             version();
             break;
         case 'f':
-            arguments->verify = True;
+            arguments->verify = true;
             break;
 
         case ARGP_KEY_ARG:
index 4413633c3e04ebbed00f6ce6e9770e54198cfe96..4f604f64d3849c6e1224060beeb19fd9fa67f9ab 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdbool.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
index 5134770c0f857c2622aeb41c7971dc63fff2fe23..554a693778e98d6efd4cc15339c86f0b25b1aca5 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include <stdlib.h>
+#include <stdbool.h>
 #include <zck.h>
 #include "../../src/lib/zck_private.h"