From a631ce45f7f14ae3d091e233d1d54d1bac4afa60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Podg=C3=B3rski?= Date: Sat, 6 Mar 2021 18:13:11 +0100 Subject: [PATCH] clang-format --- CONTRIBUTING.md | 1 + src/zip.c | 22 ++++++++++++---------- src/zip.h | 4 ++-- test/test.c | 3 ++- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8da7a6d..bec8e09 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,3 +6,4 @@ for file in $(git ls-files | \grep -E '\.(c|h)$' | \grep -v -- '#') do clang-format -i $file done +``` diff --git a/src/zip.c b/src/zip.c index fd9a682..9311be8 100644 --- a/src/zip.c +++ b/src/zip.c @@ -1078,7 +1078,8 @@ struct entry_mark { mz_uint64 lf_length; }; -struct zip_t *zip_open_stream(const char *stream, size_t size, int level, char mode) { +struct zip_t *zip_open_stream(const char *stream, size_t size, int level, + char mode) { struct zip_t *zip = NULL; zip = (struct zip_t *)calloc((size_t)1, sizeof(struct zip_t)); if (!zip) { @@ -1091,17 +1092,17 @@ struct zip_t *zip_open_stream(const char *stream, size_t size, int level, char m goto cleanup; } zip->level = (mz_uint)level; - if((stream != NULL) && (size > 0) && (mode == 'r')){ + if ((stream != NULL) && (size > 0) && (mode == 'r')) { if (!mz_zip_reader_init_mem(&(zip->archive), stream, size, 0)) { goto cleanup; } - }else if((stream == NULL) && (size == 0) && (mode == 'w')){ + } else if ((stream == NULL) && (size == 0) && (mode == 'w')) { // Create a new archive. if (!mz_zip_writer_init_heap(&(zip->archive), 0, 1024)) { // Cannot initialize zip_archive writer goto cleanup; } - }else{ + } else { goto cleanup; } return zip; @@ -1111,24 +1112,25 @@ cleanup: return NULL; } -static inline void zip_write_end(struct zip_t *zip){ - if (zip) { +static inline void zip_write_end(struct zip_t *zip) { + if (zip) { mz_zip_writer_finalize_archive(&(zip->archive)); file_truncate(&(zip->archive)); } } -ssize_t zip_copy_stream(struct zip_t *zip, void **buf, ssize_t *bufsize){ - if(zip == NULL) return -1; +ssize_t zip_copy_stream(struct zip_t *zip, void **buf, ssize_t *bufsize) { + if (zip == NULL) + return -1; zip_write_end(zip); - if(bufsize != NULL) + if (bufsize != NULL) *bufsize = zip->archive.m_archive_size; *buf = (char *)calloc(sizeof(unsigned char), zip->archive.m_archive_size); memcpy(*buf, zip->archive.m_pState->m_pMem, zip->archive.m_archive_size); return zip->archive.m_archive_size; } -void zip_close_stream(struct zip_t *zip){ +void zip_close_stream(struct zip_t *zip) { if (zip) { mz_zip_writer_end(&(zip->archive)); mz_zip_reader_end(&(zip->archive)); diff --git a/src/zip.h b/src/zip.h index b771fa7..1ff5737 100644 --- a/src/zip.h +++ b/src/zip.h @@ -331,8 +331,8 @@ extern int zip_extract_stream(const char *stream, size_t size, const char *dir, * * @return the zip archive handler or NULL on error */ -extern struct zip_t *zip_open_stream(const char *stream, size_t size, - int level, char mode); +extern struct zip_t *zip_open_stream(const char *stream, size_t size, int level, + char mode); /** * Copy zip archive stream output buffer. diff --git a/test/test.c b/test/test.c index 1185798..dfe141d 100644 --- a/test/test.c +++ b/test/test.c @@ -548,7 +548,8 @@ static void test_open_stream(void) { #else remove(ZIPNAME); /* COMPRESS MEM TO MEM */ - struct zip_t *zip = zip_open_stream(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w'); + struct zip_t *zip = + zip_open_stream(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w'); assert(zip != NULL); assert(0 == zip_entry_open(zip, "test/test-1.txt"));