From 8ccafbaef1ec43893e7f988bf510049927c6ea28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Podg=C3=B3rski?= Date: Sat, 30 Sep 2023 21:43:44 +0200 Subject: [PATCH] clang-format --- src/miniz.h | 2 +- src/zip.c | 28 ++++++++++++++++------------ src/zip.h | 40 +++++++++++++++++++++++----------------- test/test_open.c | 43 ++++++++++++++++++++++--------------------- 4 files changed, 62 insertions(+), 51 deletions(-) diff --git a/src/miniz.h b/src/miniz.h index 04756ade..71958ccf 100644 --- a/src/miniz.h +++ b/src/miniz.h @@ -4986,7 +4986,7 @@ static int mz_mkdir(const char *pDirname) { #else #pragma message( \ - "Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.") + "Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.") #ifndef MINIZ_NO_TIME #include #endif diff --git a/src/zip.c b/src/zip.c index dab56201..fb812a41 100644 --- a/src/zip.c +++ b/src/zip.c @@ -357,8 +357,7 @@ static int zip_archive_extract(mz_zip_archive *zip_archive, const char *dir, } #if defined(_MSC_VER) - strncpy_s(&path[dirlen], filename_size, info.m_filename, - filename_size); + strncpy_s(&path[dirlen], filename_size, info.m_filename, filename_size); #else strncpy(&path[dirlen], info.m_filename, filename_size); #endif @@ -379,8 +378,9 @@ static int zip_archive_extract(mz_zip_archive *zip_archive, const char *dir, defined(__MINGW32__) #else if (info.m_uncomp_size > MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE || - !mz_zip_reader_extract_to_mem_no_alloc(zip_archive, i, symlink_to, - MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE, 0, NULL, 0)) { + !mz_zip_reader_extract_to_mem_no_alloc( + zip_archive, i, symlink_to, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE, 0, + NULL, 0)) { err = ZIP_EMEMNOALLOC; goto out; } @@ -819,7 +819,8 @@ struct zip_t *zip_open(const char *zipname, int level, char mode) { return zip_openwitherror(zipname, level, mode, &errnum); } -struct zip_t *zip_openwitherror(const char *zipname, int level, char mode, int *errnum) { +struct zip_t *zip_openwitherror(const char *zipname, int level, char mode, + int *errnum) { struct zip_t *zip = NULL; *errnum = 0; @@ -878,7 +879,8 @@ struct zip_t *zip_openwitherror(const char *zipname, int level, char mode, int * goto cleanup; } if ((mode == 'a' || mode == 'd')) { - if (!mz_zip_writer_init_from_reader_v2_noreopen(&(zip->archive), zipname, 0)) { + if (!mz_zip_writer_init_from_reader_v2_noreopen(&(zip->archive), zipname, + 0)) { *errnum = ZIP_EWRINIT; mz_zip_reader_end(&(zip->archive)); goto cleanup; @@ -904,16 +906,16 @@ void zip_close(struct zip_t *zip) { // Always finalize, even if adding failed for some reason, so we have a // valid central directory. if (pZip->m_zip_mode == MZ_ZIP_MODE_WRITING) { - mz_zip_writer_finalize_archive(pZip); + mz_zip_writer_finalize_archive(pZip); } if (pZip->m_zip_mode == MZ_ZIP_MODE_WRITING || pZip->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED) { - zip_archive_truncate(pZip); - mz_zip_writer_end(pZip); + zip_archive_truncate(pZip); + mz_zip_writer_end(pZip); } if (pZip->m_zip_mode == MZ_ZIP_MODE_READING) { - mz_zip_reader_end(pZip); + mz_zip_reader_end(pZip); } CLEANUP(zip); @@ -1651,12 +1653,14 @@ int zip_stream_extract(const char *stream, size_t size, const char *dir, return zip_archive_extract(&zip_archive, dir, on_extract, arg); } -struct zip_t *zip_stream_open(const char *stream, size_t size, int level, char mode) { +struct zip_t *zip_stream_open(const char *stream, size_t size, int level, + char mode) { int errnum = 0; return zip_stream_openwitherror(stream, size, level, mode, &errnum); } -struct zip_t *zip_stream_openwitherror(const char *stream, size_t size, int level, char mode, int *errnum) { +struct zip_t *zip_stream_openwitherror(const char *stream, size_t size, + int level, char mode, int *errnum) { struct zip_t *zip = (struct zip_t *)calloc((size_t)1, sizeof(struct zip_t)); if (!zip) { // out of memory diff --git a/src/zip.h b/src/zip.h index 20a88dcb..a08c16ab 100644 --- a/src/zip.h +++ b/src/zip.h @@ -124,23 +124,25 @@ struct zip_t; * * @return the zip archive handler or NULL on error */ -extern ZIP_EXPORT struct zip_t *zip_open(const char *zipname, int level, char mode); +extern ZIP_EXPORT struct zip_t *zip_open(const char *zipname, int level, + char mode); /** - * Opens zip archive with compression level using the given mode. - * The function additionally returns @param errnum - - * - * @param zipname zip archive file name. - * @param level compression level (0-9 are the standard zlib-style levels). - * @param mode file access mode. - * - 'r': opens a file for reading/extracting (the file must exists). - * - 'w': creates an empty file for writing. - * - 'a': appends to an existing archive. - * @param errnum 0 on success, negative number (< 0) on error. - * - * @return the zip archive handler or NULL on error - */ -extern ZIP_EXPORT struct zip_t *zip_openwitherror(const char *zipname, int level, char mode, int *errnum); + * Opens zip archive with compression level using the given mode. + * The function additionally returns @param errnum - + * + * @param zipname zip archive file name. + * @param level compression level (0-9 are the standard zlib-style levels). + * @param mode file access mode. + * - 'r': opens a file for reading/extracting (the file must exists). + * - 'w': creates an empty file for writing. + * - 'a': appends to an existing archive. + * @param errnum 0 on success, negative number (< 0) on error. + * + * @return the zip archive handler or NULL on error + */ +extern ZIP_EXPORT struct zip_t * +zip_openwitherror(const char *zipname, int level, char mode, int *errnum); /** * Closes the zip archive, releases resources - always finalize. @@ -423,7 +425,8 @@ zip_stream_extract(const char *stream, size_t size, const char *dir, * * @return the zip archive handler or NULL on error */ -extern ZIP_EXPORT struct zip_t *zip_stream_open(const char *stream, size_t size, int level, char mode); +extern ZIP_EXPORT struct zip_t *zip_stream_open(const char *stream, size_t size, + int level, char mode); /** * Opens zip archive stream into memory. @@ -440,7 +443,10 @@ extern ZIP_EXPORT struct zip_t *zip_stream_open(const char *stream, size_t size, * * @return the zip archive handler or NULL on error */ -extern ZIP_EXPORT struct zip_t *zip_stream_openwitherror(const char *stream, size_t size, int level, char mode, int *errnum); +extern ZIP_EXPORT struct zip_t *zip_stream_openwitherror(const char *stream, + size_t size, int level, + char mode, + int *errnum); /** * Copy zip archive stream output buffer. diff --git a/test/test_open.c b/test/test_open.c index fe25aa51..a5432d6c 100644 --- a/test/test_open.c +++ b/test/test_open.c @@ -12,34 +12,35 @@ void test_setup(void) { mktemp(ZIPNAME); } -void test_teardown(void) { - remove(ZIPNAME); -} +void test_teardown(void) { remove(ZIPNAME); } MU_TEST(test_openwitherror) { - int errnum; - struct zip_t *zip = zip_openwitherror(ZIPNAME, ZIP_DEFAULT_COMPRESSION_LEVEL, 'r', &errnum); - mu_check(zip == NULL); - mu_assert_int_eq(ZIP_ERINIT, errnum); + int errnum; + struct zip_t *zip = + zip_openwitherror(ZIPNAME, ZIP_DEFAULT_COMPRESSION_LEVEL, 'r', &errnum); + mu_check(zip == NULL); + mu_assert_int_eq(ZIP_ERINIT, errnum); - zip = zip_openwitherror(ZIPNAME, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w', &errnum); - mu_check(zip != NULL); - mu_assert_int_eq(0, errnum); + zip = zip_openwitherror(ZIPNAME, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w', &errnum); + mu_check(zip != NULL); + mu_assert_int_eq(0, errnum); - zip_close(zip); + zip_close(zip); } MU_TEST(test_stream_openwitherror) { - int errnum; - struct zip_t *zip = zip_stream_openwitherror(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'r', &errnum); - mu_check(zip == NULL); - mu_assert_int_eq(ZIP_EINVMODE, errnum); - - zip = zip_stream_openwitherror(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w', &errnum); - mu_check(zip != NULL); - mu_assert_int_eq(0, errnum); - - zip_stream_close(zip); + int errnum; + struct zip_t *zip = zip_stream_openwitherror( + NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'r', &errnum); + mu_check(zip == NULL); + mu_assert_int_eq(ZIP_EINVMODE, errnum); + + zip = zip_stream_openwitherror(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w', + &errnum); + mu_check(zip != NULL); + mu_assert_int_eq(0, errnum); + + zip_stream_close(zip); } MU_TEST_SUITE(test_entry_suite) {