Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-- committed Sep 30, 2023
1 parent 70d7018 commit 8ccafba
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/miniz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <utime.h>
#endif
Expand Down
28 changes: 16 additions & 12 deletions src/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
40 changes: 23 additions & 17 deletions src/zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
43 changes: 22 additions & 21 deletions test/test_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8ccafba

Please sign in to comment.