clang-format

This commit is contained in:
Kuba Podgórski 2021-03-06 18:13:11 +01:00
parent bfcfd1aa4e
commit a631ce45f7
4 changed files with 17 additions and 13 deletions

View File

@ -6,3 +6,4 @@ for file in $(git ls-files | \grep -E '\.(c|h)$' | \grep -v -- '#')
do
clang-format -i $file
done
```

View File

@ -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));

View File

@ -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.

View File

@ -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"));