From: Jonathan Dieter Date: Tue, 24 Jul 2018 21:30:30 +0000 (+0100) Subject: API CHANGE: Update API with new error functions X-Git-Tag: archive/raspbian/1.1.9+ds1-1+rpi1~1^2~183 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=db48f69a0111237fed336cdcf60898e62798f1f0;p=zchunk.git API CHANGE: Update API with new error functions Signed-off-by: Jonathan Dieter --- diff --git a/include/zck.h.in b/include/zck.h.in index 6f6e4c7..5d71e86 100644 --- a/include/zck.h.in +++ b/include/zck.h.in @@ -56,8 +56,11 @@ typedef size_t (*zck_wcb)(void *ptr, size_t l, size_t c, void *dl_v); /******************************************************************* * Reading a zchunk file *******************************************************************/ +/* Initialize zchunk context */ +zckCtx *zck_create() + __attribute__ ((warn_unused_result)); /* Initialize zchunk for reading */ -zckCtx *zck_init_read (int src_fd) +int 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) @@ -68,7 +71,7 @@ ssize_t zck_read(zckCtx *zck, char *dst, size_t dst_size) * Writing a zchunk file *******************************************************************/ /* Initialize zchunk for writing */ -zckCtx *zck_init_write (int dst_fd) +int 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 @@ -111,6 +114,10 @@ int zck_set_ioption(zckCtx *zck, zck_ioption option, ssize_t value) void zck_set_log_level(zck_log_type ll); /* Set logging fd */ void zck_set_log_fd(int fd); +/* Check whether zck is in error state + * Returns 0 if not, 1 if recoverable error, 2 if fatal error */ +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 */ char *zck_get_error(zckCtx *zck); @@ -122,10 +129,11 @@ int zck_clear_error(zckCtx *zck); * Miscellaneous utilities *******************************************************************/ /* Validate the chunk and data checksums for the current file. - * Returns -1 for error, 0 for invalid checksum and 1 for valid checksum */ + * Returns 0 for error, -1 for invalid checksum and 1 for valid checksum */ int zck_validate_checksums(zckCtx *zck) __attribute__ ((warn_unused_result)); -/* Validate just the data checksum for the current file */ +/* Validate just the data checksum for the current file + * 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 */ @@ -139,13 +147,14 @@ int zck_find_valid_chunks(zckCtx *zck) zckRange *zck_get_missing_range(zckCtx *zck, int max_ranges) __attribute__ ((warn_unused_result)); /* Get a string representation of a zckRange */ -char *zck_get_range_char(zckRange *range) +char *zck_get_range_char(zckCtx *zck, zckRange *range) __attribute__ ((warn_unused_result)); /* Get file descriptor attached to zchunk context */ int zck_get_fd(zckCtx *zck) __attribute__ ((warn_unused_result)); /* Set file descriptor attached to zchunk context */ -void zck_set_fd(zckCtx *zck, int fd); +int zck_set_fd(zckCtx *zck, int fd) + __attribute__ ((warn_unused_result)); /* Return number of missing chunks (-1 if error) */ int zck_missing_chunks(zckCtx *zck) @@ -166,9 +175,6 @@ void zck_reset_failed_chunks(zckCtx *zck); /******************************************************************* * Advanced miscellaneous zchunk functions *******************************************************************/ -/* Initialize zchunk context */ -zckCtx *zck_create() - __attribute__ ((warn_unused_result)); /* Get lead length */ ssize_t zck_get_lead_length(zckCtx *zck) __attribute__ ((warn_unused_result)); @@ -203,7 +209,7 @@ const char *zck_comp_name_from_type(int comp_type) * Advanced zchunk reading functions *******************************************************************/ /* Initialize zchunk for reading using advanced options */ -zckCtx *zck_init_adv_read (int src_fd) +int zck_init_adv_read (zckCtx *zck, int src_fd) __attribute__ ((warn_unused_result)); /* Read zchunk lead */ int zck_read_lead(zckCtx *zck) @@ -211,7 +217,7 @@ int zck_read_lead(zckCtx *zck) /* Read zchunk header */ int zck_read_header(zckCtx *zck) __attribute__ ((warn_unused_result)); - +/* Validate lead */ int zck_validate_lead(zckCtx *zck) __attribute__ ((warn_unused_result)); @@ -312,10 +318,10 @@ void zck_dl_clear_regex(zckDL *dl); int zck_dl_get_header(zckCtx *zck, zckDL *dl, char *url) __attribute__ ((warn_unused_result)); /* Get number of bytes downloaded using download context */ -size_t zck_dl_get_bytes_downloaded(zckDL *dl) +ssize_t zck_dl_get_bytes_downloaded(zckDL *dl) __attribute__ ((warn_unused_result)); /* Get number of bytes uploaded using download context */ -size_t zck_dl_get_bytes_uploaded(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)