#define ZCK_VERSION "@version@"
-#define True 1
-#define False 0
-
typedef enum zck_hash {
ZCK_HASH_SHA1,
ZCK_HASH_SHA256,
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)
* 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
*******************************************************************/
/* 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 */
* 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));
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
* 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));
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) */
* 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));
/*******************************************************************
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));
/*******************************************************************
* 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);
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)
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
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <zck.h>
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);
/* 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 */
} 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,
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);
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);
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;
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;
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");
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);
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)
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;
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);
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",
/* 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) {
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 */
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;
}
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) ||
#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);
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);
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;
#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);
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
* 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);
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);
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) {
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);
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;
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;
#include <stdlib.h>
#include <stdint.h>
+#include <stdbool.h>
#include <zck.h>
#include "zck_private.h"
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++)
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) {
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,
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;
}
#include <stdlib.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <curl/curl.h>
#include <unistd.h>
}
/* 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);
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 */
}
/* 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);
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);
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;
tgt_idx->comp_length, tgt_idx->start);
}
free(digest);
- return True;
+ return true;
}
/* Split current read into the appropriate chunks and write appropriately */
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) {
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;
continue;
}
- int found = False;
+ bool found = false;
src_idx = src_info->first;
while(src_idx) {
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;
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) {
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) {
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;
}
/*******************************************************************
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;
#include <stdlib.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <regex.h>
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);
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) {
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) {
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 */
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <errno.h>
}
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;
}
}
}
-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;
} 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) {
#include <assert.h>
#include <string.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <zck.h>
#include "zck_private.h"
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;
}
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <zck.h>
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) {
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) {
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));
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));
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) {
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) {
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));
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 */
#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;
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;
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;
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;
/* 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");
/* 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;
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 +
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 */
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;
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;
/* 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);
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;
/* 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
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);
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 */
/* 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 +
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);
/* 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;
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;
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));
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;
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)
zck->header_length = 0;
zck->hdr_digest_loc = 0;
hash_reset(&(zck->hash_type));
- return False;
+ return false;
}
lead += to_read;
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) {
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;
"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;
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;
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) {
#include <stdlib.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <zck.h>
#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);
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);
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);
}
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;
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;
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;
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) {
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;
}
#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;
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 */
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;
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 */
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;
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;
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;
}
free(zck->index_string);
zck->index_string = NULL;
- return True;
+ return true;
}
ssize_t PUBLIC zck_get_chunk_count(zckCtx *zck) {
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) {
#include <stdlib.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
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) {
}
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) {
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;
}
#include <stdio.h>
#include <stdint.h>
+#include <stdbool.h>
#include <stdarg.h>
#include <unistd.h>
#include <zck.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
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);
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);
"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);
} 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 */
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) {
set_error(zck,
"Header size validation can't be less than zero: %li",
value);
- return False;
+ return false;
}
zck->prep_hdr_size = 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) {
/* 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) {
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) {
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;
}
#define ZCK_PRIVATE_H
#include <stdarg.h>
#include <stdint.h>
+#include <stdbool.h>
#include <stddef.h>
#include <regex.h>
#include "buzhash/buzhash.h"
#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, \
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) \
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) { \
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;
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));
__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));
/* 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));
__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 */
#include <stdio.h>
#include <string.h>
#include <stdint.h>
+#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
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) {
arguments->log_level = ZCK_LOG_DDEBUG;
break;
case 'c':
- arguments->stdout = 1;
+ arguments->stdout = true;
break;
case 'V':
version();
}
}
- int good_exit = False;
+ bool good_exit = false;
zckCtx *zck = zck_create();
if(zck == NULL)
}
size_t total = 0;
- while(True) {
+ while(true) {
ssize_t read = zck_read(zck, data, BUF_SIZE);
if(read < 0)
goto error2;
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)
#include <stdlib.h>
#include <stdio.h>
+#include <stdbool.h>
#include <zck.h>
#include "util_common.h"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
+#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
char *args[1];
zck_log_type log_level;
char *split_string;
- int manual_chunk;
+ bool manual_chunk;
char *output;
char *dict;
};
arguments->split_string = arg;
break;
case 'm':
- arguments->manual_chunk = 1;
+ arguments->manual_chunk = true;
break;
case 'o':
arguments->output = arg;
#include <stdio.h>
#include <string.h>
#include <stdint.h>
+#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
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;
}
}
#include <stdio.h>
#include <string.h>
#include <stdint.h>
+#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
+#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
struct arguments {
char *args[1];
- int verify;
- int quiet;
- int show_chunks;
+ bool verify;
+ bool quiet;
+ bool show_chunks;
zck_log_type log_level;
};
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:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <stdbool.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
*/
#include <stdlib.h>
+#include <stdbool.h>
#include <zck.h>
#include "../../src/lib/zck_private.h"