Format using clang-format.
diff --git a/lib/compat.h b/lib/compat.h
index f2a5467..6ff97b1 100644
--- a/lib/compat.h
+++ b/lib/compat.h
@@ -20,7 +20,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -51,8 +51,8 @@
#include <stdbool.h>
#else
typedef char bool;
-#define true 1
-#define false 0
+#define true 1
+#define false 0
#endif
#include <errno.h>
@@ -73,57 +73,57 @@
#ifdef _WIN32
#if defined(HAVE__CHMOD)
-#define chmod _chmod
+#define chmod _chmod
#endif
#if defined(HAVE__CLOSE)
-#define close _close
+#define close _close
#endif
#if defined(HAVE__DUP)
-#define dup _dup
+#define dup _dup
#endif
/* crashes reported when using fdopen instead of _fdopen on Windows/Visual Studio 10/Win64 */
#if defined(HAVE__FDOPEN)
-#define fdopen _fdopen
+#define fdopen _fdopen
#endif
#if !defined(HAVE_FILENO) && defined(HAVE__FILENO)
-#define fileno _fileno
+#define fileno _fileno
#endif
/* Windows' open() doesn't understand Unix permissions */
#if defined(HAVE__OPEN)
-#define open(a, b, c) _open((a), (b))
+#define open(a, b, c) _open((a), (b))
#endif
#if defined(HAVE__SNPRINTF)
-#define snprintf _snprintf
+#define snprintf _snprintf
#endif
#if defined(HAVE__STRDUP)
#if !defined(HAVE_STRDUP) || defined(_WIN32)
#undef strdup
-#define strdup _strdup
+#define strdup _strdup
#endif
#endif
#if !defined(HAVE__SETMODE) && defined(HAVE_SETMODE)
-#define _setmode setmode
+#define _setmode setmode
#endif
#if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
-#define strtoll _strtoi64
+#define strtoll _strtoi64
#endif
#if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
-#define strtoull _strtoui64
+#define strtoull _strtoui64
#endif
#if defined(HAVE__UMASK)
-#define umask _umask
+#define umask _umask
#endif
#if defined(HAVE__UNLINK)
-#define unlink _unlink
+#define unlink _unlink
#endif
#endif
#ifndef HAVE_FSEEKO
-#define fseeko(s, o, w) (fseek((s), (long int)(o), (w)))
+#define fseeko(s, o, w) (fseek((s), (long int)(o), (w)))
#endif
#ifndef HAVE_FTELLO
-#define ftello(s) ((long)ftell((s)))
+#define ftello(s) ((long)ftell((s)))
#endif
#ifndef HAVE_MKSTEMP
@@ -133,9 +133,9 @@
#if !defined(HAVE_STRCASECMP)
#if defined(HAVE__STRICMP)
-#define strcasecmp _stricmp
+#define strcasecmp _stricmp
#elif defined(HAVE_STRICMP)
-#define strcasecmp stricmp
+#define strcasecmp stricmp
#endif
#endif
@@ -190,7 +190,7 @@
#endif
#ifndef S_ISDIR
-#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
#endif
#endif /* compat.h */
diff --git a/lib/gladman-fcrypt.c b/lib/gladman-fcrypt.c
index 44622d3..53bec6a 100644
--- a/lib/gladman-fcrypt.c
+++ b/lib/gladman-fcrypt.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
diff --git a/lib/gladman-fcrypt.h b/lib/gladman-fcrypt.h
index fc61b67..8490566 100644
--- a/lib/gladman-fcrypt.h
+++ b/lib/gladman-fcrypt.h
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
diff --git a/lib/mkstemp.c b/lib/mkstemp.c
index cdfc0e2..01a531f 100644
--- a/lib/mkstemp.c
+++ b/lib/mkstemp.c
@@ -31,16 +31,16 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#ifdef _WIN32
-#include <process.h>
#include <io.h>
+#include <process.h>
#else
#include <unistd.h>
#endif
@@ -53,101 +53,101 @@
int
-_zip_mkstemp(char *path)
-{
+_zip_mkstemp(char *path) {
#ifdef _WIN32
- int ret;
- ret = _creat(_mktemp(path), _S_IREAD|_S_IWRITE);
- if (ret == -1) {
- return 0;
- } else {
- return ret;
- }
+ int ret;
+ ret = _creat(_mktemp(path), _S_IREAD | _S_IWRITE);
+ if (ret == -1) {
+ return 0;
+ }
+ else {
+ return ret;
+ }
#else
- int fd;
- char *start, *trv;
- struct stat sbuf;
- pid_t pid;
+ int fd;
+ char *start, *trv;
+ struct stat sbuf;
+ pid_t pid;
- /* To guarantee multiple calls generate unique names even if
- the file is not created. 676 different possibilities with 7
- or more X's, 26 with 6 or less. */
- static char xtra[2] = "aa";
- int xcnt = 0;
+ /* To guarantee multiple calls generate unique names even if
+ the file is not created. 676 different possibilities with 7
+ or more X's, 26 with 6 or less. */
+ static char xtra[2] = "aa";
+ int xcnt = 0;
- pid = getpid();
+ pid = getpid();
- /* Move to end of path and count trailing X's. */
- for (trv = path; *trv; ++trv)
- if (*trv == 'X')
- xcnt++;
+ /* Move to end of path and count trailing X's. */
+ for (trv = path; *trv; ++trv)
+ if (*trv == 'X')
+ xcnt++;
+ else
+ xcnt = 0;
+
+ /* Use at least one from xtra. Use 2 if more than 6 X's. */
+ if (*(trv - 1) == 'X')
+ *--trv = xtra[0];
+ if (xcnt > 6 && *(trv - 1) == 'X')
+ *--trv = xtra[1];
+
+ /* Set remaining X's to pid digits with 0's to the left. */
+ while (*--trv == 'X') {
+ *trv = (pid % 10) + '0';
+ pid /= 10;
+ }
+
+ /* update xtra for next call. */
+ if (xtra[0] != 'z')
+ xtra[0]++;
+ else {
+ xtra[0] = 'a';
+ if (xtra[1] != 'z')
+ xtra[1]++;
+ else
+ xtra[1] = 'a';
+ }
+
+ /*
+ * check the target directory; if you have six X's and it
+ * doesn't exist this runs for a *very* long time.
+ */
+ for (start = trv + 1;; --trv) {
+ if (trv <= path)
+ break;
+ if (*trv == '/') {
+ *trv = '\0';
+ if (stat(path, &sbuf))
+ return (0);
+ if (!S_ISDIR(sbuf.st_mode)) {
+ errno = ENOTDIR;
+ return (0);
+ }
+ *trv = '/';
+ break;
+ }
+ }
+
+ for (;;) {
+ if ((fd = open(path, O_CREAT | O_EXCL | O_RDWR | O_BINARY, 0600)) >= 0)
+ return (fd);
+ if (errno != EEXIST)
+ return (0);
+
+ /* tricky little algorithm for backward compatibility */
+ for (trv = start;;) {
+ if (!*trv)
+ return (0);
+ if (*trv == 'z')
+ *trv++ = 'a';
+ else {
+ if (isdigit((unsigned char)*trv))
+ *trv = 'a';
else
- xcnt = 0;
-
- /* Use at least one from xtra. Use 2 if more than 6 X's. */
- if (*(trv - 1) == 'X')
- *--trv = xtra[0];
- if (xcnt > 6 && *(trv - 1) == 'X')
- *--trv = xtra[1];
-
- /* Set remaining X's to pid digits with 0's to the left. */
- while (*--trv == 'X') {
- *trv = (pid % 10) + '0';
- pid /= 10;
+ ++*trv;
+ break;
+ }
}
-
- /* update xtra for next call. */
- if (xtra[0] != 'z')
- xtra[0]++;
- else {
- xtra[0] = 'a';
- if (xtra[1] != 'z')
- xtra[1]++;
- else
- xtra[1] = 'a';
- }
-
- /*
- * check the target directory; if you have six X's and it
- * doesn't exist this runs for a *very* long time.
- */
- for (start = trv + 1;; --trv) {
- if (trv <= path)
- break;
- if (*trv == '/') {
- *trv = '\0';
- if (stat(path, &sbuf))
- return (0);
- if (!S_ISDIR(sbuf.st_mode)) {
- errno = ENOTDIR;
- return (0);
- }
- *trv = '/';
- break;
- }
- }
-
- for (;;) {
- if ((fd=open(path, O_CREAT|O_EXCL|O_RDWR|O_BINARY, 0600)) >= 0)
- return (fd);
- if (errno != EEXIST)
- return (0);
-
- /* tricky little algorithm for backward compatibility */
- for (trv = start;;) {
- if (!*trv)
- return (0);
- if (*trv == 'z')
- *trv++ = 'a';
- else {
- if (isdigit((unsigned char)*trv))
- *trv = 'a';
- else
- ++*trv;
- break;
- }
- }
- }
+ }
/*NOTREACHED*/
#endif
}
diff --git a/lib/zip.h b/lib/zip.h
index 79a0759..2d83a99 100644
--- a/lib/zip.h
+++ b/lib/zip.h
@@ -45,195 +45,195 @@
#include <zipconf.h>
#ifndef ZIP_EXTERN
-# ifndef ZIP_STATIC
-# ifdef _WIN32
-# define ZIP_EXTERN __declspec(dllimport)
-# elif defined(__GNUC__) && __GNUC__ >= 4
-# define ZIP_EXTERN __attribute__ ((visibility ("default")))
-# else
-# define ZIP_EXTERN
-# endif
-# else
-# define ZIP_EXTERN
-# endif
+#ifndef ZIP_STATIC
+#ifdef _WIN32
+#define ZIP_EXTERN __declspec(dllimport)
+#elif defined(__GNUC__) && __GNUC__ >= 4
+#define ZIP_EXTERN __attribute__((visibility("default")))
+#else
+#define ZIP_EXTERN
+#endif
+#else
+#define ZIP_EXTERN
+#endif
#endif
-#include <sys/types.h>
#include <stdio.h>
+#include <sys/types.h>
#include <time.h>
/* flags for zip_open */
-#define ZIP_CREATE 1
-#define ZIP_EXCL 2
-#define ZIP_CHECKCONS 4
-#define ZIP_TRUNCATE 8
-#define ZIP_RDONLY 16
+#define ZIP_CREATE 1
+#define ZIP_EXCL 2
+#define ZIP_CHECKCONS 4
+#define ZIP_TRUNCATE 8
+#define ZIP_RDONLY 16
/* flags for zip_name_locate, zip_fopen, zip_stat, ... */
-#define ZIP_FL_NOCASE 1u /* ignore case on name lookup */
-#define ZIP_FL_NODIR 2u /* ignore directory component */
-#define ZIP_FL_COMPRESSED 4u /* read compressed data */
-#define ZIP_FL_UNCHANGED 8u /* use original data, ignoring changes */
-#define ZIP_FL_RECOMPRESS 16u /* force recompression of data */
-#define ZIP_FL_ENCRYPTED 32u /* read encrypted data (implies ZIP_FL_COMPRESSED) */
-#define ZIP_FL_ENC_GUESS 0u /* guess string encoding (is default) */
-#define ZIP_FL_ENC_RAW 64u /* get unmodified string */
-#define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */
-#define ZIP_FL_LOCAL 256u /* in local header */
-#define ZIP_FL_CENTRAL 512u /* in central directory */
+#define ZIP_FL_NOCASE 1u /* ignore case on name lookup */
+#define ZIP_FL_NODIR 2u /* ignore directory component */
+#define ZIP_FL_COMPRESSED 4u /* read compressed data */
+#define ZIP_FL_UNCHANGED 8u /* use original data, ignoring changes */
+#define ZIP_FL_RECOMPRESS 16u /* force recompression of data */
+#define ZIP_FL_ENCRYPTED 32u /* read encrypted data (implies ZIP_FL_COMPRESSED) */
+#define ZIP_FL_ENC_GUESS 0u /* guess string encoding (is default) */
+#define ZIP_FL_ENC_RAW 64u /* get unmodified string */
+#define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */
+#define ZIP_FL_LOCAL 256u /* in local header */
+#define ZIP_FL_CENTRAL 512u /* in central directory */
/* 1024u reserved for internal use */
-#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
-#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */
-#define ZIP_FL_OVERWRITE 8192u /* zip_file_add: if file with name exists, overwrite (replace) it */
+#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
+#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */
+#define ZIP_FL_OVERWRITE 8192u /* zip_file_add: if file with name exists, overwrite (replace) it */
/* archive global flags flags */
-#define ZIP_AFL_RDONLY 2u /* read only -- cannot be cleared */
+#define ZIP_AFL_RDONLY 2u /* read only -- cannot be cleared */
/* create a new extra field */
-#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
-#define ZIP_EXTRA_FIELD_NEW ZIP_UINT16_MAX
+#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
+#define ZIP_EXTRA_FIELD_NEW ZIP_UINT16_MAX
/* libzip error codes */
-#define ZIP_ER_OK 0 /* N No error */
-#define ZIP_ER_MULTIDISK 1 /* N Multi-disk zip archives not supported */
-#define ZIP_ER_RENAME 2 /* S Renaming temporary file failed */
-#define ZIP_ER_CLOSE 3 /* S Closing zip archive failed */
-#define ZIP_ER_SEEK 4 /* S Seek error */
-#define ZIP_ER_READ 5 /* S Read error */
-#define ZIP_ER_WRITE 6 /* S Write error */
-#define ZIP_ER_CRC 7 /* N CRC error */
-#define ZIP_ER_ZIPCLOSED 8 /* N Containing zip archive was closed */
-#define ZIP_ER_NOENT 9 /* N No such file */
-#define ZIP_ER_EXISTS 10 /* N File already exists */
-#define ZIP_ER_OPEN 11 /* S Can't open file */
-#define ZIP_ER_TMPOPEN 12 /* S Failure to create temporary file */
-#define ZIP_ER_ZLIB 13 /* Z Zlib error */
-#define ZIP_ER_MEMORY 14 /* N Malloc failure */
-#define ZIP_ER_CHANGED 15 /* N Entry has been changed */
-#define ZIP_ER_COMPNOTSUPP 16 /* N Compression method not supported */
-#define ZIP_ER_EOF 17 /* N Premature end of file */
-#define ZIP_ER_INVAL 18 /* N Invalid argument */
-#define ZIP_ER_NOZIP 19 /* N Not a zip archive */
-#define ZIP_ER_INTERNAL 20 /* N Internal error */
-#define ZIP_ER_INCONS 21 /* N Zip archive inconsistent */
-#define ZIP_ER_REMOVE 22 /* S Can't remove file */
-#define ZIP_ER_DELETED 23 /* N Entry has been deleted */
-#define ZIP_ER_ENCRNOTSUPP 24 /* N Encryption method not supported */
-#define ZIP_ER_RDONLY 25 /* N Read-only archive */
-#define ZIP_ER_NOPASSWD 26 /* N No password provided */
-#define ZIP_ER_WRONGPASSWD 27 /* N Wrong password provided */
-#define ZIP_ER_OPNOTSUPP 28 /* N Operation not supported */
-#define ZIP_ER_INUSE 29 /* N Resource still in use */
-#define ZIP_ER_TELL 30 /* S Tell error */
-#define ZIP_ER_COMPRESSED_DATA 31 /* N Compressed data invalid */
+#define ZIP_ER_OK 0 /* N No error */
+#define ZIP_ER_MULTIDISK 1 /* N Multi-disk zip archives not supported */
+#define ZIP_ER_RENAME 2 /* S Renaming temporary file failed */
+#define ZIP_ER_CLOSE 3 /* S Closing zip archive failed */
+#define ZIP_ER_SEEK 4 /* S Seek error */
+#define ZIP_ER_READ 5 /* S Read error */
+#define ZIP_ER_WRITE 6 /* S Write error */
+#define ZIP_ER_CRC 7 /* N CRC error */
+#define ZIP_ER_ZIPCLOSED 8 /* N Containing zip archive was closed */
+#define ZIP_ER_NOENT 9 /* N No such file */
+#define ZIP_ER_EXISTS 10 /* N File already exists */
+#define ZIP_ER_OPEN 11 /* S Can't open file */
+#define ZIP_ER_TMPOPEN 12 /* S Failure to create temporary file */
+#define ZIP_ER_ZLIB 13 /* Z Zlib error */
+#define ZIP_ER_MEMORY 14 /* N Malloc failure */
+#define ZIP_ER_CHANGED 15 /* N Entry has been changed */
+#define ZIP_ER_COMPNOTSUPP 16 /* N Compression method not supported */
+#define ZIP_ER_EOF 17 /* N Premature end of file */
+#define ZIP_ER_INVAL 18 /* N Invalid argument */
+#define ZIP_ER_NOZIP 19 /* N Not a zip archive */
+#define ZIP_ER_INTERNAL 20 /* N Internal error */
+#define ZIP_ER_INCONS 21 /* N Zip archive inconsistent */
+#define ZIP_ER_REMOVE 22 /* S Can't remove file */
+#define ZIP_ER_DELETED 23 /* N Entry has been deleted */
+#define ZIP_ER_ENCRNOTSUPP 24 /* N Encryption method not supported */
+#define ZIP_ER_RDONLY 25 /* N Read-only archive */
+#define ZIP_ER_NOPASSWD 26 /* N No password provided */
+#define ZIP_ER_WRONGPASSWD 27 /* N Wrong password provided */
+#define ZIP_ER_OPNOTSUPP 28 /* N Operation not supported */
+#define ZIP_ER_INUSE 29 /* N Resource still in use */
+#define ZIP_ER_TELL 30 /* S Tell error */
+#define ZIP_ER_COMPRESSED_DATA 31 /* N Compressed data invalid */
/* type of system error value */
-#define ZIP_ET_NONE 0 /* sys_err unused */
-#define ZIP_ET_SYS 1 /* sys_err is errno */
-#define ZIP_ET_ZLIB 2 /* sys_err is zlib error code */
+#define ZIP_ET_NONE 0 /* sys_err unused */
+#define ZIP_ET_SYS 1 /* sys_err is errno */
+#define ZIP_ET_ZLIB 2 /* sys_err is zlib error code */
/* compression methods */
-#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
-#define ZIP_CM_STORE 0 /* stored (uncompressed) */
-#define ZIP_CM_SHRINK 1 /* shrunk */
-#define ZIP_CM_REDUCE_1 2 /* reduced with factor 1 */
-#define ZIP_CM_REDUCE_2 3 /* reduced with factor 2 */
-#define ZIP_CM_REDUCE_3 4 /* reduced with factor 3 */
-#define ZIP_CM_REDUCE_4 5 /* reduced with factor 4 */
-#define ZIP_CM_IMPLODE 6 /* imploded */
+#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
+#define ZIP_CM_STORE 0 /* stored (uncompressed) */
+#define ZIP_CM_SHRINK 1 /* shrunk */
+#define ZIP_CM_REDUCE_1 2 /* reduced with factor 1 */
+#define ZIP_CM_REDUCE_2 3 /* reduced with factor 2 */
+#define ZIP_CM_REDUCE_3 4 /* reduced with factor 3 */
+#define ZIP_CM_REDUCE_4 5 /* reduced with factor 4 */
+#define ZIP_CM_IMPLODE 6 /* imploded */
/* 7 - Reserved for Tokenizing compression algorithm */
-#define ZIP_CM_DEFLATE 8 /* deflated */
-#define ZIP_CM_DEFLATE64 9 /* deflate64 */
-#define ZIP_CM_PKWARE_IMPLODE 10 /* PKWARE imploding */
+#define ZIP_CM_DEFLATE 8 /* deflated */
+#define ZIP_CM_DEFLATE64 9 /* deflate64 */
+#define ZIP_CM_PKWARE_IMPLODE 10 /* PKWARE imploding */
/* 11 - Reserved by PKWARE */
-#define ZIP_CM_BZIP2 12 /* compressed using BZIP2 algorithm */
+#define ZIP_CM_BZIP2 12 /* compressed using BZIP2 algorithm */
/* 13 - Reserved by PKWARE */
-#define ZIP_CM_LZMA 14 /* LZMA (EFS) */
+#define ZIP_CM_LZMA 14 /* LZMA (EFS) */
/* 15-17 - Reserved by PKWARE */
-#define ZIP_CM_TERSE 18 /* compressed using IBM TERSE (new) */
-#define ZIP_CM_LZ77 19 /* IBM LZ77 z Architecture (PFS) */
-#define ZIP_CM_XZ 95 /* XZ compressed data */
-#define ZIP_CM_JPEG 96 /* Compressed Jpeg data */
-#define ZIP_CM_WAVPACK 97 /* WavPack compressed data */
-#define ZIP_CM_PPMD 98 /* PPMd version I, Rev 1 */
+#define ZIP_CM_TERSE 18 /* compressed using IBM TERSE (new) */
+#define ZIP_CM_LZ77 19 /* IBM LZ77 z Architecture (PFS) */
+#define ZIP_CM_XZ 95 /* XZ compressed data */
+#define ZIP_CM_JPEG 96 /* Compressed Jpeg data */
+#define ZIP_CM_WAVPACK 97 /* WavPack compressed data */
+#define ZIP_CM_PPMD 98 /* PPMd version I, Rev 1 */
/* encryption methods */
-#define ZIP_EM_NONE 0 /* not encrypted */
-#define ZIP_EM_TRAD_PKWARE 1 /* traditional PKWARE encryption */
-#if 0 /* Strong Encryption Header not parsed yet */
-#define ZIP_EM_DES 0x6601 /* strong encryption: DES */
-#define ZIP_EM_RC2_OLD 0x6602 /* strong encryption: RC2, version < 5.2 */
-#define ZIP_EM_3DES_168 0x6603
-#define ZIP_EM_3DES_112 0x6609
-#define ZIP_EM_PKZIP_AES_128 0x660e
-#define ZIP_EM_PKZIP_AES_192 0x660f
-#define ZIP_EM_PKZIP_AES_256 0x6610
-#define ZIP_EM_RC2 0x6702 /* strong encryption: RC2, version >= 5.2 */
-#define ZIP_EM_RC4 0x6801
+#define ZIP_EM_NONE 0 /* not encrypted */
+#define ZIP_EM_TRAD_PKWARE 1 /* traditional PKWARE encryption */
+#if 0 /* Strong Encryption Header not parsed yet */
+#define ZIP_EM_DES 0x6601 /* strong encryption: DES */
+#define ZIP_EM_RC2_OLD 0x6602 /* strong encryption: RC2, version < 5.2 */
+#define ZIP_EM_3DES_168 0x6603
+#define ZIP_EM_3DES_112 0x6609
+#define ZIP_EM_PKZIP_AES_128 0x660e
+#define ZIP_EM_PKZIP_AES_192 0x660f
+#define ZIP_EM_PKZIP_AES_256 0x6610
+#define ZIP_EM_RC2 0x6702 /* strong encryption: RC2, version >= 5.2 */
+#define ZIP_EM_RC4 0x6801
#endif
-#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
-#define ZIP_EM_AES_192 0x0102
-#define ZIP_EM_AES_256 0x0103
-#define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */
+#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
+#define ZIP_EM_AES_192 0x0102
+#define ZIP_EM_AES_256 0x0103
+#define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */
-#define ZIP_OPSYS_DOS 0x00u
-#define ZIP_OPSYS_AMIGA 0x01u
-#define ZIP_OPSYS_OPENVMS 0x02u
-#define ZIP_OPSYS_UNIX 0x03u
-#define ZIP_OPSYS_VM_CMS 0x04u
-#define ZIP_OPSYS_ATARI_ST 0x05u
-#define ZIP_OPSYS_OS_2 0x06u
-#define ZIP_OPSYS_MACINTOSH 0x07u
-#define ZIP_OPSYS_Z_SYSTEM 0x08u
-#define ZIP_OPSYS_CPM 0x09u
-#define ZIP_OPSYS_WINDOWS_NTFS 0x0au
-#define ZIP_OPSYS_MVS 0x0bu
-#define ZIP_OPSYS_VSE 0x0cu
-#define ZIP_OPSYS_ACORN_RISC 0x0du
-#define ZIP_OPSYS_VFAT 0x0eu
-#define ZIP_OPSYS_ALTERNATE_MVS 0x0fu
-#define ZIP_OPSYS_BEOS 0x10u
-#define ZIP_OPSYS_TANDEM 0x11u
-#define ZIP_OPSYS_OS_400 0x12u
-#define ZIP_OPSYS_OS_X 0x13u
+#define ZIP_OPSYS_DOS 0x00u
+#define ZIP_OPSYS_AMIGA 0x01u
+#define ZIP_OPSYS_OPENVMS 0x02u
+#define ZIP_OPSYS_UNIX 0x03u
+#define ZIP_OPSYS_VM_CMS 0x04u
+#define ZIP_OPSYS_ATARI_ST 0x05u
+#define ZIP_OPSYS_OS_2 0x06u
+#define ZIP_OPSYS_MACINTOSH 0x07u
+#define ZIP_OPSYS_Z_SYSTEM 0x08u
+#define ZIP_OPSYS_CPM 0x09u
+#define ZIP_OPSYS_WINDOWS_NTFS 0x0au
+#define ZIP_OPSYS_MVS 0x0bu
+#define ZIP_OPSYS_VSE 0x0cu
+#define ZIP_OPSYS_ACORN_RISC 0x0du
+#define ZIP_OPSYS_VFAT 0x0eu
+#define ZIP_OPSYS_ALTERNATE_MVS 0x0fu
+#define ZIP_OPSYS_BEOS 0x10u
+#define ZIP_OPSYS_TANDEM 0x11u
+#define ZIP_OPSYS_OS_400 0x12u
+#define ZIP_OPSYS_OS_X 0x13u
-#define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX
+#define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX
enum zip_source_cmd {
- ZIP_SOURCE_OPEN, /* prepare for reading */
- ZIP_SOURCE_READ, /* read data */
- ZIP_SOURCE_CLOSE, /* reading is done */
- ZIP_SOURCE_STAT, /* get meta information */
- ZIP_SOURCE_ERROR, /* get error information */
- ZIP_SOURCE_FREE, /* cleanup and free resources */
- ZIP_SOURCE_SEEK, /* set position for reading */
- ZIP_SOURCE_TELL, /* get read position */
- ZIP_SOURCE_BEGIN_WRITE, /* prepare for writing */
- ZIP_SOURCE_COMMIT_WRITE, /* writing is done */
- ZIP_SOURCE_ROLLBACK_WRITE, /* discard written changes */
- ZIP_SOURCE_WRITE, /* write data */
- ZIP_SOURCE_SEEK_WRITE, /* set position for writing */
- ZIP_SOURCE_TELL_WRITE, /* get write position */
- ZIP_SOURCE_SUPPORTS, /* check whether source supports command */
- ZIP_SOURCE_REMOVE, /* remove file */
- ZIP_SOURCE_GET_COMPRESSION_FLAGS, /* get compression flags, internal only */
- ZIP_SOURCE_BEGIN_WRITE_CLONING /* like ZIP_SOURCE_BEGIN_WRITE, but keep part of original file */
+ ZIP_SOURCE_OPEN, /* prepare for reading */
+ ZIP_SOURCE_READ, /* read data */
+ ZIP_SOURCE_CLOSE, /* reading is done */
+ ZIP_SOURCE_STAT, /* get meta information */
+ ZIP_SOURCE_ERROR, /* get error information */
+ ZIP_SOURCE_FREE, /* cleanup and free resources */
+ ZIP_SOURCE_SEEK, /* set position for reading */
+ ZIP_SOURCE_TELL, /* get read position */
+ ZIP_SOURCE_BEGIN_WRITE, /* prepare for writing */
+ ZIP_SOURCE_COMMIT_WRITE, /* writing is done */
+ ZIP_SOURCE_ROLLBACK_WRITE, /* discard written changes */
+ ZIP_SOURCE_WRITE, /* write data */
+ ZIP_SOURCE_SEEK_WRITE, /* set position for writing */
+ ZIP_SOURCE_TELL_WRITE, /* get write position */
+ ZIP_SOURCE_SUPPORTS, /* check whether source supports command */
+ ZIP_SOURCE_REMOVE, /* remove file */
+ ZIP_SOURCE_GET_COMPRESSION_FLAGS, /* get compression flags, internal only */
+ ZIP_SOURCE_BEGIN_WRITE_CLONING /* like ZIP_SOURCE_BEGIN_WRITE, but keep part of original file */
};
typedef enum zip_source_cmd zip_source_cmd_t;
-#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1)<<(cmd))
+#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
// clang-format off
@@ -273,32 +273,32 @@
/* error information */
/* use zip_error_*() to access */
struct zip_error {
- int zip_err; /* libzip error code (ZIP_ER_*) */
- int sys_err; /* copy of errno (E*) or zlib error code */
- char *str; /* string representation or NULL */
+ int zip_err; /* libzip error code (ZIP_ER_*) */
+ int sys_err; /* copy of errno (E*) or zlib error code */
+ char *str; /* string representation or NULL */
};
-#define ZIP_STAT_NAME 0x0001u
-#define ZIP_STAT_INDEX 0x0002u
-#define ZIP_STAT_SIZE 0x0004u
-#define ZIP_STAT_COMP_SIZE 0x0008u
-#define ZIP_STAT_MTIME 0x0010u
-#define ZIP_STAT_CRC 0x0020u
-#define ZIP_STAT_COMP_METHOD 0x0040u
-#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
-#define ZIP_STAT_FLAGS 0x0100u
+#define ZIP_STAT_NAME 0x0001u
+#define ZIP_STAT_INDEX 0x0002u
+#define ZIP_STAT_SIZE 0x0004u
+#define ZIP_STAT_COMP_SIZE 0x0008u
+#define ZIP_STAT_MTIME 0x0010u
+#define ZIP_STAT_CRC 0x0020u
+#define ZIP_STAT_COMP_METHOD 0x0040u
+#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
+#define ZIP_STAT_FLAGS 0x0100u
struct zip_stat {
- zip_uint64_t valid; /* which fields have valid values */
- const char *name; /* name of the file */
- zip_uint64_t index; /* index within archive */
- zip_uint64_t size; /* size of file (uncompressed) */
- zip_uint64_t comp_size; /* size of file (compressed) */
- time_t mtime; /* modification time */
- zip_uint32_t crc; /* crc of file data */
- zip_uint16_t comp_method; /* compression method used */
- zip_uint16_t encryption_method; /* encryption method used */
- zip_uint32_t flags; /* reserved for future use */
+ zip_uint64_t valid; /* which fields have valid values */
+ const char *name; /* name of the file */
+ zip_uint64_t index; /* index within archive */
+ zip_uint64_t size; /* size of file (uncompressed) */
+ zip_uint64_t comp_size; /* size of file (compressed) */
+ time_t mtime; /* modification time */
+ zip_uint32_t crc; /* crc of file data */
+ zip_uint16_t comp_method; /* compression method used */
+ zip_uint16_t encryption_method; /* encryption method used */
+ zip_uint32_t flags; /* reserved for future use */
};
struct zip_buffer_fragment {
@@ -326,17 +326,17 @@
typedef void (*zip_progress_callback_t)(double);
ZIP_EXTERN void zip_register_progress_callback(zip_t *, zip_progress_callback_t); /* use zip_register_progress_callback_with_state */
-ZIP_EXTERN zip_int64_t zip_add(zip_t *, const char *, zip_source_t *); /* use zip_file_add */
-ZIP_EXTERN zip_int64_t zip_add_dir(zip_t *, const char *); /* use zip_dir_add */
+ZIP_EXTERN zip_int64_t zip_add(zip_t *, const char *, zip_source_t *); /* use zip_file_add */
+ZIP_EXTERN zip_int64_t zip_add_dir(zip_t *, const char *); /* use zip_dir_add */
ZIP_EXTERN const char *zip_get_file_comment(zip_t *, zip_uint64_t, int *, int); /* use zip_file_get_comment */
-ZIP_EXTERN int zip_get_num_files(zip_t *); /* use zip_get_num_entries instead */
-ZIP_EXTERN int zip_rename(zip_t *, zip_uint64_t, const char *); /* use zip_file_rename */
-ZIP_EXTERN int zip_replace(zip_t *, zip_uint64_t, zip_source_t *); /* use zip_file_replace */
-ZIP_EXTERN int zip_set_file_comment(zip_t *, zip_uint64_t, const char *, int); /* use zip_file_set_comment */
-ZIP_EXTERN int zip_error_get_sys_type(int); /* use zip_error_system_type */
-ZIP_EXTERN void zip_error_get(zip_t *, int *, int *); /* use zip_get_error, zip_error_code_zip / zip_error_code_system */
-ZIP_EXTERN int zip_error_to_str(char *, zip_uint64_t, int, int); /* use zip_error_init_with_code / zip_error_strerror */
-ZIP_EXTERN void zip_file_error_get(zip_file_t *, int *, int *); /* use zip_file_get_error, zip_error_code_zip / zip_error_code_system */
+ZIP_EXTERN int zip_get_num_files(zip_t *); /* use zip_get_num_entries instead */
+ZIP_EXTERN int zip_rename(zip_t *, zip_uint64_t, const char *); /* use zip_file_rename */
+ZIP_EXTERN int zip_replace(zip_t *, zip_uint64_t, zip_source_t *); /* use zip_file_replace */
+ZIP_EXTERN int zip_set_file_comment(zip_t *, zip_uint64_t, const char *, int); /* use zip_file_set_comment */
+ZIP_EXTERN int zip_error_get_sys_type(int); /* use zip_error_system_type */
+ZIP_EXTERN void zip_error_get(zip_t *, int *, int *); /* use zip_get_error, zip_error_code_zip / zip_error_code_system */
+ZIP_EXTERN int zip_error_to_str(char *, zip_uint64_t, int, int); /* use zip_error_init_with_code / zip_error_strerror */
+ZIP_EXTERN void zip_file_error_get(zip_file_t *, int *, int *); /* use zip_file_get_error, zip_error_code_zip / zip_error_code_system */
#endif
ZIP_EXTERN int zip_close(zip_t *);
diff --git a/lib/zip_add.c b/lib/zip_add.c
index d1be133..69966d3 100644
--- a/lib/zip_add.c
+++ b/lib/zip_add.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,13 +38,12 @@
/*
NOTE: Return type is signed so we can return -1 on error.
- The index can not be larger than ZIP_INT64_MAX since the size
- of the central directory cannot be larger than
- ZIP_UINT64_MAX, and each entry is larger than 2 bytes.
+ The index can not be larger than ZIP_INT64_MAX since the size
+ of the central directory cannot be larger than
+ ZIP_UINT64_MAX, and each entry is larger than 2 bytes.
*/
ZIP_EXTERN zip_int64_t
-zip_add(zip_t *za, const char *name, zip_source_t *source)
-{
+zip_add(zip_t *za, const char *name, zip_source_t *source) {
return zip_file_add(za, name, source, 0);
}
diff --git a/lib/zip_add_dir.c b/lib/zip_add_dir.c
index 14bdeda..a0026a7 100644
--- a/lib/zip_add_dir.c
+++ b/lib/zip_add_dir.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,7 +39,6 @@
/* NOTE: Signed due to -1 on error. See zip_add.c for more details. */
ZIP_EXTERN zip_int64_t
-zip_add_dir(zip_t *za, const char *name)
-{
+zip_add_dir(zip_t *za, const char *name) {
return zip_dir_add(za, name, 0);
}
diff --git a/lib/zip_add_entry.c b/lib/zip_add_entry.c
index f6212f1..f1de445 100644
--- a/lib/zip_add_entry.c
+++ b/lib/zip_add_entry.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -40,11 +40,10 @@
/* NOTE: Signed due to -1 on error. See zip_add.c for more details. */
zip_int64_t
-_zip_add_entry(zip_t *za)
-{
+_zip_add_entry(zip_t *za) {
zip_uint64_t idx;
- if (za->nentry+1 >= za->nentry_alloc) {
+ if (za->nentry + 1 >= za->nentry_alloc) {
zip_entry_t *rentries;
zip_uint64_t nalloc = za->nentry_alloc;
zip_uint64_t additional_entries = 2 * nalloc;
@@ -75,7 +74,7 @@
idx = za->nentry++;
- _zip_entry_init(za->entry+idx);
+ _zip_entry_init(za->entry + idx);
return (zip_int64_t)idx;
}
diff --git a/lib/zip_algorithm_bzip2.c b/lib/zip_algorithm_bzip2.c
index b07fc62..f2fb162 100644
--- a/lib/zip_algorithm_bzip2.c
+++ b/lib/zip_algorithm_bzip2.c
@@ -126,7 +126,6 @@
default:
return ZIP_ER_INTERNAL;
}
-
}
static bool
@@ -141,7 +140,6 @@
if (ctx->compress) {
ret = BZ2_bzCompressInit(&ctx->zstr, ctx->compression_flags, 0, 30);
-
}
else {
ret = BZ2_bzDecompressInit(&ctx->zstr, 0, 0);
@@ -177,7 +175,8 @@
}
-static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
+static bool
+input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
struct ctx *ctx = (struct ctx *)ud;
if (length > UINT_MAX || ctx->zstr.avail_in > 0) {
@@ -192,7 +191,8 @@
}
-static void end_of_input(void *ud) {
+static void
+end_of_input(void *ud) {
struct ctx *ctx = (struct ctx *)ud;
ctx->end_of_input = true;
@@ -226,7 +226,7 @@
case BZ_FINISH_OK: /* compression */
return ZIP_COMPRESSION_OK;
- case BZ_OK: /* decompression */
+ case BZ_OK: /* decompression */
case BZ_RUN_OK: /* compression */
if (ctx->zstr.avail_in == 0) {
return ZIP_COMPRESSION_NEED_DATA;
diff --git a/lib/zip_algorithm_deflate.c b/lib/zip_algorithm_deflate.c
index 4e4eab1..2a1c904 100644
--- a/lib/zip_algorithm_deflate.c
+++ b/lib/zip_algorithm_deflate.c
@@ -157,7 +157,8 @@
}
-static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
+static bool
+input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
struct ctx *ctx = (struct ctx *)ud;
if (length > UINT_MAX || ctx->zstr.avail_in > 0) {
@@ -172,7 +173,8 @@
}
-static void end_of_input(void *ud) {
+static void
+end_of_input(void *ud) {
struct ctx *ctx = (struct ctx *)ud;
ctx->end_of_input = true;
diff --git a/lib/zip_buffer.c b/lib/zip_buffer.c
index 7addc4b..96010b2 100644
--- a/lib/zip_buffer.c
+++ b/lib/zip_buffer.c
@@ -37,21 +37,19 @@
#include "zipint.h"
zip_uint8_t *
-_zip_buffer_data(zip_buffer_t *buffer)
-{
+_zip_buffer_data(zip_buffer_t *buffer) {
return buffer->data;
}
void
-_zip_buffer_free(zip_buffer_t *buffer)
-{
+_zip_buffer_free(zip_buffer_t *buffer) {
if (buffer == NULL) {
- return;
+ return;
}
if (buffer->free_data) {
- free(buffer->data);
+ free(buffer->data);
}
free(buffer);
@@ -59,15 +57,13 @@
bool
-_zip_buffer_eof(zip_buffer_t *buffer)
-{
+_zip_buffer_eof(zip_buffer_t *buffer) {
return buffer->ok && buffer->offset == buffer->size;
}
zip_uint8_t *
-_zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length)
-{
+_zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length) {
zip_uint8_t *data;
data = _zip_buffer_peek(buffer, length);
@@ -81,12 +77,11 @@
zip_uint16_t
-_zip_buffer_get_16(zip_buffer_t *buffer)
-{
+_zip_buffer_get_16(zip_buffer_t *buffer) {
zip_uint8_t *data = _zip_buffer_get(buffer, 2);
if (data == NULL) {
- return 0;
+ return 0;
}
return (zip_uint16_t)(data[0] + (data[1] << 8));
@@ -94,12 +89,11 @@
zip_uint32_t
-_zip_buffer_get_32(zip_buffer_t *buffer)
-{
+_zip_buffer_get_32(zip_buffer_t *buffer) {
zip_uint8_t *data = _zip_buffer_get(buffer, 4);
if (data == NULL) {
- return 0;
+ return 0;
}
return ((((((zip_uint32_t)data[3] << 8) + data[2]) << 8) + data[1]) << 8) + data[0];
@@ -107,26 +101,23 @@
zip_uint64_t
-_zip_buffer_get_64(zip_buffer_t *buffer)
-{
+_zip_buffer_get_64(zip_buffer_t *buffer) {
zip_uint8_t *data = _zip_buffer_get(buffer, 8);
if (data == NULL) {
- return 0;
+ return 0;
}
return ((zip_uint64_t)data[7] << 56) + ((zip_uint64_t)data[6] << 48) + ((zip_uint64_t)data[5] << 40) + ((zip_uint64_t)data[4] << 32) + ((zip_uint64_t)data[3] << 24) + ((zip_uint64_t)data[2] << 16) + ((zip_uint64_t)data[1] << 8) + (zip_uint64_t)data[0];
}
-
zip_uint8_t
-_zip_buffer_get_8(zip_buffer_t *buffer)
-{
+_zip_buffer_get_8(zip_buffer_t *buffer) {
zip_uint8_t *data = _zip_buffer_get(buffer, 1);
if (data == NULL) {
- return 0;
+ return 0;
}
return data[0];
@@ -134,15 +125,13 @@
zip_uint64_t
-_zip_buffer_left(zip_buffer_t *buffer)
-{
+_zip_buffer_left(zip_buffer_t *buffer) {
return buffer->ok ? buffer->size - buffer->offset : 0;
}
zip_uint64_t
-_zip_buffer_read(zip_buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length)
-{
+_zip_buffer_read(zip_buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) {
if (_zip_buffer_left(buffer) < length) {
length = _zip_buffer_left(buffer);
}
@@ -154,22 +143,21 @@
zip_buffer_t *
-_zip_buffer_new(zip_uint8_t *data, zip_uint64_t size)
-{
+_zip_buffer_new(zip_uint8_t *data, zip_uint64_t size) {
bool free_data = (data == NULL);
zip_buffer_t *buffer;
if (data == NULL) {
- if ((data = (zip_uint8_t *)malloc(size)) == NULL) {
- return NULL;
- }
+ if ((data = (zip_uint8_t *)malloc(size)) == NULL) {
+ return NULL;
+ }
}
if ((buffer = (zip_buffer_t *)malloc(sizeof(*buffer))) == NULL) {
- if (free_data) {
- free(data);
- }
- return NULL;
+ if (free_data) {
+ free(data);
+ }
+ return NULL;
}
buffer->ok = true;
@@ -183,18 +171,17 @@
zip_buffer_t *
-_zip_buffer_new_from_source(zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error)
-{
+_zip_buffer_new_from_source(zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error) {
zip_buffer_t *buffer;
if ((buffer = _zip_buffer_new(buf, size)) == NULL) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- return NULL;
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return NULL;
}
if (_zip_read(src, buffer->data, size, error) < 0) {
- _zip_buffer_free(buffer);
- return NULL;
+ _zip_buffer_free(buffer);
+ return NULL;
}
return buffer;
@@ -202,28 +189,24 @@
zip_uint64_t
-_zip_buffer_offset(zip_buffer_t *buffer)
-{
+_zip_buffer_offset(zip_buffer_t *buffer) {
return buffer->ok ? buffer->offset : 0;
}
bool
-_zip_buffer_ok(zip_buffer_t *buffer)
-{
+_zip_buffer_ok(zip_buffer_t *buffer) {
return buffer->ok;
}
-
zip_uint8_t *
-_zip_buffer_peek(zip_buffer_t *buffer, zip_uint64_t length)
-{
+_zip_buffer_peek(zip_buffer_t *buffer, zip_uint64_t length) {
zip_uint8_t *data;
if (!buffer->ok || buffer->offset + length < length || buffer->offset + length > buffer->size) {
- buffer->ok = false;
- return NULL;
+ buffer->ok = false;
+ return NULL;
}
data = buffer->data + buffer->offset;
@@ -231,12 +214,11 @@
}
int
-_zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length)
-{
+_zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length) {
zip_uint8_t *dst = _zip_buffer_get(buffer, length);
if (dst == NULL) {
- return -1;
+ return -1;
}
memcpy(dst, src, length);
@@ -245,12 +227,11 @@
int
-_zip_buffer_put_16(zip_buffer_t *buffer, zip_uint16_t i)
-{
+_zip_buffer_put_16(zip_buffer_t *buffer, zip_uint16_t i) {
zip_uint8_t *data = _zip_buffer_get(buffer, 2);
if (data == NULL) {
- return -1;
+ return -1;
}
data[0] = (zip_uint8_t)(i & 0xff);
@@ -261,12 +242,11 @@
int
-_zip_buffer_put_32(zip_buffer_t *buffer, zip_uint32_t i)
-{
+_zip_buffer_put_32(zip_buffer_t *buffer, zip_uint32_t i) {
zip_uint8_t *data = _zip_buffer_get(buffer, 4);
if (data == NULL) {
- return -1;
+ return -1;
}
data[0] = (zip_uint8_t)(i & 0xff);
@@ -279,12 +259,11 @@
int
-_zip_buffer_put_64(zip_buffer_t *buffer, zip_uint64_t i)
-{
+_zip_buffer_put_64(zip_buffer_t *buffer, zip_uint64_t i) {
zip_uint8_t *data = _zip_buffer_get(buffer, 8);
if (data == NULL) {
- return -1;
+ return -1;
}
data[0] = (zip_uint8_t)(i & 0xff);
@@ -301,12 +280,11 @@
int
-_zip_buffer_put_8(zip_buffer_t *buffer, zip_uint8_t i)
-{
+_zip_buffer_put_8(zip_buffer_t *buffer, zip_uint8_t i) {
zip_uint8_t *data = _zip_buffer_get(buffer, 1);
if (data == NULL) {
- return -1;
+ return -1;
}
data[0] = i;
@@ -316,11 +294,10 @@
int
-_zip_buffer_set_offset(zip_buffer_t *buffer, zip_uint64_t offset)
-{
+_zip_buffer_set_offset(zip_buffer_t *buffer, zip_uint64_t offset) {
if (offset > buffer->size) {
- buffer->ok = false;
- return -1;
+ buffer->ok = false;
+ return -1;
}
buffer->ok = true;
@@ -335,14 +312,13 @@
zip_uint64_t offset = buffer->offset + length;
if (offset < buffer->offset) {
- buffer->ok = false;
- return -1;
+ buffer->ok = false;
+ return -1;
}
return _zip_buffer_set_offset(buffer, offset);
}
zip_uint64_t
-_zip_buffer_size(zip_buffer_t *buffer)
-{
+_zip_buffer_size(zip_buffer_t *buffer) {
return buffer->size;
}
diff --git a/lib/zip_close.c b/lib/zip_close.c
index a4b1761..c46e1b3 100644
--- a/lib/zip_close.c
+++ b/lib/zip_close.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -43,11 +43,11 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/types.h>
#ifdef _WIN32
-#include <io.h>
#include <fcntl.h>
+#include <io.h>
#endif
@@ -57,8 +57,7 @@
static int write_cdir(zip_t *, const zip_filelist_t *, zip_uint64_t);
ZIP_EXTERN int
-zip_close(zip_t *za)
-{
+zip_close(zip_t *za) {
zip_uint64_t i, j, survivors, unchanged_offset;
zip_int64_t off;
int error;
@@ -80,7 +79,7 @@
}
zip_discard(za);
return 0;
- }
+ }
if (!changed) {
zip_discard(za);
@@ -88,102 +87,102 @@
}
if (survivors > za->nentry) {
- zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
- return -1;
+ zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
+ return -1;
}
-
- if ((filelist=(zip_filelist_t *)malloc(sizeof(filelist[0])*(size_t)survivors)) == NULL)
+
+ if ((filelist = (zip_filelist_t *)malloc(sizeof(filelist[0]) * (size_t)survivors)) == NULL)
return -1;
unchanged_offset = ZIP_UINT64_MAX;
/* create list of files with index into original archive */
- for (i=j=0; i<za->nentry; i++) {
- if (za->entry[i].orig != NULL && ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
- unchanged_offset = ZIP_MIN(unchanged_offset, za->entry[i].orig->offset);
- }
- if (za->entry[i].deleted) {
+ for (i = j = 0; i < za->nentry; i++) {
+ if (za->entry[i].orig != NULL && ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
+ unchanged_offset = ZIP_MIN(unchanged_offset, za->entry[i].orig->offset);
+ }
+ if (za->entry[i].deleted) {
continue;
- }
+ }
- if (j >= survivors) {
- free(filelist);
- zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
- return -1;
- }
-
+ if (j >= survivors) {
+ free(filelist);
+ zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
+ return -1;
+ }
+
filelist[j].idx = i;
j++;
}
if (j < survivors) {
- free(filelist);
- zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
- return -1;
+ free(filelist);
+ zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
+ return -1;
}
if ((zip_source_supports(za->src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING)) == 0) {
- unchanged_offset = 0;
+ unchanged_offset = 0;
}
else {
- if (unchanged_offset == ZIP_UINT64_MAX) {
- /* we're keeping all file data, find the end of the last one */
- zip_uint64_t last_index = ZIP_UINT64_MAX;
- unchanged_offset = 0;
+ if (unchanged_offset == ZIP_UINT64_MAX) {
+ /* we're keeping all file data, find the end of the last one */
+ zip_uint64_t last_index = ZIP_UINT64_MAX;
+ unchanged_offset = 0;
- for (i = 0; i < za->nentry; i++) {
- if (za->entry[i].orig != NULL) {
- if (za->entry[i].orig->offset >= unchanged_offset) {
- unchanged_offset = za->entry[i].orig->offset;
- last_index = i;
- }
- }
- }
- if (last_index != ZIP_UINT64_MAX) {
- if ((unchanged_offset = _zip_file_get_end(za, last_index, &za->error)) == 0) {
- free(filelist);
- return -1;
- }
- }
- }
- if (unchanged_offset > 0) {
- if (zip_source_begin_write_cloning(za->src, unchanged_offset) < 0) {
- /* cloning not supported, need to copy everything */
- unchanged_offset = 0;
- }
- }
+ for (i = 0; i < za->nentry; i++) {
+ if (za->entry[i].orig != NULL) {
+ if (za->entry[i].orig->offset >= unchanged_offset) {
+ unchanged_offset = za->entry[i].orig->offset;
+ last_index = i;
+ }
+ }
+ }
+ if (last_index != ZIP_UINT64_MAX) {
+ if ((unchanged_offset = _zip_file_get_end(za, last_index, &za->error)) == 0) {
+ free(filelist);
+ return -1;
+ }
+ }
+ }
+ if (unchanged_offset > 0) {
+ if (zip_source_begin_write_cloning(za->src, unchanged_offset) < 0) {
+ /* cloning not supported, need to copy everything */
+ unchanged_offset = 0;
+ }
+ }
}
if (unchanged_offset == 0) {
- if (zip_source_begin_write(za->src) < 0) {
- _zip_error_set_from_source(&za->error, za->src);
- free(filelist);
- return -1;
- }
+ if (zip_source_begin_write(za->src) < 0) {
+ _zip_error_set_from_source(&za->error, za->src);
+ free(filelist);
+ return -1;
+ }
}
_zip_progress_start(za->progress);
error = 0;
- for (j=0; j<survivors; j++) {
+ for (j = 0; j < survivors; j++) {
int new_data;
zip_entry_t *entry;
zip_dirent_t *de;
- _zip_progress_subrange(za->progress, (double)j / (double)survivors, (double)(j+1) / (double)survivors);
+ _zip_progress_subrange(za->progress, (double)j / (double)survivors, (double)(j + 1) / (double)survivors);
i = filelist[j].idx;
- entry = za->entry+i;
+ entry = za->entry + i;
- if (entry->orig != NULL && entry->orig->offset < unchanged_offset) {
- /* already implicitly copied by cloning */
- continue;
- }
+ if (entry->orig != NULL && entry->orig->offset < unchanged_offset) {
+ /* already implicitly copied by cloning */
+ continue;
+ }
new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD));
/* create new local directory entry */
if (entry->changes == NULL) {
- if ((entry->changes=_zip_dirent_clone(entry->orig)) == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- error = 1;
- break;
+ if ((entry->changes = _zip_dirent_clone(entry->orig)) == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ error = 1;
+ break;
}
}
de = entry->changes;
@@ -193,18 +192,18 @@
break;
}
- if ((off = zip_source_tell_write(za->src)) < 0) {
- error = 1;
- break;
- }
- de->offset = (zip_uint64_t)off;
+ if ((off = zip_source_tell_write(za->src)) < 0) {
+ error = 1;
+ break;
+ }
+ de->offset = (zip_uint64_t)off;
if (new_data) {
zip_source_t *zs;
zs = NULL;
if (!ZIP_ENTRY_DATA_CHANGED(entry)) {
- if ((zs=_zip_source_zip_new(za, za, i, ZIP_FL_UNCHANGED, 0, 0, NULL)) == NULL) {
+ if ((zs = _zip_source_zip_new(za, za, i, ZIP_FL_UNCHANGED, 0, 0, NULL)) == NULL) {
error = 1;
break;
}
@@ -229,7 +228,7 @@
error = 1;
break;
}
- if ((offset=_zip_file_get_offset(za, i, &za->error)) == 0) {
+ if ((offset = _zip_file_get_offset(za, i, &za->error)) == 0) {
error = 1;
break;
}
@@ -263,7 +262,7 @@
if (error) {
zip_source_rollback_write(za->src);
- return -1;
+ return -1;
}
zip_discard(za);
@@ -273,8 +272,7 @@
static int
-add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de)
-{
+add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de) {
zip_int64_t offstart, offdata, offend, data_length;
struct zip_stat st;
zip_source_t *src_final, *src_tmp;
@@ -320,7 +318,7 @@
de->uncomp_size = st.size;
/* this is technically incorrect (copy_source counts compressed data), but it's the best we have */
data_length = (zip_int64_t)st.size;
-
+
if ((st.valid & ZIP_STAT_COMP_SIZE) == 0) {
zip_uint64_t max_size;
@@ -354,12 +352,12 @@
if ((offstart = zip_source_tell_write(za->src)) < 0) {
_zip_error_set_from_source(&za->error, za->src);
- return -1;
+ return -1;
}
/* as long as we don't support non-seekable output, clear data descriptor bit */
de->bitflags &= (zip_uint16_t)~ZIP_GPBF_DATA_DESCRIPTOR;
- if ((is_zip64=_zip_dirent_write(za, de, flags)) < 0) {
+ if ((is_zip64 = _zip_dirent_write(za, de, flags)) < 0) {
return -1;
}
@@ -377,7 +375,7 @@
if (needs_decrypt) {
zip_encryption_implementation impl;
-
+
if ((impl = _zip_get_encryption_implementation(st.encryption_method, ZIP_CODEC_DECODE)) == NULL) {
zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
zip_source_free(src_final);
@@ -392,7 +390,7 @@
zip_source_free(src_final);
src_final = src_tmp;
}
-
+
if (needs_decompress) {
if ((src_tmp = zip_source_decompress(za, src_final, st.comp_method)) == NULL) {
zip_source_free(src_final);
@@ -418,22 +416,23 @@
zip_source_free(src_final);
return -1;
}
-
+
zip_source_free(src_final);
src_final = src_tmp;
}
-
+
if (needs_encrypt) {
zip_encryption_implementation impl;
const char *password = NULL;
if (de->password) {
password = de->password;
- } else if (za->default_password) {
+ }
+ else if (za->default_password) {
password = za->default_password;
}
-
+
if ((impl = _zip_get_encryption_implementation(de->encryption_method, ZIP_CODEC_ENCODE)) == NULL) {
zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
zip_source_free(src_final);
@@ -452,11 +451,11 @@
if ((offdata = zip_source_tell_write(za->src)) < 0) {
_zip_error_set_from_source(&za->error, za->src);
- return -1;
+ return -1;
}
ret = copy_source(za, src_final, data_length);
-
+
if (zip_source_stat(src_final, &st) < 0) {
_zip_error_set_from_source(&za->error, src_final);
ret = -1;
@@ -475,7 +474,7 @@
if ((offend = zip_source_tell_write(za->src)) < 0) {
_zip_error_set_from_source(&za->error, za->src);
- return -1;
+ return -1;
}
if (zip_source_seek_write(za->src, offstart, SEEK_SET) < 0) {
@@ -483,16 +482,16 @@
return -1;
}
- if ((st.valid & (ZIP_STAT_COMP_METHOD|ZIP_STAT_CRC|ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD|ZIP_STAT_CRC|ZIP_STAT_SIZE)) {
+ if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
return -1;
}
if ((de->changed & ZIP_DIRENT_LAST_MOD) == 0) {
- if (st.valid & ZIP_STAT_MTIME)
- de->last_mod = st.mtime;
- else
- time(&de->last_mod);
+ if (st.valid & ZIP_STAT_MTIME)
+ de->last_mod = st.mtime;
+ else
+ time(&de->last_mod);
}
de->comp_method = st.comp_method;
de->crc = st.crc;
@@ -500,16 +499,16 @@
de->comp_size = (zip_uint64_t)(offend - offdata);
de->bitflags = (zip_uint16_t)((de->bitflags & (zip_uint16_t)~6) | ((zip_uint8_t)compression_flags << 1));
_zip_dirent_set_version_needed(de, (flags & ZIP_FL_FORCE_ZIP64) != 0);
-
- if ((ret=_zip_dirent_write(za, de, flags)) < 0)
+
+ if ((ret = _zip_dirent_write(za, de, flags)) < 0)
return -1;
-
+
if (is_zip64 != ret) {
/* Zip64 mismatch between preliminary file header written before data and final file header written afterwards */
zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
return -1;
}
-
+
if (zip_source_seek_write(za->src, offend, SEEK_SET) < 0) {
_zip_error_set_from_source(&za->error, za->src);
return -1;
@@ -520,8 +519,7 @@
static int
-copy_data(zip_t *za, zip_uint64_t len)
-{
+copy_data(zip_t *za, zip_uint64_t len) {
zip_uint8_t buf[BUFSIZE];
size_t n;
double total = (double)len;
@@ -535,10 +533,10 @@
if (_zip_write(za, buf, n) < 0) {
return -1;
}
-
+
len -= n;
- _zip_progress_update(za->progress, (total - (double)len) / total);
+ _zip_progress_update(za->progress, (total - (double)len) / total);
}
return 0;
@@ -546,8 +544,7 @@
static int
-copy_source(zip_t *za, zip_source_t *src, zip_int64_t data_length)
-{
+copy_source(zip_t *za, zip_source_t *src, zip_int64_t data_length) {
zip_uint8_t buf[BUFSIZE];
zip_int64_t n, current;
int ret;
@@ -559,42 +556,41 @@
ret = 0;
current = 0;
- while ((n=zip_source_read(src, buf, sizeof(buf))) > 0) {
+ while ((n = zip_source_read(src, buf, sizeof(buf))) > 0) {
if (_zip_write(za, buf, (zip_uint64_t)n) < 0) {
ret = -1;
break;
}
if (n == sizeof(buf) && za->progress && data_length > 0) {
current += n;
- _zip_progress_update(za->progress, (double)current/(double)data_length);
+ _zip_progress_update(za->progress, (double)current / (double)data_length);
}
}
-
+
if (n < 0) {
_zip_error_set_from_source(&za->error, src);
ret = -1;
}
zip_source_close(src);
-
+
return ret;
}
static int
-write_cdir(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors)
-{
+write_cdir(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors) {
zip_int64_t cd_start, end, size;
-
- if ((cd_start = zip_source_tell_write(za->src)) < 0) {
- return -1;
- }
- if ((size=_zip_cdir_write(za, filelist, survivors)) < 0) {
+ if ((cd_start = zip_source_tell_write(za->src)) < 0) {
return -1;
}
-
+
+ if ((size = _zip_cdir_write(za, filelist, survivors)) < 0) {
+ return -1;
+ }
+
if ((end = zip_source_tell_write(za->src)) < 0) {
- return -1;
+ return -1;
}
return 0;
@@ -602,8 +598,7 @@
int
-_zip_changed(const zip_t *za, zip_uint64_t *survivorsp)
-{
+_zip_changed(const zip_t *za, zip_uint64_t *survivorsp) {
int changed;
zip_uint64_t i, survivors;
@@ -614,13 +609,13 @@
changed = 1;
}
- for (i=0; i<za->nentry; i++) {
- if (ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
+ for (i = 0; i < za->nentry; i++) {
+ if (ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
changed = 1;
- }
- if (!za->entry[i].deleted) {
- survivors++;
- }
+ }
+ if (!za->entry[i].deleted) {
+ survivors++;
+ }
}
if (survivorsp) {
diff --git a/lib/zip_delete.c b/lib/zip_delete.c
index e160210..ae8f5a6 100644
--- a/lib/zip_delete.c
+++ b/lib/zip_delete.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
ZIP_EXTERN int
-zip_delete(zip_t *za, zip_uint64_t idx)
-{
+zip_delete(zip_t *za, zip_uint64_t idx) {
const char *name;
if (idx >= za->nentry) {
@@ -50,7 +49,7 @@
return -1;
}
- if ((name=_zip_get_name(za, idx, 0, &za->error)) == NULL) {
+ if ((name = _zip_get_name(za, idx, 0, &za->error)) == NULL) {
return -1;
}
@@ -67,4 +66,3 @@
return 0;
}
-
diff --git a/lib/zip_dir_add.c b/lib/zip_dir_add.c
index f535b21..236b439 100644
--- a/lib/zip_dir_add.c
+++ b/lib/zip_dir_add.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -41,8 +41,7 @@
/* NOTE: Signed due to -1 on error. See zip_add.c for more details. */
ZIP_EXTERN zip_int64_t
-zip_dir_add(zip_t *za, const char *name, zip_flags_t flags)
-{
+zip_dir_add(zip_t *za, const char *name, zip_flags_t flags) {
size_t len;
zip_int64_t idx;
char *s;
@@ -61,21 +60,21 @@
s = NULL;
len = strlen(name);
- if (name[len-1] != '/') {
- if ((s=(char *)malloc(len+2)) == NULL) {
+ if (name[len - 1] != '/') {
+ if ((s = (char *)malloc(len + 2)) == NULL) {
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return -1;
}
strcpy(s, name);
s[len] = '/';
- s[len+1] = '\0';
+ s[len + 1] = '\0';
}
- if ((source=zip_source_buffer(za, NULL, 0, 0)) == NULL) {
+ if ((source = zip_source_buffer(za, NULL, 0, 0)) == NULL) {
free(s);
return -1;
}
-
+
idx = _zip_file_replace(za, ZIP_UINT64_MAX, s ? s : name, source, flags);
free(s);
diff --git a/lib/zip_dirent.c b/lib/zip_dirent.c
index b9feb84..060e1e9 100644
--- a/lib/zip_dirent.c
+++ b/lib/zip_dirent.c
@@ -35,8 +35,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <time.h>
#include "zipint.h"
@@ -48,15 +48,14 @@
void
-_zip_cdir_free(zip_cdir_t *cd)
-{
+_zip_cdir_free(zip_cdir_t *cd) {
zip_uint64_t i;
if (!cd)
return;
- for (i=0; i<cd->nentry; i++)
- _zip_entry_finalize(cd->entry+i);
+ for (i = 0; i < cd->nentry; i++)
+ _zip_entry_finalize(cd->entry + i);
free(cd->entry);
_zip_string_free(cd->comment);
free(cd);
@@ -64,11 +63,10 @@
zip_cdir_t *
-_zip_cdir_new(zip_uint64_t nentry, zip_error_t *error)
-{
+_zip_cdir_new(zip_uint64_t nentry, zip_error_t *error) {
zip_cdir_t *cd;
- if ((cd=(zip_cdir_t *)malloc(sizeof(*cd))) == NULL) {
+ if ((cd = (zip_cdir_t *)malloc(sizeof(*cd))) == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return NULL;
}
@@ -89,8 +87,7 @@
bool
-_zip_cdir_grow(zip_cdir_t *cd, zip_uint64_t additional_entries, zip_error_t *error)
-{
+_zip_cdir_grow(zip_cdir_t *cd, zip_uint64_t additional_entries, zip_error_t *error) {
zip_uint64_t i, new_alloc;
zip_entry_t *new_entry;
@@ -100,12 +97,12 @@
new_alloc = cd->nentry_alloc + additional_entries;
- if (new_alloc < additional_entries || new_alloc > SIZE_MAX/sizeof(*(cd->entry))) {
+ if (new_alloc < additional_entries || new_alloc > SIZE_MAX / sizeof(*(cd->entry))) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return false;
}
- if ((new_entry = (zip_entry_t *)realloc(cd->entry, sizeof(*(cd->entry))*(size_t)new_alloc)) == NULL) {
+ if ((new_entry = (zip_entry_t *)realloc(cd->entry, sizeof(*(cd->entry)) * (size_t)new_alloc)) == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return false;
}
@@ -113,7 +110,7 @@
cd->entry = new_entry;
for (i = cd->nentry; i < new_alloc; i++) {
- _zip_entry_init(cd->entry+i);
+ _zip_entry_init(cd->entry + i);
}
cd->nentry = cd->nentry_alloc = new_alloc;
@@ -123,8 +120,7 @@
zip_int64_t
-_zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors)
-{
+_zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors) {
zip_uint64_t offset, size;
zip_string_t *comment;
zip_uint8_t buf[EOCDLEN + EOCD64LEN + EOCD64LOCLEN];
@@ -135,25 +131,25 @@
int ret;
if ((off = zip_source_tell_write(za->src)) < 0) {
- _zip_error_set_from_source(&za->error, za->src);
- return -1;
+ _zip_error_set_from_source(&za->error, za->src);
+ return -1;
}
offset = (zip_uint64_t)off;
is_zip64 = false;
- for (i=0; i<survivors; i++) {
- zip_entry_t *entry = za->entry+filelist[i].idx;
+ for (i = 0; i < survivors; i++) {
+ zip_entry_t *entry = za->entry + filelist[i].idx;
- if ((ret=_zip_dirent_write(za, entry->changes ? entry->changes : entry->orig, ZIP_FL_CENTRAL)) < 0)
+ if ((ret = _zip_dirent_write(za, entry->changes ? entry->changes : entry->orig, ZIP_FL_CENTRAL)) < 0)
return -1;
if (ret)
is_zip64 = true;
}
if ((off = zip_source_tell_write(za->src)) < 0) {
- _zip_error_set_from_source(&za->error, za->src);
- return -1;
+ _zip_error_set_from_source(&za->error, za->src);
+ return -1;
}
size = (zip_uint64_t)off - offset;
@@ -162,13 +158,13 @@
if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- return -1;
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return -1;
}
if (is_zip64) {
_zip_buffer_put(buffer, EOCD64_MAGIC, 4);
- _zip_buffer_put_64(buffer, EOCD64LEN-12);
+ _zip_buffer_put_64(buffer, EOCD64LEN - 12);
_zip_buffer_put_16(buffer, 45);
_zip_buffer_put_16(buffer, 45);
_zip_buffer_put_32(buffer, 0);
@@ -179,7 +175,7 @@
_zip_buffer_put_64(buffer, offset);
_zip_buffer_put(buffer, EOCD64LOC_MAGIC, 4);
_zip_buffer_put_32(buffer, 0);
- _zip_buffer_put_64(buffer, offset+size);
+ _zip_buffer_put_64(buffer, offset + size);
_zip_buffer_put_32(buffer, 1);
}
@@ -195,13 +191,13 @@
_zip_buffer_put_16(buffer, (zip_uint16_t)(comment ? comment->length : 0));
if (!_zip_buffer_ok(buffer)) {
- zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
- _zip_buffer_free(buffer);
- return -1;
+ zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
+ _zip_buffer_free(buffer);
+ return -1;
}
if (_zip_write(za, _zip_buffer_data(buffer), _zip_buffer_offset(buffer)) < 0) {
- _zip_buffer_free(buffer);
+ _zip_buffer_free(buffer);
return -1;
}
@@ -218,11 +214,10 @@
zip_dirent_t *
-_zip_dirent_clone(const zip_dirent_t *sde)
-{
+_zip_dirent_clone(const zip_dirent_t *sde) {
zip_dirent_t *tde;
- if ((tde=(zip_dirent_t *)malloc(sizeof(*tde))) == NULL)
+ if ((tde = (zip_dirent_t *)malloc(sizeof(*tde))) == NULL)
return NULL;
if (sde)
@@ -238,8 +233,7 @@
void
-_zip_dirent_finalize(zip_dirent_t *zde)
-{
+_zip_dirent_finalize(zip_dirent_t *zde) {
if (!zde->cloned || zde->changed & ZIP_DIRENT_FILENAME) {
_zip_string_free(zde->filename);
zde->filename = NULL;
@@ -263,8 +257,7 @@
void
-_zip_dirent_free(zip_dirent_t *zde)
-{
+_zip_dirent_free(zip_dirent_t *zde) {
if (zde == NULL)
return;
@@ -274,8 +267,7 @@
void
-_zip_dirent_init(zip_dirent_t *de)
-{
+_zip_dirent_init(zip_dirent_t *de) {
de->changed = 0;
de->local_extra_fields_read = 0;
de->cloned = 0;
@@ -303,10 +295,8 @@
bool
-_zip_dirent_needs_zip64(const zip_dirent_t *de, zip_flags_t flags)
-{
- if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX
- || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX))
+_zip_dirent_needs_zip64(const zip_dirent_t *de, zip_flags_t flags) {
+ if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX))
return true;
return false;
@@ -314,11 +304,10 @@
zip_dirent_t *
-_zip_dirent_new(void)
-{
+_zip_dirent_new(void) {
zip_dirent_t *de;
- if ((de=(zip_dirent_t *)malloc(sizeof(*de))) == NULL)
+ if ((de = (zip_dirent_t *)malloc(sizeof(*de))) == NULL)
return NULL;
_zip_dirent_init(de);
@@ -337,8 +326,7 @@
*/
zip_int64_t
-_zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, bool local, zip_error_t *error)
-{
+_zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, bool local, zip_error_t *error) {
zip_uint8_t buf[CDENTRYSIZE];
zip_uint16_t dostime, dosdate;
zip_uint32_t size, variable_size;
@@ -349,22 +337,22 @@
size = local ? LENTRYSIZE : CDENTRYSIZE;
if (buffer) {
- if (_zip_buffer_left(buffer) < size) {
- zip_error_set(error, ZIP_ER_NOZIP, 0);
- return -1;
- }
+ if (_zip_buffer_left(buffer) < size) {
+ zip_error_set(error, ZIP_ER_NOZIP, 0);
+ return -1;
+ }
}
else {
- if ((buffer = _zip_buffer_new_from_source(src, size, buf, error)) == NULL) {
- return -1;
- }
+ if ((buffer = _zip_buffer_new_from_source(src, size, buf, error)) == NULL) {
+ return -1;
+ }
}
if (memcmp(_zip_buffer_get(buffer, 4), (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
zip_error_set(error, ZIP_ER_NOZIP, 0);
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
return -1;
}
@@ -397,7 +385,8 @@
zde->int_attrib = 0;
zde->ext_attrib = 0;
zde->offset = 0;
- } else {
+ }
+ else {
comment_len = _zip_buffer_get_16(buffer);
zde->disk_number = _zip_buffer_get_16(buffer);
zde->int_attrib = _zip_buffer_get_16(buffer);
@@ -406,11 +395,11 @@
}
if (!_zip_buffer_ok(buffer)) {
- zip_error_set(error, ZIP_ER_INTERNAL, 0);
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
- return -1;
+ zip_error_set(error, ZIP_ER_INTERNAL, 0);
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
+ return -1;
}
if (zde->bitflags & ZIP_GPBF_ENCRYPTED) {
@@ -430,40 +419,40 @@
zde->extra_fields = NULL;
zde->comment = NULL;
- variable_size = (zip_uint32_t)filename_len+(zip_uint32_t)ef_len+(zip_uint32_t)comment_len;
+ variable_size = (zip_uint32_t)filename_len + (zip_uint32_t)ef_len + (zip_uint32_t)comment_len;
if (from_buffer) {
- if (_zip_buffer_left(buffer) < variable_size) {
- zip_error_set(error, ZIP_ER_INCONS, 0);
- return -1;
- }
+ if (_zip_buffer_left(buffer) < variable_size) {
+ zip_error_set(error, ZIP_ER_INCONS, 0);
+ return -1;
+ }
}
else {
- _zip_buffer_free(buffer);
+ _zip_buffer_free(buffer);
- if ((buffer = _zip_buffer_new_from_source(src, variable_size, NULL, error)) == NULL) {
- return -1;
- }
+ if ((buffer = _zip_buffer_new_from_source(src, variable_size, NULL, error)) == NULL) {
+ return -1;
+ }
}
if (filename_len) {
zde->filename = _zip_read_string(buffer, src, filename_len, 1, error);
- if (!zde->filename) {
- if (zip_error_code_zip(error) == ZIP_ER_EOF) {
- zip_error_set(error, ZIP_ER_INCONS, 0);
- }
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (!zde->filename) {
+ if (zip_error_code_zip(error) == ZIP_ER_EOF) {
+ zip_error_set(error, ZIP_ER_INCONS, 0);
+ }
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
return -1;
- }
+ }
if (zde->bitflags & ZIP_GPBF_ENCODING_UTF_8) {
if (_zip_guess_encoding(zde->filename, ZIP_ENCODING_UTF8_KNOWN) == ZIP_ENCODING_ERROR) {
zip_error_set(error, ZIP_ER_INCONS, 0);
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
return -1;
}
}
@@ -472,17 +461,17 @@
if (ef_len) {
zip_uint8_t *ef = _zip_read_data(buffer, src, ef_len, 0, error);
- if (ef == NULL) {
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (ef == NULL) {
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
return -1;
- }
- if (!_zip_ef_parse(ef, ef_len, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, &zde->extra_fields, error)) {
+ }
+ if (!_zip_ef_parse(ef, ef_len, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, &zde->extra_fields, error)) {
free(ef);
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
return -1;
}
free(ef);
@@ -492,18 +481,18 @@
if (comment_len) {
zde->comment = _zip_read_string(buffer, src, comment_len, 0, error);
- if (!zde->comment) {
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (!zde->comment) {
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
return -1;
- }
+ }
if (zde->bitflags & ZIP_GPBF_ENCODING_UTF_8) {
if (_zip_guess_encoding(zde->comment, ZIP_ENCODING_UTF8_KNOWN) == ZIP_ENCODING_ERROR) {
zip_error_set(error, ZIP_ER_INCONS, 0);
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
return -1;
}
}
@@ -516,30 +505,30 @@
if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) {
zip_uint16_t got_len;
- zip_buffer_t *ef_buffer;
+ zip_buffer_t *ef_buffer;
const zip_uint8_t *ef = _zip_ef_get_by_id(zde->extra_fields, &got_len, ZIP_EF_ZIP64, 0, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error);
/* TODO: if got_len == 0 && !ZIP64_EOCD: no error, 0xffffffff is valid value */
- if (ef == NULL) {
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (ef == NULL) {
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
return -1;
- }
+ }
- if ((ef_buffer = _zip_buffer_new((zip_uint8_t *)ef, got_len)) == NULL) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
- return -1;
- }
+ if ((ef_buffer = _zip_buffer_new((zip_uint8_t *)ef, got_len)) == NULL) {
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
+ return -1;
+ }
if (zde->uncomp_size == ZIP_UINT32_MAX)
zde->uncomp_size = _zip_buffer_get_64(ef_buffer);
else if (local) {
/* From appnote.txt: This entry in the Local header MUST
include BOTH original and compressed file size fields. */
- (void)_zip_buffer_skip(ef_buffer, 8); /* error is caught by _zip_buffer_eof() call */
+ (void)_zip_buffer_skip(ef_buffer, 8); /* error is caught by _zip_buffer_eof() call */
}
if (zde->comp_size == ZIP_UINT32_MAX)
zde->comp_size = _zip_buffer_get_64(ef_buffer);
@@ -550,26 +539,26 @@
zde->disk_number = _zip_buffer_get_32(buffer);
}
- if (!_zip_buffer_eof(ef_buffer)) {
- zip_error_set(error, ZIP_ER_INCONS, 0);
- _zip_buffer_free(ef_buffer);
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
- return -1;
- }
- _zip_buffer_free(ef_buffer);
+ if (!_zip_buffer_eof(ef_buffer)) {
+ zip_error_set(error, ZIP_ER_INCONS, 0);
+ _zip_buffer_free(ef_buffer);
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
+ return -1;
+ }
+ _zip_buffer_free(ef_buffer);
}
if (!_zip_buffer_ok(buffer)) {
- zip_error_set(error, ZIP_ER_INTERNAL, 0);
- if (!from_buffer) {
- _zip_buffer_free(buffer);
- }
- return -1;
+ zip_error_set(error, ZIP_ER_INTERNAL, 0);
+ if (!from_buffer) {
+ _zip_buffer_free(buffer);
+ }
+ return -1;
}
if (!from_buffer) {
- _zip_buffer_free(buffer);
+ _zip_buffer_free(buffer);
}
/* zip_source_seek / zip_source_tell don't support values > ZIP_INT64_MAX */
@@ -589,8 +578,7 @@
static zip_string_t *
-_zip_dirent_process_ef_utf_8(const zip_dirent_t *de, zip_uint16_t id, zip_string_t *str)
-{
+_zip_dirent_process_ef_utf_8(const zip_dirent_t *de, zip_uint16_t id, zip_string_t *str) {
zip_uint16_t ef_len;
zip_uint32_t ef_crc;
zip_buffer_t *buffer;
@@ -602,15 +590,15 @@
}
if ((buffer = _zip_buffer_new((zip_uint8_t *)ef, ef_len)) == NULL) {
- return str;
+ return str;
}
_zip_buffer_get_8(buffer);
ef_crc = _zip_buffer_get_32(buffer);
if (_zip_string_crc32(str) == ef_crc) {
- zip_uint16_t len = (zip_uint16_t)_zip_buffer_left(buffer);
- zip_string_t *ef_str = _zip_string_new(_zip_buffer_get(buffer, len), len, ZIP_FL_ENC_UTF_8, NULL);
+ zip_uint16_t len = (zip_uint16_t)_zip_buffer_left(buffer);
+ zip_string_t *ef_str = _zip_string_new(_zip_buffer_get(buffer, len), len, ZIP_FL_ENC_UTF_8, NULL);
if (ef_str != NULL) {
_zip_string_free(str);
@@ -625,8 +613,7 @@
static bool
-_zip_dirent_process_winzip_aes(zip_dirent_t *de, zip_error_t *error)
-{
+_zip_dirent_process_winzip_aes(zip_dirent_t *de, zip_error_t *error) {
zip_uint16_t ef_len;
zip_buffer_t *buffer;
const zip_uint8_t *ef;
@@ -647,7 +634,7 @@
if ((buffer = _zip_buffer_new((zip_uint8_t *)ef, ef_len)) == NULL) {
zip_error_set(error, ZIP_ER_INTERNAL, 0);
- return false;
+ return false;
}
/* version */
@@ -709,8 +696,7 @@
zip_int32_t
-_zip_dirent_size(zip_source_t *src, zip_uint16_t flags, zip_error_t *error)
-{
+_zip_dirent_size(zip_source_t *src, zip_uint16_t flags, zip_error_t *error) {
zip_int32_t size;
bool local = (flags & ZIP_EF_LOCAL) != 0;
int i;
@@ -720,7 +706,7 @@
size = local ? LENTRYSIZE : CDENTRYSIZE;
if (zip_source_seek(src, local ? 26 : 28, SEEK_CUR) < 0) {
- _zip_error_set_from_source(error, src);
+ _zip_error_set_from_source(error, src);
return -1;
}
@@ -728,14 +714,14 @@
return -1;
}
- for (i=0; i<(local ? 2 : 3); i++) {
+ for (i = 0; i < (local ? 2 : 3); i++) {
size += _zip_buffer_get_16(buffer);
}
if (!_zip_buffer_eof(buffer)) {
- zip_error_set(error, ZIP_ER_INTERNAL, 0);
+ zip_error_set(error, ZIP_ER_INTERNAL, 0);
_zip_buffer_free(buffer);
- return -1;
+ return -1;
}
_zip_buffer_free(buffer);
@@ -754,8 +740,7 @@
*/
int
-_zip_dirent_write(zip_t *za, zip_dirent_t *de, zip_flags_t flags)
-{
+_zip_dirent_write(zip_t *za, zip_dirent_t *de, zip_flags_t flags) {
zip_uint16_t dostime, dosdate;
zip_encoding_type_t com_enc, name_enc;
zip_extra_field_t *ef;
@@ -772,9 +757,7 @@
name_enc = _zip_guess_encoding(de->filename, ZIP_ENCODING_UNKNOWN);
com_enc = _zip_guess_encoding(de->comment, ZIP_ENCODING_UNKNOWN);
- if ((name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_ASCII) ||
- (name_enc == ZIP_ENCODING_ASCII && com_enc == ZIP_ENCODING_UTF8_KNOWN) ||
- (name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_UTF8_KNOWN))
+ if ((name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_ASCII) || (name_enc == ZIP_ENCODING_ASCII && com_enc == ZIP_ENCODING_UTF8_KNOWN) || (name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_UTF8_KNOWN))
de->bitflags |= ZIP_GPBF_ENCODING_UTF_8;
else {
de->bitflags &= (zip_uint16_t)~ZIP_GPBF_ENCODING_UTF_8;
@@ -783,7 +766,7 @@
if (ef == NULL)
return -1;
}
- if ((flags & ZIP_FL_LOCAL) == 0 && com_enc == ZIP_ENCODING_UTF8_KNOWN){
+ if ((flags & ZIP_FL_LOCAL) == 0 && com_enc == ZIP_ENCODING_UTF8_KNOWN) {
zip_extra_field_t *ef2 = _zip_ef_utf8(ZIP_EF_UTF_8_COMMENT, de->comment, &za->error);
if (ef2 == NULL) {
_zip_ef_free(ef);
@@ -802,90 +785,90 @@
}
is_really_zip64 = _zip_dirent_needs_zip64(de, flags);
- is_zip64 = (flags & (ZIP_FL_LOCAL|ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL|ZIP_FL_FORCE_ZIP64) || is_really_zip64;
+ is_zip64 = (flags & (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64) || is_really_zip64;
is_winzip_aes = de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256;
if (is_zip64) {
- zip_uint8_t ef_zip64[EFZIP64SIZE];
- zip_buffer_t *ef_buffer = _zip_buffer_new(ef_zip64, sizeof(ef_zip64));
- if (ef_buffer == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ zip_uint8_t ef_zip64[EFZIP64SIZE];
+ zip_buffer_t *ef_buffer = _zip_buffer_new(ef_zip64, sizeof(ef_zip64));
+ if (ef_buffer == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
_zip_ef_free(ef);
- return -1;
- }
+ return -1;
+ }
- if (flags & ZIP_FL_LOCAL) {
- if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX) {
- _zip_buffer_put_64(ef_buffer, de->uncomp_size);
- _zip_buffer_put_64(ef_buffer, de->comp_size);
- }
- }
- else {
- if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
- if (de->uncomp_size >= ZIP_UINT32_MAX) {
- _zip_buffer_put_64(ef_buffer, de->uncomp_size);
- }
- if (de->comp_size >= ZIP_UINT32_MAX) {
- _zip_buffer_put_64(ef_buffer, de->comp_size);
- }
- if (de->offset >= ZIP_UINT32_MAX) {
- _zip_buffer_put_64(ef_buffer, de->offset);
- }
- }
- }
+ if (flags & ZIP_FL_LOCAL) {
+ if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX) {
+ _zip_buffer_put_64(ef_buffer, de->uncomp_size);
+ _zip_buffer_put_64(ef_buffer, de->comp_size);
+ }
+ }
+ else {
+ if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
+ if (de->uncomp_size >= ZIP_UINT32_MAX) {
+ _zip_buffer_put_64(ef_buffer, de->uncomp_size);
+ }
+ if (de->comp_size >= ZIP_UINT32_MAX) {
+ _zip_buffer_put_64(ef_buffer, de->comp_size);
+ }
+ if (de->offset >= ZIP_UINT32_MAX) {
+ _zip_buffer_put_64(ef_buffer, de->offset);
+ }
+ }
+ }
- if (!_zip_buffer_ok(ef_buffer)) {
- zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
- _zip_buffer_free(ef_buffer);
+ if (!_zip_buffer_ok(ef_buffer)) {
+ zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
+ _zip_buffer_free(ef_buffer);
_zip_ef_free(ef);
- return -1;
- }
+ return -1;
+ }
- ef64 = _zip_ef_new(ZIP_EF_ZIP64, (zip_uint16_t)(_zip_buffer_offset(ef_buffer)), ef_zip64, ZIP_EF_BOTH);
- _zip_buffer_free(ef_buffer);
- ef64->next = ef;
- ef = ef64;
+ ef64 = _zip_ef_new(ZIP_EF_ZIP64, (zip_uint16_t)(_zip_buffer_offset(ef_buffer)), ef_zip64, ZIP_EF_BOTH);
+ _zip_buffer_free(ef_buffer);
+ ef64->next = ef;
+ ef = ef64;
}
if (is_winzip_aes) {
zip_uint8_t data[EF_WINZIP_AES_SIZE];
- zip_buffer_t *ef_buffer = _zip_buffer_new(data, sizeof(data));
+ zip_buffer_t *ef_buffer = _zip_buffer_new(data, sizeof(data));
zip_extra_field_t *ef_winzip;
-
- if (ef_buffer == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+
+ if (ef_buffer == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
_zip_ef_free(ef);
- return -1;
- }
+ return -1;
+ }
_zip_buffer_put_16(ef_buffer, 2);
_zip_buffer_put(ef_buffer, "AE", 2);
_zip_buffer_put_8(ef_buffer, (zip_uint8_t)(de->encryption_method & 0xff));
_zip_buffer_put_16(ef_buffer, (zip_uint16_t)de->comp_method);
- if (!_zip_buffer_ok(ef_buffer)) {
- zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
- _zip_buffer_free(ef_buffer);
+ if (!_zip_buffer_ok(ef_buffer)) {
+ zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
+ _zip_buffer_free(ef_buffer);
_zip_ef_free(ef);
- return -1;
- }
+ return -1;
+ }
- ef_winzip = _zip_ef_new(ZIP_EF_WINZIP_AES, EF_WINZIP_AES_SIZE, data, ZIP_EF_BOTH);
- _zip_buffer_free(ef_buffer);
- ef_winzip->next = ef;
- ef = ef_winzip;
+ ef_winzip = _zip_ef_new(ZIP_EF_WINZIP_AES, EF_WINZIP_AES_SIZE, data, ZIP_EF_BOTH);
+ _zip_buffer_free(ef_buffer);
+ ef_winzip->next = ef;
+ ef = ef_winzip;
}
if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- _zip_ef_free(ef);
- return -1;
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ _zip_ef_free(ef);
+ return -1;
}
_zip_buffer_put(buffer, (flags & ZIP_FL_LOCAL) ? LOCAL_MAGIC : CENTRAL_MAGIC, 4);
if ((flags & ZIP_FL_LOCAL) == 0) {
- _zip_buffer_put_16(buffer, (zip_uint16_t)(is_really_zip64 ? 45 : de->version_madeby));
+ _zip_buffer_put_16(buffer, (zip_uint16_t)(is_really_zip64 ? 45 : de->version_madeby));
}
_zip_buffer_put_16(buffer, (zip_uint16_t)(is_really_zip64 ? 45 : de->version_needed));
_zip_buffer_put_16(buffer, de->bitflags);
@@ -900,7 +883,7 @@
_zip_buffer_put_16(buffer, dostime);
_zip_buffer_put_16(buffer, dosdate);
- if (is_winzip_aes && de->uncomp_size < 20) {
+ if (is_winzip_aes && de->uncomp_size < 20) {
_zip_buffer_put_32(buffer, 0);
}
else {
@@ -917,18 +900,18 @@
_zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
}
else {
- if (de->comp_size < ZIP_UINT32_MAX) {
+ if (de->comp_size < ZIP_UINT32_MAX) {
_zip_buffer_put_32(buffer, (zip_uint32_t)de->comp_size);
- }
- else {
+ }
+ else {
_zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
- }
- if (de->uncomp_size < ZIP_UINT32_MAX) {
+ }
+ if (de->uncomp_size < ZIP_UINT32_MAX) {
_zip_buffer_put_32(buffer, (zip_uint32_t)de->uncomp_size);
- }
- else {
+ }
+ else {
_zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
- }
+ }
}
_zip_buffer_put_16(buffer, _zip_string_length(de->filename));
@@ -948,30 +931,30 @@
}
if (!_zip_buffer_ok(buffer)) {
- zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
- _zip_buffer_free(buffer);
- _zip_ef_free(ef);
- return -1;
+ zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
+ _zip_buffer_free(buffer);
+ _zip_ef_free(ef);
+ return -1;
}
if (_zip_write(za, buf, _zip_buffer_offset(buffer)) < 0) {
- _zip_buffer_free(buffer);
- _zip_ef_free(ef);
- return -1;
+ _zip_buffer_free(buffer);
+ _zip_ef_free(ef);
+ return -1;
}
_zip_buffer_free(buffer);
if (de->filename) {
if (_zip_string_write(za, de->filename) < 0) {
- _zip_ef_free(ef);
+ _zip_ef_free(ef);
return -1;
}
}
if (ef) {
if (_zip_ef_write(za, ef, ZIP_EF_BOTH) < 0) {
- _zip_ef_free(ef);
+ _zip_ef_free(ef);
return -1;
}
}
@@ -996,8 +979,7 @@
static time_t
-_zip_d2u_time(zip_uint16_t dtime, zip_uint16_t ddate)
-{
+_zip_d2u_time(zip_uint16_t dtime, zip_uint16_t ddate) {
struct tm tm;
memset(&tm, 0, sizeof(tm));
@@ -1005,37 +987,36 @@
/* let mktime decide if DST is in effect */
tm.tm_isdst = -1;
- tm.tm_year = ((ddate>>9)&127) + 1980 - 1900;
- tm.tm_mon = ((ddate>>5)&15) - 1;
- tm.tm_mday = ddate&31;
+ tm.tm_year = ((ddate >> 9) & 127) + 1980 - 1900;
+ tm.tm_mon = ((ddate >> 5) & 15) - 1;
+ tm.tm_mday = ddate & 31;
- tm.tm_hour = (dtime>>11)&31;
- tm.tm_min = (dtime>>5)&63;
- tm.tm_sec = (dtime<<1)&62;
+ tm.tm_hour = (dtime >> 11) & 31;
+ tm.tm_min = (dtime >> 5) & 63;
+ tm.tm_sec = (dtime << 1) & 62;
return mktime(&tm);
}
static zip_extra_field_t *
-_zip_ef_utf8(zip_uint16_t id, zip_string_t *str, zip_error_t *error)
-{
+_zip_ef_utf8(zip_uint16_t id, zip_string_t *str, zip_error_t *error) {
const zip_uint8_t *raw;
zip_uint32_t len;
zip_buffer_t *buffer;
zip_extra_field_t *ef;
- if ((raw=_zip_string_get(str, &len, ZIP_FL_ENC_RAW, NULL)) == NULL) {
+ if ((raw = _zip_string_get(str, &len, ZIP_FL_ENC_RAW, NULL)) == NULL) {
/* error already set */
return NULL;
}
- if (len+5 > ZIP_UINT16_MAX) {
- zip_error_set(error, ZIP_ER_INVAL, 0); /* TODO: better error code? */
- return NULL;
+ if (len + 5 > ZIP_UINT16_MAX) {
+ zip_error_set(error, ZIP_ER_INVAL, 0); /* TODO: better error code? */
+ return NULL;
}
- if ((buffer = _zip_buffer_new(NULL, len+5)) == NULL) {
+ if ((buffer = _zip_buffer_new(NULL, len + 5)) == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return NULL;
}
@@ -1045,9 +1026,9 @@
_zip_buffer_put(buffer, raw, len);
if (!_zip_buffer_ok(buffer)) {
- zip_error_set(error, ZIP_ER_INTERNAL, 0);
- _zip_buffer_free(buffer);
- return NULL;
+ zip_error_set(error, ZIP_ER_INTERNAL, 0);
+ _zip_buffer_free(buffer);
+ return NULL;
}
ef = _zip_ef_new(id, (zip_uint16_t)(_zip_buffer_offset(buffer)), _zip_buffer_data(buffer), ZIP_EF_BOTH);
@@ -1058,8 +1039,7 @@
zip_dirent_t *
-_zip_get_dirent(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error)
-{
+_zip_get_dirent(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error) {
if (error == NULL)
error = &za->error;
@@ -1084,11 +1064,8 @@
}
-
-
void
-_zip_u2d_time(time_t intime, zip_uint16_t *dtime, zip_uint16_t *ddate)
-{
+_zip_u2d_time(time_t intime, zip_uint16_t *dtime, zip_uint16_t *ddate) {
struct tm *tm;
tm = localtime(&intime);
@@ -1096,8 +1073,8 @@
tm->tm_year = 80;
}
- *ddate = (zip_uint16_t)(((tm->tm_year+1900-1980)<<9) + ((tm->tm_mon+1)<<5) + tm->tm_mday);
- *dtime = (zip_uint16_t)(((tm->tm_hour)<<11) + ((tm->tm_min)<<5) + ((tm->tm_sec)>>1));
+ *ddate = (zip_uint16_t)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday);
+ *dtime = (zip_uint16_t)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1));
return;
}
@@ -1121,7 +1098,7 @@
de->version_needed = 45;
return;
}
-
+
if (de->comp_method == ZIP_CM_DEFLATE || de->encryption_method == ZIP_EM_TRAD_PKWARE) {
de->version_needed = 20;
return;
@@ -1129,11 +1106,11 @@
/* directory */
if ((length = _zip_string_length(de->filename)) > 0) {
- if (de->filename->raw[length-1] == '/') {
+ if (de->filename->raw[length - 1] == '/') {
de->version_needed = 20;
return;
}
}
-
+
de->version_needed = 10;
}
diff --git a/lib/zip_discard.c b/lib/zip_discard.c
index f0188b5..5bbf8d6 100644
--- a/lib/zip_discard.c
+++ b/lib/zip_discard.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -42,8 +42,7 @@
corresponding file. */
void
-zip_discard(zip_t *za)
-{
+zip_discard(zip_t *za) {
zip_uint64_t i;
if (za == NULL)
@@ -61,12 +60,12 @@
_zip_hash_free(za->names);
if (za->entry) {
- for (i=0; i<za->nentry; i++)
- _zip_entry_finalize(za->entry+i);
+ for (i = 0; i < za->nentry; i++)
+ _zip_entry_finalize(za->entry + i);
free(za->entry);
}
- for (i=0; i<za->nopen_source; i++) {
+ for (i = 0; i < za->nopen_source; i++) {
_zip_source_invalidate(za->open_source[i]);
}
free(za->open_source);
@@ -74,7 +73,7 @@
_zip_progress_free(za->progress);
zip_error_fini(&za->error);
-
+
free(za);
return;
diff --git a/lib/zip_entry.c b/lib/zip_entry.c
index 6f89006..f083412 100644
--- a/lib/zip_entry.c
+++ b/lib/zip_entry.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,8 +35,7 @@
#include "zipint.h"
void
-_zip_entry_finalize(zip_entry_t *e)
-{
+_zip_entry_finalize(zip_entry_t *e) {
_zip_unchange_data(e);
_zip_dirent_free(e->orig);
_zip_dirent_free(e->changes);
@@ -44,8 +43,7 @@
void
-_zip_entry_init(zip_entry_t *e)
-{
+_zip_entry_init(zip_entry_t *e) {
e->orig = NULL;
e->changes = NULL;
e->source = NULL;
diff --git a/lib/zip_err_str.c b/lib/zip_err_str.c
index 724849b..3d9ee54 100644
--- a/lib/zip_err_str.c
+++ b/lib/zip_err_str.c
@@ -5,78 +5,16 @@
#include "zipint.h"
-const char * const _zip_err_str[] = {
- "No error",
- "Multi-disk zip archives not supported",
- "Renaming temporary file failed",
- "Closing zip archive failed",
- "Seek error",
- "Read error",
- "Write error",
- "CRC error",
- "Containing zip archive was closed",
- "No such file",
- "File already exists",
- "Can't open file",
- "Failure to create temporary file",
- "Zlib error",
- "Malloc failure",
- "Entry has been changed",
- "Compression method not supported",
- "Premature end of file",
- "Invalid argument",
- "Not a zip archive",
- "Internal error",
- "Zip archive inconsistent",
- "Can't remove file",
- "Entry has been deleted",
- "Encryption method not supported",
- "Read-only archive",
- "No password provided",
- "Wrong password provided",
- "Operation not supported",
- "Resource still in use",
- "Tell error",
- "Compressed data invalid",
+const char *const _zip_err_str[] = {
+ "No error", "Multi-disk zip archives not supported", "Renaming temporary file failed", "Closing zip archive failed", "Seek error", "Read error", "Write error", "CRC error", "Containing zip archive was closed", "No such file", "File already exists", "Can't open file", "Failure to create temporary file", "Zlib error", "Malloc failure", "Entry has been changed", "Compression method not supported", "Premature end of file", "Invalid argument", "Not a zip archive", "Internal error", "Zip archive inconsistent", "Can't remove file", "Entry has been deleted", "Encryption method not supported", "Read-only archive", "No password provided", "Wrong password provided", "Operation not supported", "Resource still in use", "Tell error", "Compressed data invalid",
};
-const int _zip_nerr_str = sizeof(_zip_err_str)/sizeof(_zip_err_str[0]);
+const int _zip_nerr_str = sizeof(_zip_err_str) / sizeof(_zip_err_str[0]);
#define N ZIP_ET_NONE
#define S ZIP_ET_SYS
#define Z ZIP_ET_ZLIB
const int _zip_err_type[] = {
- N,
- N,
- S,
- S,
- S,
- S,
- S,
- N,
- N,
- N,
- N,
- S,
- S,
- Z,
- N,
- N,
- N,
- N,
- N,
- N,
- N,
- N,
- S,
- N,
- N,
- N,
- N,
- N,
- N,
- N,
- S,
- N,
+ N, N, S, S, S, S, S, N, N, N, N, S, S, Z, N, N, N, N, N, N, N, N, S, N, N, N, N, N, N, N, S, N,
};
diff --git a/lib/zip_error.c b/lib/zip_error.c
index 2e0a49d..9ccaf91 100644
--- a/lib/zip_error.c
+++ b/lib/zip_error.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,24 +49,21 @@
ZIP_EXTERN void
-zip_error_fini(zip_error_t *err)
-{
+zip_error_fini(zip_error_t *err) {
free(err->str);
err->str = NULL;
}
ZIP_EXTERN void
-zip_error_init(zip_error_t *err)
-{
+zip_error_init(zip_error_t *err) {
err->zip_err = ZIP_ER_OK;
err->sys_err = 0;
err->str = NULL;
}
ZIP_EXTERN void
-zip_error_init_with_code(zip_error_t *error, int ze)
-{
+zip_error_init_with_code(zip_error_t *error, int ze) {
zip_error_init(error);
error->zip_err = ze;
switch (zip_error_system_type(error)) {
@@ -77,22 +74,21 @@
default:
error->sys_err = 0;
break;
- }
+ }
}
ZIP_EXTERN int
zip_error_system_type(const zip_error_t *error) {
if (error->zip_err < 0 || error->zip_err >= _zip_nerr_str)
- return ZIP_ET_NONE;
-
+ return ZIP_ET_NONE;
+
return _zip_err_type[error->zip_err];
}
void
-_zip_error_clear(zip_error_t *err)
-{
+_zip_error_clear(zip_error_t *err) {
if (err == NULL)
return;
@@ -102,20 +98,18 @@
void
-_zip_error_copy(zip_error_t *dst, const zip_error_t *src)
-{
+_zip_error_copy(zip_error_t *dst, const zip_error_t *src) {
if (dst == NULL) {
- return;
+ return;
}
-
+
dst->zip_err = src->zip_err;
dst->sys_err = src->sys_err;
}
void
-_zip_error_get(const zip_error_t *err, int *zep, int *sep)
-{
+_zip_error_get(const zip_error_t *err, int *zep, int *sep) {
if (zep)
*zep = err->zip_err;
if (sep) {
@@ -128,8 +122,7 @@
void
-zip_error_set(zip_error_t *err, int ze, int se)
-{
+zip_error_set(zip_error_t *err, int ze, int se) {
if (err) {
err->zip_err = ze;
err->sys_err = se;
@@ -138,22 +131,20 @@
void
-_zip_error_set_from_source(zip_error_t *err, zip_source_t *src)
-{
+_zip_error_set_from_source(zip_error_t *err, zip_source_t *src) {
_zip_error_copy(err, zip_source_error(src));
}
zip_int64_t
-zip_error_to_data(const zip_error_t *error, void *data, zip_uint64_t length)
-{
+zip_error_to_data(const zip_error_t *error, void *data, zip_uint64_t length) {
int *e = (int *)data;
-
- if (length < sizeof(int)*2) {
- return -1;
+
+ if (length < sizeof(int) * 2) {
+ return -1;
}
-
+
e[0] = zip_error_code_zip(error);
e[1] = zip_error_code_system(error);
- return sizeof(int)*2;
+ return sizeof(int) * 2;
}
diff --git a/lib/zip_error_clear.c b/lib/zip_error_clear.c
index ec45e68..2cce450 100644
--- a/lib/zip_error_clear.c
+++ b/lib/zip_error_clear.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
ZIP_EXTERN void
-zip_error_clear(zip_t *za)
-{
+zip_error_clear(zip_t *za) {
if (za == NULL)
return;
diff --git a/lib/zip_error_get.c b/lib/zip_error_get.c
index c222018..1f02ed3 100644
--- a/lib/zip_error_get.c
+++ b/lib/zip_error_get.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,21 +37,18 @@
ZIP_EXTERN void
-zip_error_get(zip_t *za, int *zep, int *sep)
-{
+zip_error_get(zip_t *za, int *zep, int *sep) {
_zip_error_get(&za->error, zep, sep);
}
ZIP_EXTERN zip_error_t *
-zip_get_error(zip_t *za)
-{
+zip_get_error(zip_t *za) {
return &za->error;
}
ZIP_EXTERN zip_error_t *
-zip_file_get_error(zip_file_t *f)
-{
+zip_file_get_error(zip_file_t *f) {
return &f->error;
}
diff --git a/lib/zip_error_get_sys_type.c b/lib/zip_error_get_sys_type.c
index 7e27bbf..d7a594e 100644
--- a/lib/zip_error_get_sys_type.c
+++ b/lib/zip_error_get_sys_type.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
ZIP_EXTERN int
-zip_error_get_sys_type(int ze)
-{
+zip_error_get_sys_type(int ze) {
if (ze < 0 || ze >= _zip_nerr_str)
return 0;
diff --git a/lib/zip_error_strerror.c b/lib/zip_error_strerror.c
index bdc1e44..6baf900 100644
--- a/lib/zip_error_strerror.c
+++ b/lib/zip_error_strerror.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -40,8 +40,7 @@
ZIP_EXTERN const char *
-zip_error_strerror(zip_error_t *err)
-{
+zip_error_strerror(zip_error_t *err) {
const char *zs, *ss;
char buf[128], *s;
@@ -54,7 +53,7 @@
}
else {
zs = _zip_err_str[err->zip_err];
-
+
switch (_zip_err_type[err->zip_err]) {
case ZIP_ET_SYS:
ss = strerror(err->sys_err);
@@ -72,14 +71,10 @@
if (ss == NULL)
return zs;
else {
- if ((s=(char *)malloc(strlen(ss)
- + (zs ? strlen(zs)+2 : 0) + 1)) == NULL)
+ if ((s = (char *)malloc(strlen(ss) + (zs ? strlen(zs) + 2 : 0) + 1)) == NULL)
return _zip_err_str[ZIP_ER_MEMORY];
-
- sprintf(s, "%s%s%s",
- (zs ? zs : ""),
- (zs ? ": " : ""),
- ss);
+
+ sprintf(s, "%s%s%s", (zs ? zs : ""), (zs ? ": " : ""), ss);
err->str = s;
return s;
diff --git a/lib/zip_error_to_str.c b/lib/zip_error_to_str.c
index 019feff..518c0e5 100644
--- a/lib/zip_error_to_str.c
+++ b/lib/zip_error_to_str.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -41,28 +41,26 @@
ZIP_EXTERN int
-zip_error_to_str(char *buf, zip_uint64_t len, int ze, int se)
-{
+zip_error_to_str(char *buf, zip_uint64_t len, int ze, int se) {
const char *zs, *ss;
if (ze < 0 || ze >= _zip_nerr_str)
return snprintf(buf, len, "Unknown error %d", ze);
zs = _zip_err_str[ze];
-
+
switch (_zip_err_type[ze]) {
case ZIP_ET_SYS:
ss = strerror(se);
break;
-
+
case ZIP_ET_ZLIB:
ss = zError(se);
break;
-
+
default:
ss = NULL;
}
- return snprintf(buf, len, "%s%s%s",
- zs, (ss ? ": " : ""), (ss ? ss : ""));
+ return snprintf(buf, len, "%s%s%s", zs, (ss ? ": " : ""), (ss ? ss : ""));
}
diff --git a/lib/zip_extra_field.c b/lib/zip_extra_field.c
index 92f36de..42f97d0 100644
--- a/lib/zip_extra_field.c
+++ b/lib/zip_extra_field.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,42 +38,40 @@
zip_extra_field_t *
-_zip_ef_clone(const zip_extra_field_t *ef, zip_error_t *error)
-{
+_zip_ef_clone(const zip_extra_field_t *ef, zip_error_t *error) {
zip_extra_field_t *head, *prev, *def;
-
+
head = prev = NULL;
-
+
while (ef) {
- if ((def=_zip_ef_new(ef->id, ef->size, ef->data, ef->flags)) == NULL) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- _zip_ef_free(head);
- return NULL;
- }
-
- if (head == NULL)
- head = def;
- if (prev)
- prev->next = def;
- prev = def;
+ if ((def = _zip_ef_new(ef->id, ef->size, ef->data, ef->flags)) == NULL) {
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ _zip_ef_free(head);
+ return NULL;
+ }
+
+ if (head == NULL)
+ head = def;
+ if (prev)
+ prev->next = def;
+ prev = def;
ef = ef->next;
}
-
+
return head;
}
zip_extra_field_t *
-_zip_ef_delete_by_id(zip_extra_field_t *ef, zip_uint16_t id, zip_uint16_t id_idx, zip_flags_t flags)
-{
+_zip_ef_delete_by_id(zip_extra_field_t *ef, zip_uint16_t id, zip_uint16_t id_idx, zip_flags_t flags) {
zip_extra_field_t *head, *prev;
int i;
i = 0;
head = ef;
prev = NULL;
- for (; ef; ef=(prev ? prev->next : head)) {
+ for (; ef; ef = (prev ? prev->next : head)) {
if ((ef->flags & flags & ZIP_EF_BOTH) && ((ef->id == id) || (id == ZIP_EXTRA_FIELD_ALL))) {
if (id_idx == ZIP_EXTRA_FIELD_ALL || i == id_idx) {
ef->flags &= ~(flags & ZIP_EF_BOTH);
@@ -89,7 +87,7 @@
continue;
}
}
-
+
i++;
if (i > id_idx)
break;
@@ -101,10 +99,8 @@
}
-
void
-_zip_ef_free(zip_extra_field_t *ef)
-{
+_zip_ef_free(zip_extra_field_t *ef) {
zip_extra_field_t *ef2;
while (ef) {
@@ -117,14 +113,13 @@
const zip_uint8_t *
-_zip_ef_get_by_id(const zip_extra_field_t *ef, zip_uint16_t *lenp, zip_uint16_t id, zip_uint16_t id_idx, zip_flags_t flags, zip_error_t *error)
-{
- static const zip_uint8_t empty[1] = { '\0' };
-
+_zip_ef_get_by_id(const zip_extra_field_t *ef, zip_uint16_t *lenp, zip_uint16_t id, zip_uint16_t id_idx, zip_flags_t flags, zip_error_t *error) {
+ static const zip_uint8_t empty[1] = {'\0'};
+
int i;
i = 0;
- for (; ef; ef=ef->next) {
+ for (; ef; ef = ef->next) {
if (ef->id == id && (ef->flags & flags & ZIP_EF_BOTH)) {
if (i < id_idx) {
i++;
@@ -146,22 +141,21 @@
zip_extra_field_t *
-_zip_ef_merge(zip_extra_field_t *to, zip_extra_field_t *from)
-{
+_zip_ef_merge(zip_extra_field_t *to, zip_extra_field_t *from) {
zip_extra_field_t *ef2, *tt, *tail;
int duplicate;
if (to == NULL)
return from;
- for (tail=to; tail->next; tail=tail->next)
+ for (tail = to; tail->next; tail = tail->next)
;
- for (; from; from=ef2) {
+ for (; from; from = ef2) {
ef2 = from->next;
duplicate = 0;
- for (tt=to; tt; tt=tt->next) {
+ for (tt = to; tt; tt = tt->next) {
if (tt->id == from->id && tt->size == from->size && (tt->size == 0 || memcmp(tt->data, from->data, tt->size) == 0)) {
tt->flags |= (from->flags & ZIP_EF_BOTH);
duplicate = 1;
@@ -181,11 +175,10 @@
zip_extra_field_t *
-_zip_ef_new(zip_uint16_t id, zip_uint16_t size, const zip_uint8_t *data, zip_flags_t flags)
-{
+_zip_ef_new(zip_uint16_t id, zip_uint16_t size, const zip_uint8_t *data, zip_flags_t flags) {
zip_extra_field_t *ef;
- if ((ef=(zip_extra_field_t *)malloc(sizeof(*ef))) == NULL)
+ if ((ef = (zip_extra_field_t *)malloc(sizeof(*ef))) == NULL)
return NULL;
ef->next = NULL;
@@ -193,7 +186,7 @@
ef->id = id;
ef->size = size;
if (size > 0) {
- if ((ef->data=(zip_uint8_t *)_zip_memdup(data, size, NULL)) == NULL) {
+ if ((ef->data = (zip_uint8_t *)_zip_memdup(data, size, NULL)) == NULL) {
free(ef);
return NULL;
}
@@ -206,36 +199,35 @@
bool
-_zip_ef_parse(const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags, zip_extra_field_t **ef_head_p, zip_error_t *error)
-{
+_zip_ef_parse(const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags, zip_extra_field_t **ef_head_p, zip_error_t *error) {
zip_buffer_t *buffer;
zip_extra_field_t *ef, *ef2, *ef_head;
if ((buffer = _zip_buffer_new((zip_uint8_t *)data, len)) == NULL) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- return false;
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return false;
}
-
- ef_head = ef = NULL;
-
- while (_zip_buffer_ok(buffer) && _zip_buffer_left(buffer) >= 4) {
- zip_uint16_t fid, flen;
- zip_uint8_t *ef_data;
-
- fid = _zip_buffer_get_16(buffer);
- flen = _zip_buffer_get_16(buffer);
- ef_data = _zip_buffer_get(buffer, flen);
- if (ef_data == NULL) {
+ ef_head = ef = NULL;
+
+ while (_zip_buffer_ok(buffer) && _zip_buffer_left(buffer) >= 4) {
+ zip_uint16_t fid, flen;
+ zip_uint8_t *ef_data;
+
+ fid = _zip_buffer_get_16(buffer);
+ flen = _zip_buffer_get_16(buffer);
+ ef_data = _zip_buffer_get(buffer, flen);
+
+ if (ef_data == NULL) {
zip_error_set(error, ZIP_ER_INCONS, 0);
- _zip_buffer_free(buffer);
+ _zip_buffer_free(buffer);
_zip_ef_free(ef_head);
return false;
- }
-
- if ((ef2=_zip_ef_new(fid, flen, ef_data, flags)) == NULL) {
+ }
+
+ if ((ef2 = _zip_ef_new(fid, flen, ef_data, flags)) == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
- _zip_buffer_free(buffer);
+ _zip_buffer_free(buffer);
_zip_ef_free(ef_head);
return false;
}
@@ -268,52 +260,50 @@
*ef_head_p = ef_head;
}
else {
- _zip_ef_free(ef_head);
+ _zip_ef_free(ef_head);
}
-
+
return true;
}
zip_extra_field_t *
-_zip_ef_remove_internal(zip_extra_field_t *ef)
-{
+_zip_ef_remove_internal(zip_extra_field_t *ef) {
zip_extra_field_t *ef_head;
zip_extra_field_t *prev, *next;
-
+
ef_head = ef;
prev = NULL;
-
+
while (ef) {
- if (ZIP_EF_IS_INTERNAL(ef->id)) {
- next = ef->next;
- if (ef_head == ef)
- ef_head = next;
- ef->next = NULL;
- _zip_ef_free(ef);
- if (prev)
- prev->next = next;
- ef = next;
- }
- else {
- prev = ef;
- ef = ef->next;
- }
+ if (ZIP_EF_IS_INTERNAL(ef->id)) {
+ next = ef->next;
+ if (ef_head == ef)
+ ef_head = next;
+ ef->next = NULL;
+ _zip_ef_free(ef);
+ if (prev)
+ prev->next = next;
+ ef = next;
+ }
+ else {
+ prev = ef;
+ ef = ef->next;
+ }
}
-
+
return ef_head;
}
zip_uint16_t
-_zip_ef_size(const zip_extra_field_t *ef, zip_flags_t flags)
-{
+_zip_ef_size(const zip_extra_field_t *ef, zip_flags_t flags) {
zip_uint16_t size;
size = 0;
- for (; ef; ef=ef->next) {
+ for (; ef; ef = ef->next) {
if (ef->flags & flags & ZIP_EF_BOTH)
- size = (zip_uint16_t)(size+4+ef->size);
+ size = (zip_uint16_t)(size + 4 + ef->size);
}
return size;
@@ -321,8 +311,7 @@
int
-_zip_ef_write(zip_t *za, const zip_extra_field_t *ef, zip_flags_t flags)
-{
+_zip_ef_write(zip_t *za, const zip_extra_field_t *ef, zip_flags_t flags) {
zip_uint8_t b[4];
zip_buffer_t *buffer = _zip_buffer_new(b, sizeof(b));
@@ -330,37 +319,36 @@
return -1;
}
- for (; ef; ef=ef->next) {
+ for (; ef; ef = ef->next) {
if (ef->flags & flags & ZIP_EF_BOTH) {
- _zip_buffer_set_offset(buffer, 0);
- _zip_buffer_put_16(buffer, ef->id);
+ _zip_buffer_set_offset(buffer, 0);
+ _zip_buffer_put_16(buffer, ef->id);
_zip_buffer_put_16(buffer, ef->size);
- if (!_zip_buffer_ok(buffer)) {
- zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
- _zip_buffer_free(buffer);
- return -1;
- }
+ if (!_zip_buffer_ok(buffer)) {
+ zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
+ _zip_buffer_free(buffer);
+ return -1;
+ }
if (_zip_write(za, b, 4) < 0) {
- _zip_buffer_free(buffer);
- return -1;
+ _zip_buffer_free(buffer);
+ return -1;
}
if (ef->size > 0) {
if (_zip_write(za, ef->data, ef->size) < 0) {
- _zip_buffer_free(buffer);
- return -1;
+ _zip_buffer_free(buffer);
+ return -1;
}
}
}
}
-
+
_zip_buffer_free(buffer);
return 0;
}
int
-_zip_read_local_ef(zip_t *za, zip_uint64_t idx)
-{
+_zip_read_local_ef(zip_t *za, zip_uint64_t idx) {
zip_entry_t *e;
unsigned char b[4];
zip_buffer_t *buffer;
@@ -371,7 +359,7 @@
return -1;
}
- e = za->entry+idx;
+ e = za->entry + idx;
if (e->orig == NULL || e->orig->local_extra_fields_read)
return 0;
@@ -379,28 +367,28 @@
if (e->orig->offset + 26 > ZIP_INT64_MAX) {
zip_error_set(&za->error, ZIP_ER_SEEK, EFBIG);
return -1;
- }
+ }
if (zip_source_seek(za->src, (zip_int64_t)(e->orig->offset + 26), SEEK_SET) < 0) {
_zip_error_set_from_source(&za->error, za->src);
return -1;
}
-
+
if ((buffer = _zip_buffer_new_from_source(za->src, sizeof(b), b, &za->error)) == NULL) {
- return -1;
+ return -1;
}
-
+
fname_len = _zip_buffer_get_16(buffer);
ef_len = _zip_buffer_get_16(buffer);
-
+
if (!_zip_buffer_eof(buffer)) {
- _zip_buffer_free(buffer);
- zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
- return -1;
+ _zip_buffer_free(buffer);
+ zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
+ return -1;
}
-
+
_zip_buffer_free(buffer);
-
+
if (ef_len > 0) {
zip_extra_field_t *ef;
zip_uint8_t *ef_raw;
@@ -428,7 +416,7 @@
}
e->orig->local_extra_fields_read = 1;
-
+
if (e->changes && e->changes->local_extra_fields_read == 0) {
e->changes->extra_fields = e->orig->extra_fields;
e->changes->local_extra_fields_read = 1;
diff --git a/lib/zip_extra_field_api.c b/lib/zip_extra_field_api.c
index ed93944..469abd2 100644
--- a/lib/zip_extra_field_api.c
+++ b/lib/zip_extra_field_api.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
ZIP_EXTERN int
-zip_file_extra_field_delete(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_flags_t flags)
-{
+zip_file_extra_field_delete(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_flags_t flags) {
zip_dirent_t *de;
if ((flags & ZIP_EF_BOTH) == 0) {
@@ -49,28 +48,27 @@
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return -1;
}
-
+
if (_zip_get_dirent(za, idx, 0, NULL) == NULL)
return -1;
-
+
if (ZIP_IS_RDONLY(za)) {
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
return -1;
}
if (_zip_file_extra_field_prepare_for_change(za, idx) < 0)
- return -1;
-
+ return -1;
+
de = za->entry[idx].changes;
-
+
de->extra_fields = _zip_ef_delete_by_id(de->extra_fields, ZIP_EXTRA_FIELD_ALL, ef_idx, flags);
return 0;
}
ZIP_EXTERN int
-zip_file_extra_field_delete_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_flags_t flags)
-{
+zip_file_extra_field_delete_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_flags_t flags) {
zip_dirent_t *de;
if ((flags & ZIP_EF_BOTH) == 0) {
@@ -82,7 +80,7 @@
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return -1;
}
-
+
if (_zip_get_dirent(za, idx, 0, NULL) == NULL)
return -1;
@@ -90,10 +88,10 @@
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
return -1;
}
-
+
if (_zip_file_extra_field_prepare_for_change(za, idx) < 0)
- return -1;
-
+ return -1;
+
de = za->entry[idx].changes;
de->extra_fields = _zip_ef_delete_by_id(de->extra_fields, ef_id, ef_idx, flags);
@@ -102,9 +100,8 @@
ZIP_EXTERN const zip_uint8_t *
-zip_file_extra_field_get(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_uint16_t *idp, zip_uint16_t *lenp, zip_flags_t flags)
-{
- static const zip_uint8_t empty[1] = { '\0' };
+zip_file_extra_field_get(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_uint16_t *idp, zip_uint16_t *lenp, zip_flags_t flags) {
+ static const zip_uint8_t empty[1] = {'\0'};
zip_dirent_t *de;
zip_extra_field_t *ef;
@@ -115,7 +112,7 @@
return NULL;
}
- if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL)
+ if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL)
return NULL;
if (flags & ZIP_FL_LOCAL)
@@ -123,7 +120,7 @@
return NULL;
i = 0;
- for (ef=de->extra_fields; ef; ef=ef->next) {
+ for (ef = de->extra_fields; ef; ef = ef->next) {
if (ef->flags & flags & ZIP_EF_BOTH) {
if (i < ef_idx) {
i++;
@@ -143,13 +140,11 @@
zip_error_set(&za->error, ZIP_ER_NOENT, 0);
return NULL;
-
}
ZIP_EXTERN const zip_uint8_t *
-zip_file_extra_field_get_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_uint16_t *lenp, zip_flags_t flags)
-{
+zip_file_extra_field_get_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_uint16_t *lenp, zip_flags_t flags) {
zip_dirent_t *de;
if ((flags & ZIP_EF_BOTH) == 0) {
@@ -157,7 +152,7 @@
return NULL;
}
- if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL)
+ if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL)
return NULL;
if (flags & ZIP_FL_LOCAL)
@@ -169,8 +164,7 @@
ZIP_EXTERN zip_int16_t
-zip_file_extra_fields_count(zip_t *za, zip_uint64_t idx, zip_flags_t flags)
-{
+zip_file_extra_fields_count(zip_t *za, zip_uint64_t idx, zip_flags_t flags) {
zip_dirent_t *de;
zip_extra_field_t *ef;
zip_uint16_t n;
@@ -180,7 +174,7 @@
return -1;
}
- if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL)
+ if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL)
return -1;
if (flags & ZIP_FL_LOCAL)
@@ -188,7 +182,7 @@
return -1;
n = 0;
- for (ef=de->extra_fields; ef; ef=ef->next)
+ for (ef = de->extra_fields; ef; ef = ef->next)
if (ef->flags & flags & ZIP_EF_BOTH)
n++;
@@ -197,8 +191,7 @@
ZIP_EXTERN zip_int16_t
-zip_file_extra_fields_count_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_flags_t flags)
-{
+zip_file_extra_fields_count_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_flags_t flags) {
zip_dirent_t *de;
zip_extra_field_t *ef;
zip_uint16_t n;
@@ -208,7 +201,7 @@
return -1;
}
- if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL)
+ if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL)
return -1;
if (flags & ZIP_FL_LOCAL)
@@ -216,7 +209,7 @@
return -1;
n = 0;
- for (ef=de->extra_fields; ef; ef=ef->next)
+ for (ef = de->extra_fields; ef; ef = ef->next)
if (ef->id == ef_id && (ef->flags & flags & ZIP_EF_BOTH))
n++;
@@ -225,8 +218,7 @@
ZIP_EXTERN int
-zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags)
-{
+zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags) {
zip_dirent_t *de;
zip_uint16_t ls, cs;
zip_extra_field_t *ef, *ef_prev, *ef_new;
@@ -239,20 +231,20 @@
if (_zip_get_dirent(za, idx, 0, NULL) == NULL)
return -1;
-
+
if (ZIP_IS_RDONLY(za)) {
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
return -1;
}
-
+
if (ZIP_EF_IS_INTERNAL(ef_id)) {
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return -1;
}
if (_zip_file_extra_field_prepare_for_change(za, idx) < 0)
- return -1;
-
+ return -1;
+
de = za->entry[idx].changes;
ef = de->extra_fields;
@@ -260,7 +252,7 @@
i = 0;
found = 0;
- for (; ef; ef=ef->next) {
+ for (; ef; ef = ef->next) {
if (ef->id == ef_id && (ef->flags & flags & ZIP_EF_BOTH)) {
if (i == ef_idx) {
found = 1;
@@ -294,8 +286,8 @@
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return -1;
}
-
- if ((ef_new=_zip_ef_new(ef_id, len, data, flags)) == NULL) {
+
+ if ((ef_new = _zip_ef_new(ef_id, len, data, flags)) == NULL) {
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return -1;
}
@@ -314,7 +306,7 @@
ef->flags &= ~(flags & ZIP_EF_BOTH);
ef_new->next = ef->next;
ef->next = ef_new;
- }
+ }
}
else if (ef_prev) {
ef_new->next = ef_prev->next;
@@ -322,45 +314,42 @@
}
else
de->extra_fields = ef_new;
-
+
return 0;
}
-
int
-_zip_file_extra_field_prepare_for_change(zip_t *za, zip_uint64_t idx)
-{
+_zip_file_extra_field_prepare_for_change(zip_t *za, zip_uint64_t idx) {
zip_entry_t *e;
-
+
if (idx >= za->nentry) {
- zip_error_set(&za->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
- e = za->entry+idx;
-
+
+ e = za->entry + idx;
+
if (e->changes && (e->changes->changed & ZIP_DIRENT_EXTRA_FIELD))
- return 0;
+ return 0;
if (e->orig) {
if (_zip_read_local_ef(za, idx) < 0)
return -1;
}
-
+
if (e->changes == NULL) {
- if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- return -1;
- }
+ if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return -1;
+ }
}
-
+
if (e->orig && e->orig->extra_fields) {
- if ((e->changes->extra_fields=_zip_ef_clone(e->orig->extra_fields, &za->error)) == NULL)
+ if ((e->changes->extra_fields = _zip_ef_clone(e->orig->extra_fields, &za->error)) == NULL)
return -1;
}
e->changes->changed |= ZIP_DIRENT_EXTRA_FIELD;
-
+
return 0;
}
-
diff --git a/lib/zip_fclose.c b/lib/zip_fclose.c
index 25a201b..be98cc0 100644
--- a/lib/zip_fclose.c
+++ b/lib/zip_fclose.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,10 +38,9 @@
ZIP_EXTERN int
-zip_fclose(zip_file_t *zf)
-{
+zip_fclose(zip_file_t *zf) {
int ret;
-
+
if (zf->src)
zip_source_free(zf->src);
diff --git a/lib/zip_fdopen.c b/lib/zip_fdopen.c
index 3fd771f..b1fc22b 100644
--- a/lib/zip_fdopen.c
+++ b/lib/zip_fdopen.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,28 +39,27 @@
ZIP_EXTERN zip_t *
-zip_fdopen(int fd_orig, int _flags, int *zep)
-{
+zip_fdopen(int fd_orig, int _flags, int *zep) {
int fd;
FILE *fp;
zip_t *za;
zip_source_t *src;
struct zip_error error;
- if (_flags < 0 || (_flags & ~(ZIP_CHECKCONS|ZIP_RDONLY))) {
+ if (_flags < 0 || (_flags & ~(ZIP_CHECKCONS | ZIP_RDONLY))) {
_zip_set_open_error(zep, NULL, ZIP_ER_INVAL);
- return NULL;
+ return NULL;
}
-
+
/* We dup() here to avoid messing with the passed in fd.
We could not restore it to the original state in case of error. */
- if ((fd=dup(fd_orig)) < 0) {
+ if ((fd = dup(fd_orig)) < 0) {
_zip_set_open_error(zep, NULL, ZIP_ER_OPEN);
return NULL;
}
- if ((fp=fdopen(fd, "rb")) == NULL) {
+ if ((fp = fdopen(fd, "rb")) == NULL) {
close(fd);
_zip_set_open_error(zep, NULL, ZIP_ER_OPEN);
return NULL;
diff --git a/lib/zip_file_add.c b/lib/zip_file_add.c
index 9944c0f..ec8ef06 100644
--- a/lib/zip_file_add.c
+++ b/lib/zip_file_add.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,18 +36,17 @@
/*
NOTE: Return type is signed so we can return -1 on error.
- The index can not be larger than ZIP_INT64_MAX since the size
- of the central directory cannot be larger than
- ZIP_UINT64_MAX, and each entry is larger than 2 bytes.
+ The index can not be larger than ZIP_INT64_MAX since the size
+ of the central directory cannot be larger than
+ ZIP_UINT64_MAX, and each entry is larger than 2 bytes.
*/
ZIP_EXTERN zip_int64_t
-zip_file_add(zip_t *za, const char *name, zip_source_t *source, zip_flags_t flags)
-{
+zip_file_add(zip_t *za, const char *name, zip_source_t *source, zip_flags_t flags) {
if (name == NULL || source == NULL) {
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return -1;
}
-
+
return _zip_file_replace(za, ZIP_UINT64_MAX, name, source, flags);
}
diff --git a/lib/zip_file_error_clear.c b/lib/zip_file_error_clear.c
index be45498..666beca 100644
--- a/lib/zip_file_error_clear.c
+++ b/lib/zip_file_error_clear.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
ZIP_EXTERN void
-zip_file_error_clear(zip_file_t *zf)
-{
+zip_file_error_clear(zip_file_t *zf) {
if (zf == NULL)
return;
diff --git a/lib/zip_file_error_get.c b/lib/zip_file_error_get.c
index be764fd..d7e0191 100644
--- a/lib/zip_file_error_get.c
+++ b/lib/zip_file_error_get.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,7 +36,6 @@
ZIP_EXTERN void
-zip_file_error_get(zip_file_t *zf, int *zep, int *sep)
-{
+zip_file_error_get(zip_file_t *zf, int *zep, int *sep) {
_zip_error_get(&zf->error, zep, sep);
}
diff --git a/lib/zip_file_get_comment.c b/lib/zip_file_get_comment.c
index 55e7dc2..478f3d7 100644
--- a/lib/zip_file_get_comment.c
+++ b/lib/zip_file_get_comment.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,16 +37,15 @@
/* lenp is 32 bit because converted comment can be longer than ZIP_UINT16_MAX */
ZIP_EXTERN const char *
-zip_file_get_comment(zip_t *za, zip_uint64_t idx, zip_uint32_t *lenp, zip_flags_t flags)
-{
+zip_file_get_comment(zip_t *za, zip_uint64_t idx, zip_uint32_t *lenp, zip_flags_t flags) {
zip_dirent_t *de;
zip_uint32_t len;
const zip_uint8_t *str;
- if ((de=_zip_get_dirent(za, idx, flags, NULL)) == NULL)
+ if ((de = _zip_get_dirent(za, idx, flags, NULL)) == NULL)
return NULL;
- if ((str=_zip_string_get(de->comment, &len, flags, &za->error)) == NULL)
+ if ((str = _zip_string_get(de->comment, &len, flags, &za->error)) == NULL)
return NULL;
if (lenp)
diff --git a/lib/zip_file_get_external_attributes.c b/lib/zip_file_get_external_attributes.c
index b6526cf..e3ede74 100644
--- a/lib/zip_file_get_external_attributes.c
+++ b/lib/zip_file_get_external_attributes.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -34,11 +34,10 @@
#include "zipint.h"
int
-zip_file_get_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t *opsys, zip_uint32_t *attributes)
-{
+zip_file_get_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t *opsys, zip_uint32_t *attributes) {
zip_dirent_t *de;
- if ((de=_zip_get_dirent(za, idx, flags, NULL)) == NULL)
+ if ((de = _zip_get_dirent(za, idx, flags, NULL)) == NULL)
return -1;
if (opsys)
diff --git a/lib/zip_file_get_offset.c b/lib/zip_file_get_offset.c
index 16becaf..877c179 100644
--- a/lib/zip_file_get_offset.c
+++ b/lib/zip_file_get_offset.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,8 +35,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include "zipint.h"
@@ -48,14 +48,13 @@
*/
zip_uint64_t
-_zip_file_get_offset(const zip_t *za, zip_uint64_t idx, zip_error_t *error)
-{
+_zip_file_get_offset(const zip_t *za, zip_uint64_t idx, zip_error_t *error) {
zip_uint64_t offset;
zip_int32_t size;
if (za->entry[idx].orig == NULL) {
- zip_error_set(error, ZIP_ER_INTERNAL, 0);
- return 0;
+ zip_error_set(error, ZIP_ER_INTERNAL, 0);
+ return 0;
}
offset = za->entry[idx].orig->offset;
@@ -66,56 +65,55 @@
}
/* TODO: cache? */
- if ((size=_zip_dirent_size(za->src, ZIP_EF_LOCAL, error)) < 0)
+ if ((size = _zip_dirent_size(za->src, ZIP_EF_LOCAL, error)) < 0)
return 0;
- if (offset+(zip_uint32_t)size > ZIP_INT64_MAX) {
- zip_error_set(error, ZIP_ER_SEEK, EFBIG);
- return 0;
+ if (offset + (zip_uint32_t)size > ZIP_INT64_MAX) {
+ zip_error_set(error, ZIP_ER_SEEK, EFBIG);
+ return 0;
}
-
+
return offset + (zip_uint32_t)size;
}
zip_uint64_t
-_zip_file_get_end(const zip_t *za, zip_uint64_t index, zip_error_t *error)
-{
+_zip_file_get_end(const zip_t *za, zip_uint64_t index, zip_error_t *error) {
zip_uint64_t offset;
zip_dirent_t *entry;
if ((offset = _zip_file_get_offset(za, index, error)) == 0) {
- return 0;
+ return 0;
}
entry = za->entry[index].orig;
if (offset + entry->comp_size < offset || offset + entry->comp_size > ZIP_INT64_MAX) {
- zip_error_set(error, ZIP_ER_SEEK, EFBIG);
- return 0;
+ zip_error_set(error, ZIP_ER_SEEK, EFBIG);
+ return 0;
}
offset += entry->comp_size;
if (entry->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
- zip_uint8_t buf[4];
- if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) {
- _zip_error_set_from_source(error, za->src);
- return 0;
- }
- if (zip_source_read(za->src, buf, 4) != 4) {
- _zip_error_set_from_source(error, za->src);
- return 0;
- }
- if (memcmp(buf, DATADES_MAGIC, 4) == 0) {
- offset += 4;
- }
- offset += 12;
- if (_zip_dirent_needs_zip64(entry, 0)) {
- offset += 8;
- }
- if (offset > ZIP_INT64_MAX) {
- zip_error_set(error, ZIP_ER_SEEK, EFBIG);
- return 0;
- }
+ zip_uint8_t buf[4];
+ if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) {
+ _zip_error_set_from_source(error, za->src);
+ return 0;
+ }
+ if (zip_source_read(za->src, buf, 4) != 4) {
+ _zip_error_set_from_source(error, za->src);
+ return 0;
+ }
+ if (memcmp(buf, DATADES_MAGIC, 4) == 0) {
+ offset += 4;
+ }
+ offset += 12;
+ if (_zip_dirent_needs_zip64(entry, 0)) {
+ offset += 8;
+ }
+ if (offset > ZIP_INT64_MAX) {
+ zip_error_set(error, ZIP_ER_SEEK, EFBIG);
+ return 0;
+ }
}
return offset;
diff --git a/lib/zip_file_rename.c b/lib/zip_file_rename.c
index 4400938..1eb7fac 100644
--- a/lib/zip_file_rename.c
+++ b/lib/zip_file_rename.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,11 +38,10 @@
ZIP_EXTERN int
-zip_file_rename(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags)
-{
+zip_file_rename(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags) {
const char *old_name;
int old_is_dir, new_is_dir;
-
+
if (idx >= za->nentry || (name != NULL && strlen(name) > ZIP_UINT16_MAX)) {
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return -1;
@@ -53,11 +52,11 @@
return -1;
}
- if ((old_name=zip_get_name(za, idx, 0)) == NULL)
+ if ((old_name = zip_get_name(za, idx, 0)) == NULL)
return -1;
-
- new_is_dir = (name != NULL && name[strlen(name)-1] == '/');
- old_is_dir = (old_name[strlen(old_name)-1] == '/');
+
+ new_is_dir = (name != NULL && name[strlen(name) - 1] == '/');
+ old_is_dir = (old_name[strlen(old_name) - 1] == '/');
if (new_is_dir != old_is_dir) {
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
diff --git a/lib/zip_file_replace.c b/lib/zip_file_replace.c
index e430efa..e42f5cd 100644
--- a/lib/zip_file_replace.c
+++ b/lib/zip_file_replace.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
ZIP_EXTERN int
-zip_file_replace(zip_t *za, zip_uint64_t idx, zip_source_t *source, zip_flags_t flags)
-{
+zip_file_replace(zip_t *za, zip_uint64_t idx, zip_source_t *source, zip_flags_t flags) {
if (idx >= za->nentry || source == NULL) {
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return -1;
@@ -50,14 +49,12 @@
}
-
/* NOTE: Signed due to -1 on error. See zip_add.c for more details. */
zip_int64_t
-_zip_file_replace(zip_t *za, zip_uint64_t idx, const char *name, zip_source_t *source, zip_flags_t flags)
-{
+_zip_file_replace(zip_t *za, zip_uint64_t idx, const char *name, zip_source_t *source, zip_flags_t flags) {
zip_uint64_t za_nentry_prev;
-
+
if (ZIP_IS_RDONLY(za)) {
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
return -1;
@@ -66,21 +63,21 @@
za_nentry_prev = za->nentry;
if (idx == ZIP_UINT64_MAX) {
zip_int64_t i = -1;
-
+
if (flags & ZIP_FL_OVERWRITE)
i = _zip_name_locate(za, name, flags, NULL);
if (i == -1) {
/* create and use new entry, used by zip_add */
- if ((i=_zip_add_entry(za)) < 0)
+ if ((i = _zip_add_entry(za)) < 0)
return -1;
}
idx = (zip_uint64_t)i;
}
-
+
if (name && _zip_set_name(za, idx, name, flags) != 0) {
if (za->nentry != za_nentry_prev) {
- _zip_entry_finalize(za->entry+idx);
+ _zip_entry_finalize(za->entry + idx);
za->nentry = za_nentry_prev;
}
return -1;
@@ -88,20 +85,20 @@
/* does not change any name related data, so we can do it here;
* needed for a double add of the same file name */
- _zip_unchange_data(za->entry+idx);
+ _zip_unchange_data(za->entry + idx);
if (za->entry[idx].orig != NULL && (za->entry[idx].changes == NULL || (za->entry[idx].changes->changed & ZIP_DIRENT_COMP_METHOD) == 0)) {
- if (za->entry[idx].changes == NULL) {
- if ((za->entry[idx].changes=_zip_dirent_clone(za->entry[idx].orig)) == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- return -1;
- }
- }
+ if (za->entry[idx].changes == NULL) {
+ if ((za->entry[idx].changes = _zip_dirent_clone(za->entry[idx].orig)) == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return -1;
+ }
+ }
- za->entry[idx].changes->comp_method = ZIP_CM_REPLACED_DEFAULT;
- za->entry[idx].changes->changed |= ZIP_DIRENT_COMP_METHOD;
+ za->entry[idx].changes->comp_method = ZIP_CM_REPLACED_DEFAULT;
+ za->entry[idx].changes->changed |= ZIP_DIRENT_COMP_METHOD;
}
-
+
za->entry[idx].source = source;
return (zip_int64_t)idx;
diff --git a/lib/zip_file_set_comment.c b/lib/zip_file_set_comment.c
index e455fbd..964486b 100644
--- a/lib/zip_file_set_comment.c
+++ b/lib/zip_file_set_comment.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,9 +38,7 @@
ZIP_EXTERN int
-zip_file_set_comment(zip_t *za, zip_uint64_t idx,
- const char *comment, zip_uint16_t len, zip_flags_t flags)
-{
+zip_file_set_comment(zip_t *za, zip_uint64_t idx, const char *comment, zip_uint16_t len, zip_flags_t flags) {
zip_entry_t *e;
zip_string_t *cstr;
int changed;
@@ -59,7 +57,7 @@
}
if (len > 0) {
- if ((cstr=_zip_string_new((const zip_uint8_t *)comment, len, flags, &za->error)) == NULL)
+ if ((cstr = _zip_string_new((const zip_uint8_t *)comment, len, flags, &za->error)) == NULL)
return -1;
if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(cstr, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED)
cstr->encoding = ZIP_ENCODING_UTF8_KNOWN;
@@ -67,7 +65,7 @@
else
cstr = NULL;
- e = za->entry+idx;
+ e = za->entry + idx;
if (e->changes) {
_zip_string_free(e->changes->comment);
@@ -79,17 +77,17 @@
changed = !_zip_string_equal(e->orig->comment, cstr);
else
changed = (cstr != NULL);
-
+
if (changed) {
- if (e->changes == NULL) {
- if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ if (e->changes == NULL) {
+ if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
_zip_string_free(cstr);
- return -1;
- }
- }
- e->changes->comment = cstr;
- e->changes->changed |= ZIP_DIRENT_COMMENT;
+ return -1;
+ }
+ }
+ e->changes->comment = cstr;
+ e->changes->changed |= ZIP_DIRENT_COMMENT;
}
else {
_zip_string_free(cstr);
diff --git a/lib/zip_file_set_encryption.c b/lib/zip_file_set_encryption.c
index 6e16135..b0cbe5c 100644
--- a/lib/zip_file_set_encryption.c
+++ b/lib/zip_file_set_encryption.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,8 +38,7 @@
#include <string.h>
ZIP_EXTERN int
-zip_file_set_encryption(zip_t *za, zip_uint64_t idx, zip_uint16_t method, const char *password)
-{
+zip_file_set_encryption(zip_t *za, zip_uint64_t idx, zip_uint16_t method, const char *password) {
zip_entry_t *e;
zip_uint16_t old_method;
@@ -58,10 +57,10 @@
return -1;
}
- e = za->entry+idx;
-
+ e = za->entry + idx;
+
old_method = (e->orig == NULL ? ZIP_EM_NONE : e->orig->encryption_method);
-
+
if (method == old_method && password == NULL) {
if (e->changes) {
if (e->changes->changed & ZIP_DIRENT_PASSWORD) {
@@ -69,7 +68,7 @@
free(e->changes->password);
e->changes->password = (e->orig == NULL ? NULL : e->orig->password);
}
- e->changes->changed &= ~(ZIP_DIRENT_ENCRYPTION_METHOD|ZIP_DIRENT_PASSWORD);
+ e->changes->changed &= ~(ZIP_DIRENT_ENCRYPTION_METHOD | ZIP_DIRENT_PASSWORD);
if (e->changes->changed == 0) {
_zip_dirent_free(e->changes);
e->changes = NULL;
@@ -85,20 +84,20 @@
return -1;
}
}
-
- if (e->changes == NULL) {
- if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) {
+
+ if (e->changes == NULL) {
+ if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
if (our_password) {
_zip_crypto_clear(our_password, strlen(our_password));
}
free(our_password);
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- return -1;
- }
- }
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return -1;
+ }
+ }
- e->changes->encryption_method = method;
- e->changes->changed |= ZIP_DIRENT_ENCRYPTION_METHOD;
+ e->changes->encryption_method = method;
+ e->changes->changed |= ZIP_DIRENT_ENCRYPTION_METHOD;
if (password) {
e->changes->password = our_password;
e->changes->changed |= ZIP_DIRENT_PASSWORD;
@@ -112,6 +111,6 @@
}
}
}
-
+
return 0;
}
diff --git a/lib/zip_file_set_external_attributes.c b/lib/zip_file_set_external_attributes.c
index b772c31..cd46e88 100644
--- a/lib/zip_file_set_external_attributes.c
+++ b/lib/zip_file_set_external_attributes.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -34,8 +34,7 @@
#include "zipint.h"
ZIP_EXTERN int
-zip_file_set_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t opsys, zip_uint32_t attributes)
-{
+zip_file_set_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t opsys, zip_uint32_t attributes) {
zip_entry_t *e;
int changed;
zip_uint8_t unchanged_opsys;
@@ -49,23 +48,23 @@
return -1;
}
- e = za->entry+idx;
+ e = za->entry + idx;
- unchanged_opsys = (e->orig ? (zip_uint8_t)(e->orig->version_madeby>>8) : (zip_uint8_t)ZIP_OPSYS_DEFAULT);
+ unchanged_opsys = (e->orig ? (zip_uint8_t)(e->orig->version_madeby >> 8) : (zip_uint8_t)ZIP_OPSYS_DEFAULT);
unchanged_attributes = e->orig ? e->orig->ext_attrib : ZIP_EXT_ATTRIB_DEFAULT;
changed = (opsys != unchanged_opsys || attributes != unchanged_attributes);
if (changed) {
- if (e->changes == NULL) {
- if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- return -1;
- }
- }
- e->changes->version_madeby = (zip_uint16_t)((opsys << 8) | (e->changes->version_madeby & 0xff));
+ if (e->changes == NULL) {
+ if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return -1;
+ }
+ }
+ e->changes->version_madeby = (zip_uint16_t)((opsys << 8) | (e->changes->version_madeby & 0xff));
e->changes->ext_attrib = attributes;
- e->changes->changed |= ZIP_DIRENT_ATTRIBUTES;
+ e->changes->changed |= ZIP_DIRENT_ATTRIBUTES;
}
else if (e->changes) {
e->changes->changed &= ~ZIP_DIRENT_ATTRIBUTES;
diff --git a/lib/zip_file_set_mtime.c b/lib/zip_file_set_mtime.c
index 0cdd31a..15316d3 100644
--- a/lib/zip_file_set_mtime.c
+++ b/lib/zip_file_set_mtime.c
@@ -1,10 +1,10 @@
/*
zip_file_set_mtime.c -- set modification time of entry.
Copyright (C) 2014 Dieter Baron and Thomas Klausner
-
+
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
-
+
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -33,42 +33,42 @@
#include "zipint.h"
-ZIP_EXTERN int zip_file_set_mtime(zip_t *za, zip_uint64_t idx, time_t mtime, zip_flags_t flags)
-{
+ZIP_EXTERN int
+zip_file_set_mtime(zip_t *za, zip_uint64_t idx, time_t mtime, zip_flags_t flags) {
zip_entry_t *e;
int changed;
-
+
if (_zip_get_dirent(za, idx, 0, NULL) == NULL)
- return -1;
-
+ return -1;
+
if (ZIP_IS_RDONLY(za)) {
- zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
- return -1;
+ zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
+ return -1;
}
-
- e = za->entry+idx;
+
+ e = za->entry + idx;
changed = e->orig == NULL || mtime != e->orig->last_mod;
-
+
if (changed) {
- if (e->changes == NULL) {
- if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- return -1;
- }
- }
- e->changes->last_mod = mtime;
- e->changes->changed |= ZIP_DIRENT_LAST_MOD;
+ if (e->changes == NULL) {
+ if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return -1;
+ }
+ }
+ e->changes->last_mod = mtime;
+ e->changes->changed |= ZIP_DIRENT_LAST_MOD;
}
else {
- if (e->changes) {
- e->changes->changed &= ~ZIP_DIRENT_LAST_MOD;
- if (e->changes->changed == 0) {
+ if (e->changes) {
+ e->changes->changed &= ~ZIP_DIRENT_LAST_MOD;
+ if (e->changes->changed == 0) {
_zip_dirent_free(e->changes);
- e->changes = NULL;
- }
- }
+ e->changes = NULL;
+ }
+ }
}
-
+
return 0;
}
diff --git a/lib/zip_file_strerror.c b/lib/zip_file_strerror.c
index 8366f1e..fd4008a 100644
--- a/lib/zip_file_strerror.c
+++ b/lib/zip_file_strerror.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,7 +36,6 @@
ZIP_EXTERN const char *
-zip_file_strerror(zip_file_t *zf)
-{
+zip_file_strerror(zip_file_t *zf) {
return zip_error_strerror(&zf->error);
}
diff --git a/lib/zip_filerange_crc.c b/lib/zip_filerange_crc.c
index 775af9a..6c4be27 100644
--- a/lib/zip_filerange_crc.c
+++ b/lib/zip_filerange_crc.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,10 +37,8 @@
#include "zipint.h"
-
int
-_zip_filerange_crc(zip_source_t *src, zip_uint64_t start, zip_uint64_t len, uLong *crcp, zip_error_t *error)
-{
+_zip_filerange_crc(zip_source_t *src, zip_uint64_t start, zip_uint64_t len, uLong *crcp, zip_error_t *error) {
Bytef buf[BUFSIZE];
zip_int64_t n;
@@ -55,7 +53,7 @@
_zip_error_set_from_source(error, src);
return -1;
}
-
+
while (len > 0) {
n = (zip_int64_t)(len > BUFSIZE ? BUFSIZE : len);
if ((n = zip_source_read(src, buf, (zip_uint64_t)n)) < 0) {
diff --git a/lib/zip_fopen.c b/lib/zip_fopen.c
index 3adb5de..cb45cc2 100644
--- a/lib/zip_fopen.c
+++ b/lib/zip_fopen.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,11 +36,10 @@
ZIP_EXTERN zip_file_t *
-zip_fopen(zip_t *za, const char *fname, zip_flags_t flags)
-{
+zip_fopen(zip_t *za, const char *fname, zip_flags_t flags) {
zip_int64_t idx;
- if ((idx=zip_name_locate(za, fname, flags)) < 0)
+ if ((idx = zip_name_locate(za, fname, flags)) < 0)
return NULL;
return zip_fopen_index_encrypted(za, (zip_uint64_t)idx, flags, za->default_password);
diff --git a/lib/zip_fopen_encrypted.c b/lib/zip_fopen_encrypted.c
index 5eaf2b0..abcf6ac 100644
--- a/lib/zip_fopen_encrypted.c
+++ b/lib/zip_fopen_encrypted.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,11 +36,10 @@
ZIP_EXTERN zip_file_t *
-zip_fopen_encrypted(zip_t *za, const char *fname, zip_flags_t flags, const char *password)
-{
+zip_fopen_encrypted(zip_t *za, const char *fname, zip_flags_t flags, const char *password) {
zip_int64_t idx;
- if ((idx=zip_name_locate(za, fname, flags)) < 0)
+ if ((idx = zip_name_locate(za, fname, flags)) < 0)
return NULL;
return zip_fopen_index_encrypted(za, (zip_uint64_t)idx, flags, password);
diff --git a/lib/zip_fopen_index.c b/lib/zip_fopen_index.c
index 0fb150b..7dcf1f7 100644
--- a/lib/zip_fopen_index.c
+++ b/lib/zip_fopen_index.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,7 +39,6 @@
ZIP_EXTERN zip_file_t *
-zip_fopen_index(zip_t *za, zip_uint64_t index, zip_flags_t flags)
-{
+zip_fopen_index(zip_t *za, zip_uint64_t index, zip_flags_t flags) {
return zip_fopen_index_encrypted(za, index, flags, za->default_password);
}
diff --git a/lib/zip_fopen_index_encrypted.c b/lib/zip_fopen_index_encrypted.c
index 4c32e02..6b32008 100644
--- a/lib/zip_fopen_index_encrypted.c
+++ b/lib/zip_fopen_index_encrypted.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -41,13 +41,11 @@
ZIP_EXTERN zip_file_t *
-zip_fopen_index_encrypted(zip_t *za, zip_uint64_t index, zip_flags_t flags,
- const char *password)
-{
+zip_fopen_index_encrypted(zip_t *za, zip_uint64_t index, zip_flags_t flags, const char *password) {
zip_file_t *zf;
zip_source_t *src;
- if ((src=_zip_source_zip_new(za, za, index, flags, 0, 0, password)) == NULL)
+ if ((src = _zip_source_zip_new(za, za, index, flags, 0, 0, password)) == NULL)
return NULL;
if (zip_source_open(src) < 0) {
@@ -56,7 +54,7 @@
return NULL;
}
- if ((zf=_zip_file_new(za)) == NULL) {
+ if ((zf = _zip_file_new(za)) == NULL) {
zip_source_free(src);
return NULL;
}
@@ -68,11 +66,10 @@
static zip_file_t *
-_zip_file_new(zip_t *za)
-{
+_zip_file_new(zip_t *za) {
zip_file_t *zf;
- if ((zf=(zip_file_t *)malloc(sizeof(struct zip_file))) == NULL) {
+ if ((zf = (zip_file_t *)malloc(sizeof(struct zip_file))) == NULL) {
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return NULL;
}
diff --git a/lib/zip_fread.c b/lib/zip_fread.c
index 9c1cbe0..be46cf0 100644
--- a/lib/zip_fread.c
+++ b/lib/zip_fread.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
ZIP_EXTERN zip_int64_t
-zip_fread(zip_file_t *zf, void *outbuf, zip_uint64_t toread)
-{
+zip_fread(zip_file_t *zf, void *outbuf, zip_uint64_t toread) {
zip_int64_t n;
if (!zf)
@@ -54,7 +53,7 @@
if ((zf->eof) || (toread == 0))
return 0;
- if ((n=zip_source_read(zf->src, outbuf, toread)) < 0) {
+ if ((n = zip_source_read(zf->src, outbuf, toread)) < 0) {
_zip_error_set_from_source(&zf->error, zf->src);
return -1;
}
diff --git a/lib/zip_fseek.c b/lib/zip_fseek.c
index a16af1a..c939ebf 100644
--- a/lib/zip_fseek.c
+++ b/lib/zip_fseek.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,9 +36,7 @@
#include <stdio.h>
ZIP_EXTERN zip_int8_t
-zip_fseek(zip_file_t *zf, zip_int64_t offset, int whence)
-{
-
+zip_fseek(zip_file_t *zf, zip_int64_t offset, int whence) {
if (!zf)
return -1;
diff --git a/lib/zip_ftell.c b/lib/zip_ftell.c
index abbf296..ff062df 100644
--- a/lib/zip_ftell.c
+++ b/lib/zip_ftell.c
@@ -36,8 +36,7 @@
#include <stdio.h>
ZIP_EXTERN zip_int64_t
-zip_ftell(zip_file_t *zf)
-{
+zip_ftell(zip_file_t *zf) {
zip_int64_t res;
if (!zf)
diff --git a/lib/zip_get_archive_comment.c b/lib/zip_get_archive_comment.c
index 78f8ca0..a3d5a19 100644
--- a/lib/zip_get_archive_comment.c
+++ b/lib/zip_get_archive_comment.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,8 +38,7 @@
ZIP_EXTERN const char *
-zip_get_archive_comment(zip_t *za, int *lenp, zip_flags_t flags)
-{
+zip_get_archive_comment(zip_t *za, int *lenp, zip_flags_t flags) {
zip_string_t *comment;
zip_uint32_t len;
const zip_uint8_t *str;
@@ -49,7 +48,7 @@
else
comment = za->comment_changes;
- if ((str=_zip_string_get(comment, &len, flags, &za->error)) == NULL)
+ if ((str = _zip_string_get(comment, &len, flags, &za->error)) == NULL)
return NULL;
if (lenp)
diff --git a/lib/zip_get_archive_flag.c b/lib/zip_get_archive_flag.c
index bffe10c..67fe4f8 100644
--- a/lib/zip_get_archive_flag.c
+++ b/lib/zip_get_archive_flag.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
ZIP_EXTERN int
-zip_get_archive_flag(zip_t *za, zip_flags_t flag, zip_flags_t flags)
-{
+zip_get_archive_flag(zip_t *za, zip_flags_t flag, zip_flags_t flags) {
unsigned int fl;
fl = (flags & ZIP_FL_UNCHANGED) ? za->flags : za->ch_flags;
diff --git a/lib/zip_get_encryption_implementation.c b/lib/zip_get_encryption_implementation.c
index f8af7b0..927e9b9 100644
--- a/lib/zip_get_encryption_implementation.c
+++ b/lib/zip_get_encryption_implementation.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
zip_encryption_implementation
-_zip_get_encryption_implementation(zip_uint16_t em, int operation)
-{
+_zip_get_encryption_implementation(zip_uint16_t em, int operation) {
switch (em) {
case ZIP_EM_TRAD_PKWARE:
if (operation == ZIP_CODEC_ENCODE) {
diff --git a/lib/zip_get_file_comment.c b/lib/zip_get_file_comment.c
index d5f50bf..44e5917 100644
--- a/lib/zip_get_file_comment.c
+++ b/lib/zip_get_file_comment.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,12 +37,11 @@
ZIP_EXTERN const char *
-zip_get_file_comment(zip_t *za, zip_uint64_t idx, int *lenp, int flags)
-{
+zip_get_file_comment(zip_t *za, zip_uint64_t idx, int *lenp, int flags) {
zip_uint32_t len;
const char *s;
- if ((s=zip_file_get_comment(za, idx, &len, (zip_flags_t)flags)) != NULL) {
+ if ((s = zip_file_get_comment(za, idx, &len, (zip_flags_t)flags)) != NULL) {
if (lenp)
*lenp = (int)len;
}
diff --git a/lib/zip_get_name.c b/lib/zip_get_name.c
index d29e636..d42f14a 100644
--- a/lib/zip_get_name.c
+++ b/lib/zip_get_name.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,22 +38,20 @@
ZIP_EXTERN const char *
-zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags)
-{
+zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags) {
return _zip_get_name(za, idx, flags, &za->error);
}
const char *
-_zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error)
-{
+_zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error) {
zip_dirent_t *de;
const zip_uint8_t *str;
- if ((de=_zip_get_dirent(za, idx, flags, error)) == NULL)
+ if ((de = _zip_get_dirent(za, idx, flags, error)) == NULL)
return NULL;
- if ((str=_zip_string_get(de->filename, NULL, flags, error)) == NULL)
+ if ((str = _zip_string_get(de->filename, NULL, flags, error)) == NULL)
return NULL;
return (const char *)str;
diff --git a/lib/zip_get_num_entries.c b/lib/zip_get_num_entries.c
index c8644a4..78f30dc 100644
--- a/lib/zip_get_num_entries.c
+++ b/lib/zip_get_num_entries.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
ZIP_EXTERN zip_int64_t
-zip_get_num_entries(zip_t *za, zip_flags_t flags)
-{
+zip_get_num_entries(zip_t *za, zip_flags_t flags) {
zip_uint64_t n;
if (za == NULL)
@@ -45,7 +44,7 @@
if (flags & ZIP_FL_UNCHANGED) {
n = za->nentry;
- while (n>0 && za->entry[n-1].orig == NULL)
+ while (n > 0 && za->entry[n - 1].orig == NULL)
--n;
return (zip_int64_t)n;
}
diff --git a/lib/zip_get_num_files.c b/lib/zip_get_num_files.c
index cf96353..3ccf400 100644
--- a/lib/zip_get_num_files.c
+++ b/lib/zip_get_num_files.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,8 +38,7 @@
ZIP_EXTERN int
-zip_get_num_files(zip_t *za)
-{
+zip_get_num_files(zip_t *za) {
if (za == NULL)
return -1;
diff --git a/lib/zip_hash.c b/lib/zip_hash.c
index 992e9d9..0d9e996 100644
--- a/lib/zip_hash.c
+++ b/lib/zip_hash.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -31,9 +31,9 @@
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "zipint.h"
#include <stdlib.h>
#include <string.h>
-#include "zipint.h"
/* parameter for the string hash function */
#define HASH_MULTIPLIER 33
@@ -65,8 +65,7 @@
/* free list of entries */
static void
-free_list(zip_hash_entry_t *entry)
-{
+free_list(zip_hash_entry_t *entry) {
while (entry != NULL) {
zip_hash_entry_t *next = entry->next;
free(entry);
@@ -77,8 +76,7 @@
/* compute hash of string, full 32 bit value */
static zip_uint32_t
-hash_string(const zip_uint8_t *name)
-{
+hash_string(const zip_uint8_t *name) {
zip_uint64_t value = HASH_START;
if (name == NULL) {
@@ -96,15 +94,14 @@
/* resize hash table; new_size must be a power of 2, can be larger or smaller than current size */
static bool
-hash_resize(zip_hash_t *hash, zip_uint32_t new_size, zip_error_t *error)
-{
+hash_resize(zip_hash_t *hash, zip_uint32_t new_size, zip_error_t *error) {
zip_hash_entry_t **new_table;
if (new_size == hash->table_size) {
return true;
}
- if ((new_table = (zip_hash_entry_t**)calloc(new_size, sizeof(zip_hash_entry_t *))) == NULL) {
+ if ((new_table = (zip_hash_entry_t **)calloc(new_size, sizeof(zip_hash_entry_t *))) == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return false;
}
@@ -167,26 +164,24 @@
zip_hash_t *
-_zip_hash_new(zip_error_t *error)
-{
+_zip_hash_new(zip_error_t *error) {
zip_hash_t *hash;
if ((hash = (zip_hash_t *)malloc(sizeof(zip_hash_t))) == NULL) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- return NULL;
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return NULL;
}
hash->table_size = 0;
hash->nentries = 0;
hash->table = NULL;
-
+
return hash;
}
void
-_zip_hash_free(zip_hash_t *hash)
-{
+_zip_hash_free(zip_hash_t *hash) {
zip_uint32_t i;
if (hash == NULL) {
@@ -194,7 +189,7 @@
}
if (hash->table != NULL) {
- for (i=0; i<hash->table_size; i++) {
+ for (i = 0; i < hash->table_size; i++) {
if (hash->table[i] != NULL) {
free_list(hash->table[i]);
}
@@ -207,8 +202,7 @@
/* insert into hash, return error on existence or memory issues */
bool
-_zip_hash_add(zip_hash_t *hash, const zip_uint8_t *name, zip_uint64_t index, zip_flags_t flags, zip_error_t *error)
-{
+_zip_hash_add(zip_hash_t *hash, const zip_uint8_t *name, zip_uint64_t index, zip_flags_t flags, zip_error_t *error) {
zip_uint32_t hash_value, table_index;
zip_hash_entry_t *entry;
@@ -227,28 +221,28 @@
table_index = hash_value % hash->table_size;
for (entry = hash->table[table_index]; entry != NULL; entry = entry->next) {
- if (entry->hash_value == hash_value && strcmp((const char *)name, (const char *)entry->name) == 0) {
- if (((flags & ZIP_FL_UNCHANGED) && entry->orig_index != -1) || entry->current_index != -1) {
- zip_error_set(error, ZIP_ER_EXISTS, 0);
- return false;
- }
- else {
- break;
- }
- }
+ if (entry->hash_value == hash_value && strcmp((const char *)name, (const char *)entry->name) == 0) {
+ if (((flags & ZIP_FL_UNCHANGED) && entry->orig_index != -1) || entry->current_index != -1) {
+ zip_error_set(error, ZIP_ER_EXISTS, 0);
+ return false;
+ }
+ else {
+ break;
+ }
+ }
}
if (entry == NULL) {
- if ((entry = (zip_hash_entry_t *)malloc(sizeof(zip_hash_entry_t))) == NULL) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- return false;
- }
- entry->name = name;
- entry->next = hash->table[table_index];
- hash->table[table_index] = entry;
- entry->hash_value = hash_value;
- entry->orig_index = -1;
- hash->nentries++;
+ if ((entry = (zip_hash_entry_t *)malloc(sizeof(zip_hash_entry_t))) == NULL) {
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return false;
+ }
+ entry->name = name;
+ entry->next = hash->table[table_index];
+ hash->table[table_index] = entry;
+ entry->hash_value = hash_value;
+ entry->orig_index = -1;
+ hash->nentries++;
if (hash->nentries > hash->table_size * HASH_MAX_FILL && hash->table_size < HASH_MAX_SIZE) {
if (!hash_resize(hash, hash->table_size * 2, error)) {
return false;
@@ -257,7 +251,7 @@
}
if (flags & ZIP_FL_UNCHANGED) {
- entry->orig_index = (zip_int64_t)index;
+ entry->orig_index = (zip_int64_t)index;
}
entry->current_index = (zip_int64_t)index;
@@ -267,8 +261,7 @@
/* remove entry from hash, error if not found */
bool
-_zip_hash_delete(zip_hash_t *hash, const zip_uint8_t *name, zip_error_t *error)
-{
+_zip_hash_delete(zip_hash_t *hash, const zip_uint8_t *name, zip_error_t *error) {
zip_uint32_t hash_value, index;
zip_hash_entry_t *entry, *previous;
@@ -316,14 +309,13 @@
/* find value for entry in hash, -1 if not found */
zip_int64_t
-_zip_hash_lookup(zip_hash_t *hash, const zip_uint8_t *name, zip_flags_t flags, zip_error_t *error)
-{
+_zip_hash_lookup(zip_hash_t *hash, const zip_uint8_t *name, zip_flags_t flags, zip_error_t *error) {
zip_uint32_t hash_value, index;
zip_hash_entry_t *entry;
if (hash == NULL || name == NULL) {
- zip_error_set(error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(error, ZIP_ER_INVAL, 0);
+ return -1;
}
if (hash->nentries > 0) {
@@ -352,8 +344,7 @@
bool
-_zip_hash_reserve_capacity(zip_hash_t *hash, zip_uint64_t capacity, zip_error_t *error)
-{
+_zip_hash_reserve_capacity(zip_hash_t *hash, zip_uint64_t capacity, zip_error_t *error) {
zip_uint32_t new_size;
if (capacity == 0) {
@@ -367,7 +358,7 @@
}
if (!hash_resize(hash, new_size, error)) {
- return false;
+ return false;
}
return true;
@@ -375,35 +366,34 @@
bool
-_zip_hash_revert(zip_hash_t *hash, zip_error_t *error)
-{
+_zip_hash_revert(zip_hash_t *hash, zip_error_t *error) {
zip_uint32_t i;
zip_hash_entry_t *entry, *previous;
-
+
for (i = 0; i < hash->table_size; i++) {
- previous = NULL;
- entry = hash->table[i];
- while (entry) {
- if (entry->orig_index == -1) {
- zip_hash_entry_t *p;
- if (previous) {
- previous->next = entry->next;
- }
- else {
- hash->table[i] = entry->next;
- }
- p = entry;
- entry = entry->next;
- /* previous does not change */
- free(p);
- hash->nentries--;
- }
- else {
- entry->current_index = entry->orig_index;
- previous = entry;
- entry = entry->next;
- }
- }
+ previous = NULL;
+ entry = hash->table[i];
+ while (entry) {
+ if (entry->orig_index == -1) {
+ zip_hash_entry_t *p;
+ if (previous) {
+ previous->next = entry->next;
+ }
+ else {
+ hash->table[i] = entry->next;
+ }
+ p = entry;
+ entry = entry->next;
+ /* previous does not change */
+ free(p);
+ hash->nentries--;
+ }
+ else {
+ entry->current_index = entry->orig_index;
+ previous = entry;
+ entry = entry->next;
+ }
+ }
}
if (hash->nentries < hash->table_size * HASH_MIN_FILL && hash->table_size > HASH_MIN_SIZE) {
diff --git a/lib/zip_io_util.c b/lib/zip_io_util.c
index 53a5dd2..77be8f0 100644
--- a/lib/zip_io_util.c
+++ b/lib/zip_io_util.c
@@ -1,10 +1,10 @@
/*
zip_io_util.c -- I/O helper functions
Copyright (C) 1999-2016 Dieter Baron and Thomas Klausner
-
+
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
-
+
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,8 +37,7 @@
#include "zipint.h"
int
-_zip_read(zip_source_t *src, zip_uint8_t *b, zip_uint64_t length, zip_error_t *error)
-{
+_zip_read(zip_source_t *src, zip_uint8_t *b, zip_uint64_t length, zip_error_t *error) {
zip_int64_t n;
if (length > ZIP_INT64_MAX) {
@@ -61,10 +60,9 @@
zip_uint8_t *
-_zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error)
-{
+_zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error) {
zip_uint8_t *r;
-
+
if (length == 0 && !nulp) {
return NULL;
}
@@ -76,13 +74,13 @@
}
if (buffer) {
- zip_uint8_t *data = _zip_buffer_get(buffer, length);
-
- if (data == NULL) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- free(r);
- return NULL;
- }
+ zip_uint8_t *data = _zip_buffer_get(buffer, length);
+
+ if (data == NULL) {
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ free(r);
+ return NULL;
+ }
memcpy(r, data, length);
}
else {
@@ -96,7 +94,7 @@
zip_uint8_t *o;
/* replace any in-string NUL characters with spaces */
r[length] = 0;
- for (o=r; o<r+length; o++)
+ for (o = r; o < r + length; o++)
if (*o == '\0')
*o = ' ';
}
@@ -106,12 +104,11 @@
zip_string_t *
-_zip_read_string(zip_buffer_t *buffer, zip_source_t *src, zip_uint16_t len, bool nulp, zip_error_t *error)
-{
+_zip_read_string(zip_buffer_t *buffer, zip_source_t *src, zip_uint16_t len, bool nulp, zip_error_t *error) {
zip_uint8_t *raw;
zip_string_t *s;
- if ((raw=_zip_read_data(buffer, src, len, nulp, error)) == NULL)
+ if ((raw = _zip_read_data(buffer, src, len, nulp, error)) == NULL)
return NULL;
s = _zip_string_new(raw, len, ZIP_FL_ENC_GUESS, error);
@@ -121,18 +118,17 @@
int
-_zip_write(zip_t *za, const void *data, zip_uint64_t length)
-{
+_zip_write(zip_t *za, const void *data, zip_uint64_t length) {
zip_int64_t n;
-
+
if ((n = zip_source_write(za->src, data, length)) < 0) {
- _zip_error_set_from_source(&za->error, za->src);
- return -1;
+ _zip_error_set_from_source(&za->error, za->src);
+ return -1;
}
if ((zip_uint64_t)n != length) {
- zip_error_set(&za->error, ZIP_ER_WRITE, EINTR);
- return -1;
+ zip_error_set(&za->error, ZIP_ER_WRITE, EINTR);
+ return -1;
}
-
+
return 0;
}
diff --git a/lib/zip_libzip_version.c b/lib/zip_libzip_version.c
index 44d5612..72f1025 100644
--- a/lib/zip_libzip_version.c
+++ b/lib/zip_libzip_version.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,7 +36,6 @@
ZIP_EXTERN const char *
-zip_libzip_version(void)
-{
+zip_libzip_version(void) {
return LIBZIP_VERSION;
}
diff --git a/lib/zip_memdup.c b/lib/zip_memdup.c
index cc6d767..9d7949d 100644
--- a/lib/zip_memdup.c
+++ b/lib/zip_memdup.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,8 +38,7 @@
void *
-_zip_memdup(const void *mem, size_t len, zip_error_t *error)
-{
+_zip_memdup(const void *mem, size_t len, zip_error_t *error) {
void *ret;
if (len == 0)
diff --git a/lib/zip_name_locate.c b/lib/zip_name_locate.c
index 706093f..6713cab 100644
--- a/lib/zip_name_locate.c
+++ b/lib/zip_name_locate.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -41,15 +41,13 @@
ZIP_EXTERN zip_int64_t
-zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags)
-{
+zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags) {
return _zip_name_locate(za, fname, flags, &za->error);
}
zip_int64_t
-_zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *error)
-{
+_zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *error) {
int (*cmp)(const char *, const char *);
const char *fn, *p;
zip_uint64_t i;
@@ -62,23 +60,23 @@
return -1;
}
- if (flags & (ZIP_FL_NOCASE|ZIP_FL_NODIR|ZIP_FL_ENC_CP437)) {
+ if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_CP437)) {
/* can't use hash table */
cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp;
- for (i=0; i<za->nentry; i++) {
+ for (i = 0; i < za->nentry; i++) {
fn = _zip_get_name(za, i, flags, error);
-
+
/* newly added (partially filled) entry or error */
if (fn == NULL)
continue;
-
+
if (flags & ZIP_FL_NODIR) {
p = strrchr(fn, '/');
if (p)
- fn = p+1;
+ fn = p + 1;
}
-
+
if (cmp(fname, fn) == 0) {
_zip_error_clear(error);
return (zip_int64_t)i;
diff --git a/lib/zip_new.c b/lib/zip_new.c
index da841ff..19155f4 100644
--- a/lib/zip_new.c
+++ b/lib/zip_new.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -42,8 +42,7 @@
the new struct. */
zip_t *
-_zip_new(zip_error_t *error)
-{
+_zip_new(zip_error_t *error) {
zip_t *za;
za = (zip_t *)malloc(sizeof(struct zip));
@@ -69,6 +68,6 @@
za->nopen_source = za->nopen_source_alloc = 0;
za->open_source = NULL;
za->progress = NULL;
-
+
return za;
}
diff --git a/lib/zip_open.c b/lib/zip_open.c
index 6c62eef..1886c9d 100644
--- a/lib/zip_open.c
+++ b/lib/zip_open.c
@@ -32,11 +32,11 @@
*/
-#include <sys/stat.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
#include "zipint.h"
@@ -58,8 +58,7 @@
ZIP_EXTERN zip_t *
-zip_open(const char *fn, int _flags, int *zep)
-{
+zip_open(const char *fn, int _flags, int *zep) {
zip_t *za;
zip_source_t *src;
struct zip_error error;
@@ -84,8 +83,7 @@
ZIP_EXTERN zip_t *
-zip_open_from_source(zip_source_t *src, int _flags, zip_error_t *error)
-{
+zip_open_from_source(zip_source_t *src, int _flags, zip_error_t *error) {
static zip_int64_t needed_support_read = -1;
static zip_int64_t needed_support_write = -1;
@@ -95,24 +93,24 @@
if (_flags < 0 || src == NULL) {
zip_error_set(error, ZIP_ER_INVAL, 0);
- return NULL;
+ return NULL;
}
flags = (unsigned int)_flags;
supported = zip_source_supports(src);
if (needed_support_read == -1) {
- needed_support_read = zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_STAT, -1);
- needed_support_write = zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, -1);
+ needed_support_read = zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_STAT, -1);
+ needed_support_write = zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, -1);
}
if ((supported & needed_support_read) != needed_support_read) {
- zip_error_set(error, ZIP_ER_OPNOTSUPP, 0);
- return NULL;
+ zip_error_set(error, ZIP_ER_OPNOTSUPP, 0);
+ return NULL;
}
if ((supported & needed_support_write) != needed_support_write) {
- flags |= ZIP_RDONLY;
+ flags |= ZIP_RDONLY;
}
- if ((flags & (ZIP_RDONLY|ZIP_TRUNCATE)) == (ZIP_RDONLY|ZIP_TRUNCATE)) {
+ if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
zip_error_set(error, ZIP_ER_RDONLY, 0);
return NULL;
}
@@ -159,8 +157,7 @@
zip_t *
-_zip_open(zip_source_t *src, unsigned int flags, zip_error_t *error)
-{
+_zip_open(zip_source_t *src, unsigned int flags, zip_error_t *error) {
zip_t *za;
zip_cdir_t *cdir;
struct zip_stat st;
@@ -179,7 +176,7 @@
/* treat empty files as empty archives */
if (len == 0) {
- if ((za=_zip_allocate_new(src, flags, error)) == NULL) {
+ if ((za = _zip_allocate_new(src, flags, error)) == NULL) {
zip_source_free(src);
return NULL;
}
@@ -187,12 +184,12 @@
return za;
}
- if ((za=_zip_allocate_new(src, flags, error)) == NULL) {
- return NULL;
+ if ((za = _zip_allocate_new(src, flags, error)) == NULL) {
+ return NULL;
}
if ((cdir = _zip_find_central_dir(za, len)) == NULL) {
- _zip_error_copy(error, &za->error);
+ _zip_error_copy(error, &za->error);
/* keep src so discard does not get rid of it */
zip_source_keep(src);
zip_discard(za);
@@ -207,14 +204,14 @@
free(cdir);
_zip_hash_reserve_capacity(za->names, za->nentry, &za->error);
-
+
for (idx = 0; idx < za->nentry; idx++) {
const zip_uint8_t *name = _zip_string_get(za->entry[idx].orig->filename, NULL, 0, error);
if (name == NULL) {
- /* keep src so discard does not get rid of it */
- zip_source_keep(src);
- zip_discard(za);
- return NULL;
+ /* keep src so discard does not get rid of it */
+ zip_source_keep(src);
+ zip_discard(za);
+ return NULL;
}
if (_zip_hash_add(za->names, name, idx, ZIP_FL_UNCHANGED, &za->error) == false) {
@@ -235,8 +232,7 @@
void
-_zip_set_open_error(int *zep, const zip_error_t *err, int ze)
-{
+_zip_set_open_error(int *zep, const zip_error_t *err, int ze) {
if (err) {
ze = zip_error_code_zip(err);
if (zip_error_system_type(err) == ZIP_ET_SYS) {
@@ -256,8 +252,7 @@
entries, or NULL if unsuccessful. */
static zip_cdir_t *
-_zip_read_cdir(zip_t *za, zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_error_t *error)
-{
+_zip_read_cdir(zip_t *za, zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_error_t *error) {
zip_cdir_t *cd;
zip_uint16_t comment_len;
zip_uint64_t i, left;
@@ -277,12 +272,12 @@
}
if (eocd_offset >= EOCD64LOCLEN && memcmp(_zip_buffer_data(buffer) + eocd_offset - EOCD64LOCLEN, EOCD64LOC_MAGIC, 4) == 0) {
- _zip_buffer_set_offset(buffer, eocd_offset - EOCD64LOCLEN);
- cd = _zip_read_eocd64(za->src, buffer, buf_offset, za->flags, error);
+ _zip_buffer_set_offset(buffer, eocd_offset - EOCD64LOCLEN);
+ cd = _zip_read_eocd64(za->src, buffer, buf_offset, za->flags, error);
}
else {
- _zip_buffer_set_offset(buffer, eocd_offset);
- cd = _zip_read_eocd(buffer, buf_offset, za->flags, error);
+ _zip_buffer_set_offset(buffer, eocd_offset);
+ cd = _zip_read_eocd(buffer, buf_offset, za->flags, error);
}
if (cd == NULL)
@@ -299,63 +294,63 @@
}
if (comment_len || (za->open_flags & ZIP_CHECKCONS)) {
- zip_uint64_t tail_len;
+ zip_uint64_t tail_len;
- _zip_buffer_set_offset(buffer, eocd_offset + EOCDLEN);
- tail_len = _zip_buffer_left(buffer);
+ _zip_buffer_set_offset(buffer, eocd_offset + EOCDLEN);
+ tail_len = _zip_buffer_left(buffer);
- if (tail_len < comment_len || ((za->open_flags & ZIP_CHECKCONS) && tail_len != comment_len)) {
- zip_error_set(error, ZIP_ER_INCONS, 0);
- _zip_cdir_free(cd);
- return NULL;
- }
+ if (tail_len < comment_len || ((za->open_flags & ZIP_CHECKCONS) && tail_len != comment_len)) {
+ zip_error_set(error, ZIP_ER_INCONS, 0);
+ _zip_cdir_free(cd);
+ return NULL;
+ }
- if (comment_len) {
- if ((cd->comment=_zip_string_new(_zip_buffer_get(buffer, comment_len), comment_len, ZIP_FL_ENC_GUESS, error)) == NULL) {
- _zip_cdir_free(cd);
- return NULL;
- }
- }
+ if (comment_len) {
+ if ((cd->comment = _zip_string_new(_zip_buffer_get(buffer, comment_len), comment_len, ZIP_FL_ENC_GUESS, error)) == NULL) {
+ _zip_cdir_free(cd);
+ return NULL;
+ }
+ }
}
if (cd->offset >= buf_offset) {
- zip_uint8_t *data;
+ zip_uint8_t *data;
/* if buffer already read in, use it */
- _zip_buffer_set_offset(buffer, cd->offset - buf_offset);
+ _zip_buffer_set_offset(buffer, cd->offset - buf_offset);
- if ((data = _zip_buffer_get(buffer, cd->size)) == NULL) {
- zip_error_set(error, ZIP_ER_INCONS, 0);
- _zip_cdir_free(cd);
- return NULL;
- }
- if ((cd_buffer = _zip_buffer_new(data, cd->size)) == NULL) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- _zip_cdir_free(cd);
- return NULL;
- }
+ if ((data = _zip_buffer_get(buffer, cd->size)) == NULL) {
+ zip_error_set(error, ZIP_ER_INCONS, 0);
+ _zip_cdir_free(cd);
+ return NULL;
+ }
+ if ((cd_buffer = _zip_buffer_new(data, cd->size)) == NULL) {
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ _zip_cdir_free(cd);
+ return NULL;
+ }
}
else {
- cd_buffer = NULL;
+ cd_buffer = NULL;
- if (zip_source_seek(za->src, (zip_int64_t)cd->offset, SEEK_SET) < 0) {
- _zip_error_set_from_source(error, za->src);
- _zip_cdir_free(cd);
- return NULL;
- }
+ if (zip_source_seek(za->src, (zip_int64_t)cd->offset, SEEK_SET) < 0) {
+ _zip_error_set_from_source(error, za->src);
+ _zip_cdir_free(cd);
+ return NULL;
+ }
/* possible consistency check: cd->offset = len-(cd->size+cd->comment_len+EOCDLEN) ? */
if (zip_source_tell(za->src) != (zip_int64_t)cd->offset) {
- zip_error_set(error, ZIP_ER_NOZIP, 0);
+ zip_error_set(error, ZIP_ER_NOZIP, 0);
_zip_cdir_free(cd);
return NULL;
}
}
left = (zip_uint64_t)cd->size;
- i=0;
+ i = 0;
while (left > 0) {
bool grown = false;
- zip_int64_t entry_size;
+ zip_int64_t entry_size;
if (i == cd->nentry) {
/* InfoZIP has a hack to avoid using Zip64: it stores nentries % 0x10000 */
@@ -373,48 +368,48 @@
grown = true;
}
- if ((cd->entry[i].orig=_zip_dirent_new()) == NULL || (entry_size = _zip_dirent_read(cd->entry[i].orig, za->src, cd_buffer, false, error)) < 0) {
+ if ((cd->entry[i].orig = _zip_dirent_new()) == NULL || (entry_size = _zip_dirent_read(cd->entry[i].orig, za->src, cd_buffer, false, error)) < 0) {
if (grown && zip_error_code_zip(error) == ZIP_ER_NOZIP) {
zip_error_set(error, ZIP_ER_INCONS, 0);
}
_zip_cdir_free(cd);
- _zip_buffer_free(cd_buffer);
+ _zip_buffer_free(cd_buffer);
return NULL;
}
i++;
- left -= (zip_uint64_t)entry_size;
+ left -= (zip_uint64_t)entry_size;
}
if (i != cd->nentry || left > 0) {
- zip_error_set(error, ZIP_ER_INCONS, 0);
- _zip_buffer_free(cd_buffer);
- _zip_cdir_free(cd);
- return NULL;
+ zip_error_set(error, ZIP_ER_INCONS, 0);
+ _zip_buffer_free(cd_buffer);
+ _zip_cdir_free(cd);
+ return NULL;
}
if (za->open_flags & ZIP_CHECKCONS) {
- bool ok;
+ bool ok;
- if (cd_buffer) {
- ok = _zip_buffer_eof(cd_buffer);
- }
- else {
- zip_int64_t offset = zip_source_tell(za->src);
+ if (cd_buffer) {
+ ok = _zip_buffer_eof(cd_buffer);
+ }
+ else {
+ zip_int64_t offset = zip_source_tell(za->src);
- if (offset < 0) {
- _zip_error_set_from_source(error, za->src);
- _zip_cdir_free(cd);
- return NULL;
- }
- ok = ((zip_uint64_t)offset == cd->offset + cd->size);
- }
+ if (offset < 0) {
+ _zip_error_set_from_source(error, za->src);
+ _zip_cdir_free(cd);
+ return NULL;
+ }
+ ok = ((zip_uint64_t)offset == cd->offset + cd->size);
+ }
- if (!ok) {
- zip_error_set(error, ZIP_ER_INCONS, 0);
- _zip_buffer_free(cd_buffer);
- _zip_cdir_free(cd);
- return NULL;
- }
+ if (!ok) {
+ zip_error_set(error, ZIP_ER_INCONS, 0);
+ _zip_buffer_free(cd_buffer);
+ _zip_cdir_free(cd);
+ return NULL;
+ }
}
_zip_buffer_free(cd_buffer);
@@ -429,8 +424,7 @@
difference between the lowest and the highest fileposition reached */
static zip_int64_t
-_zip_checkcons(zip_t *za, zip_cdir_t *cd, zip_error_t *error)
-{
+_zip_checkcons(zip_t *za, zip_cdir_t *cd, zip_error_t *error) {
zip_uint64_t i;
zip_uint64_t min, max, j;
struct zip_dirent temp;
@@ -443,7 +437,7 @@
else
min = max = 0;
- for (i=0; i<cd->nentry; i++) {
+ for (i = 0; i < cd->nentry; i++) {
if (cd->entry[i].orig->offset < min)
min = cd->entry[i].orig->offset;
if (min > (zip_uint64_t)cd->offset) {
@@ -451,8 +445,7 @@
return -1;
}
- j = cd->entry[i].orig->offset + cd->entry[i].orig->comp_size
- + _zip_string_length(cd->entry[i].orig->filename) + LENTRYSIZE;
+ j = cd->entry[i].orig->offset + cd->entry[i].orig->comp_size + _zip_string_length(cd->entry[i].orig->filename) + LENTRYSIZE;
if (j > max)
max = j;
if (max > (zip_uint64_t)cd->offset) {
@@ -460,9 +453,9 @@
return -1;
}
- if (zip_source_seek(za->src, (zip_int64_t)cd->entry[i].orig->offset, SEEK_SET) < 0) {
- _zip_error_set_from_source(error, za->src);
- return -1;
+ if (zip_source_seek(za->src, (zip_int64_t)cd->entry[i].orig->offset, SEEK_SET) < 0) {
+ _zip_error_set_from_source(error, za->src);
+ return -1;
}
if (_zip_dirent_read(&temp, za->src, NULL, true, error) == -1) {
@@ -483,7 +476,7 @@
_zip_dirent_finalize(&temp);
}
- return (max-min) < ZIP_INT64_MAX ? (zip_int64_t)(max-min) : ZIP_INT64_MAX;
+ return (max - min) < ZIP_INT64_MAX ? (zip_int64_t)(max - min) : ZIP_INT64_MAX;
}
@@ -492,25 +485,20 @@
Return 0 if they are consistent, -1 if not. */
static int
-_zip_headercomp(const zip_dirent_t *central, const zip_dirent_t *local)
-{
+_zip_headercomp(const zip_dirent_t *central, const zip_dirent_t *local) {
if ((central->version_needed < local->version_needed)
#if 0
/* some zip-files have different values in local
and global headers for the bitflags */
|| (central->bitflags != local->bitflags)
#endif
- || (central->comp_method != local->comp_method)
- || (central->last_mod != local->last_mod)
- || !_zip_string_equal(central->filename, local->filename))
+ || (central->comp_method != local->comp_method) || (central->last_mod != local->last_mod) || !_zip_string_equal(central->filename, local->filename))
return -1;
- if ((central->crc != local->crc) || (central->comp_size != local->comp_size)
- || (central->uncomp_size != local->uncomp_size)) {
+ if ((central->crc != local->crc) || (central->comp_size != local->comp_size) || (central->uncomp_size != local->uncomp_size)) {
/* InfoZip stores valid values in local header even when data descriptor is used.
This is in violation of the appnote. */
- if (((local->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0
- || local->crc != 0 || local->comp_size != 0 || local->uncomp_size != 0))
+ if (((local->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0 || local->crc != 0 || local->comp_size != 0 || local->uncomp_size != 0))
return -1;
}
@@ -519,8 +507,7 @@
static zip_t *
-_zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error)
-{
+_zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error) {
zip_t *za;
if ((za = _zip_new(error)) == NULL) {
@@ -530,8 +517,8 @@
za->src = src;
za->open_flags = flags;
if (flags & ZIP_RDONLY) {
- za->flags |= ZIP_AFL_RDONLY;
- za->ch_flags |= ZIP_AFL_RDONLY;
+ za->flags |= ZIP_AFL_RDONLY;
+ za->ch_flags |= ZIP_AFL_RDONLY;
}
return za;
}
@@ -541,14 +528,13 @@
* tests for file existence
*/
static exists_t
-_zip_file_exists(zip_source_t *src, zip_error_t *error)
-{
+_zip_file_exists(zip_source_t *src, zip_error_t *error) {
struct zip_stat st;
zip_stat_init(&st);
if (zip_source_stat(src, &st) != 0) {
- zip_error_t *src_error = zip_source_error(src);
- if (zip_error_code_zip(src_error) == ZIP_ER_READ && zip_error_code_system(src_error) == ENOENT) {
+ zip_error_t *src_error = zip_source_error(src);
+ if (zip_error_code_zip(src_error) == ZIP_ER_READ && zip_error_code_system(src_error) == ENOENT) {
return EXISTS_NOT;
}
_zip_error_copy(error, src_error);
@@ -560,8 +546,7 @@
static zip_cdir_t *
-_zip_find_central_dir(zip_t *za, zip_uint64_t len)
-{
+_zip_find_central_dir(zip_t *za, zip_uint64_t len) {
zip_cdir_t *cdir, *cdirnew;
zip_uint8_t *match;
zip_int64_t buf_offset;
@@ -573,7 +558,7 @@
if (len < EOCDLEN) {
zip_error_set(&za->error, ZIP_ER_NOZIP, 0);
- return NULL;
+ return NULL;
}
buflen = (len < CDBUFSIZE ? len : CDBUFSIZE);
@@ -586,62 +571,62 @@
}
}
if ((buf_offset = zip_source_tell(za->src)) < 0) {
- _zip_error_set_from_source(&za->error, za->src);
- return NULL;
+ _zip_error_set_from_source(&za->error, za->src);
+ return NULL;
}
if ((buffer = _zip_buffer_new_from_source(za->src, buflen, NULL, &za->error)) == NULL) {
- return NULL;
+ return NULL;
}
best = -1;
cdir = NULL;
if (buflen >= CDBUFSIZE) {
- /* EOCD64 locator is before EOCD, so leave place for it */
- _zip_buffer_set_offset(buffer, EOCD64LOCLEN);
+ /* EOCD64 locator is before EOCD, so leave place for it */
+ _zip_buffer_set_offset(buffer, EOCD64LOCLEN);
}
zip_error_set(&error, ZIP_ER_NOZIP, 0);
match = _zip_buffer_get(buffer, 0);
- while ((match=_zip_memmem(match, _zip_buffer_left(buffer)-(EOCDLEN-4), (const unsigned char *)EOCD_MAGIC, 4)) != NULL) {
- _zip_buffer_set_offset(buffer, (zip_uint64_t)(match - _zip_buffer_data(buffer)));
- if ((cdirnew = _zip_read_cdir(za, buffer, (zip_uint64_t)buf_offset, &error)) != NULL) {
- if (cdir) {
- if (best <= 0) {
- best = _zip_checkcons(za, cdir, &error);
- }
+ while ((match = _zip_memmem(match, _zip_buffer_left(buffer) - (EOCDLEN - 4), (const unsigned char *)EOCD_MAGIC, 4)) != NULL) {
+ _zip_buffer_set_offset(buffer, (zip_uint64_t)(match - _zip_buffer_data(buffer)));
+ if ((cdirnew = _zip_read_cdir(za, buffer, (zip_uint64_t)buf_offset, &error)) != NULL) {
+ if (cdir) {
+ if (best <= 0) {
+ best = _zip_checkcons(za, cdir, &error);
+ }
- a = _zip_checkcons(za, cdirnew, &error);
- if (best < a) {
- _zip_cdir_free(cdir);
- cdir = cdirnew;
- best = a;
- }
- else {
- _zip_cdir_free(cdirnew);
- }
- }
- else {
- cdir = cdirnew;
- if (za->open_flags & ZIP_CHECKCONS)
- best = _zip_checkcons(za, cdir, &error);
- else {
- best = 0;
- }
- }
- cdirnew = NULL;
- }
+ a = _zip_checkcons(za, cdirnew, &error);
+ if (best < a) {
+ _zip_cdir_free(cdir);
+ cdir = cdirnew;
+ best = a;
+ }
+ else {
+ _zip_cdir_free(cdirnew);
+ }
+ }
+ else {
+ cdir = cdirnew;
+ if (za->open_flags & ZIP_CHECKCONS)
+ best = _zip_checkcons(za, cdir, &error);
+ else {
+ best = 0;
+ }
+ }
+ cdirnew = NULL;
+ }
- match++;
- _zip_buffer_set_offset(buffer, (zip_uint64_t)(match - _zip_buffer_data(buffer)));
+ match++;
+ _zip_buffer_set_offset(buffer, (zip_uint64_t)(match - _zip_buffer_data(buffer)));
}
_zip_buffer_free(buffer);
if (best < 0) {
- _zip_error_copy(&za->error, &error);
- _zip_cdir_free(cdir);
- return NULL;
+ _zip_error_copy(&za->error, &error);
+ _zip_cdir_free(cdir);
+ return NULL;
}
return cdir;
@@ -649,16 +634,14 @@
static unsigned char *
-_zip_memmem(const unsigned char *big, size_t biglen, const unsigned char *little, size_t littlelen)
-{
+_zip_memmem(const unsigned char *big, size_t biglen, const unsigned char *little, size_t littlelen) {
const unsigned char *p;
if ((biglen < littlelen) || (littlelen == 0))
return NULL;
- p = big-1;
- while ((p=(const unsigned char *)
- memchr(p+1, little[0], (size_t)(big-(p+1))+(size_t)(biglen-littlelen)+1)) != NULL) {
- if (memcmp(p+1, little+1, littlelen-1)==0)
+ p = big - 1;
+ while ((p = (const unsigned char *)memchr(p + 1, little[0], (size_t)(big - (p + 1)) + (size_t)(biglen - littlelen) + 1)) != NULL) {
+ if (memcmp(p + 1, little + 1, littlelen - 1) == 0)
return (unsigned char *)p;
}
@@ -667,8 +650,7 @@
static zip_cdir_t *
-_zip_read_eocd(zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error)
-{
+_zip_read_eocd(zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error) {
zip_cdir_t *cd;
zip_uint64_t i, nentry, size, offset, eocd_offset;
@@ -699,23 +681,23 @@
size = _zip_buffer_get_32(buffer);
offset = _zip_buffer_get_32(buffer);
- if (offset+size < offset) {
- zip_error_set(error, ZIP_ER_SEEK, EFBIG);
- return NULL;
+ if (offset + size < offset) {
+ zip_error_set(error, ZIP_ER_SEEK, EFBIG);
+ return NULL;
}
- if (offset+size > buf_offset + eocd_offset) {
+ if (offset + size > buf_offset + eocd_offset) {
/* cdir spans past EOCD record */
zip_error_set(error, ZIP_ER_INCONS, 0);
return NULL;
}
- if ((flags & ZIP_CHECKCONS) && offset+size != buf_offset + eocd_offset) {
+ if ((flags & ZIP_CHECKCONS) && offset + size != buf_offset + eocd_offset) {
zip_error_set(error, ZIP_ER_INCONS, 0);
return NULL;
}
- if ((cd=_zip_cdir_new(nentry, error)) == NULL)
+ if ((cd = _zip_cdir_new(nentry, error)) == NULL)
return NULL;
cd->is_zip64 = false;
@@ -727,8 +709,7 @@
static zip_cdir_t *
-_zip_read_eocd64(zip_source_t *src, zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error)
-{
+_zip_read_eocd64(zip_source_t *src, zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error) {
zip_cdir_t *cd;
zip_uint64_t offset;
zip_uint8_t eocd[EOCD64LEN];
@@ -746,8 +727,8 @@
eocd_offset = _zip_buffer_get_64(buffer);
if (eocd_offset > ZIP_INT64_MAX || eocd_offset + EOCD64LEN < eocd_offset) {
- zip_error_set(error, ZIP_ER_SEEK, EFBIG);
- return NULL;
+ zip_error_set(error, ZIP_ER_SEEK, EFBIG);
+ return NULL;
}
if (eocd_offset + EOCD64LEN > eocdloc_offset + buf_offset) {
@@ -756,25 +737,25 @@
}
if (eocd_offset >= buf_offset && eocd_offset + EOCD64LEN <= buf_offset + _zip_buffer_size(buffer)) {
- _zip_buffer_set_offset(buffer, eocd_offset - buf_offset);
- free_buffer = false;
+ _zip_buffer_set_offset(buffer, eocd_offset - buf_offset);
+ free_buffer = false;
}
else {
- if (zip_source_seek(src, (zip_int64_t)eocd_offset, SEEK_SET) < 0) {
- _zip_error_set_from_source(error, src);
- return NULL;
- }
- if ((buffer = _zip_buffer_new_from_source(src, EOCD64LEN, eocd, error)) == NULL) {
- return NULL;
- }
- free_buffer = true;
+ if (zip_source_seek(src, (zip_int64_t)eocd_offset, SEEK_SET) < 0) {
+ _zip_error_set_from_source(error, src);
+ return NULL;
+ }
+ if ((buffer = _zip_buffer_new_from_source(src, EOCD64LEN, eocd, error)) == NULL) {
+ return NULL;
+ }
+ free_buffer = true;
}
if (memcmp(_zip_buffer_get(buffer, 4), EOCD64_MAGIC, 4) != 0) {
zip_error_set(error, ZIP_ER_INCONS, 0);
- if (free_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (free_buffer) {
+ _zip_buffer_free(buffer);
+ }
return NULL;
}
@@ -782,10 +763,10 @@
if ((flags & ZIP_CHECKCONS) && size + eocd_offset + 12 != buf_offset + eocdloc_offset) {
zip_error_set(error, ZIP_ER_INCONS, 0);
- if (free_buffer) {
- _zip_buffer_free(buffer);
- }
- return NULL;
+ if (free_buffer) {
+ _zip_buffer_free(buffer);
+ }
+ return NULL;
}
_zip_buffer_get(buffer, 4); /* skip version made by/needed */
@@ -804,16 +785,16 @@
}
if ((flags & ZIP_CHECKCONS) && (eocd_disk != eocd_disk64 || num_disks != num_disks64)) {
zip_error_set(error, ZIP_ER_INCONS, 0);
- if (free_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (free_buffer) {
+ _zip_buffer_free(buffer);
+ }
return NULL;
}
if (num_disks != 0 || eocd_disk != 0) {
zip_error_set(error, ZIP_ER_MULTIDISK, 0);
- if (free_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (free_buffer) {
+ _zip_buffer_free(buffer);
+ }
return NULL;
}
@@ -822,9 +803,9 @@
if (nentry != i) {
zip_error_set(error, ZIP_ER_MULTIDISK, 0);
- if (free_buffer) {
- _zip_buffer_free(buffer);
- }
+ if (free_buffer) {
+ _zip_buffer_free(buffer);
+ }
return NULL;
}
@@ -832,32 +813,32 @@
offset = _zip_buffer_get_64(buffer);
if (!_zip_buffer_ok(buffer)) {
- zip_error_set(error, ZIP_ER_INTERNAL, 0);
- if (free_buffer) {
- _zip_buffer_free(buffer);
- }
- return NULL;
+ zip_error_set(error, ZIP_ER_INTERNAL, 0);
+ if (free_buffer) {
+ _zip_buffer_free(buffer);
+ }
+ return NULL;
}
if (free_buffer) {
- _zip_buffer_free(buffer);
+ _zip_buffer_free(buffer);
}
- if (offset > ZIP_INT64_MAX || offset+size < offset) {
- zip_error_set(error, ZIP_ER_SEEK, EFBIG);
- return NULL;
+ if (offset > ZIP_INT64_MAX || offset + size < offset) {
+ zip_error_set(error, ZIP_ER_SEEK, EFBIG);
+ return NULL;
}
- if (offset+size > buf_offset + eocd_offset) {
+ if (offset + size > buf_offset + eocd_offset) {
/* cdir spans past EOCD record */
zip_error_set(error, ZIP_ER_INCONS, 0);
return NULL;
}
- if ((flags & ZIP_CHECKCONS) && offset+size != buf_offset + eocd_offset) {
+ if ((flags & ZIP_CHECKCONS) && offset + size != buf_offset + eocd_offset) {
zip_error_set(error, ZIP_ER_INCONS, 0);
return NULL;
}
- if ((cd=_zip_cdir_new(nentry, error)) == NULL)
+ if ((cd = _zip_cdir_new(nentry, error)) == NULL)
return NULL;
cd->is_zip64 = true;
diff --git a/lib/zip_progress.c b/lib/zip_progress.c
index b1b6e58..46c8bb8 100644
--- a/lib/zip_progress.c
+++ b/lib/zip_progress.c
@@ -48,10 +48,10 @@
double precision;
/* state */
- double last_update; /* last value callback function was called with */
+ double last_update; /* last value callback function was called with */
- double start; /* start of sub-progress section */
- double end; /* end of sub-progress section */
+ double start; /* start of sub-progress section */
+ double end; /* end of sub-progress section */
};
@@ -64,11 +64,11 @@
void
_zip_progress_free(zip_progress_t *progress) {
if (progress == NULL) {
- return;
+ return;
}
if (progress->ud_free) {
- progress->ud_free(progress->ud);
+ progress->ud_free(progress->ud);
}
free(progress);
@@ -80,8 +80,8 @@
zip_progress_t *progress = (zip_progress_t *)malloc(sizeof(*progress));
if (progress == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- return NULL;
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return NULL;
}
progress->za = za;
@@ -97,7 +97,7 @@
void
_zip_progress_start(zip_progress_t *progress) {
if (progress == NULL) {
- return;
+ return;
}
progress->last_update = 0.0;
@@ -108,7 +108,7 @@
void
_zip_progress_subrange(zip_progress_t *progress, double start, double end) {
if (progress == NULL) {
- return;
+ return;
}
progress->start = start;
@@ -122,14 +122,14 @@
double current;
if (progress == NULL) {
- return;
+ return;
}
current = ZIP_MIN(ZIP_MAX(sub_current, 0.0), 1.0) * (progress->end - progress->start) + progress->start;
if (current - progress->last_update > progress->precision) {
- progress->callback(progress->za, current, progress->ud);
- progress->last_update = current;
+ progress->callback(progress->za, current, progress->ud);
+ progress->last_update = current;
}
}
@@ -139,9 +139,9 @@
zip_progress_t *progress = NULL;
if (callback != NULL) {
- if ((progress = _zip_progress_new(za, precision, callback, ud_free, ud)) == NULL) {
- return -1;
- }
+ if ((progress = _zip_progress_new(za, precision, callback, ud_free, ud)) == NULL) {
+ return -1;
+ }
}
_zip_progress_free(za->progress);
@@ -164,21 +164,20 @@
}
ZIP_EXTERN void
-zip_register_progress_callback(zip_t *za, zip_progress_callback_t progress_callback)
-{
+zip_register_progress_callback(zip_t *za, zip_progress_callback_t progress_callback) {
struct legacy_ud *ud;
-
+
if (progress_callback == NULL) {
- zip_register_progress_callback_with_state(za, 0, NULL, NULL, NULL);
+ zip_register_progress_callback_with_state(za, 0, NULL, NULL, NULL);
}
if ((ud = (struct legacy_ud *)malloc(sizeof(*ud))) == NULL) {
- return;
+ return;
}
ud->callback = progress_callback;
if (zip_register_progress_callback_with_state(za, 0.001, _zip_legacy_progress_callback, free, ud) < 0) {
- free(ud);
+ free(ud);
}
}
diff --git a/lib/zip_random_unix.c b/lib/zip_random_unix.c
index 2684456..6e853b2 100644
--- a/lib/zip_random_unix.c
+++ b/lib/zip_random_unix.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,8 +37,7 @@
#include <unistd.h>
bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length)
-{
+zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
int fd;
if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
diff --git a/lib/zip_random_uwp.c b/lib/zip_random_uwp.c
index aeead0f..bb99aaf 100644
--- a/lib/zip_random_uwp.c
+++ b/lib/zip_random_uwp.c
@@ -31,16 +31,15 @@
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <windows.h>
-#include <ntstatus.h>
#include <bcrypt.h>
+#include <ntstatus.h>
+#include <windows.h>
#include "zipint.h"
#include "zipwin32.h"
bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length)
-{
+zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
BCRYPT_ALG_HANDLE hAlg = NULL;
NTSTATUS hr = BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_RNG_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
if (hr != STATUS_SUCCESS || hAlg == NULL) {
diff --git a/lib/zip_random_win32.c b/lib/zip_random_win32.c
index f0aa48d..7f6f22b 100644
--- a/lib/zip_random_win32.c
+++ b/lib/zip_random_win32.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,8 +37,7 @@
#include <wincrypt.h>
bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length)
-{
+zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
HCRYPTPROV hprov;
if (!CryptAcquireContext(&hprov, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
return false;
diff --git a/lib/zip_rename.c b/lib/zip_rename.c
index 14e101d..0cc81ed 100644
--- a/lib/zip_rename.c
+++ b/lib/zip_rename.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,7 +39,6 @@
ZIP_EXTERN int
-zip_rename(zip_t *za, zip_uint64_t idx, const char *name)
-{
+zip_rename(zip_t *za, zip_uint64_t idx, const char *name) {
return zip_file_rename(za, idx, name, 0);
}
diff --git a/lib/zip_replace.c b/lib/zip_replace.c
index eed019a..34b922e 100644
--- a/lib/zip_replace.c
+++ b/lib/zip_replace.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,7 +37,6 @@
ZIP_EXTERN int
-zip_replace(zip_t *za, zip_uint64_t idx, zip_source_t *source)
-{
+zip_replace(zip_t *za, zip_uint64_t idx, zip_source_t *source) {
return zip_file_replace(za, idx, source, 0);
}
diff --git a/lib/zip_set_archive_comment.c b/lib/zip_set_archive_comment.c
index 9090eec..221fde5 100644
--- a/lib/zip_set_archive_comment.c
+++ b/lib/zip_set_archive_comment.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,8 +38,7 @@
ZIP_EXTERN int
-zip_set_archive_comment(zip_t *za, const char *comment, zip_uint16_t len)
-{
+zip_set_archive_comment(zip_t *za, const char *comment, zip_uint16_t len) {
zip_string_t *cstr;
if (ZIP_IS_RDONLY(za)) {
@@ -53,7 +52,7 @@
}
if (len > 0) {
- if ((cstr=_zip_string_new((const zip_uint8_t *)comment, len, ZIP_FL_ENC_GUESS, &za->error)) == NULL)
+ if ((cstr = _zip_string_new((const zip_uint8_t *)comment, len, ZIP_FL_ENC_GUESS, &za->error)) == NULL)
return -1;
if (_zip_guess_encoding(cstr, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_CP437) {
@@ -68,8 +67,7 @@
_zip_string_free(za->comment_changes);
za->comment_changes = NULL;
- if (((za->comment_orig && _zip_string_equal(za->comment_orig, cstr))
- || (za->comment_orig == NULL && cstr == NULL))) {
+ if (((za->comment_orig && _zip_string_equal(za->comment_orig, cstr)) || (za->comment_orig == NULL && cstr == NULL))) {
_zip_string_free(cstr);
za->comment_changed = 0;
}
@@ -77,6 +75,6 @@
za->comment_changes = cstr;
za->comment_changed = 1;
}
-
+
return 0;
}
diff --git a/lib/zip_set_archive_flag.c b/lib/zip_set_archive_flag.c
index 2625b2e..6fb1131 100644
--- a/lib/zip_set_archive_flag.c
+++ b/lib/zip_set_archive_flag.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,10 +36,9 @@
ZIP_EXTERN int
-zip_set_archive_flag(zip_t *za, zip_flags_t flag, int value)
-{
+zip_set_archive_flag(zip_t *za, zip_flags_t flag, int value) {
unsigned int new_flags;
-
+
if (value)
new_flags = za->ch_flags | flag;
else
@@ -53,8 +52,7 @@
return -1;
}
- if ((flag & ZIP_AFL_RDONLY) && value
- && (za->ch_flags & ZIP_AFL_RDONLY) == 0) {
+ if ((flag & ZIP_AFL_RDONLY) && value && (za->ch_flags & ZIP_AFL_RDONLY) == 0) {
if (_zip_changed(za, NULL)) {
zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
return -1;
diff --git a/lib/zip_set_default_password.c b/lib/zip_set_default_password.c
index ff7e35a..33c1754 100644
--- a/lib/zip_set_default_password.c
+++ b/lib/zip_set_default_password.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,15 +39,14 @@
ZIP_EXTERN int
-zip_set_default_password(zip_t *za, const char *passwd)
-{
+zip_set_default_password(zip_t *za, const char *passwd) {
if (za == NULL)
return -1;
free(za->default_password);
-
+
if (passwd) {
- if ((za->default_password=strdup(passwd)) == NULL) {
+ if ((za->default_password = strdup(passwd)) == NULL) {
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return -1;
}
diff --git a/lib/zip_set_file_comment.c b/lib/zip_set_file_comment.c
index d356693..93594f0 100644
--- a/lib/zip_set_file_comment.c
+++ b/lib/zip_set_file_comment.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,11 +39,10 @@
ZIP_EXTERN int
-zip_set_file_comment(zip_t *za, zip_uint64_t idx, const char *comment, int len)
-{
+zip_set_file_comment(zip_t *za, zip_uint64_t idx, const char *comment, int len) {
if (len < 0 || len > ZIP_UINT16_MAX) {
- zip_error_set(&za->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+ return -1;
}
return zip_file_set_comment(za, idx, comment, (zip_uint16_t)len, 0);
}
diff --git a/lib/zip_set_file_compression.c b/lib/zip_set_file_compression.c
index 5738aab..6de2d40 100644
--- a/lib/zip_set_file_compression.c
+++ b/lib/zip_set_file_compression.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,8 +36,7 @@
ZIP_EXTERN int
-zip_set_file_compression(zip_t *za, zip_uint64_t idx, zip_int32_t method, zip_uint32_t flags)
-{
+zip_set_file_compression(zip_t *za, zip_uint64_t idx, zip_int32_t method, zip_uint32_t flags) {
zip_entry_t *e;
zip_int32_t old_method;
@@ -56,15 +55,15 @@
return -1;
}
- e = za->entry+idx;
-
+ e = za->entry + idx;
+
old_method = (e->orig == NULL ? ZIP_CM_DEFAULT : e->orig->comp_method);
-
+
/* TODO: do we want to recompress if level is set? Only if it's
* different than what bit flags tell us, but those are not
* defined for all compression methods, or not directly mappable
* to levels */
-
+
if (method == old_method) {
if (e->changes) {
e->changes->changed &= ~ZIP_DIRENT_COMP_METHOD;
@@ -76,17 +75,17 @@
}
}
else {
- if (e->changes == NULL) {
- if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- return -1;
- }
- }
+ if (e->changes == NULL) {
+ if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return -1;
+ }
+ }
- e->changes->comp_method = method;
+ e->changes->comp_method = method;
e->changes->compression_level = (zip_uint16_t)flags;
- e->changes->changed |= ZIP_DIRENT_COMP_METHOD;
+ e->changes->changed |= ZIP_DIRENT_COMP_METHOD;
}
-
+
return 0;
}
diff --git a/lib/zip_set_name.c b/lib/zip_set_name.c
index 34b7615..33fb4bc 100644
--- a/lib/zip_set_name.c
+++ b/lib/zip_set_name.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,8 +39,7 @@
int
-_zip_set_name(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags)
-{
+_zip_set_name(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags) {
zip_entry_t *e;
zip_string_t *str;
bool same_as_orig;
@@ -59,8 +58,8 @@
}
if (name && name[0] != '\0') {
- /* TODO: check for string too long */
- if ((str=_zip_string_new((const zip_uint8_t *)name, (zip_uint16_t)strlen(name), flags, &za->error)) == NULL)
+ /* TODO: check for string too long */
+ if ((str = _zip_string_new((const zip_uint8_t *)name, (zip_uint16_t)strlen(name), flags, &za->error)) == NULL)
return -1;
if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(str, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED)
str->encoding = ZIP_ENCODING_UTF8_KNOWN;
@@ -69,19 +68,19 @@
str = NULL;
/* TODO: encoding flags needed for CP437? */
- if ((i=_zip_name_locate(za, name, 0, NULL)) >= 0 && (zip_uint64_t)i != idx) {
+ if ((i = _zip_name_locate(za, name, 0, NULL)) >= 0 && (zip_uint64_t)i != idx) {
_zip_string_free(str);
zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
return -1;
}
/* no effective name change */
- if (i>=0 && (zip_uint64_t)i == idx) {
+ if (i >= 0 && (zip_uint64_t)i == idx) {
_zip_string_free(str);
return 0;
}
- e = za->entry+idx;
+ e = za->entry + idx;
if (e->orig)
same_as_orig = _zip_string_equal(e->orig->filename, str);
@@ -89,7 +88,7 @@
same_as_orig = false;
if (!same_as_orig && e->changes == NULL) {
- if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) {
+ if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
_zip_string_free(str);
return -1;
@@ -110,7 +109,7 @@
else {
old_str = NULL;
}
-
+
if (old_str) {
if ((old_name = _zip_string_get(old_str, NULL, 0, &za->error)) == NULL) {
_zip_string_free(str);
diff --git a/lib/zip_source_begin_write.c b/lib/zip_source_begin_write.c
index 0459337..0b010df 100644
--- a/lib/zip_source_begin_write.c
+++ b/lib/zip_source_begin_write.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,18 +36,17 @@
ZIP_EXTERN int
-zip_source_begin_write(zip_source_t *src)
-{
+zip_source_begin_write(zip_source_t *src) {
if (ZIP_SOURCE_IS_OPEN_WRITING(src)) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
+
if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_BEGIN_WRITE) < 0) {
- return -1;
+ return -1;
}
src->write_state = ZIP_SOURCE_WRITE_OPEN;
-
+
return 0;
}
diff --git a/lib/zip_source_begin_write_cloning.c b/lib/zip_source_begin_write_cloning.c
index ad2cfac..8c4cf71 100644
--- a/lib/zip_source_begin_write_cloning.c
+++ b/lib/zip_source_begin_write_cloning.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,18 +36,17 @@
ZIP_EXTERN int
-zip_source_begin_write_cloning(zip_source_t *src, zip_uint64_t offset)
-{
+zip_source_begin_write_cloning(zip_source_t *src, zip_uint64_t offset) {
if (ZIP_SOURCE_IS_OPEN_WRITING(src)) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
+
if (_zip_source_call(src, NULL, offset, ZIP_SOURCE_BEGIN_WRITE_CLONING) < 0) {
- return -1;
+ return -1;
}
src->write_state = ZIP_SOURCE_WRITE_OPEN;
-
+
return 0;
}
diff --git a/lib/zip_source_buffer.c b/lib/zip_source_buffer.c
index 86ed750..a9251ed 100644
--- a/lib/zip_source_buffer.c
+++ b/lib/zip_source_buffer.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,23 +37,23 @@
#include "zipint.h"
#ifndef WRITE_FRAGMENT_SIZE
-#define WRITE_FRAGMENT_SIZE (64*1024)
+#define WRITE_FRAGMENT_SIZE (64 * 1024)
#endif
struct buffer {
- zip_buffer_fragment_t *fragments; /* fragments */
- zip_uint64_t *fragment_offsets; /* offset of each fragment from start of buffer, nfragments+1 entries */
- zip_uint64_t nfragments; /* number of allocated fragments */
- zip_uint64_t fragments_capacity; /* size of fragments (number of pointers) */
+ zip_buffer_fragment_t *fragments; /* fragments */
+ zip_uint64_t *fragment_offsets; /* offset of each fragment from start of buffer, nfragments+1 entries */
+ zip_uint64_t nfragments; /* number of allocated fragments */
+ zip_uint64_t fragments_capacity; /* size of fragments (number of pointers) */
- zip_uint64_t first_owned_fragment; /* first fragment to free data from */
+ zip_uint64_t first_owned_fragment; /* first fragment to free data from */
- zip_uint64_t shared_fragments; /* number of shared fragments */
- struct buffer *shared_buffer; /* buffer fragments are shared with */
- zip_uint64_t size; /* size of buffer */
+ zip_uint64_t shared_fragments; /* number of shared fragments */
+ struct buffer *shared_buffer; /* buffer fragments are shared with */
+ zip_uint64_t size; /* size of buffer */
- zip_uint64_t offset; /* current offset in buffer */
- zip_uint64_t current_fragment; /* fragment current offset is in */
+ zip_uint64_t offset; /* current offset in buffer */
+ zip_uint64_t current_fragment; /* fragment current offset is in */
};
typedef struct buffer buffer_t;
@@ -65,8 +65,8 @@
buffer_t *out;
};
-#define buffer_capacity(buffer) ((buffer)->fragment_offsets[(buffer)->nfragments])
-#define buffer_size(buffer) ((buffer)->size)
+#define buffer_capacity(buffer) ((buffer)->fragment_offsets[(buffer)->nfragments])
+#define buffer_size(buffer) ((buffer)->size)
static buffer_t *buffer_clone(buffer_t *buffer, zip_uint64_t length, zip_error_t *error);
static zip_uint64_t buffer_find_fragment(const buffer_t *buffer, zip_uint64_t offset);
@@ -81,8 +81,7 @@
ZIP_EXTERN zip_source_t *
-zip_source_buffer(zip_t *za, const void *data, zip_uint64_t len, int freep)
-{
+zip_source_buffer(zip_t *za, const void *data, zip_uint64_t len, int freep) {
if (za == NULL)
return NULL;
@@ -91,13 +90,12 @@
ZIP_EXTERN zip_source_t *
-zip_source_buffer_create(const void *data, zip_uint64_t len, int freep, zip_error_t *error)
-{
+zip_source_buffer_create(const void *data, zip_uint64_t len, int freep, zip_error_t *error) {
zip_buffer_fragment_t fragment;
if (data == NULL && len > 0) {
- zip_error_set(error, ZIP_ER_INVAL, 0);
- return NULL;
+ zip_error_set(error, ZIP_ER_INVAL, 0);
+ return NULL;
}
fragment.data = (zip_uint8_t *)data;
@@ -108,10 +106,9 @@
ZIP_EXTERN zip_source_t *
-zip_source_buffer_fragment(zip_t *za, const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int freep)
-{
+zip_source_buffer_fragment(zip_t *za, const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int freep) {
if (za == NULL) {
- return NULL;
+ return NULL;
}
return zip_source_buffer_fragment_create(fragments, nfragments, freep, &za->error);
@@ -119,24 +116,23 @@
ZIP_EXTERN zip_source_t *
-zip_source_buffer_fragment_create(const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int freep, zip_error_t *error)
-{
+zip_source_buffer_fragment_create(const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int freep, zip_error_t *error) {
struct read_data *ctx;
zip_source_t *zs;
buffer_t *buffer;
if (fragments == NULL && nfragments > 0) {
- zip_error_set(error, ZIP_ER_INVAL, 0);
- return NULL;
+ zip_error_set(error, ZIP_ER_INVAL, 0);
+ return NULL;
}
if ((buffer = buffer_new(fragments, nfragments, freep, error)) == NULL) {
- return NULL;
+ return NULL;
}
- if ((ctx=(struct read_data *)malloc(sizeof(*ctx))) == NULL) {
+ if ((ctx = (struct read_data *)malloc(sizeof(*ctx))) == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
- buffer_free(buffer);
+ buffer_free(buffer);
return NULL;
}
@@ -144,8 +140,8 @@
ctx->out = NULL;
ctx->mtime = time(NULL);
zip_error_init(&ctx->error);
-
- if ((zs=zip_source_function_create(read_data, ctx, error)) == NULL) {
+
+ if ((zs = zip_source_function_create(read_data, ctx, error)) == NULL) {
buffer_free(ctx->in);
free(ctx);
return NULL;
@@ -156,130 +152,127 @@
static zip_int64_t
-read_data(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd)
-{
+read_data(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
struct read_data *ctx = (struct read_data *)state;
switch (cmd) {
- case ZIP_SOURCE_BEGIN_WRITE:
- if ((ctx->out = buffer_new(NULL, 0, 0, &ctx->error)) == NULL) {
- return -1;
- }
- ctx->out->offset = 0;
- ctx->out->current_fragment = 0;
- return 0;
+ case ZIP_SOURCE_BEGIN_WRITE:
+ if ((ctx->out = buffer_new(NULL, 0, 0, &ctx->error)) == NULL) {
+ return -1;
+ }
+ ctx->out->offset = 0;
+ ctx->out->current_fragment = 0;
+ return 0;
- case ZIP_SOURCE_BEGIN_WRITE_CLONING:
- if ((ctx->out = buffer_clone(ctx->in, len, &ctx->error)) == NULL) {
- return -1;
- }
- ctx->out->offset = len;
- ctx->out->current_fragment = ctx->out->nfragments;
- return 0;
+ case ZIP_SOURCE_BEGIN_WRITE_CLONING:
+ if ((ctx->out = buffer_clone(ctx->in, len, &ctx->error)) == NULL) {
+ return -1;
+ }
+ ctx->out->offset = len;
+ ctx->out->current_fragment = ctx->out->nfragments;
+ return 0;
- case ZIP_SOURCE_CLOSE:
- return 0;
-
- case ZIP_SOURCE_COMMIT_WRITE:
- buffer_free(ctx->in);
- ctx->in = ctx->out;
- ctx->out = NULL;
- return 0;
+ case ZIP_SOURCE_CLOSE:
+ return 0;
- case ZIP_SOURCE_ERROR:
- return zip_error_to_data(&ctx->error, data, len);
-
- case ZIP_SOURCE_FREE:
- buffer_free(ctx->in);
- buffer_free(ctx->out);
- free(ctx);
- return 0;
-
- case ZIP_SOURCE_OPEN:
- ctx->in->offset = 0;
- ctx->in->current_fragment = 0;
- return 0;
-
- case ZIP_SOURCE_READ:
- if (len > ZIP_INT64_MAX) {
- zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
- return -1;
- }
- return buffer_read(ctx->in, data, len);
-
- case ZIP_SOURCE_REMOVE:
- {
- buffer_t *empty = buffer_new(NULL, 0, 0, &ctx->error);
- if (empty == NULL) {
- return -1;
- }
-
- buffer_free(ctx->in);
- ctx->in = empty;
- return 0;
+ case ZIP_SOURCE_COMMIT_WRITE:
+ buffer_free(ctx->in);
+ ctx->in = ctx->out;
+ ctx->out = NULL;
+ return 0;
+
+ case ZIP_SOURCE_ERROR:
+ return zip_error_to_data(&ctx->error, data, len);
+
+ case ZIP_SOURCE_FREE:
+ buffer_free(ctx->in);
+ buffer_free(ctx->out);
+ free(ctx);
+ return 0;
+
+ case ZIP_SOURCE_OPEN:
+ ctx->in->offset = 0;
+ ctx->in->current_fragment = 0;
+ return 0;
+
+ case ZIP_SOURCE_READ:
+ if (len > ZIP_INT64_MAX) {
+ zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
+ return -1;
+ }
+ return buffer_read(ctx->in, data, len);
+
+ case ZIP_SOURCE_REMOVE: {
+ buffer_t *empty = buffer_new(NULL, 0, 0, &ctx->error);
+ if (empty == NULL) {
+ return -1;
}
- case ZIP_SOURCE_ROLLBACK_WRITE:
- buffer_free(ctx->out);
- ctx->out = NULL;
- return 0;
+ buffer_free(ctx->in);
+ ctx->in = empty;
+ return 0;
+ }
- case ZIP_SOURCE_SEEK:
- return buffer_seek(ctx->in, data, len, &ctx->error);
+ case ZIP_SOURCE_ROLLBACK_WRITE:
+ buffer_free(ctx->out);
+ ctx->out = NULL;
+ return 0;
- case ZIP_SOURCE_SEEK_WRITE:
- return buffer_seek(ctx->out, data, len, &ctx->error);
-
- case ZIP_SOURCE_STAT:
- {
- zip_stat_t *st;
-
- if (len < sizeof(*st)) {
- zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
- return -1;
- }
+ case ZIP_SOURCE_SEEK:
+ return buffer_seek(ctx->in, data, len, &ctx->error);
- st = (zip_stat_t *)data;
+ case ZIP_SOURCE_SEEK_WRITE:
+ return buffer_seek(ctx->out, data, len, &ctx->error);
- zip_stat_init(st);
- st->mtime = ctx->mtime;
- st->size = ctx->in->size;
- st->comp_size = st->size;
- st->comp_method = ZIP_CM_STORE;
- st->encryption_method = ZIP_EM_NONE;
- st->valid = ZIP_STAT_MTIME|ZIP_STAT_SIZE|ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD|ZIP_STAT_ENCRYPTION_METHOD;
-
- return sizeof(*st);
+ case ZIP_SOURCE_STAT: {
+ zip_stat_t *st;
+
+ if (len < sizeof(*st)) {
+ zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
+ return -1;
}
- case ZIP_SOURCE_SUPPORTS:
- return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_BEGIN_WRITE_CLONING, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_WRITE, -1);
-
- case ZIP_SOURCE_TELL:
- if (ctx->in->offset > ZIP_INT64_MAX) {
- zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
- return -1;
- }
- return (zip_int64_t)ctx->in->offset;
-
-
- case ZIP_SOURCE_TELL_WRITE:
- if (ctx->out->offset > ZIP_INT64_MAX) {
- zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
- return -1;
- }
- return (zip_int64_t)ctx->out->offset;
+ st = (zip_stat_t *)data;
- case ZIP_SOURCE_WRITE:
- if (len > ZIP_INT64_MAX) {
- zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
- return -1;
- }
- return buffer_write(ctx->out, data, len, &ctx->error);
+ zip_stat_init(st);
+ st->mtime = ctx->mtime;
+ st->size = ctx->in->size;
+ st->comp_size = st->size;
+ st->comp_method = ZIP_CM_STORE;
+ st->encryption_method = ZIP_EM_NONE;
+ st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
- default:
- zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
- return -1;
+ return sizeof(*st);
+ }
+
+ case ZIP_SOURCE_SUPPORTS:
+ return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_BEGIN_WRITE_CLONING, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_WRITE, -1);
+
+ case ZIP_SOURCE_TELL:
+ if (ctx->in->offset > ZIP_INT64_MAX) {
+ zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
+ return -1;
+ }
+ return (zip_int64_t)ctx->in->offset;
+
+
+ case ZIP_SOURCE_TELL_WRITE:
+ if (ctx->out->offset > ZIP_INT64_MAX) {
+ zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
+ return -1;
+ }
+ return (zip_int64_t)ctx->out->offset;
+
+ case ZIP_SOURCE_WRITE:
+ if (len > ZIP_INT64_MAX) {
+ zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
+ return -1;
+ }
+ return buffer_write(ctx->out, data, len, &ctx->error);
+
+ default:
+ zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
+ return -1;
}
}
@@ -290,34 +283,34 @@
buffer_t *clone;
if (offset == 0) {
- return buffer_new(NULL, 0, 1, error);
+ return buffer_new(NULL, 0, 1, error);
}
if (offset > buffer->size) {
- zip_error_set(error, ZIP_ER_INVAL, 0);
- return NULL;
+ zip_error_set(error, ZIP_ER_INVAL, 0);
+ return NULL;
}
if (buffer->shared_buffer != NULL) {
- zip_error_set(error, ZIP_ER_INUSE, 0);
- return NULL;
+ zip_error_set(error, ZIP_ER_INUSE, 0);
+ return NULL;
}
fragment = buffer_find_fragment(buffer, offset);
fragment_offset = offset - buffer->fragment_offsets[fragment];
if (fragment_offset == 0) {
- fragment--;
- fragment_offset = buffer->fragments[fragment].length;
+ fragment--;
+ fragment_offset = buffer->fragments[fragment].length;
}
waste = buffer->fragments[fragment].length - fragment_offset;
if (waste > offset) {
- zip_error_set(error, ZIP_ER_OPNOTSUPP, 0);
- return NULL;
+ zip_error_set(error, ZIP_ER_OPNOTSUPP, 0);
+ return NULL;
}
if ((clone = buffer_new(buffer->fragments, fragment + 1, 0, error)) == NULL) {
- return NULL;
+ return NULL;
}
clone->fragments[clone->nfragments - 1].length = fragment_offset;
@@ -343,16 +336,16 @@
high = buffer->nfragments - 1;
while (low < high) {
- mid = (high - low) / 2 + low;
- if (buffer->fragment_offsets[mid] > offset) {
- high = mid - 1;
- }
- else if (mid == buffer->nfragments || buffer->fragment_offsets[mid + 1] > offset) {
- return mid;
- }
- else {
- low = mid + 1;
- }
+ mid = (high - low) / 2 + low;
+ if (buffer->fragment_offsets[mid] > offset) {
+ high = mid - 1;
+ }
+ else if (mid == buffer->nfragments || buffer->fragment_offsets[mid + 1] > offset) {
+ return mid;
+ }
+ else {
+ low = mid + 1;
+ }
}
return low;
@@ -360,23 +353,22 @@
static void
-buffer_free(buffer_t *buffer)
-{
+buffer_free(buffer_t *buffer) {
zip_uint64_t i;
if (buffer == NULL) {
- return;
+ return;
}
if (buffer->shared_buffer != NULL) {
- buffer->shared_buffer->shared_buffer = NULL;
- buffer->shared_buffer->shared_fragments = 0;
+ buffer->shared_buffer->shared_buffer = NULL;
+ buffer->shared_buffer->shared_fragments = 0;
- buffer->first_owned_fragment = ZIP_MAX(buffer->first_owned_fragment, buffer->shared_fragments);
+ buffer->first_owned_fragment = ZIP_MAX(buffer->first_owned_fragment, buffer->shared_fragments);
}
for (i = buffer->first_owned_fragment; i < buffer->nfragments; i++) {
- free(buffer->fragments[i].data);
+ free(buffer->fragments[i].data);
}
free(buffer->fragments);
free(buffer);
@@ -384,20 +376,18 @@
static bool
-buffer_grow_fragments(buffer_t *buffer, zip_uint64_t capacity, zip_error_t *error)
-{
+buffer_grow_fragments(buffer_t *buffer, zip_uint64_t capacity, zip_error_t *error) {
zip_buffer_fragment_t *fragments;
zip_uint64_t *offsets;
if (capacity < buffer->fragments_capacity) {
- return true;
+ return true;
}
- if ((fragments = realloc(buffer->fragments, sizeof(buffer->fragments[0]) * capacity)) == NULL
- || (offsets = realloc(buffer->fragment_offsets, sizeof(buffer->fragment_offsets[0]) * (capacity + 1))) == NULL) {
- free(fragments);
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- return false;
+ if ((fragments = realloc(buffer->fragments, sizeof(buffer->fragments[0]) * capacity)) == NULL || (offsets = realloc(buffer->fragment_offsets, sizeof(buffer->fragment_offsets[0]) * (capacity + 1))) == NULL) {
+ free(fragments);
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return false;
}
buffer->fragments = fragments;
@@ -409,8 +399,7 @@
static buffer_t *
-buffer_new(const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int free_data, zip_error_t *error)
-{
+buffer_new(const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int free_data, zip_error_t *error) {
buffer_t *buffer;
if ((buffer = malloc(sizeof(*buffer))) == NULL) {
@@ -428,50 +417,49 @@
buffer->shared_fragments = 0;
if (nfragments == 0) {
- if ((buffer->fragment_offsets = malloc(sizeof(buffer->fragment_offsets[0]))) == NULL) {
- free(buffer);
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- return NULL;
- }
- buffer->fragment_offsets[0] = 0;
+ if ((buffer->fragment_offsets = malloc(sizeof(buffer->fragment_offsets[0]))) == NULL) {
+ free(buffer);
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return NULL;
+ }
+ buffer->fragment_offsets[0] = 0;
}
else {
- zip_uint64_t i, j, offset;
+ zip_uint64_t i, j, offset;
- if (!buffer_grow_fragments(buffer, nfragments, NULL)) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- buffer_free(buffer);
- return NULL;
- }
+ if (!buffer_grow_fragments(buffer, nfragments, NULL)) {
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ buffer_free(buffer);
+ return NULL;
+ }
- offset = 0;
- for (i = 0, j = 0; i < nfragments; i++) {
- if (fragments[i].length == 0) {
- continue;
- }
- if (fragments[i].data == NULL) {
- zip_error_set(error, ZIP_ER_INVAL, 0);
- buffer_free(buffer);
- return NULL;
- }
- buffer->fragments[j].data = fragments[i].data;
- buffer->fragments[j].length = fragments[i].length;
- buffer->fragment_offsets[i] = offset;
- offset += fragments[i].length;
- j++;
- }
- buffer->nfragments = j;
- buffer->first_owned_fragment = free_data ? 0 : buffer->nfragments;
- buffer->fragment_offsets[nfragments] = offset;
- buffer->size = offset;
+ offset = 0;
+ for (i = 0, j = 0; i < nfragments; i++) {
+ if (fragments[i].length == 0) {
+ continue;
+ }
+ if (fragments[i].data == NULL) {
+ zip_error_set(error, ZIP_ER_INVAL, 0);
+ buffer_free(buffer);
+ return NULL;
+ }
+ buffer->fragments[j].data = fragments[i].data;
+ buffer->fragments[j].length = fragments[i].length;
+ buffer->fragment_offsets[i] = offset;
+ offset += fragments[i].length;
+ j++;
+ }
+ buffer->nfragments = j;
+ buffer->first_owned_fragment = free_data ? 0 : buffer->nfragments;
+ buffer->fragment_offsets[nfragments] = offset;
+ buffer->size = offset;
}
return buffer;
}
static zip_int64_t
-buffer_read(buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length)
-{
+buffer_read(buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) {
zip_uint64_t n, i, fragment_offset;
length = ZIP_MIN(length, buffer->size - buffer->offset);
@@ -488,12 +476,12 @@
n = 0;
while (n < length) {
zip_uint64_t left = ZIP_MIN(length - n, buffer->fragments[i].length - fragment_offset);
-
+
memcpy(data + n, buffer->fragments[i].data + fragment_offset, left);
- if (left == buffer->fragments[i].length - fragment_offset) {
- i++;
- }
+ if (left == buffer->fragments[i].length - fragment_offset) {
+ i++;
+ }
n += left;
fragment_offset = 0;
}
@@ -505,12 +493,11 @@
static int
-buffer_seek(buffer_t *buffer, void *data, zip_uint64_t len, zip_error_t *error)
-{
+buffer_seek(buffer_t *buffer, void *data, zip_uint64_t len, zip_error_t *error) {
zip_int64_t new_offset = zip_source_seek_compute_offset(buffer->offset, buffer->size, data, len, error);
-
+
if (new_offset < 0) {
- return -1;
+ return -1;
}
buffer->offset = (zip_uint64_t)new_offset;
@@ -520,8 +507,7 @@
static zip_int64_t
-buffer_write(buffer_t *buffer, const zip_uint8_t *data, zip_uint64_t length, zip_error_t *error)
-{
+buffer_write(buffer_t *buffer, const zip_uint8_t *data, zip_uint64_t length, zip_error_t *error) {
zip_uint64_t n, i, fragment_offset, capacity;
if (buffer->offset + length + WRITE_FRAGMENT_SIZE - 1 < length) {
@@ -532,19 +518,19 @@
/* grow buffer if needed */
capacity = buffer_capacity(buffer);
if (buffer->offset + length > capacity) {
- zip_uint64_t needed_fragments = buffer->nfragments + (length - (capacity - buffer->offset) + WRITE_FRAGMENT_SIZE - 1) / WRITE_FRAGMENT_SIZE;
+ zip_uint64_t needed_fragments = buffer->nfragments + (length - (capacity - buffer->offset) + WRITE_FRAGMENT_SIZE - 1) / WRITE_FRAGMENT_SIZE;
if (needed_fragments > buffer->fragments_capacity) {
zip_uint64_t new_capacity = buffer->fragments_capacity;
- if (new_capacity == 0) {
- new_capacity = 16;
- }
+ if (new_capacity == 0) {
+ new_capacity = 16;
+ }
while (new_capacity < needed_fragments) {
new_capacity *= 2;
}
- if (!buffer_grow_fragments(buffer, new_capacity, error)) {
+ if (!buffer_grow_fragments(buffer, new_capacity, error)) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return -1;
}
@@ -555,10 +541,10 @@
zip_error_set(error, ZIP_ER_MEMORY, 0);
return -1;
}
- buffer->fragments[buffer->nfragments].length = WRITE_FRAGMENT_SIZE;
- buffer->nfragments++;
- capacity += WRITE_FRAGMENT_SIZE;
- buffer->fragment_offsets[buffer->nfragments] = capacity;
+ buffer->fragments[buffer->nfragments].length = WRITE_FRAGMENT_SIZE;
+ buffer->nfragments++;
+ capacity += WRITE_FRAGMENT_SIZE;
+ buffer->fragment_offsets[buffer->nfragments] = capacity;
}
}
@@ -567,12 +553,12 @@
n = 0;
while (n < length) {
zip_uint64_t left = ZIP_MIN(length - n, buffer->fragments[i].length - fragment_offset);
-
+
memcpy(buffer->fragments[i].data + fragment_offset, data + n, left);
- if (n == buffer->fragments[i].length - fragment_offset) {
- i++;
- }
+ if (n == buffer->fragments[i].length - fragment_offset) {
+ i++;
+ }
n += left;
fragment_offset = 0;
}
diff --git a/lib/zip_source_call.c b/lib/zip_source_call.c
index 21f28bc..ec54b92 100644
--- a/lib/zip_source_call.c
+++ b/lib/zip_source_call.c
@@ -1,10 +1,10 @@
/*
zip_source_call.c -- invoke callback command on zip_source
Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner
-
+
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
-
+
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,33 +36,32 @@
zip_int64_t
-_zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command)
-{
+_zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command) {
zip_int64_t ret;
-
+
if ((src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(command)) == 0) {
- zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
- return -1;
+ zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
+ return -1;
}
if (src->src == NULL) {
- ret = src->cb.f(src->ud, data, length, command);
+ ret = src->cb.f(src->ud, data, length, command);
}
else {
- ret = src->cb.l(src->src, src->ud, data, length, command);
+ ret = src->cb.l(src->src, src->ud, data, length, command);
}
-
+
if (ret < 0) {
- if (command != ZIP_SOURCE_ERROR && command != ZIP_SOURCE_SUPPORTS) {
- int e[2];
-
- if (_zip_source_call(src, e, sizeof(e), ZIP_SOURCE_ERROR) < 0) {
- zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
- }
- else {
- zip_error_set(&src->error, e[0], e[1]);
- }
- }
+ if (command != ZIP_SOURCE_ERROR && command != ZIP_SOURCE_SUPPORTS) {
+ int e[2];
+
+ if (_zip_source_call(src, e, sizeof(e), ZIP_SOURCE_ERROR) < 0) {
+ zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
+ }
+ else {
+ zip_error_set(&src->error, e[0], e[1]);
+ }
+ }
}
return ret;
diff --git a/lib/zip_source_close.c b/lib/zip_source_close.c
index 36bc842..cbc3bea 100644
--- a/lib/zip_source_close.c
+++ b/lib/zip_source_close.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,13 +36,12 @@
int
-zip_source_close(zip_source_t *src)
-{
+zip_source_close(zip_source_t *src) {
if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
+
src->open_count--;
if (src->open_count == 0) {
_zip_source_call(src, NULL, 0, ZIP_SOURCE_CLOSE);
diff --git a/lib/zip_source_commit_write.c b/lib/zip_source_commit_write.c
index ba77abc..26c3dd7 100644
--- a/lib/zip_source_commit_write.c
+++ b/lib/zip_source_commit_write.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,29 +36,28 @@
ZIP_EXTERN int
-zip_source_commit_write(zip_source_t *src)
-{
+zip_source_commit_write(zip_source_t *src) {
if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
+
if (src->open_count > 1) {
zip_error_set(&src->error, ZIP_ER_INUSE, 0);
return -1;
}
else if (ZIP_SOURCE_IS_OPEN_READING(src)) {
- if (zip_source_close(src) < 0) {
+ if (zip_source_close(src) < 0) {
return -1;
}
}
-
+
if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_COMMIT_WRITE) < 0) {
- src->write_state = ZIP_SOURCE_WRITE_FAILED;
- return -1;
+ src->write_state = ZIP_SOURCE_WRITE_FAILED;
+ return -1;
}
-
+
src->write_state = ZIP_SOURCE_WRITE_CLOSED;
-
+
return 0;
}
diff --git a/lib/zip_source_compress.c b/lib/zip_source_compress.c
index 0b97f93..a1ac3e0 100644
--- a/lib/zip_source_compress.c
+++ b/lib/zip_source_compress.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -31,9 +31,9 @@
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <limits.h>
#include <stdlib.h>
#include <string.h>
-#include <limits.h>
#include "zipint.h"
@@ -43,14 +43,14 @@
bool end_of_input;
bool end_of_stream;
bool can_store;
- bool is_stored; /* only valid if end_of_stream is true */
+ bool is_stored; /* only valid if end_of_stream is true */
bool compress;
zip_int32_t method;
-
+
zip_uint64_t size;
zip_int64_t first_read;
zip_uint8_t buffer[BUFSIZE];
-
+
zip_compression_algorithm_t *algorithm;
void *ud;
};
@@ -63,9 +63,9 @@
};
static struct implementation implementations[] = {
- { ZIP_CM_DEFLATE, &zip_algorithm_deflate_compress, &zip_algorithm_deflate_decompress },
+ {ZIP_CM_DEFLATE, &zip_algorithm_deflate_compress, &zip_algorithm_deflate_decompress},
#if defined(HAVE_LIBBZ2)
- { ZIP_CM_BZIP2, &zip_algorithm_bzip2_compress, &zip_algorithm_bzip2_decompress },
+ {ZIP_CM_BZIP2, &zip_algorithm_bzip2_compress, &zip_algorithm_bzip2_decompress},
#endif
};
@@ -116,12 +116,11 @@
static zip_source_t *
-compression_source_new(zip_t *za, zip_source_t *src, zip_int32_t method, bool compress, int compression_flags)
-{
+compression_source_new(zip_t *za, zip_source_t *src, zip_int32_t method, bool compress, int compression_flags) {
struct context *ctx;
zip_source_t *s2;
zip_compression_algorithm_t *algorithm = NULL;
-
+
if (src == NULL) {
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return NULL;
@@ -136,7 +135,7 @@
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return NULL;
}
-
+
if ((s2 = zip_source_layered(za, src, compress_callback, ctx)) == NULL) {
context_free(ctx);
return NULL;
@@ -149,7 +148,7 @@
static struct context *
context_new(zip_int32_t method, bool compress, int compression_flags, zip_compression_algorithm_t *algorithm) {
struct context *ctx;
-
+
if ((ctx = (struct context *)malloc(sizeof(*ctx))) == NULL) {
return NULL;
}
@@ -161,13 +160,13 @@
ctx->end_of_input = false;
ctx->end_of_stream = false;
ctx->is_stored = false;
-
+
if ((ctx->ud = ctx->algorithm->allocate(ZIP_CM_ACTUAL(method), compression_flags, &ctx->error)) == NULL) {
zip_error_fini(&ctx->error);
free(ctx);
return NULL;
}
-
+
return ctx;
}
@@ -186,8 +185,7 @@
static zip_int64_t
-compress_read(zip_source_t *src, struct context *ctx, void *data, zip_uint64_t len)
-{
+compress_read(zip_source_t *src, struct context *ctx, void *data, zip_uint64_t len) {
zip_compression_status_t ret;
bool end;
zip_int64_t n;
@@ -197,11 +195,11 @@
if (zip_error_code_zip(&ctx->error) != ZIP_ER_OK) {
return -1;
}
-
+
if (len == 0 || ctx->end_of_stream) {
return 0;
}
-
+
out_offset = 0;
end = false;
@@ -214,7 +212,7 @@
}
switch (ret) {
- case ZIP_COMPRESSION_END:
+ case ZIP_COMPRESSION_END:
ctx->end_of_stream = true;
if (!ctx->end_of_input) {
@@ -227,15 +225,15 @@
end = true;
break;
}
- if (ctx->can_store && (zip_uint64_t)ctx->first_read <= out_offset) {
- ctx->is_stored = true;
- ctx->size = (zip_uint64_t)ctx->first_read;
- memcpy(data, ctx->buffer, ctx->size);
- return (zip_int64_t)ctx->size;
- }
+ if (ctx->can_store && (zip_uint64_t)ctx->first_read <= out_offset) {
+ ctx->is_stored = true;
+ ctx->size = (zip_uint64_t)ctx->first_read;
+ memcpy(data, ctx->buffer, ctx->size);
+ return (zip_int64_t)ctx->size;
+ }
end = true;
break;
-
+
case ZIP_COMPRESSION_OK:
break;
@@ -270,7 +268,7 @@
ctx->algorithm->input(ctx->ud, ctx->buffer, (zip_uint64_t)n);
}
break;
-
+
case ZIP_COMPRESSION_ERROR:
/* error set by algorithm */
if (zip_error_code_zip(&ctx->error) == ZIP_ER_OK) {
@@ -292,8 +290,7 @@
static zip_int64_t
-compress_callback(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd)
-{
+compress_callback(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
struct context *ctx;
ctx = (struct context *)ud;
@@ -305,7 +302,7 @@
ctx->end_of_stream = false;
ctx->is_stored = false;
ctx->first_read = -1;
-
+
if (!ctx->algorithm->start(ctx->ud)) {
return -1;
}
@@ -321,51 +318,50 @@
}
return 0;
- case ZIP_SOURCE_STAT:
- {
- zip_stat_t *st;
+ case ZIP_SOURCE_STAT: {
+ zip_stat_t *st;
- st = (zip_stat_t *)data;
+ st = (zip_stat_t *)data;
- if (ctx->compress) {
- if (ctx->end_of_stream) {
- st->comp_method = ctx->is_stored ? ZIP_CM_STORE : ZIP_CM_ACTUAL(ctx->method);
- st->comp_size = ctx->size;
- st->valid |= ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD;
- }
- else {
- st->valid &= ~(ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD);
- }
+ if (ctx->compress) {
+ if (ctx->end_of_stream) {
+ st->comp_method = ctx->is_stored ? ZIP_CM_STORE : ZIP_CM_ACTUAL(ctx->method);
+ st->comp_size = ctx->size;
+ st->valid |= ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD;
}
else {
- st->comp_method = ZIP_CM_STORE;
- st->valid |= ZIP_STAT_COMP_METHOD;
- if (ctx->end_of_stream) {
- st->size = ctx->size;
- st->valid |= ZIP_STAT_SIZE;
- }
- else {
- st->valid &= ~ZIP_STAT_SIZE;
- }
+ st->valid &= ~(ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD);
}
}
+ else {
+ st->comp_method = ZIP_CM_STORE;
+ st->valid |= ZIP_STAT_COMP_METHOD;
+ if (ctx->end_of_stream) {
+ st->size = ctx->size;
+ st->valid |= ZIP_STAT_SIZE;
+ }
+ else {
+ st->valid &= ~ZIP_STAT_SIZE;
+ }
+ }
+ }
return 0;
case ZIP_SOURCE_GET_COMPRESSION_FLAGS:
return ctx->is_stored ? 0 : ctx->algorithm->compression_flags(ctx->ud);
case ZIP_SOURCE_ERROR:
- return zip_error_to_data(&ctx->error, data, len);
+ return zip_error_to_data(&ctx->error, data, len);
case ZIP_SOURCE_FREE:
context_free(ctx);
return 0;
case ZIP_SOURCE_SUPPORTS:
- return ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_GET_COMPRESSION_FLAGS, -1);
-
+ return ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_GET_COMPRESSION_FLAGS, -1);
+
default:
- zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
+ zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
return -1;
}
}
diff --git a/lib/zip_source_crc.c b/lib/zip_source_crc.c
index 3c9c105..8797dfe 100644
--- a/lib/zip_source_crc.c
+++ b/lib/zip_source_crc.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -32,18 +32,18 @@
*/
+#include <limits.h>
#include <stdlib.h>
#include <string.h>
-#include <limits.h>
#include "zipint.h"
struct crc_context {
- int validate; /* whether to check CRC on EOF and return error on mismatch */
+ int validate; /* whether to check CRC on EOF and return error on mismatch */
int crc_complete; /* whether CRC was computed for complete file */
zip_error_t error;
zip_uint64_t size;
- zip_uint64_t position; /* current reading position */
+ zip_uint64_t position; /* current reading position */
zip_uint64_t crc_position; /* how far we've computed the CRC */
zip_uint32_t crc;
};
@@ -52,8 +52,7 @@
zip_source_t *
-zip_source_crc(zip_t *za, zip_source_t *src, int validate)
-{
+zip_source_crc(zip_t *za, zip_source_t *src, int validate) {
struct crc_context *ctx;
if (src == NULL) {
@@ -61,7 +60,7 @@
return NULL;
}
- if ((ctx=(struct crc_context *)malloc(sizeof(*ctx))) == NULL) {
+ if ((ctx = (struct crc_context *)malloc(sizeof(*ctx))) == NULL) {
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return NULL;
}
@@ -78,125 +77,122 @@
static zip_int64_t
-crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd)
-{
+crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
struct crc_context *ctx;
zip_int64_t n;
ctx = (struct crc_context *)_ctx;
switch (cmd) {
- case ZIP_SOURCE_OPEN:
- ctx->position = 0;
- return 0;
-
- case ZIP_SOURCE_READ:
- if ((n = zip_source_read(src, data, len)) < 0) {
- _zip_error_set_from_source(&ctx->error, src);
- return -1;
- }
-
- if (n == 0) {
- if (ctx->crc_position == ctx->position) {
- ctx->crc_complete = 1;
- ctx->size = ctx->position;
+ case ZIP_SOURCE_OPEN:
+ ctx->position = 0;
+ return 0;
- if (ctx->validate) {
- struct zip_stat st;
-
- if (zip_source_stat(src, &st) < 0) {
- _zip_error_set_from_source(&ctx->error, src);
- return -1;
- }
-
- if ((st.valid & ZIP_STAT_CRC) && st.crc != ctx->crc) {
- zip_error_set(&ctx->error, ZIP_ER_CRC, 0);
- return -1;
- }
- if ((st.valid & ZIP_STAT_SIZE) && st.size != ctx->size) {
- zip_error_set(&ctx->error, ZIP_ER_INCONS, 0);
- return -1;
- }
- }
- }
- }
- else if (!ctx->crc_complete && ctx->position <= ctx->crc_position) {
- zip_uint64_t i, nn;
+ case ZIP_SOURCE_READ:
+ if ((n = zip_source_read(src, data, len)) < 0) {
+ _zip_error_set_from_source(&ctx->error, src);
+ return -1;
+ }
- for (i = ctx->crc_position - ctx->position; i < (zip_uint64_t)n; i += nn) {
- nn = ZIP_MIN(UINT_MAX, (zip_uint64_t)n-i);
+ if (n == 0) {
+ if (ctx->crc_position == ctx->position) {
+ ctx->crc_complete = 1;
+ ctx->size = ctx->position;
- ctx->crc = (zip_uint32_t)crc32(ctx->crc, (const Bytef *)data+i, (uInt)nn);
- ctx->crc_position += nn;
+ if (ctx->validate) {
+ struct zip_stat st;
+
+ if (zip_source_stat(src, &st) < 0) {
+ _zip_error_set_from_source(&ctx->error, src);
+ return -1;
+ }
+
+ if ((st.valid & ZIP_STAT_CRC) && st.crc != ctx->crc) {
+ zip_error_set(&ctx->error, ZIP_ER_CRC, 0);
+ return -1;
+ }
+ if ((st.valid & ZIP_STAT_SIZE) && st.size != ctx->size) {
+ zip_error_set(&ctx->error, ZIP_ER_INCONS, 0);
+ return -1;
+ }
}
- }
- ctx->position += (zip_uint64_t)n;
- return n;
-
- case ZIP_SOURCE_CLOSE:
- return 0;
-
- case ZIP_SOURCE_STAT:
- {
- zip_stat_t *st;
-
- st = (zip_stat_t *)data;
-
- if (ctx->crc_complete) {
- /* TODO: Set comp_size, comp_method, encryption_method?
- After all, this only works for uncompressed data. */
- st->size = ctx->size;
- st->crc = ctx->crc;
- st->comp_size = ctx->size;
- st->comp_method = ZIP_CM_STORE;
- st->encryption_method = ZIP_EM_NONE;
- st->valid |= ZIP_STAT_SIZE|ZIP_STAT_CRC|ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD|ZIP_STAT_ENCRYPTION_METHOD;;
}
- return 0;
- }
-
- case ZIP_SOURCE_ERROR:
- return zip_error_to_data(&ctx->error, data, len);
+ }
+ else if (!ctx->crc_complete && ctx->position <= ctx->crc_position) {
+ zip_uint64_t i, nn;
- case ZIP_SOURCE_FREE:
- free(ctx);
- return 0;
-
- case ZIP_SOURCE_SUPPORTS:
- {
- zip_int64_t mask = zip_source_supports(src);
+ for (i = ctx->crc_position - ctx->position; i < (zip_uint64_t)n; i += nn) {
+ nn = ZIP_MIN(UINT_MAX, (zip_uint64_t)n - i);
- if (mask < 0) {
- _zip_error_set_from_source(&ctx->error, src);
- return -1;
- }
-
- return mask & ~zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_GET_COMPRESSION_FLAGS, -1);
- }
-
- case ZIP_SOURCE_SEEK:
- {
- zip_int64_t new_position;
- zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
-
- if (args == NULL) {
- return -1;
+ ctx->crc = (zip_uint32_t)crc32(ctx->crc, (const Bytef *)data + i, (uInt)nn);
+ ctx->crc_position += nn;
}
- if (zip_source_seek(src, args->offset, args->whence) < 0 || (new_position = zip_source_tell(src)) < 0) {
- _zip_error_set_from_source(&ctx->error, src);
- return -1;
- }
+ }
+ ctx->position += (zip_uint64_t)n;
+ return n;
- ctx->position = (zip_uint64_t)new_position;
+ case ZIP_SOURCE_CLOSE:
+ return 0;
- return 0;
- }
+ case ZIP_SOURCE_STAT: {
+ zip_stat_t *st;
- case ZIP_SOURCE_TELL:
- return (zip_int64_t)ctx->position;
-
- default:
- zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
- return -1;
+ st = (zip_stat_t *)data;
+
+ if (ctx->crc_complete) {
+ /* TODO: Set comp_size, comp_method, encryption_method?
+ After all, this only works for uncompressed data. */
+ st->size = ctx->size;
+ st->crc = ctx->crc;
+ st->comp_size = ctx->size;
+ st->comp_method = ZIP_CM_STORE;
+ st->encryption_method = ZIP_EM_NONE;
+ st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
+ ;
+ }
+ return 0;
+ }
+
+ case ZIP_SOURCE_ERROR:
+ return zip_error_to_data(&ctx->error, data, len);
+
+ case ZIP_SOURCE_FREE:
+ free(ctx);
+ return 0;
+
+ case ZIP_SOURCE_SUPPORTS: {
+ zip_int64_t mask = zip_source_supports(src);
+
+ if (mask < 0) {
+ _zip_error_set_from_source(&ctx->error, src);
+ return -1;
+ }
+
+ return mask & ~zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_GET_COMPRESSION_FLAGS, -1);
+ }
+
+ case ZIP_SOURCE_SEEK: {
+ zip_int64_t new_position;
+ zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
+
+ if (args == NULL) {
+ return -1;
+ }
+ if (zip_source_seek(src, args->offset, args->whence) < 0 || (new_position = zip_source_tell(src)) < 0) {
+ _zip_error_set_from_source(&ctx->error, src);
+ return -1;
+ }
+
+ ctx->position = (zip_uint64_t)new_position;
+
+ return 0;
+ }
+
+ case ZIP_SOURCE_TELL:
+ return (zip_int64_t)ctx->position;
+
+ default:
+ zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
+ return -1;
}
}
diff --git a/lib/zip_source_error.c b/lib/zip_source_error.c
index 91e2dd6..5145169 100644
--- a/lib/zip_source_error.c
+++ b/lib/zip_source_error.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,13 +36,11 @@
zip_error_t *
-zip_source_error(zip_source_t *src)
-{
+zip_source_error(zip_source_t *src) {
return &src->error;
}
bool
-_zip_source_had_error(zip_source_t *src)
-{
+_zip_source_had_error(zip_source_t *src) {
return zip_source_error(src)->zip_err != ZIP_ER_OK;
}
diff --git a/lib/zip_source_file.c b/lib/zip_source_file.c
index 6a10c01..77376f4 100644
--- a/lib/zip_source_file.c
+++ b/lib/zip_source_file.c
@@ -42,8 +42,7 @@
#endif
ZIP_EXTERN zip_source_t *
-zip_source_file(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len)
-{
+zip_source_file(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len) {
if (za == NULL)
return NULL;
@@ -52,8 +51,7 @@
ZIP_EXTERN zip_source_t *
-zip_source_file_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error)
-{
+zip_source_file_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) {
if (fname == NULL || length < -1) {
zip_error_set(error, ZIP_ER_INVAL, 0);
return NULL;
diff --git a/lib/zip_source_filep.c b/lib/zip_source_filep.c
index 83b6646..5d3a2ec 100644
--- a/lib/zip_source_filep.c
+++ b/lib/zip_source_filep.c
@@ -31,10 +31,10 @@
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
#include "zipint.h"
@@ -48,8 +48,8 @@
#define CAN_CLONE
#endif
#ifdef HAVE_FICLONERANGE
-#include <sys/ioctl.h>
#include <linux/fs.h>
+#include <sys/ioctl.h>
#define CAN_CLONE
#endif
@@ -60,7 +60,7 @@
/* Windows sys/types.h does not provide these */
#ifndef S_ISREG
-#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
#endif
#if defined(S_IXUSR) && defined(S_IRWXG) && defined(S_IRWXO)
#define _SAFE_MASK (S_IXUSR | S_IRWXG | S_IRWXO)
@@ -76,7 +76,7 @@
#endif
struct read_file {
- zip_error_t error; /* last error information */
+ zip_error_t error; /* last error information */
zip_int64_t supports;
/* reading */
@@ -103,8 +103,7 @@
ZIP_EXTERN zip_source_t *
-zip_source_filep(zip_t *za, FILE *file, zip_uint64_t start, zip_int64_t len)
-{
+zip_source_filep(zip_t *za, FILE *file, zip_uint64_t start, zip_int64_t len) {
if (za == NULL)
return NULL;
@@ -113,8 +112,7 @@
ZIP_EXTERN zip_source_t *
-zip_source_filep_create(FILE *file, zip_uint64_t start, zip_int64_t length, zip_error_t *error)
-{
+zip_source_filep_create(FILE *file, zip_uint64_t start, zip_int64_t length, zip_error_t *error) {
if (file == NULL || length < -1) {
zip_error_set(error, ZIP_ER_INVAL, 0);
return NULL;
@@ -125,8 +123,7 @@
zip_source_t *
-_zip_source_file_or_p(const char *fname, FILE *file, zip_uint64_t start, zip_int64_t len, const zip_stat_t *st, zip_error_t *error)
-{
+_zip_source_file_or_p(const char *fname, FILE *file, zip_uint64_t start, zip_int64_t len, const zip_stat_t *st, zip_error_t *error) {
struct read_file *ctx;
zip_source_t *zs;
struct stat sb;
@@ -146,14 +143,14 @@
return NULL;
}
- if ((ctx=(struct read_file *)malloc(sizeof(struct read_file))) == NULL) {
+ if ((ctx = (struct read_file *)malloc(sizeof(struct read_file))) == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return NULL;
}
ctx->fname = NULL;
if (fname) {
- if ((ctx->fname=strdup(fname)) == NULL) {
+ if ((ctx->fname = strdup(fname)) == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
free(ctx);
return NULL;
@@ -164,8 +161,8 @@
ctx->end = (zip_uint64_t)len;
if (st) {
memcpy(&ctx->st, st, sizeof(ctx->st));
- ctx->st.name = NULL;
- ctx->st.valid &= ~ZIP_STAT_NAME;
+ ctx->st.name = NULL;
+ ctx->st.valid &= ~ZIP_STAT_NAME;
}
else {
zip_stat_init(&ctx->st);
@@ -219,7 +216,7 @@
if (ctx->end == 0) {
ctx->st.size = (zip_uint64_t)sb.st_size - ctx->start;
ctx->st.valid |= ZIP_STAT_SIZE;
-
+
if (ctx->fname && start == 0) {
ctx->supports = ZIP_SOURCE_SUPPORTS_WRITABLE;
}
@@ -229,11 +226,11 @@
#ifdef CAN_CLONE
if (ctx->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE)) {
- ctx->supports |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING);
+ ctx->supports |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING);
}
#endif
- if ((zs=zip_source_function_create(read_file, ctx, error)) == NULL) {
+ if ((zs = zip_source_function_create(read_file, ctx, error)) == NULL) {
free(ctx->fname);
free(ctx);
return NULL;
@@ -244,34 +241,33 @@
static int
-create_temp_output(struct read_file *ctx)
-{
+create_temp_output(struct read_file *ctx) {
char *temp;
int tfd;
mode_t mask;
FILE *tfp;
- if ((temp=(char *)malloc(strlen(ctx->fname)+8)) == NULL) {
+ if ((temp = (char *)malloc(strlen(ctx->fname) + 8)) == NULL) {
zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
return -1;
}
sprintf(temp, "%s.XXXXXX", ctx->fname);
mask = umask(_SAFE_MASK);
- if ((tfd=mkstemp(temp)) == -1) {
- zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
+ if ((tfd = mkstemp(temp)) == -1) {
+ zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
umask(mask);
- free(temp);
- return -1;
+ free(temp);
+ return -1;
}
umask(mask);
- if ((tfp=fdopen(tfd, "r+b")) == NULL) {
- zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
- close(tfd);
- (void)remove(temp);
- free(temp);
- return -1;
+ if ((tfp = fdopen(tfd, "r+b")) == NULL) {
+ zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
+ close(tfd);
+ (void)remove(temp);
+ free(temp);
+ return -1;
}
#ifdef _WIN32
@@ -279,7 +275,7 @@
According to Pierre Joye, Windows in some environments per
default creates text files, so force binary mode.
*/
- _setmode(_fileno(tfp), _O_BINARY );
+ _setmode(_fileno(tfp), _O_BINARY);
#endif
ctx->fout = tfp;
@@ -289,94 +285,92 @@
}
#ifdef CAN_CLONE
-zip_int64_t
-static create_temp_output_cloning(struct read_file *ctx, zip_uint64_t offset)
-{
+zip_int64_t static create_temp_output_cloning(struct read_file *ctx, zip_uint64_t offset) {
char *temp;
FILE *tfp;
if (offset > ZIP_OFF_MAX) {
- zip_error_set(&ctx->error, ZIP_ER_SEEK, E2BIG);
- return -1;
+ zip_error_set(&ctx->error, ZIP_ER_SEEK, E2BIG);
+ return -1;
}
- if ((temp=(char *)malloc(strlen(ctx->fname)+8)) == NULL) {
- zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
- return -1;
+ if ((temp = (char *)malloc(strlen(ctx->fname) + 8)) == NULL) {
+ zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
+ return -1;
}
sprintf(temp, "%s.XXXXXX", ctx->fname);
#ifdef HAVE_CLONEFILE
if (mktemp(temp) == NULL) {
- zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
- free(temp);
- return -1;
+ zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
+ free(temp);
+ return -1;
}
if (clonefile(ctx->fname, temp, 0) < 0) {
- zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
- free(temp);
- return -1;
+ zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
+ free(temp);
+ return -1;
}
- if ((tfp=fopen(temp, "r+b")) == NULL) {
- zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
- (void)remove(temp);
- free(temp);
- return -1;
+ if ((tfp = fopen(temp, "r+b")) == NULL) {
+ zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
+ (void)remove(temp);
+ free(temp);
+ return -1;
}
if (ftruncate(fileno(tfp), (off_t)offset) < 0) {
- (void)fclose(tfp);
- (void)remove(temp);
- free(temp);
- return -1;
+ (void)fclose(tfp);
+ (void)remove(temp);
+ free(temp);
+ return -1;
}
#else
{
- int fd;
- struct file_clone_range range;
- struct stat st;
+ int fd;
+ struct file_clone_range range;
+ struct stat st;
- if (fstat(fileno(ctx->f), &st) < 0) {
- zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
- return -1;
- }
+ if (fstat(fileno(ctx->f), &st) < 0) {
+ zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
+ return -1;
+ }
- if ((fd = mkstemp(temp)) < 0) {
- zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
- free(temp);
- return -1;
- }
+ if ((fd = mkstemp(temp)) < 0) {
+ zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
+ free(temp);
+ return -1;
+ }
- range.src_fd = fileno(ctx->f);
- range.src_offset = 0;
- range.src_length = ((offset + st.st_blksize - 1) / st.st_blksize) * st.st_blksize;
- if (range.src_length > st.st_size) {
- range.src_length = 0;
- }
- range.dest_offset = 0;
- if (ioctl(fd, FICLONERANGE, &range) < 0) {
- zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
- (void)close(fd);
- (void)remove(temp);
- free(temp);
- return -1;
- }
+ range.src_fd = fileno(ctx->f);
+ range.src_offset = 0;
+ range.src_length = ((offset + st.st_blksize - 1) / st.st_blksize) * st.st_blksize;
+ if (range.src_length > st.st_size) {
+ range.src_length = 0;
+ }
+ range.dest_offset = 0;
+ if (ioctl(fd, FICLONERANGE, &range) < 0) {
+ zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
+ (void)close(fd);
+ (void)remove(temp);
+ free(temp);
+ return -1;
+ }
- if ((tfp = fdopen(fd, "r+b")) == NULL) {
- zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
- (void)close(fd);
- (void)remove(temp);
- free(temp);
- return -1;
- }
+ if ((tfp = fdopen(fd, "r+b")) == NULL) {
+ zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
+ (void)close(fd);
+ (void)remove(temp);
+ free(temp);
+ return -1;
+ }
}
#endif
if (fseeko(tfp, (off_t)offset, SEEK_SET) < 0) {
- (void)fclose(tfp);
- (void)remove(temp);
- free(temp);
- zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
+ (void)fclose(tfp);
+ (void)remove(temp);
+ free(temp);
+ zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
}
ctx->fout = tfp;
@@ -388,8 +382,7 @@
static zip_int64_t
-read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd)
-{
+read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
struct read_file *ctx;
char *buf;
zip_uint64_t n;
@@ -399,244 +392,240 @@
buf = (char *)data;
switch (cmd) {
- case ZIP_SOURCE_BEGIN_WRITE:
- if (ctx->fname == NULL) {
- zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
- return -1;
- }
- return create_temp_output(ctx);
+ case ZIP_SOURCE_BEGIN_WRITE:
+ if (ctx->fname == NULL) {
+ zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
+ return -1;
+ }
+ return create_temp_output(ctx);
#ifdef CAN_CLONE
- case ZIP_SOURCE_BEGIN_WRITE_CLONING:
- if (ctx->fname == NULL) {
- zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
- return -1;
- }
- return create_temp_output_cloning(ctx, len);
+ case ZIP_SOURCE_BEGIN_WRITE_CLONING:
+ if (ctx->fname == NULL) {
+ zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
+ return -1;
+ }
+ return create_temp_output_cloning(ctx, len);
#endif
- case ZIP_SOURCE_COMMIT_WRITE: {
- mode_t mask;
+ case ZIP_SOURCE_COMMIT_WRITE: {
+ mode_t mask;
- if (fclose(ctx->fout) < 0) {
- ctx->fout = NULL;
- zip_error_set(&ctx->error, ZIP_ER_WRITE, errno);
- }
- ctx->fout = NULL;
- if (rename(ctx->tmpname, ctx->fname) < 0) {
- zip_error_set(&ctx->error, ZIP_ER_RENAME, errno);
- return -1;
- }
- mask = umask(022);
- umask(mask);
- /* not much we can do if chmod fails except make the whole commit fail */
- (void)chmod(ctx->fname, 0666&~mask);
- free(ctx->tmpname);
- ctx->tmpname = NULL;
- return 0;
+ if (fclose(ctx->fout) < 0) {
+ ctx->fout = NULL;
+ zip_error_set(&ctx->error, ZIP_ER_WRITE, errno);
}
+ ctx->fout = NULL;
+ if (rename(ctx->tmpname, ctx->fname) < 0) {
+ zip_error_set(&ctx->error, ZIP_ER_RENAME, errno);
+ return -1;
+ }
+ mask = umask(022);
+ umask(mask);
+ /* not much we can do if chmod fails except make the whole commit fail */
+ (void)chmod(ctx->fname, 0666 & ~mask);
+ free(ctx->tmpname);
+ ctx->tmpname = NULL;
+ return 0;
+ }
- case ZIP_SOURCE_CLOSE:
- if (ctx->fname) {
- fclose(ctx->f);
- ctx->f = NULL;
- }
- return 0;
+ case ZIP_SOURCE_CLOSE:
+ if (ctx->fname) {
+ fclose(ctx->f);
+ ctx->f = NULL;
+ }
+ return 0;
- case ZIP_SOURCE_ERROR:
- return zip_error_to_data(&ctx->error, data, len);
+ case ZIP_SOURCE_ERROR:
+ return zip_error_to_data(&ctx->error, data, len);
- case ZIP_SOURCE_FREE:
- free(ctx->fname);
- free(ctx->tmpname);
- if (ctx->f)
- fclose(ctx->f);
- free(ctx);
- return 0;
+ case ZIP_SOURCE_FREE:
+ free(ctx->fname);
+ free(ctx->tmpname);
+ if (ctx->f)
+ fclose(ctx->f);
+ free(ctx);
+ return 0;
- case ZIP_SOURCE_OPEN:
- if (ctx->fname) {
- if ((ctx->f=fopen(ctx->fname, "rb")) == NULL) {
- zip_error_set(&ctx->error, ZIP_ER_OPEN, errno);
- return -1;
- }
- }
-
- if (ctx->start > 0) {
- if (_zip_fseek_u(ctx->f, ctx->start, SEEK_SET, &ctx->error) < 0) {
- /* TODO: skip by reading */
- return -1;
- }
- }
- ctx->current = 0;
- return 0;
-
- case ZIP_SOURCE_READ:
- if (ctx->end > 0) {
- n = ctx->end - ctx->current;
- if (n > len) {
- n = len;
- }
- }
- else {
- n = len;
- }
-
- if (n > SIZE_MAX)
- n = SIZE_MAX;
-
- if ((i=fread(buf, 1, (size_t)n, ctx->f)) == 0) {
- if (ferror(ctx->f)) {
- zip_error_set(&ctx->error, ZIP_ER_READ, errno);
- return -1;
- }
- }
- ctx->current += i;
-
- return (zip_int64_t)i;
-
- case ZIP_SOURCE_REMOVE:
- if (remove(ctx->fname) < 0) {
- zip_error_set(&ctx->error, ZIP_ER_REMOVE, errno);
- return -1;
- }
- return 0;
-
- case ZIP_SOURCE_ROLLBACK_WRITE:
- if (ctx->fout) {
- fclose(ctx->fout);
- ctx->fout = NULL;
- }
- (void)remove(ctx->tmpname);
- free(ctx->tmpname);
- ctx->tmpname = NULL;
- return 0;
-
- case ZIP_SOURCE_SEEK: {
- zip_int64_t new_current;
- int need_seek;
- zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
-
- if (args == NULL)
- return -1;
-
- need_seek = 1;
-
- switch (args->whence) {
- case SEEK_SET:
- new_current = args->offset;
- break;
-
- case SEEK_END:
- if (ctx->end == 0) {
- if (_zip_fseek(ctx->f, args->offset, SEEK_END, &ctx->error) < 0) {
- return -1;
- }
- if ((new_current = ftello(ctx->f)) < 0) {
- zip_error_set(&ctx->error, ZIP_ER_SEEK, errno);
- return -1;
- }
- new_current -= (zip_int64_t)ctx->start;
- need_seek = 0;
- }
- else {
- new_current = (zip_int64_t)ctx->end + args->offset;
- }
- break;
-
- case SEEK_CUR:
- new_current = (zip_int64_t)ctx->current + args->offset;
- break;
-
- default:
- zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
- return -1;
- }
-
- if (new_current < 0 || (ctx->end != 0 && (zip_uint64_t)new_current > ctx->end)
- || (zip_uint64_t)new_current + ctx->start < ctx->start) {
- zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
- return -1;
- }
-
- ctx->current = (zip_uint64_t)new_current;
-
- if (need_seek) {
- if (_zip_fseek_u(ctx->f, ctx->current + ctx->start, SEEK_SET, &ctx->error) < 0) {
- return -1;
- }
- }
- return 0;
- }
-
- case ZIP_SOURCE_SEEK_WRITE: {
- zip_source_args_seek_t *args;
-
- args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
- if (args == NULL) {
- return -1;
- }
-
- if (_zip_fseek(ctx->fout, args->offset, args->whence, &ctx->error) < 0) {
- return -1;
- }
- return 0;
- }
-
- case ZIP_SOURCE_STAT: {
- if (len < sizeof(ctx->st))
- return -1;
-
- if (zip_error_code_zip(&ctx->stat_error) != 0) {
- zip_error_set(&ctx->error, zip_error_code_zip(&ctx->stat_error), zip_error_code_system(&ctx->stat_error));
+ case ZIP_SOURCE_OPEN:
+ if (ctx->fname) {
+ if ((ctx->f = fopen(ctx->fname, "rb")) == NULL) {
+ zip_error_set(&ctx->error, ZIP_ER_OPEN, errno);
return -1;
}
-
- memcpy(data, &ctx->st, sizeof(ctx->st));
- return sizeof(ctx->st);
}
- case ZIP_SOURCE_SUPPORTS:
- return ctx->supports;
+ if (ctx->start > 0) {
+ if (_zip_fseek_u(ctx->f, ctx->start, SEEK_SET, &ctx->error) < 0) {
+ /* TODO: skip by reading */
+ return -1;
+ }
+ }
+ ctx->current = 0;
+ return 0;
- case ZIP_SOURCE_TELL:
- return (zip_int64_t)ctx->current;
+ case ZIP_SOURCE_READ:
+ if (ctx->end > 0) {
+ n = ctx->end - ctx->current;
+ if (n > len) {
+ n = len;
+ }
+ }
+ else {
+ n = len;
+ }
- case ZIP_SOURCE_TELL_WRITE:
- {
- off_t ret = ftello(ctx->fout);
+ if (n > SIZE_MAX)
+ n = SIZE_MAX;
- if (ret < 0) {
- zip_error_set(&ctx->error, ZIP_ER_TELL, errno);
- return -1;
- }
- return ret;
- }
+ if ((i = fread(buf, 1, (size_t)n, ctx->f)) == 0) {
+ if (ferror(ctx->f)) {
+ zip_error_set(&ctx->error, ZIP_ER_READ, errno);
+ return -1;
+ }
+ }
+ ctx->current += i;
- case ZIP_SOURCE_WRITE:
- {
- size_t ret;
+ return (zip_int64_t)i;
- clearerr(ctx->fout);
- ret = fwrite(data, 1, len, ctx->fout);
- if (ret != len || ferror(ctx->fout)) {
- zip_error_set(&ctx->error, ZIP_ER_WRITE, errno);
- return -1;
- }
+ case ZIP_SOURCE_REMOVE:
+ if (remove(ctx->fname) < 0) {
+ zip_error_set(&ctx->error, ZIP_ER_REMOVE, errno);
+ return -1;
+ }
+ return 0;
- return (zip_int64_t)ret;
- }
+ case ZIP_SOURCE_ROLLBACK_WRITE:
+ if (ctx->fout) {
+ fclose(ctx->fout);
+ ctx->fout = NULL;
+ }
+ (void)remove(ctx->tmpname);
+ free(ctx->tmpname);
+ ctx->tmpname = NULL;
+ return 0;
- default:
- zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
- return -1;
+ case ZIP_SOURCE_SEEK: {
+ zip_int64_t new_current;
+ int need_seek;
+ zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
+
+ if (args == NULL)
+ return -1;
+
+ need_seek = 1;
+
+ switch (args->whence) {
+ case SEEK_SET:
+ new_current = args->offset;
+ break;
+
+ case SEEK_END:
+ if (ctx->end == 0) {
+ if (_zip_fseek(ctx->f, args->offset, SEEK_END, &ctx->error) < 0) {
+ return -1;
+ }
+ if ((new_current = ftello(ctx->f)) < 0) {
+ zip_error_set(&ctx->error, ZIP_ER_SEEK, errno);
+ return -1;
+ }
+ new_current -= (zip_int64_t)ctx->start;
+ need_seek = 0;
+ }
+ else {
+ new_current = (zip_int64_t)ctx->end + args->offset;
+ }
+ break;
+
+ case SEEK_CUR:
+ new_current = (zip_int64_t)ctx->current + args->offset;
+ break;
+
+ default:
+ zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
+ return -1;
+ }
+
+ if (new_current < 0 || (ctx->end != 0 && (zip_uint64_t)new_current > ctx->end) || (zip_uint64_t)new_current + ctx->start < ctx->start) {
+ zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
+ return -1;
+ }
+
+ ctx->current = (zip_uint64_t)new_current;
+
+ if (need_seek) {
+ if (_zip_fseek_u(ctx->f, ctx->current + ctx->start, SEEK_SET, &ctx->error) < 0) {
+ return -1;
+ }
+ }
+ return 0;
+ }
+
+ case ZIP_SOURCE_SEEK_WRITE: {
+ zip_source_args_seek_t *args;
+
+ args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
+ if (args == NULL) {
+ return -1;
+ }
+
+ if (_zip_fseek(ctx->fout, args->offset, args->whence, &ctx->error) < 0) {
+ return -1;
+ }
+ return 0;
+ }
+
+ case ZIP_SOURCE_STAT: {
+ if (len < sizeof(ctx->st))
+ return -1;
+
+ if (zip_error_code_zip(&ctx->stat_error) != 0) {
+ zip_error_set(&ctx->error, zip_error_code_zip(&ctx->stat_error), zip_error_code_system(&ctx->stat_error));
+ return -1;
+ }
+
+ memcpy(data, &ctx->st, sizeof(ctx->st));
+ return sizeof(ctx->st);
+ }
+
+ case ZIP_SOURCE_SUPPORTS:
+ return ctx->supports;
+
+ case ZIP_SOURCE_TELL:
+ return (zip_int64_t)ctx->current;
+
+ case ZIP_SOURCE_TELL_WRITE: {
+ off_t ret = ftello(ctx->fout);
+
+ if (ret < 0) {
+ zip_error_set(&ctx->error, ZIP_ER_TELL, errno);
+ return -1;
+ }
+ return ret;
+ }
+
+ case ZIP_SOURCE_WRITE: {
+ size_t ret;
+
+ clearerr(ctx->fout);
+ ret = fwrite(data, 1, len, ctx->fout);
+ if (ret != len || ferror(ctx->fout)) {
+ zip_error_set(&ctx->error, ZIP_ER_WRITE, errno);
+ return -1;
+ }
+
+ return (zip_int64_t)ret;
+ }
+
+ default:
+ zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
+ return -1;
}
}
static int
-_zip_fseek_u(FILE *f, zip_uint64_t offset, int whence, zip_error_t *error)
-{
+_zip_fseek_u(FILE *f, zip_uint64_t offset, int whence, zip_error_t *error) {
if (offset > ZIP_INT64_MAX) {
zip_error_set(error, ZIP_ER_SEEK, EOVERFLOW);
return -1;
@@ -646,8 +635,7 @@
static int
-_zip_fseek(FILE *f, zip_int64_t offset, int whence, zip_error_t *error)
-{
+_zip_fseek(FILE *f, zip_int64_t offset, int whence, zip_error_t *error) {
if (offset > ZIP_FSEEK_MAX || offset < ZIP_FSEEK_MIN) {
zip_error_set(error, ZIP_ER_SEEK, EOVERFLOW);
return -1;
diff --git a/lib/zip_source_free.c b/lib/zip_source_free.c
index 9070469..7cb3525 100644
--- a/lib/zip_source_free.c
+++ b/lib/zip_source_free.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,34 +38,33 @@
ZIP_EXTERN void
-zip_source_free(zip_source_t *src)
-{
+zip_source_free(zip_source_t *src) {
if (src == NULL)
return;
if (src->refcount > 0) {
- src->refcount--;
+ src->refcount--;
}
if (src->refcount > 0) {
- return;
+ return;
}
-
+
if (ZIP_SOURCE_IS_OPEN_READING(src)) {
src->open_count = 1; /* force close */
zip_source_close(src);
}
if (ZIP_SOURCE_IS_OPEN_WRITING(src)) {
- zip_source_rollback_write(src);
+ zip_source_rollback_write(src);
}
-
+
if (src->source_archive && !src->source_closed) {
- _zip_deregister_source(src->source_archive, src);
+ _zip_deregister_source(src->source_archive, src);
}
-
+
(void)_zip_source_call(src, NULL, 0, ZIP_SOURCE_FREE);
-
+
if (src->src) {
- zip_source_free(src->src);
+ zip_source_free(src->src);
}
free(src);
diff --git a/lib/zip_source_function.c b/lib/zip_source_function.c
index 3d4604c..56eb1c5 100644
--- a/lib/zip_source_function.c
+++ b/lib/zip_source_function.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,50 +38,46 @@
ZIP_EXTERN zip_source_t *
-zip_source_function(zip_t *za, zip_source_callback zcb, void *ud)
-{
+zip_source_function(zip_t *za, zip_source_callback zcb, void *ud) {
if (za == NULL) {
- return NULL;
+ return NULL;
}
-
+
return zip_source_function_create(zcb, ud, &za->error);
}
ZIP_EXTERN zip_source_t *
-zip_source_function_create(zip_source_callback zcb, void *ud, zip_error_t *error)
-{
+zip_source_function_create(zip_source_callback zcb, void *ud, zip_error_t *error) {
zip_source_t *zs;
- if ((zs=_zip_source_new(error)) == NULL)
+ if ((zs = _zip_source_new(error)) == NULL)
return NULL;
zs->cb.f = zcb;
zs->ud = ud;
-
+
zs->supports = zcb(ud, NULL, 0, ZIP_SOURCE_SUPPORTS);
if (zs->supports < 0) {
- zs->supports = ZIP_SOURCE_SUPPORTS_READABLE;
+ zs->supports = ZIP_SOURCE_SUPPORTS_READABLE;
}
-
+
return zs;
}
ZIP_EXTERN void
-zip_source_keep(zip_source_t *src)
-{
+zip_source_keep(zip_source_t *src) {
src->refcount++;
}
zip_source_t *
-_zip_source_new(zip_error_t *error)
-{
+_zip_source_new(zip_error_t *error) {
zip_source_t *src;
- if ((src=(zip_source_t *)malloc(sizeof(*src))) == NULL) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
+ if ((src = (zip_source_t *)malloc(sizeof(*src))) == NULL) {
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
return NULL;
}
diff --git a/lib/zip_source_get_compression_flags.c b/lib/zip_source_get_compression_flags.c
index b5bae82..e33e43b 100644
--- a/lib/zip_source_get_compression_flags.c
+++ b/lib/zip_source_get_compression_flags.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -34,11 +34,10 @@
#include "zipint.h"
-#define ZIP_COMPRESSION_BITFLAG_MAX 3
+#define ZIP_COMPRESSION_BITFLAG_MAX 3
zip_int8_t
-zip_source_get_compression_flags(zip_source_t *src)
-{
+zip_source_get_compression_flags(zip_source_t *src) {
while (src) {
if ((src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_GET_COMPRESSION_FLAGS))) {
zip_int64_t ret = _zip_source_call(src, NULL, 0, ZIP_SOURCE_GET_COMPRESSION_FLAGS);
diff --git a/lib/zip_source_is_deleted.c b/lib/zip_source_is_deleted.c
index e50cdd9..1e5d343 100644
--- a/lib/zip_source_is_deleted.c
+++ b/lib/zip_source_is_deleted.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,7 +36,6 @@
ZIP_EXTERN int
-zip_source_is_deleted(zip_source_t *src)
-{
+zip_source_is_deleted(zip_source_t *src) {
return src->write_state == ZIP_SOURCE_WRITE_REMOVED;
}
diff --git a/lib/zip_source_layered.c b/lib/zip_source_layered.c
index 94b3310..5e95bc1 100644
--- a/lib/zip_source_layered.c
+++ b/lib/zip_source_layered.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,23 +38,21 @@
zip_source_t *
-zip_source_layered(zip_t *za, zip_source_t *src, zip_source_layered_callback cb, void *ud)
-{
+zip_source_layered(zip_t *za, zip_source_t *src, zip_source_layered_callback cb, void *ud) {
if (za == NULL)
- return NULL;
+ return NULL;
return zip_source_layered_create(src, cb, ud, &za->error);
}
zip_source_t *
-zip_source_layered_create(zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error)
-{
+zip_source_layered_create(zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error) {
zip_source_t *zs;
-
- if ((zs=_zip_source_new(error)) == NULL)
- return NULL;
-
+
+ if ((zs = _zip_source_new(error)) == NULL)
+ return NULL;
+
zip_source_keep(src);
zs->src = src;
zs->cb.l = cb;
@@ -62,7 +60,7 @@
zs->supports = cb(src, ud, NULL, 0, ZIP_SOURCE_SUPPORTS);
if (zs->supports < 0) {
- zs->supports = ZIP_SOURCE_SUPPORTS_READABLE;
+ zs->supports = ZIP_SOURCE_SUPPORTS_READABLE;
}
return zs;
diff --git a/lib/zip_source_open.c b/lib/zip_source_open.c
index ec01b0d..187001c 100644
--- a/lib/zip_source_open.c
+++ b/lib/zip_source_open.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,13 +35,12 @@
#include "zipint.h"
ZIP_EXTERN int
-zip_source_open(zip_source_t *src)
-{
+zip_source_open(zip_source_t *src) {
if (src->source_closed) {
- return -1;
+ return -1;
}
if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
- zip_error_set(&src->error, ZIP_ER_DELETED, 0);
+ zip_error_set(&src->error, ZIP_ER_DELETED, 0);
return -1;
}
@@ -58,7 +57,7 @@
return -1;
}
}
-
+
if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_OPEN) < 0) {
if (ZIP_SOURCE_IS_LAYERED(src)) {
zip_source_close(src->src);
@@ -71,6 +70,6 @@
src->had_read_error = false;
_zip_error_clear(&src->error);
src->open_count++;
-
+
return 0;
}
diff --git a/lib/zip_source_pkware.c b/lib/zip_source_pkware.c
index 3957d99..b466da4 100644
--- a/lib/zip_source_pkware.c
+++ b/lib/zip_source_pkware.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -42,24 +42,20 @@
zip_uint32_t key[3];
};
-#define HEADERLEN 12
-#define KEY0 305419896
-#define KEY1 591751049
-#define KEY2 878082192
+#define HEADERLEN 12
+#define KEY0 305419896
+#define KEY1 591751049
+#define KEY2 878082192
-static void decrypt(struct trad_pkware *, zip_uint8_t *,
- const zip_uint8_t *, zip_uint64_t, int);
+static void decrypt(struct trad_pkware *, zip_uint8_t *, const zip_uint8_t *, zip_uint64_t, int);
static int decrypt_header(zip_source_t *, struct trad_pkware *);
-static zip_int64_t pkware_decrypt(zip_source_t *, void *, void *,
- zip_uint64_t, zip_source_cmd_t);
+static zip_int64_t pkware_decrypt(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t);
static void pkware_free(struct trad_pkware *);
zip_source_t *
-zip_source_pkware(zip_t *za, zip_source_t *src,
- zip_uint16_t em, int flags, const char *password)
-{
+zip_source_pkware(zip_t *za, zip_source_t *src, zip_uint16_t em, int flags, const char *password) {
struct trad_pkware *ctx;
zip_source_t *s2;
@@ -72,7 +68,7 @@
return NULL;
}
- if ((ctx=(struct trad_pkware *)malloc(sizeof(*ctx))) == NULL) {
+ if ((ctx = (struct trad_pkware *)malloc(sizeof(*ctx))) == NULL) {
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return NULL;
}
@@ -84,7 +80,7 @@
ctx->key[2] = KEY2;
decrypt(ctx, NULL, (const zip_uint8_t *)password, strlen(password), 1);
- if ((s2=zip_source_layered(za, src, pkware_decrypt, ctx)) == NULL) {
+ if ((s2 = zip_source_layered(za, src, pkware_decrypt, ctx)) == NULL) {
pkware_free(ctx);
return NULL;
}
@@ -94,14 +90,12 @@
static void
-decrypt(struct trad_pkware *ctx, zip_uint8_t *out, const zip_uint8_t *in,
- zip_uint64_t len, int update_only)
-{
+decrypt(struct trad_pkware *ctx, zip_uint8_t *out, const zip_uint8_t *in, zip_uint64_t len, int update_only) {
zip_uint16_t tmp;
zip_uint64_t i;
Bytef b;
- for (i=0; i<len; i++) {
+ for (i = 0; i < len; i++) {
b = in[i];
if (!update_only) {
@@ -125,20 +119,19 @@
static int
-decrypt_header(zip_source_t *src, struct trad_pkware *ctx)
-{
+decrypt_header(zip_source_t *src, struct trad_pkware *ctx) {
zip_uint8_t header[HEADERLEN];
struct zip_stat st;
zip_int64_t n;
unsigned short dostime, dosdate;
- if ((n=zip_source_read(src, header, HEADERLEN)) < 0) {
- _zip_error_set_from_source(&ctx->error, src);
+ if ((n = zip_source_read(src, header, HEADERLEN)) < 0) {
+ _zip_error_set_from_source(&ctx->error, src);
return -1;
}
-
+
if (n != HEADERLEN) {
- zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
+ zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
return -1;
}
@@ -151,8 +144,8 @@
_zip_u2d_time(st.mtime, &dostime, &dosdate);
- if (header[HEADERLEN-1] != st.crc>>24 && header[HEADERLEN-1] != dostime>>8) {
- zip_error_set(&ctx->error, ZIP_ER_WRONGPASSWD, 0);
+ if (header[HEADERLEN - 1] != st.crc >> 24 && header[HEADERLEN - 1] != dostime >> 8) {
+ zip_error_set(&ctx->error, ZIP_ER_WRONGPASSWD, 0);
return -1;
}
@@ -161,66 +154,62 @@
static zip_int64_t
-pkware_decrypt(zip_source_t *src, void *ud, void *data,
- zip_uint64_t len, zip_source_cmd_t cmd)
-{
+pkware_decrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
struct trad_pkware *ctx;
zip_int64_t n;
ctx = (struct trad_pkware *)ud;
switch (cmd) {
- case ZIP_SOURCE_OPEN:
- if (decrypt_header(src, ctx) < 0)
- return -1;
- return 0;
+ case ZIP_SOURCE_OPEN:
+ if (decrypt_header(src, ctx) < 0)
+ return -1;
+ return 0;
- case ZIP_SOURCE_READ:
- if ((n=zip_source_read(src, data, len)) < 0) {
- _zip_error_set_from_source(&ctx->error, src);
- return -1;
- }
+ case ZIP_SOURCE_READ:
+ if ((n = zip_source_read(src, data, len)) < 0) {
+ _zip_error_set_from_source(&ctx->error, src);
+ return -1;
+ }
- decrypt((struct trad_pkware *)ud, (zip_uint8_t *)data, (zip_uint8_t *)data, (zip_uint64_t)n, 0);
- return n;
+ decrypt((struct trad_pkware *)ud, (zip_uint8_t *)data, (zip_uint8_t *)data, (zip_uint64_t)n, 0);
+ return n;
- case ZIP_SOURCE_CLOSE:
- return 0;
+ case ZIP_SOURCE_CLOSE:
+ return 0;
- case ZIP_SOURCE_STAT:
- {
- zip_stat_t *st;
+ case ZIP_SOURCE_STAT: {
+ zip_stat_t *st;
- st = (zip_stat_t *)data;
+ st = (zip_stat_t *)data;
- st->encryption_method = ZIP_EM_NONE;
- st->valid |= ZIP_STAT_ENCRYPTION_METHOD;
- /* TODO: deduce HEADERLEN from size for uncompressed */
- if (st->valid & ZIP_STAT_COMP_SIZE)
- st->comp_size -= HEADERLEN;
-
- return 0;
- }
-
- case ZIP_SOURCE_SUPPORTS:
- return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, -1);
+ st->encryption_method = ZIP_EM_NONE;
+ st->valid |= ZIP_STAT_ENCRYPTION_METHOD;
+ /* TODO: deduce HEADERLEN from size for uncompressed */
+ if (st->valid & ZIP_STAT_COMP_SIZE)
+ st->comp_size -= HEADERLEN;
- case ZIP_SOURCE_ERROR:
- return zip_error_to_data(&ctx->error, data, len);
+ return 0;
+ }
- case ZIP_SOURCE_FREE:
- pkware_free(ctx);
- return 0;
+ case ZIP_SOURCE_SUPPORTS:
+ return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, -1);
- default:
- zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
- return -1;
+ case ZIP_SOURCE_ERROR:
+ return zip_error_to_data(&ctx->error, data, len);
+
+ case ZIP_SOURCE_FREE:
+ pkware_free(ctx);
+ return 0;
+
+ default:
+ zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
+ return -1;
}
}
static void
-pkware_free(struct trad_pkware *ctx)
-{
+pkware_free(struct trad_pkware *ctx) {
free(ctx);
}
diff --git a/lib/zip_source_read.c b/lib/zip_source_read.c
index 5288bf2..2e95b97 100644
--- a/lib/zip_source_read.c
+++ b/lib/zip_source_read.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,16 +36,15 @@
zip_int64_t
-zip_source_read(zip_source_t *src, void *data, zip_uint64_t len)
-{
+zip_source_read(zip_source_t *src, void *data, zip_uint64_t len) {
zip_uint64_t bytes_read;
zip_int64_t n;
if (src->source_closed) {
- return -1;
+ return -1;
}
if (!ZIP_SOURCE_IS_OPEN_READING(src) || len > ZIP_INT64_MAX || (len > 0 && data == NULL)) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
return -1;
}
@@ -60,7 +59,7 @@
bytes_read = 0;
while (bytes_read < len) {
if ((n = _zip_source_call(src, (zip_uint8_t *)data + bytes_read, len - bytes_read, ZIP_SOURCE_READ)) < 0) {
- src->had_read_error = true;
+ src->had_read_error = true;
if (bytes_read == 0) {
return -1;
}
@@ -82,7 +81,6 @@
bool
-_zip_source_eof(zip_source_t *src)
-{
+_zip_source_eof(zip_source_t *src) {
return src->eof;
}
diff --git a/lib/zip_source_remove.c b/lib/zip_source_remove.c
index 470a5ed..8e01e24 100644
--- a/lib/zip_source_remove.c
+++ b/lib/zip_source_remove.c
@@ -1,10 +1,10 @@
/*
zip_source_remove.c -- remove empty archive
Copyright (C) 2014 Dieter Baron and Thomas Klausner
-
+
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
-
+
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,26 +36,25 @@
int
-zip_source_remove(zip_source_t *src)
-{
+zip_source_remove(zip_source_t *src) {
if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
- return 0;
+ return 0;
}
-
+
if (ZIP_SOURCE_IS_OPEN_READING(src)) {
if (zip_source_close(src) < 0) {
return -1;
}
}
if (src->write_state != ZIP_SOURCE_WRITE_CLOSED) {
- zip_source_rollback_write(src);
+ zip_source_rollback_write(src);
}
-
+
if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_REMOVE) < 0) {
- return -1;
+ return -1;
}
-
+
src->write_state = ZIP_SOURCE_WRITE_REMOVED;
-
+
return 0;
}
diff --git a/lib/zip_source_rollback_write.c b/lib/zip_source_rollback_write.c
index c35f30f..bbccaf8 100644
--- a/lib/zip_source_rollback_write.c
+++ b/lib/zip_source_rollback_write.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,12 +36,11 @@
ZIP_EXTERN void
-zip_source_rollback_write(zip_source_t *src)
-{
+zip_source_rollback_write(zip_source_t *src) {
if (src->write_state != ZIP_SOURCE_WRITE_OPEN && src->write_state != ZIP_SOURCE_WRITE_FAILED) {
return;
}
-
+
_zip_source_call(src, NULL, 0, ZIP_SOURCE_ROLLBACK_WRITE);
src->write_state = ZIP_SOURCE_WRITE_CLOSED;
}
diff --git a/lib/zip_source_seek.c b/lib/zip_source_seek.c
index c3f4703..aed53b8 100644
--- a/lib/zip_source_seek.c
+++ b/lib/zip_source_seek.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,57 +36,55 @@
ZIP_EXTERN int
-zip_source_seek(zip_source_t *src, zip_int64_t offset, int whence)
-{
+zip_source_seek(zip_source_t *src, zip_int64_t offset, int whence) {
zip_source_args_seek_t args;
-
+
if (src->source_closed) {
- return -1;
+ return -1;
}
if (!ZIP_SOURCE_IS_OPEN_READING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ return -1;
}
args.offset = offset;
args.whence = whence;
-
+
return (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK) < 0 ? -1 : 0);
}
zip_int64_t
-zip_source_seek_compute_offset(zip_uint64_t offset, zip_uint64_t length, void *data, zip_uint64_t data_length, zip_error_t *error)
-{
+zip_source_seek_compute_offset(zip_uint64_t offset, zip_uint64_t length, void *data, zip_uint64_t data_length, zip_error_t *error) {
zip_int64_t new_offset;
zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, data_length, error);
-
+
if (args == NULL) {
- return -1;
+ return -1;
}
-
+
switch (args->whence) {
- case SEEK_CUR:
- new_offset = (zip_int64_t)offset + args->offset;
- break;
-
- case SEEK_END:
- new_offset = (zip_int64_t)length + args->offset;
- break;
-
- case SEEK_SET:
- new_offset = args->offset;
- break;
-
- default:
- zip_error_set(error, ZIP_ER_INVAL, 0);
- return -1;
+ case SEEK_CUR:
+ new_offset = (zip_int64_t)offset + args->offset;
+ break;
+
+ case SEEK_END:
+ new_offset = (zip_int64_t)length + args->offset;
+ break;
+
+ case SEEK_SET:
+ new_offset = args->offset;
+ break;
+
+ default:
+ zip_error_set(error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
+
if (new_offset < 0 || (zip_uint64_t)new_offset > length) {
- zip_error_set(error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
+
return new_offset;
}
diff --git a/lib/zip_source_seek_write.c b/lib/zip_source_seek_write.c
index 6660766..4ecbee1 100644
--- a/lib/zip_source_seek_write.c
+++ b/lib/zip_source_seek_write.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,17 +36,16 @@
ZIP_EXTERN int
-zip_source_seek_write(zip_source_t *src, zip_int64_t offset, int whence)
-{
+zip_source_seek_write(zip_source_t *src, zip_int64_t offset, int whence) {
zip_source_args_seek_t args;
-
+
if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
+
args.offset = offset;
args.whence = whence;
-
+
return (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK_WRITE) < 0 ? -1 : 0);
}
diff --git a/lib/zip_source_stat.c b/lib/zip_source_stat.c
index 864507e..987c862 100644
--- a/lib/zip_source_stat.c
+++ b/lib/zip_source_stat.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,23 +36,22 @@
ZIP_EXTERN int
-zip_source_stat(zip_source_t *src, zip_stat_t *st)
-{
+zip_source_stat(zip_source_t *src, zip_stat_t *st) {
if (src->source_closed) {
- return -1;
+ return -1;
}
if (st == NULL) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
return -1;
}
zip_stat_init(st);
-
+
if (ZIP_SOURCE_IS_LAYERED(src)) {
- if (zip_source_stat(src->src, st) < 0) {
- _zip_error_set_from_source(&src->error, src->src);
- return -1;
- }
+ if (zip_source_stat(src->src, st) < 0) {
+ _zip_error_set_from_source(&src->error, src->src);
+ return -1;
+ }
}
if (_zip_source_call(src, st, sizeof(*st), ZIP_SOURCE_STAT) < 0) {
diff --git a/lib/zip_source_supports.c b/lib/zip_source_supports.c
index c59aa1f..a47f293 100644
--- a/lib/zip_source_supports.c
+++ b/lib/zip_source_supports.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,31 +38,28 @@
zip_int64_t
-zip_source_supports(zip_source_t *src)
-{
+zip_source_supports(zip_source_t *src) {
return src->supports;
}
ZIP_EXTERN zip_int64_t
-zip_source_make_command_bitmap(zip_source_cmd_t cmd0, ...)
-{
+zip_source_make_command_bitmap(zip_source_cmd_t cmd0, ...) {
zip_int64_t bitmap;
va_list ap;
-
+
bitmap = ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd0);
-
-
-
+
+
va_start(ap, cmd0);
for (;;) {
- int cmd = va_arg(ap, int);
- if (cmd < 0) {
- break;
- }
- bitmap |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd);
+ int cmd = va_arg(ap, int);
+ if (cmd < 0) {
+ break;
+ }
+ bitmap |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd);
}
va_end(ap);
-
+
return bitmap;
}
diff --git a/lib/zip_source_tell.c b/lib/zip_source_tell.c
index f1c10b5..ab418fa 100644
--- a/lib/zip_source_tell.c
+++ b/lib/zip_source_tell.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,15 +36,14 @@
ZIP_EXTERN zip_int64_t
-zip_source_tell(zip_source_t *src)
-{
+zip_source_tell(zip_source_t *src) {
if (src->source_closed) {
- return -1;
+ return -1;
}
if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
+
return _zip_source_call(src, NULL, 0, ZIP_SOURCE_TELL);
}
diff --git a/lib/zip_source_tell_write.c b/lib/zip_source_tell_write.c
index 2fa1507..f7a8a3f 100644
--- a/lib/zip_source_tell_write.c
+++ b/lib/zip_source_tell_write.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,12 +36,11 @@
ZIP_EXTERN zip_int64_t
-zip_source_tell_write(zip_source_t *src)
-{
+zip_source_tell_write(zip_source_t *src) {
if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
+
return _zip_source_call(src, NULL, 0, ZIP_SOURCE_TELL_WRITE);
}
diff --git a/lib/zip_source_win32a.c b/lib/zip_source_win32a.c
index 12d53d6..ebb749e 100644
--- a/lib/zip_source_win32a.c
+++ b/lib/zip_source_win32a.c
@@ -37,7 +37,7 @@
#include "zipint.h"
#include "zipwin32.h"
-static void * _win32_strdup_a(const void *str);
+static void *_win32_strdup_a(const void *str);
static HANDLE _win32_open_a(_zip_source_win32_read_file_t *ctx);
static HANDLE _win32_create_temp_a(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32_t value, PSECURITY_ATTRIBUTES sa);
static int _win32_rename_temp_a(_zip_source_win32_read_file_t *ctx);
@@ -54,8 +54,7 @@
// clang-format on
ZIP_EXTERN zip_source_t *
-zip_source_win32a(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len)
-{
+zip_source_win32a(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len) {
if (za == NULL)
return NULL;
@@ -64,8 +63,7 @@
ZIP_EXTERN zip_source_t *
-zip_source_win32a_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error)
-{
+zip_source_win32a_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) {
if (fname == NULL || length < -1) {
zip_error_set(error, ZIP_ER_INVAL, 0);
return NULL;
@@ -76,22 +74,19 @@
static void *
-_win32_strdup_a(const void *str)
-{
+_win32_strdup_a(const void *str) {
return strdup((const char *)str);
}
static HANDLE
-_win32_open_a(_zip_source_win32_read_file_t *ctx)
-{
+_win32_open_a(_zip_source_win32_read_file_t *ctx) {
return CreateFileA(ctx->fname, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
}
static HANDLE
-_win32_create_temp_a(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32_t value, PSECURITY_ATTRIBUTES sa)
-{
+_win32_create_temp_a(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32_t value, PSECURITY_ATTRIBUTES sa) {
size_t len;
len = strlen((const char *)ctx->fname) + 10;
@@ -110,8 +105,7 @@
static int
-_win32_rename_temp_a(_zip_source_win32_read_file_t *ctx)
-{
+_win32_rename_temp_a(_zip_source_win32_read_file_t *ctx) {
if (!MoveFileExA(ctx->tmpname, ctx->fname, MOVEFILE_REPLACE_EXISTING))
return -1;
return 0;
@@ -119,8 +113,7 @@
static int
-_win32_remove_a(const void *fname)
-{
+_win32_remove_a(const void *fname) {
DeleteFileA((const char *)fname);
return 0;
}
diff --git a/lib/zip_source_win32handle.c b/lib/zip_source_win32handle.c
index 543593b..f495b0d 100644
--- a/lib/zip_source_win32handle.c
+++ b/lib/zip_source_win32handle.c
@@ -32,10 +32,10 @@
*/
-#include <wchar.h>
+#include <aclapi.h>
#include <stdlib.h>
#include <string.h>
-#include <aclapi.h>
+#include <wchar.h>
#include "zipint.h"
#include "zipwin32.h"
@@ -49,8 +49,7 @@
static int _zip_stat_win32(void *h, zip_stat_t *st, _zip_source_win32_read_file_t *ctx);
ZIP_EXTERN zip_source_t *
-zip_source_win32handle(zip_t *za, HANDLE h, zip_uint64_t start, zip_int64_t len)
-{
+zip_source_win32handle(zip_t *za, HANDLE h, zip_uint64_t start, zip_int64_t len) {
if (za == NULL)
return NULL;
@@ -59,8 +58,7 @@
ZIP_EXTERN zip_source_t *
-zip_source_win32handle_create(HANDLE h, zip_uint64_t start, zip_int64_t length, zip_error_t *error)
-{
+zip_source_win32handle_create(HANDLE h, zip_uint64_t start, zip_int64_t length, zip_error_t *error) {
if (h == INVALID_HANDLE_VALUE || length < -1) {
zip_error_set(error, ZIP_ER_INVAL, 0);
return NULL;
@@ -71,8 +69,7 @@
zip_source_t *
-_zip_source_win32_handle_or_name(const void *fname, HANDLE h, zip_uint64_t start, zip_int64_t len, int closep, const zip_stat_t *st, _zip_source_win32_file_ops_t *ops, zip_error_t *error)
-{
+_zip_source_win32_handle_or_name(const void *fname, HANDLE h, zip_uint64_t start, zip_int64_t len, int closep, const zip_stat_t *st, _zip_source_win32_file_ops_t *ops, zip_error_t *error) {
_zip_source_win32_read_file_t *ctx;
zip_source_t *zs;
@@ -141,8 +138,7 @@
static zip_int64_t
-_win32_read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd)
-{
+_win32_read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
_zip_source_win32_read_file_t *ctx;
char *buf;
zip_uint64_t n;
@@ -348,8 +344,8 @@
if (h == INVALID_HANDLE_VALUE) {
win32err = GetLastError();
if (win32err == ERROR_FILE_NOT_FOUND || win32err == ERROR_PATH_NOT_FOUND) {
- zip_error_set(&ctx->error, ZIP_ER_READ, ENOENT);
- return -1;
+ zip_error_set(&ctx->error, ZIP_ER_READ, ENOENT);
+ return -1;
}
}
}
@@ -377,8 +373,7 @@
case ZIP_SOURCE_TELL:
return (zip_int64_t)ctx->current;
- case ZIP_SOURCE_TELL_WRITE:
- {
+ case ZIP_SOURCE_TELL_WRITE: {
LARGE_INTEGER zero;
LARGE_INTEGER offset;
@@ -391,8 +386,7 @@
return offset.QuadPart;
}
- case ZIP_SOURCE_WRITE:
- {
+ case ZIP_SOURCE_WRITE: {
DWORD ret;
if (!WriteFile(ctx->hout, data, (DWORD)len, &ret, NULL) || ret != len) {
zip_error_set(&ctx->error, ZIP_ER_WRITE, _zip_win32_error_to_errno(GetLastError()));
@@ -410,8 +404,7 @@
static int
-_win32_create_temp_file(_zip_source_win32_read_file_t *ctx)
-{
+_win32_create_temp_file(_zip_source_win32_read_file_t *ctx) {
zip_uint32_t value;
/*
Windows has GetTempFileName(), but it closes the file after
@@ -473,8 +466,7 @@
static int
-_zip_seek_win32_u(HANDLE h, zip_uint64_t offset, int whence, zip_error_t *error)
-{
+_zip_seek_win32_u(HANDLE h, zip_uint64_t offset, int whence, zip_error_t *error) {
if (offset > ZIP_INT64_MAX) {
zip_error_set(error, ZIP_ER_SEEK, EOVERFLOW);
return -1;
@@ -484,8 +476,7 @@
static int
-_zip_seek_win32(HANDLE h, zip_int64_t offset, int whence, zip_error_t *error)
-{
+_zip_seek_win32(HANDLE h, zip_int64_t offset, int whence, zip_error_t *error) {
LARGE_INTEGER li;
DWORD method;
@@ -515,8 +506,7 @@
static int
-_zip_win32_error_to_errno(DWORD win32err)
-{
+_zip_win32_error_to_errno(DWORD win32err) {
/*
Note: This list isn't exhaustive, but should cover common cases.
*/
@@ -542,8 +532,7 @@
static int
-_zip_stat_win32(HANDLE h, zip_stat_t *st, _zip_source_win32_read_file_t *ctx)
-{
+_zip_stat_win32(HANDLE h, zip_stat_t *st, _zip_source_win32_read_file_t *ctx) {
FILETIME mtimeft;
time_t mtime;
LARGE_INTEGER size;
@@ -585,8 +574,7 @@
static int
-_zip_filetime_to_time_t(FILETIME ft, time_t *t)
-{
+_zip_filetime_to_time_t(FILETIME ft, time_t *t) {
/*
Inspired by http://stackoverflow.com/questions/6161776/convert-windows-filetime-to-second-in-unix-linux
*/
diff --git a/lib/zip_source_win32utf8.c b/lib/zip_source_win32utf8.c
index 37a5ce1..1087f7a 100644
--- a/lib/zip_source_win32utf8.c
+++ b/lib/zip_source_win32utf8.c
@@ -39,8 +39,7 @@
ZIP_EXTERN zip_source_t *
-zip_source_file(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len)
-{
+zip_source_file(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len) {
if (za == NULL)
return NULL;
@@ -49,8 +48,7 @@
ZIP_EXTERN zip_source_t *
-zip_source_file_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error)
-{
+zip_source_file_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) {
int size;
wchar_t *wfname;
zip_source_t *source;
diff --git a/lib/zip_source_win32w.c b/lib/zip_source_win32w.c
index fa665c0..2ae244f 100644
--- a/lib/zip_source_win32w.c
+++ b/lib/zip_source_win32w.c
@@ -37,7 +37,7 @@
#include "zipint.h"
#include "zipwin32.h"
-static void * _win32_strdup_w(const void *str);
+static void *_win32_strdup_w(const void *str);
static HANDLE _win32_open_w(_zip_source_win32_read_file_t *ctx);
static HANDLE _win32_create_temp_w(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32_t value, PSECURITY_ATTRIBUTES sa);
static int _win32_rename_temp_w(_zip_source_win32_read_file_t *ctx);
@@ -54,8 +54,7 @@
// clang-format on
ZIP_EXTERN zip_source_t *
-zip_source_win32w(zip_t *za, const wchar_t *fname, zip_uint64_t start, zip_int64_t len)
-{
+zip_source_win32w(zip_t *za, const wchar_t *fname, zip_uint64_t start, zip_int64_t len) {
if (za == NULL)
return NULL;
@@ -64,8 +63,7 @@
ZIP_EXTERN zip_source_t *
-zip_source_win32w_create(const wchar_t *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error)
-{
+zip_source_win32w_create(const wchar_t *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) {
if (fname == NULL || length < -1) {
zip_error_set(error, ZIP_ER_INVAL, 0);
return NULL;
@@ -76,17 +74,15 @@
static void *
-_win32_strdup_w(const void *str)
-{
+_win32_strdup_w(const void *str) {
return _wcsdup((const wchar_t *)str);
}
static HANDLE
-_win32_open_w(_zip_source_win32_read_file_t *ctx)
-{
+_win32_open_w(_zip_source_win32_read_file_t *ctx) {
#ifdef MS_UWP
- CREATEFILE2_EXTENDED_PARAMETERS extParams = { 0 };
+ CREATEFILE2_EXTENDED_PARAMETERS extParams = {0};
extParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
extParams.dwFileFlags = FILE_FLAG_RANDOM_ACCESS;
extParams.dwSecurityQosFlags = SECURITY_ANONYMOUS;
@@ -102,8 +98,7 @@
static HANDLE
-_win32_create_temp_w(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32_t value, PSECURITY_ATTRIBUTES sa)
-{
+_win32_create_temp_w(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32_t value, PSECURITY_ATTRIBUTES sa) {
size_t len;
len = wcslen((const wchar_t *)ctx->fname) + 10;
@@ -118,7 +113,7 @@
}
#ifdef MS_UWP
- CREATEFILE2_EXTENDED_PARAMETERS extParams = { 0 };
+ CREATEFILE2_EXTENDED_PARAMETERS extParams = {0};
extParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY;
extParams.dwFileFlags = FILE_FLAG_RANDOM_ACCESS;
extParams.dwSecurityQosFlags = SECURITY_ANONYMOUS;
@@ -134,8 +129,7 @@
static int
-_win32_rename_temp_w(_zip_source_win32_read_file_t *ctx)
-{
+_win32_rename_temp_w(_zip_source_win32_read_file_t *ctx) {
if (!MoveFileExW(ctx->tmpname, ctx->fname, MOVEFILE_REPLACE_EXISTING))
return -1;
return 0;
@@ -143,8 +137,7 @@
static int
-_win32_remove_w(const void *fname)
-{
+_win32_remove_w(const void *fname) {
DeleteFileW((const wchar_t *)fname);
return 0;
}
diff --git a/lib/zip_source_window.c b/lib/zip_source_window.c
index 3980370..f4701a0 100644
--- a/lib/zip_source_window.c
+++ b/lib/zip_source_window.c
@@ -38,14 +38,14 @@
#include "zipint.h"
struct window {
- zip_uint64_t start; /* where in file we start reading */
- zip_uint64_t end; /* where in file we stop reading */
+ zip_uint64_t start; /* where in file we start reading */
+ zip_uint64_t end; /* where in file we stop reading */
/* if not NULL, read file data for this file */
zip_t *source_archive;
zip_uint64_t source_index;
- zip_uint64_t offset; /* offset in src for next read */
+ zip_uint64_t offset; /* offset in src for next read */
zip_stat_t stat;
zip_int8_t compression_flags;
@@ -58,25 +58,23 @@
zip_source_t *
-zip_source_window(zip_t *za, zip_source_t *src, zip_uint64_t start, zip_uint64_t len)
-{
+zip_source_window(zip_t *za, zip_source_t *src, zip_uint64_t start, zip_uint64_t len) {
return _zip_source_window_new(src, start, len, NULL, 0, NULL, 0, &za->error);
}
zip_source_t *
-_zip_source_window_new(zip_source_t *src, zip_uint64_t start, zip_uint64_t length, zip_stat_t *st, zip_int8_t compression_flags, zip_t *source_archive, zip_uint64_t source_index, zip_error_t *error)
-{
+_zip_source_window_new(zip_source_t *src, zip_uint64_t start, zip_uint64_t length, zip_stat_t *st, zip_int8_t compression_flags, zip_t *source_archive, zip_uint64_t source_index, zip_error_t *error) {
struct window *ctx;
if (src == NULL || start + length < start || (source_archive == NULL && source_index != 0)) {
- zip_error_set(error, ZIP_ER_INVAL, 0);
- return NULL;
+ zip_error_set(error, ZIP_ER_INVAL, 0);
+ return NULL;
}
- if ((ctx=(struct window *)malloc(sizeof(*ctx))) == NULL) {
- zip_error_set(error, ZIP_ER_MEMORY, 0);
- return NULL;
+ if ((ctx = (struct window *)malloc(sizeof(*ctx))) == NULL) {
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return NULL;
}
ctx->start = start;
@@ -90,10 +88,10 @@
ctx->needs_seek = (ctx->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) ? true : false;
if (st) {
- if (_zip_stat_merge(&ctx->stat, st, error) < 0) {
- free(ctx);
- return NULL;
- }
+ if (_zip_stat_merge(&ctx->stat, st, error) < 0) {
+ free(ctx);
+ return NULL;
+ }
}
return zip_source_layered_create(src, window_read, ctx, error);
@@ -101,8 +99,7 @@
int
-_zip_source_set_source_archive(zip_source_t *src, zip_t *za)
-{
+_zip_source_set_source_archive(zip_source_t *src, zip_t *za) {
src->source_archive = za;
return _zip_register_source(za, src);
}
@@ -110,19 +107,17 @@
/* called by zip_discard to avoid operating on file from closed archive */
void
-_zip_source_invalidate(zip_source_t *src)
-{
+_zip_source_invalidate(zip_source_t *src) {
src->source_closed = 1;
if (zip_error_code_zip(&src->error) == ZIP_ER_OK) {
- zip_error_set(&src->error, ZIP_ER_ZIPCLOSED, 0);
+ zip_error_set(&src->error, ZIP_ER_ZIPCLOSED, 0);
}
}
static zip_int64_t
-window_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd)
-{
+window_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
struct window *ctx;
zip_int64_t ret;
zip_uint64_t n, i;
@@ -131,149 +126,144 @@
ctx = (struct window *)_ctx;
switch (cmd) {
- case ZIP_SOURCE_CLOSE:
- return 0;
+ case ZIP_SOURCE_CLOSE:
+ return 0;
- case ZIP_SOURCE_ERROR:
- return zip_error_to_data(&ctx->error, data, len);
+ case ZIP_SOURCE_ERROR:
+ return zip_error_to_data(&ctx->error, data, len);
- case ZIP_SOURCE_FREE:
- free(ctx);
- return 0;
+ case ZIP_SOURCE_FREE:
+ free(ctx);
+ return 0;
- case ZIP_SOURCE_OPEN:
- if (ctx->source_archive) {
- zip_uint64_t offset;
+ case ZIP_SOURCE_OPEN:
+ if (ctx->source_archive) {
+ zip_uint64_t offset;
- if ((offset = _zip_file_get_offset(ctx->source_archive, ctx->source_index, &ctx->error)) == 0) {
- return -1;
- }
- if (ctx->end + offset < ctx->end) {
- /* zip archive data claims end of data past zip64 limits */
- zip_error_set(&ctx->error, ZIP_ER_INCONS, 0);
- return -1;
- }
- ctx->start += offset;
- ctx->end += offset;
- ctx->source_archive = NULL;
+ if ((offset = _zip_file_get_offset(ctx->source_archive, ctx->source_index, &ctx->error)) == 0) {
+ return -1;
}
+ if (ctx->end + offset < ctx->end) {
+ /* zip archive data claims end of data past zip64 limits */
+ zip_error_set(&ctx->error, ZIP_ER_INCONS, 0);
+ return -1;
+ }
+ ctx->start += offset;
+ ctx->end += offset;
+ ctx->source_archive = NULL;
+ }
- if (!ctx->needs_seek) {
- for (n=0; n<ctx->start; n+=(zip_uint64_t)ret) {
- i = (ctx->start-n > sizeof(b) ? sizeof(b) : ctx->start-n);
- if ((ret=zip_source_read(src, b, i)) < 0) {
- _zip_error_set_from_source(&ctx->error, src);
- return -1;
- }
- if (ret==0) {
- zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
- return -1;
- }
- }
+ if (!ctx->needs_seek) {
+ for (n = 0; n < ctx->start; n += (zip_uint64_t)ret) {
+ i = (ctx->start - n > sizeof(b) ? sizeof(b) : ctx->start - n);
+ if ((ret = zip_source_read(src, b, i)) < 0) {
+ _zip_error_set_from_source(&ctx->error, src);
+ return -1;
+ }
+ if (ret == 0) {
+ zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
+ return -1;
+ }
+ }
+ }
+ ctx->offset = ctx->start;
+ return 0;
- }
- ctx->offset = ctx->start;
- return 0;
+ case ZIP_SOURCE_READ:
+ if (len > ctx->end - ctx->offset)
+ len = ctx->end - ctx->offset;
- case ZIP_SOURCE_READ:
- if (len > ctx->end - ctx->offset)
- len = ctx->end - ctx->offset;
+ if (len == 0)
+ return 0;
- if (len == 0)
- return 0;
+ if (ctx->needs_seek) {
+ if (zip_source_seek(src, (zip_int64_t)ctx->offset, SEEK_SET) < 0) {
+ _zip_error_set_from_source(&ctx->error, src);
+ return -1;
+ }
+ }
- if (ctx->needs_seek) {
- if (zip_source_seek(src, (zip_int64_t)ctx->offset, SEEK_SET) < 0) {
- _zip_error_set_from_source(&ctx->error, src);
- return -1;
- }
- }
+ if ((ret = zip_source_read(src, data, len)) < 0) {
+ zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
+ return -1;
+ }
- if ((ret=zip_source_read(src, data, len)) < 0) {
- zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
- return -1;
- }
+ ctx->offset += (zip_uint64_t)ret;
- ctx->offset += (zip_uint64_t)ret;
+ if (ret == 0) {
+ if (ctx->offset < ctx->end) {
+ zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
+ return -1;
+ }
+ }
+ return ret;
- if (ret == 0) {
- if (ctx->offset < ctx->end) {
- zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
- return -1;
- }
- }
- return ret;
+ case ZIP_SOURCE_SEEK: {
+ zip_int64_t new_offset = zip_source_seek_compute_offset(ctx->offset - ctx->start, ctx->end - ctx->start, data, len, &ctx->error);
- case ZIP_SOURCE_SEEK:
- {
- zip_int64_t new_offset = zip_source_seek_compute_offset(ctx->offset - ctx->start, ctx->end - ctx->start, data, len, &ctx->error);
+ if (new_offset < 0) {
+ return -1;
+ }
- if (new_offset < 0) {
- return -1;
- }
+ ctx->offset = (zip_uint64_t)new_offset + ctx->start;
+ return 0;
+ }
- ctx->offset = (zip_uint64_t)new_offset + ctx->start;
- return 0;
- }
+ case ZIP_SOURCE_STAT: {
+ zip_stat_t *st;
- case ZIP_SOURCE_STAT:
- {
- zip_stat_t *st;
+ st = (zip_stat_t *)data;
- st = (zip_stat_t *)data;
+ if (_zip_stat_merge(st, &ctx->stat, &ctx->error) < 0) {
+ return -1;
+ }
+ return 0;
+ }
- if (_zip_stat_merge(st, &ctx->stat, &ctx->error) < 0) {
- return -1;
- }
- return 0;
- }
+ case ZIP_SOURCE_GET_COMPRESSION_FLAGS:
+ return ctx->compression_flags;
- case ZIP_SOURCE_GET_COMPRESSION_FLAGS:
- return ctx->compression_flags;
+ case ZIP_SOURCE_SUPPORTS:
+ return ctx->supports;
- case ZIP_SOURCE_SUPPORTS:
- return ctx->supports;
+ case ZIP_SOURCE_TELL:
+ return (zip_int64_t)(ctx->offset - ctx->start);
- case ZIP_SOURCE_TELL:
- return (zip_int64_t)(ctx->offset - ctx->start);
-
- default:
- zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
- return -1;
+ default:
+ zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
+ return -1;
}
}
void
-_zip_deregister_source(zip_t *za, zip_source_t *src)
-{
+_zip_deregister_source(zip_t *za, zip_source_t *src) {
unsigned int i;
- for (i=0; i<za->nopen_source; i++) {
- if (za->open_source[i] == src) {
- za->open_source[i] = za->open_source[za->nopen_source-1];
- za->nopen_source--;
- break;
- }
+ for (i = 0; i < za->nopen_source; i++) {
+ if (za->open_source[i] == src) {
+ za->open_source[i] = za->open_source[za->nopen_source - 1];
+ za->nopen_source--;
+ break;
+ }
}
}
int
-_zip_register_source(zip_t *za, zip_source_t *src)
-{
+_zip_register_source(zip_t *za, zip_source_t *src) {
zip_source_t **open_source;
- if (za->nopen_source+1 >= za->nopen_source_alloc) {
- unsigned int n;
- n = za->nopen_source_alloc + 10;
- open_source = (zip_source_t **)realloc(za->open_source, n*sizeof(zip_source_t *));
- if (open_source == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- return -1;
- }
- za->nopen_source_alloc = n;
- za->open_source = open_source;
+ if (za->nopen_source + 1 >= za->nopen_source_alloc) {
+ unsigned int n;
+ n = za->nopen_source_alloc + 10;
+ open_source = (zip_source_t **)realloc(za->open_source, n * sizeof(zip_source_t *));
+ if (open_source == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return -1;
+ }
+ za->nopen_source_alloc = n;
+ za->open_source = open_source;
}
za->open_source[za->nopen_source++] = src;
diff --git a/lib/zip_source_winzip_aes_decode.c b/lib/zip_source_winzip_aes_decode.c
index ddee1c8..bd840e9 100644
--- a/lib/zip_source_winzip_aes_decode.c
+++ b/lib/zip_source_winzip_aes_decode.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,10 +39,10 @@
#include "gladman-fcrypt.h"
-#define MAX_HEADER_LENGTH (16+PWD_VER_LENGTH)
+#define MAX_HEADER_LENGTH (16 + PWD_VER_LENGTH)
#define HMAC_LENGTH 10
-static unsigned int salt_length[] = { 0, 8, 12, 16 };
+static unsigned int salt_length[] = {0, 8, 12, 16};
struct winzip_aes {
char *password;
@@ -59,12 +59,11 @@
static int decrypt_header(zip_source_t *src, struct winzip_aes *ctx);
static void winzip_aes_free(struct winzip_aes *);
static zip_int64_t winzip_aes_decrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd);
-static struct winzip_aes * winzip_aes_new(unsigned int mode, const char *password);
+static struct winzip_aes *winzip_aes_new(unsigned int mode, const char *password);
zip_source_t *
-zip_source_winzip_aes_decode(zip_t *za, zip_source_t *src, zip_uint16_t em, int flags, const char *password)
-{
+zip_source_winzip_aes_decode(zip_t *za, zip_source_t *src, zip_uint16_t em, int flags, const char *password) {
zip_source_t *s2;
unsigned int mode = 0;
zip_stat_t st;
@@ -82,7 +81,7 @@
mode = 3;
break;
}
-
+
if (password == NULL || src == NULL || mode == 0) {
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return NULL;
@@ -93,8 +92,8 @@
}
if (strlen(password) > UINT_MAX) {
- zip_error_set(&za->error, ZIP_ER_INVAL, 0); /* TODO: better error code? (password too long) */
- return NULL;
+ zip_error_set(&za->error, ZIP_ER_INVAL, 0); /* TODO: better error code? (password too long) */
+ return NULL;
}
if (zip_source_stat(src, &st) != 0) {
@@ -103,7 +102,7 @@
}
aux_length = PWD_VER_LENGTH + salt_length[mode] + HMAC_LENGTH;
-
+
if ((st.valid & ZIP_STAT_COMP_SIZE) == 0 || st.comp_size < aux_length) {
zip_error_set(&za->error, ZIP_ER_OPNOTSUPP, 0);
return NULL;
@@ -126,19 +125,18 @@
static int
-decrypt_header(zip_source_t *src, struct winzip_aes *ctx)
-{
+decrypt_header(zip_source_t *src, struct winzip_aes *ctx) {
zip_uint8_t header[MAX_HEADER_LENGTH];
zip_uint8_t password_verification[PWD_VER_LENGTH];
unsigned int headerlen;
zip_int64_t n;
headerlen = PWD_VER_LENGTH + salt_length[ctx->mode];
- if ((n=zip_source_read(src, header, headerlen)) < 0) {
+ if ((n = zip_source_read(src, header, headerlen)) < 0) {
_zip_error_set_from_source(&ctx->error, src);
return -1;
}
-
+
if (n != headerlen) {
zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
return -1;
@@ -157,8 +155,7 @@
static bool
-verify_hmac(zip_source_t *src, struct winzip_aes *ctx)
-{
+verify_hmac(zip_source_t *src, struct winzip_aes *ctx) {
unsigned char computed[HMAC_LENGTH], from_file[HMAC_LENGTH];
if (zip_source_read(src, from_file, HMAC_LENGTH) < HMAC_LENGTH) {
_zip_error_set_from_source(&ctx->error, src);
@@ -166,7 +163,7 @@
}
_zip_fcrypt_end(computed, &ctx->fcrypt_ctx);
-
+
if (memcmp(from_file, computed, HMAC_LENGTH) != 0) {
zip_error_set(&ctx->error, ZIP_ER_CRC, 0);
return false;
@@ -177,8 +174,7 @@
static zip_int64_t
-winzip_aes_decrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd)
-{
+winzip_aes_decrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
struct winzip_aes *ctx;
zip_int64_t n;
zip_uint64_t total, offset;
@@ -204,8 +200,8 @@
}
return 0;
}
-
- if ((n=zip_source_read(src, data, len)) < 0) {
+
+ if ((n = zip_source_read(src, data, len)) < 0) {
_zip_error_set_from_source(&ctx->error, src);
return -1;
}
@@ -221,8 +217,7 @@
case ZIP_SOURCE_CLOSE:
return 0;
- case ZIP_SOURCE_STAT:
- {
+ case ZIP_SOURCE_STAT: {
zip_stat_t *st;
st = (zip_stat_t *)data;
@@ -232,10 +227,10 @@
if (st->valid & ZIP_STAT_COMP_SIZE) {
st->comp_size -= 12 + salt_length[ctx->mode];
}
-
+
return 0;
}
-
+
case ZIP_SOURCE_SUPPORTS:
return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, -1);
@@ -254,8 +249,7 @@
static void
-winzip_aes_free(struct winzip_aes *ctx)
-{
+winzip_aes_free(struct winzip_aes *ctx) {
if (ctx == NULL) {
return;
}
@@ -271,11 +265,11 @@
static struct winzip_aes *
winzip_aes_new(unsigned int mode, const char *password) {
struct winzip_aes *ctx;
-
+
if ((ctx = (struct winzip_aes *)malloc(sizeof(*ctx))) == NULL) {
return NULL;
}
-
+
if ((ctx->password = strdup(password)) == NULL) {
free(ctx);
return NULL;
diff --git a/lib/zip_source_winzip_aes_encode.c b/lib/zip_source_winzip_aes_encode.c
index d2fe2c2..f3e4b42 100644
--- a/lib/zip_source_winzip_aes_encode.c
+++ b/lib/zip_source_winzip_aes_encode.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,10 +39,10 @@
#include "gladman-fcrypt.h"
-#define MAX_HEADER_LENGTH (16+PWD_VER_LENGTH)
+#define MAX_HEADER_LENGTH (16 + PWD_VER_LENGTH)
#define HMAC_LENGTH 10
-static unsigned int salt_length[] = { 0, 8, 12, 16 };
+static unsigned int salt_length[] = {0, 8, 12, 16};
struct winzip_aes {
char *password;
@@ -61,12 +61,11 @@
static int encrypt_header(zip_source_t *src, struct winzip_aes *ctx);
static void winzip_aes_free(struct winzip_aes *);
static zip_int64_t winzip_aes_encrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd);
-static struct winzip_aes * winzip_aes_new(unsigned int mode, zip_uint16_t encryption_method, const char *password);
+static struct winzip_aes *winzip_aes_new(unsigned int mode, zip_uint16_t encryption_method, const char *password);
zip_source_t *
-zip_source_winzip_aes_encode(zip_t *za, zip_source_t *src, zip_uint16_t encryption_method, int flags, const char *password)
-{
+zip_source_winzip_aes_encode(zip_t *za, zip_source_t *src, zip_uint16_t encryption_method, int flags, const char *password) {
zip_source_t *s2;
unsigned int mode = 0;
struct winzip_aes *ctx;
@@ -82,15 +81,15 @@
mode = 3;
break;
}
-
+
if (password == NULL || src == NULL || mode == 0) {
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return NULL;
}
if (strlen(password) > UINT_MAX) {
- zip_error_set(&za->error, ZIP_ER_INVAL, 0); /* TODO: better error code? (password too long) */
- return NULL;
+ zip_error_set(&za->error, ZIP_ER_INVAL, 0); /* TODO: better error code? (password too long) */
+ return NULL;
}
if ((ctx = winzip_aes_new(mode, encryption_method, password)) == NULL) {
@@ -108,14 +107,13 @@
static int
-encrypt_header(zip_source_t *src, struct winzip_aes *ctx)
-{
+encrypt_header(zip_source_t *src, struct winzip_aes *ctx) {
if (!zip_random(ctx->data, (zip_uint16_t)salt_length[ctx->mode])) {
zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
return -1;
- }
-
- if (_zip_fcrypt_init(ctx->mode, (unsigned char *)ctx->password, (unsigned int)strlen(ctx->password), ctx->data, ctx->data+salt_length[ctx->mode], &ctx->fcrypt_ctx) != 0) {
+ }
+
+ if (_zip_fcrypt_init(ctx->mode, (unsigned char *)ctx->password, (unsigned int)strlen(ctx->password), ctx->data, ctx->data + salt_length[ctx->mode], &ctx->fcrypt_ctx) != 0) {
zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
return -1;
}
@@ -124,14 +122,13 @@
zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
return -1;
}
-
+
return 0;
}
static zip_int64_t
-winzip_aes_encrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t length, zip_source_cmd_t cmd)
-{
+winzip_aes_encrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t length, zip_source_cmd_t cmd) {
struct winzip_aes *ctx;
zip_int64_t ret;
zip_uint64_t buffer_n, offset, n;
@@ -148,13 +145,13 @@
case ZIP_SOURCE_READ:
buffer_n = 0;
-
+
if (ctx->buffer) {
buffer_n = _zip_buffer_read(ctx->buffer, data, length);
data = (zip_uint8_t *)data + buffer_n;
length -= buffer_n;
-
+
if (_zip_buffer_eof(ctx->buffer)) {
_zip_buffer_free(ctx->buffer);
ctx->buffer = NULL;
@@ -190,8 +187,7 @@
case ZIP_SOURCE_CLOSE:
return 0;
- case ZIP_SOURCE_STAT:
- {
+ case ZIP_SOURCE_STAT: {
zip_stat_t *st;
st = (zip_stat_t *)data;
@@ -200,10 +196,10 @@
if (st->valid & ZIP_STAT_COMP_SIZE) {
st->comp_size += 12 + salt_length[ctx->mode];
}
-
+
return 0;
}
-
+
case ZIP_SOURCE_SUPPORTS:
return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, -1);
@@ -222,8 +218,7 @@
static void
-winzip_aes_free(struct winzip_aes *ctx)
-{
+winzip_aes_free(struct winzip_aes *ctx) {
if (ctx == NULL) {
return;
}
@@ -240,11 +235,11 @@
static struct winzip_aes *
winzip_aes_new(unsigned int mode, zip_uint16_t encryption_method, const char *password) {
struct winzip_aes *ctx;
-
+
if ((ctx = (struct winzip_aes *)malloc(sizeof(*ctx))) == NULL) {
return NULL;
}
-
+
if ((ctx->password = strdup(password)) == NULL) {
free(ctx);
return NULL;
diff --git a/lib/zip_source_write.c b/lib/zip_source_write.c
index c98f567..1646e33 100644
--- a/lib/zip_source_write.c
+++ b/lib/zip_source_write.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,12 +36,11 @@
ZIP_EXTERN zip_int64_t
-zip_source_write(zip_source_t *src, const void *data, zip_uint64_t length)
-{
+zip_source_write(zip_source_t *src, const void *data, zip_uint64_t length) {
if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || length > ZIP_INT64_MAX) {
- zip_error_set(&src->error, ZIP_ER_INVAL, 0);
- return -1;
+ zip_error_set(&src->error, ZIP_ER_INVAL, 0);
+ return -1;
}
-
+
return _zip_source_call(src, (void *)data, length, ZIP_SOURCE_WRITE);
}
diff --git a/lib/zip_source_zip.c b/lib/zip_source_zip.c
index e172ca2..b3f1805 100644
--- a/lib/zip_source_zip.c
+++ b/lib/zip_source_zip.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,17 +39,15 @@
ZIP_EXTERN zip_source_t *
-zip_source_zip(zip_t *za, zip_t *srcza, zip_uint64_t srcidx,
- zip_flags_t flags, zip_uint64_t start, zip_int64_t len)
-{
+zip_source_zip(zip_t *za, zip_t *srcza, zip_uint64_t srcidx, zip_flags_t flags, zip_uint64_t start, zip_int64_t len) {
if (len < -1) {
- zip_error_set(&za->error, ZIP_ER_INVAL, 0);
- return NULL;
+ zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+ return NULL;
}
-
+
if (len == -1)
len = 0;
-
+
if (start == 0 && len == 0)
flags |= ZIP_FL_COMPRESSED;
else
diff --git a/lib/zip_source_zip_new.c b/lib/zip_source_zip_new.c
index 8a080e1..a5cfee3 100644
--- a/lib/zip_source_zip_new.c
+++ b/lib/zip_source_zip_new.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,8 +38,7 @@
zip_source_t *
-_zip_source_zip_new(zip_t *za, zip_t *srcza, zip_uint64_t srcidx, zip_flags_t flags, zip_uint64_t start, zip_uint64_t len, const char *password)
-{
+_zip_source_zip_new(zip_t *za, zip_t *srcza, zip_uint64_t srcidx, zip_flags_t flags, zip_uint64_t start, zip_uint64_t len, const char *password) {
zip_source_t *src, *s2;
struct zip_stat st;
bool partial_data, needs_crc, needs_decrypt, needs_decompress;
@@ -52,13 +51,12 @@
return NULL;
}
- if ((flags & ZIP_FL_UNCHANGED) == 0
- && (ZIP_ENTRY_DATA_CHANGED(srcza->entry+srcidx) || srcza->entry[srcidx].deleted)) {
+ if ((flags & ZIP_FL_UNCHANGED) == 0 && (ZIP_ENTRY_DATA_CHANGED(srcza->entry + srcidx) || srcza->entry[srcidx].deleted)) {
zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
return NULL;
}
- if (zip_stat_index(srcza, srcidx, flags|ZIP_FL_UNCHANGED, &st) < 0) {
+ if (zip_stat_index(srcza, srcidx, flags | ZIP_FL_UNCHANGED, &st) < 0) {
zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
return NULL;
}
@@ -86,11 +84,11 @@
needs_decompress = ((flags & ZIP_FL_COMPRESSED) == 0) && (st.comp_method != ZIP_CM_STORE);
/* when reading the whole file, check for CRC errors */
needs_crc = ((flags & ZIP_FL_COMPRESSED) == 0 || st.comp_method == ZIP_CM_STORE) && !partial_data;
-
+
if (needs_decrypt) {
- if (password == NULL) {
- password = za->default_password;
- }
+ if (password == NULL) {
+ password = za->default_password;
+ }
if (password == NULL) {
zip_error_set(&za->error, ZIP_ER_NOPASSWD, 0);
return NULL;
@@ -103,20 +101,20 @@
if (partial_data && !needs_decrypt && !needs_decompress) {
struct zip_stat st2;
-
+
st2.size = len;
st2.comp_size = len;
st2.comp_method = ZIP_CM_STORE;
st2.mtime = st.mtime;
- st2.valid = ZIP_STAT_SIZE|ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD|ZIP_STAT_MTIME;
-
+ st2.valid = ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_MTIME;
+
if ((src = _zip_source_window_new(srcza->src, start, len, &st2, 0, srcza, srcidx, &za->error)) == NULL) {
return NULL;
}
}
else {
zip_dirent_t *de;
-
+
if ((de = _zip_get_dirent(srcza, srcidx, flags, &za->error)) == NULL) {
return NULL;
}
@@ -124,17 +122,17 @@
return NULL;
}
}
-
+
if (_zip_source_set_source_archive(src, srcza) < 0) {
zip_source_free(src);
return NULL;
}
/* creating a layered source calls zip_keep() on the lower layer, so we free it */
-
+
if (needs_decrypt) {
zip_encryption_implementation enc_impl;
-
+
if ((enc_impl = _zip_get_encryption_implementation(st.encryption_method, ZIP_CODEC_DECODE)) == NULL) {
zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
return NULL;
diff --git a/lib/zip_stat.c b/lib/zip_stat.c
index cf8e566..02cca37 100644
--- a/lib/zip_stat.c
+++ b/lib/zip_stat.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,11 +36,10 @@
ZIP_EXTERN int
-zip_stat(zip_t *za, const char *fname, zip_flags_t flags, zip_stat_t *st)
-{
+zip_stat(zip_t *za, const char *fname, zip_flags_t flags, zip_stat_t *st) {
zip_int64_t idx;
- if ((idx=zip_name_locate(za, fname, flags)) < 0)
+ if ((idx = zip_name_locate(za, fname, flags)) < 0)
return -1;
return zip_stat_index(za, (zip_uint64_t)idx, flags, st);
diff --git a/lib/zip_stat_index.c b/lib/zip_stat_index.c
index a2ef59b..109c118 100644
--- a/lib/zip_stat_index.c
+++ b/lib/zip_stat_index.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,21 +36,18 @@
ZIP_EXTERN int
-zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags,
- zip_stat_t *st)
-{
+zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags, zip_stat_t *st) {
const char *name;
zip_dirent_t *de;
- if ((de=_zip_get_dirent(za, index, flags, NULL)) == NULL)
+ if ((de = _zip_get_dirent(za, index, flags, NULL)) == NULL)
return -1;
- if ((name=zip_get_name(za, index, flags)) == NULL)
+ if ((name = zip_get_name(za, index, flags)) == NULL)
return -1;
-
- if ((flags & ZIP_FL_UNCHANGED) == 0
- && ZIP_ENTRY_DATA_CHANGED(za->entry+index)) {
+
+ if ((flags & ZIP_FL_UNCHANGED) == 0 && ZIP_ENTRY_DATA_CHANGED(za->entry + index)) {
if (zip_source_stat(za->entry[index].source, st) < 0) {
zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
return -1;
@@ -65,13 +62,12 @@
st->comp_size = de->comp_size;
st->comp_method = (zip_uint16_t)de->comp_method;
st->encryption_method = de->encryption_method;
- st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE|ZIP_STAT_MTIME
- |ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD|ZIP_STAT_ENCRYPTION_METHOD;
+ st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
}
st->index = index;
st->name = name;
- st->valid |= ZIP_STAT_INDEX|ZIP_STAT_NAME;
-
+ st->valid |= ZIP_STAT_INDEX | ZIP_STAT_NAME;
+
return 0;
}
diff --git a/lib/zip_stat_init.c b/lib/zip_stat_init.c
index 6b7d633..0be5138 100644
--- a/lib/zip_stat_init.c
+++ b/lib/zip_stat_init.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,8 +37,7 @@
ZIP_EXTERN void
-zip_stat_init(zip_stat_t *st)
-{
+zip_stat_init(zip_stat_t *st) {
st->valid = 0;
st->name = NULL;
st->index = ZIP_UINT64_MAX;
@@ -52,34 +51,33 @@
int
-_zip_stat_merge(zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error)
-{
+_zip_stat_merge(zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error) {
/* name is not merged, since zip_stat_t doesn't own it, and src may not be valid as long as dst */
if (src->valid & ZIP_STAT_INDEX) {
- dst->index = src->index;
+ dst->index = src->index;
}
if (src->valid & ZIP_STAT_SIZE) {
- dst->size = src->size;
+ dst->size = src->size;
}
if (src->valid & ZIP_STAT_COMP_SIZE) {
- dst->comp_size = src->comp_size;
+ dst->comp_size = src->comp_size;
}
if (src->valid & ZIP_STAT_MTIME) {
- dst->mtime = src->mtime;
+ dst->mtime = src->mtime;
}
if (src->valid & ZIP_STAT_CRC) {
- dst->crc = src->crc;
+ dst->crc = src->crc;
}
if (src->valid & ZIP_STAT_COMP_METHOD) {
- dst->comp_method = src->comp_method;
+ dst->comp_method = src->comp_method;
}
if (src->valid & ZIP_STAT_ENCRYPTION_METHOD) {
- dst->encryption_method = src->encryption_method;
+ dst->encryption_method = src->encryption_method;
}
if (src->valid & ZIP_STAT_FLAGS) {
- dst->flags = src->flags;
+ dst->flags = src->flags;
}
dst->valid |= src->valid;
-
+
return 0;
}
diff --git a/lib/zip_strerror.c b/lib/zip_strerror.c
index 98c4f6b..9e6e86c 100644
--- a/lib/zip_strerror.c
+++ b/lib/zip_strerror.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,7 +36,6 @@
ZIP_EXTERN const char *
-zip_strerror(zip_t *za)
-{
+zip_strerror(zip_t *za) {
return zip_error_strerror(&za->error);
}
diff --git a/lib/zip_string.c b/lib/zip_string.c
index 307a425..293766c 100644
--- a/lib/zip_string.c
+++ b/lib/zip_string.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,13 +39,12 @@
zip_uint32_t
-_zip_string_crc32(const zip_string_t *s)
-{
+_zip_string_crc32(const zip_string_t *s) {
zip_uint32_t crc;
-
+
crc = (zip_uint32_t)crc32(0L, Z_NULL, 0);
- if (s != NULL)
+ if (s != NULL)
crc = (zip_uint32_t)crc32(crc, s->raw, s->length);
return crc;
@@ -53,8 +52,7 @@
int
-_zip_string_equal(const zip_string_t *a, const zip_string_t *b)
-{
+_zip_string_equal(const zip_string_t *a, const zip_string_t *b) {
if (a == NULL || b == NULL)
return a == b;
@@ -68,8 +66,7 @@
void
-_zip_string_free(zip_string_t *s)
-{
+_zip_string_free(zip_string_t *s) {
if (s == NULL)
return;
@@ -80,8 +77,7 @@
const zip_uint8_t *
-_zip_string_get(zip_string_t *string, zip_uint32_t *lenp, zip_flags_t flags, zip_error_t *error)
-{
+_zip_string_get(zip_string_t *string, zip_uint32_t *lenp, zip_flags_t flags, zip_error_t *error) {
static const zip_uint8_t empty[1] = "";
if (string == NULL) {
@@ -95,12 +91,9 @@
if (string->encoding == ZIP_ENCODING_UNKNOWN)
_zip_guess_encoding(string, ZIP_ENCODING_UNKNOWN);
- if (((flags & ZIP_FL_ENC_STRICT)
- && string->encoding != ZIP_ENCODING_ASCII && string->encoding != ZIP_ENCODING_UTF8_KNOWN)
- || (string->encoding == ZIP_ENCODING_CP437)) {
+ if (((flags & ZIP_FL_ENC_STRICT) && string->encoding != ZIP_ENCODING_ASCII && string->encoding != ZIP_ENCODING_UTF8_KNOWN) || (string->encoding == ZIP_ENCODING_CP437)) {
if (string->converted == NULL) {
- if ((string->converted=_zip_cp437_to_utf8(string->raw, string->length,
- &string->converted_length, error)) == NULL)
+ if ((string->converted = _zip_cp437_to_utf8(string->raw, string->length, &string->converted_length, error)) == NULL)
return NULL;
}
if (lenp)
@@ -108,7 +101,7 @@
return string->converted;
}
}
-
+
if (lenp)
*lenp = string->length;
return string->raw;
@@ -116,8 +109,7 @@
zip_uint16_t
-_zip_string_length(const zip_string_t *s)
-{
+_zip_string_length(const zip_string_t *s) {
if (s == NULL)
return 0;
@@ -126,11 +118,10 @@
zip_string_t *
-_zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, zip_error_t *error)
-{
+_zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, zip_error_t *error) {
zip_string_t *s;
zip_encoding_type_t expected_encoding;
-
+
if (length == 0)
return NULL;
@@ -148,13 +139,13 @@
zip_error_set(error, ZIP_ER_INVAL, 0);
return NULL;
}
-
- if ((s=(zip_string_t *)malloc(sizeof(*s))) == NULL) {
+
+ if ((s = (zip_string_t *)malloc(sizeof(*s))) == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return NULL;
}
- if ((s->raw=(zip_uint8_t *)malloc((size_t)(length+1))) == NULL) {
+ if ((s->raw = (zip_uint8_t *)malloc((size_t)(length + 1))) == NULL) {
free(s);
return NULL;
}
@@ -173,16 +164,15 @@
return NULL;
}
}
-
+
return s;
}
int
-_zip_string_write(zip_t *za, const zip_string_t *s)
-{
+_zip_string_write(zip_t *za, const zip_string_t *s) {
if (s == NULL)
return 0;
-
+
return _zip_write(za, s->raw, s->length);
}
diff --git a/lib/zip_unchange.c b/lib/zip_unchange.c
index 4a3d642..b0bd078 100644
--- a/lib/zip_unchange.c
+++ b/lib/zip_unchange.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,18 +38,16 @@
ZIP_EXTERN int
-zip_unchange(zip_t *za, zip_uint64_t idx)
-{
+zip_unchange(zip_t *za, zip_uint64_t idx) {
return _zip_unchange(za, idx, 0);
}
int
-_zip_unchange(zip_t *za, zip_uint64_t idx, int allow_duplicates)
-{
+_zip_unchange(zip_t *za, zip_uint64_t idx, int allow_duplicates) {
zip_int64_t i;
const char *orig_name, *changed_name;
-
+
if (idx >= za->nentry) {
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return -1;
@@ -57,7 +55,7 @@
if (!allow_duplicates && za->entry[idx].changes && (za->entry[idx].changes->changed & ZIP_DIRENT_FILENAME)) {
if (za->entry[idx].orig != NULL) {
- if ((orig_name=_zip_get_name(za, idx, ZIP_FL_UNCHANGED, &za->error)) == NULL) {
+ if ((orig_name = _zip_get_name(za, idx, ZIP_FL_UNCHANGED, &za->error)) == NULL) {
return -1;
}
@@ -70,8 +68,8 @@
else {
orig_name = NULL;
}
-
- if ((changed_name=_zip_get_name(za, idx, 0, &za->error)) == NULL) {
+
+ if ((changed_name = _zip_get_name(za, idx, 0, &za->error)) == NULL) {
return -1;
}
@@ -89,7 +87,7 @@
_zip_dirent_free(za->entry[idx].changes);
za->entry[idx].changes = NULL;
- _zip_unchange_data(za->entry+idx);
+ _zip_unchange_data(za->entry + idx);
return 0;
}
diff --git a/lib/zip_unchange_all.c b/lib/zip_unchange_all.c
index 885c77d..165064b 100644
--- a/lib/zip_unchange_all.c
+++ b/lib/zip_unchange_all.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,17 +38,16 @@
ZIP_EXTERN int
-zip_unchange_all(zip_t *za)
-{
+zip_unchange_all(zip_t *za) {
int ret;
zip_uint64_t i;
if (!_zip_hash_revert(za->names, &za->error)) {
- return -1;
+ return -1;
}
-
+
ret = 0;
- for (i=0; i<za->nentry; i++)
+ for (i = 0; i < za->nentry; i++)
ret |= _zip_unchange(za, i, 1);
ret |= zip_unchange_archive(za);
diff --git a/lib/zip_unchange_archive.c b/lib/zip_unchange_archive.c
index 920255c..f70dba9 100644
--- a/lib/zip_unchange_archive.c
+++ b/lib/zip_unchange_archive.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,14 +38,13 @@
ZIP_EXTERN int
-zip_unchange_archive(zip_t *za)
-{
+zip_unchange_archive(zip_t *za) {
if (za->comment_changed) {
_zip_string_free(za->comment_changes);
za->comment_changes = NULL;
za->comment_changed = 0;
}
-
+
za->ch_flags = za->flags;
return 0;
diff --git a/lib/zip_unchange_data.c b/lib/zip_unchange_data.c
index 839d9a3..1addaa8 100644
--- a/lib/zip_unchange_data.c
+++ b/lib/zip_unchange_data.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,8 +35,7 @@
#include "zipint.h"
void
-_zip_unchange_data(zip_entry_t *ze)
-{
+_zip_unchange_data(zip_entry_t *ze) {
if (ze->source) {
zip_source_free(ze->source);
ze->source = NULL;
@@ -52,4 +51,3 @@
ze->deleted = 0;
}
-
diff --git a/lib/zip_utf-8.c b/lib/zip_utf-8.c
index f38eea0..8f02f88 100644
--- a/lib/zip_utf-8.c
+++ b/lib/zip_utf-8.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,83 +39,65 @@
static const zip_uint16_t _cp437_to_unicode[256] = {
/* 0x00 - 0x0F */
- 0x2007, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022,
- 0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C,
+ 0x2007, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, 0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C,
/* 0x10 - 0x1F */
- 0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8,
- 0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC,
+ 0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8, 0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC,
/* 0x20 - 0x2F */
- 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
- 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
+ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
/* 0x30 - 0x3F */
- 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
- 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
/* 0x40 - 0x4F */
- 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
- 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
/* 0x50 - 0x5F */
- 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
- 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
/* 0x60 - 0x6F */
- 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
- 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
/* 0x70 - 0x7F */
- 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
- 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x2302,
+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x2302,
/* 0x80 - 0x8F */
- 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
- 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
+ 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
/* 0x90 - 0x9F */
- 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
- 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
+ 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
/* 0xA0 - 0xAF */
- 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
- 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+ 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
/* 0xB0 - 0xBF */
- 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
- 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+ 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
/* 0xC0 - 0xCF */
- 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
- 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+ 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
/* 0xD0 - 0xDF */
- 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
- 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+ 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
/* 0xE0 - 0xEF */
- 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
- 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
+ 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
/* 0xF0 - 0xFF */
- 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
- 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
-};
+ 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0};
-#define UTF_8_LEN_2_MASK 0xe0
-#define UTF_8_LEN_2_MATCH 0xc0
-#define UTF_8_LEN_3_MASK 0xf0
-#define UTF_8_LEN_3_MATCH 0xe0
-#define UTF_8_LEN_4_MASK 0xf8
-#define UTF_8_LEN_4_MATCH 0xf0
-#define UTF_8_CONTINUE_MASK 0xc0
+#define UTF_8_LEN_2_MASK 0xe0
+#define UTF_8_LEN_2_MATCH 0xc0
+#define UTF_8_LEN_3_MASK 0xf0
+#define UTF_8_LEN_3_MATCH 0xe0
+#define UTF_8_LEN_4_MASK 0xf8
+#define UTF_8_LEN_4_MATCH 0xf0
+#define UTF_8_CONTINUE_MASK 0xc0
#define UTF_8_CONTINUE_MATCH 0x80
zip_encoding_type_t
-_zip_guess_encoding(zip_string_t *str, zip_encoding_type_t expected_encoding)
-{
+_zip_guess_encoding(zip_string_t *str, zip_encoding_type_t expected_encoding) {
zip_encoding_type_t enc;
const zip_uint8_t *name;
zip_uint32_t i, j, ulen;
@@ -129,7 +111,7 @@
enc = str->encoding;
else {
enc = ZIP_ENCODING_ASCII;
- for (i=0; i<str->length; i++) {
+ for (i = 0; i < str->length; i++) {
if ((name[i] > 31 && name[i] < 128) || name[i] == '\r' || name[i] == '\n' || name[i] == '\t')
continue;
@@ -150,8 +132,8 @@
break;
}
- for (j=1; j<=ulen; j++) {
- if ((name[i+j] & UTF_8_CONTINUE_MASK) != UTF_8_CONTINUE_MATCH) {
+ for (j = 1; j <= ulen; j++) {
+ if ((name[i + j] & UTF_8_CONTINUE_MASK) != UTF_8_CONTINUE_MATCH) {
enc = ZIP_ENCODING_CP437;
goto done;
}
@@ -170,14 +152,13 @@
if (expected_encoding != enc && enc != ZIP_ENCODING_ASCII)
return ZIP_ENCODING_ERROR;
}
-
+
return enc;
}
static zip_uint32_t
-_zip_unicode_to_utf8_len(zip_uint32_t codepoint)
-{
+_zip_unicode_to_utf8_len(zip_uint32_t codepoint) {
if (codepoint < 0x0080)
return 1;
if (codepoint < 0x0800)
@@ -189,8 +170,7 @@
static zip_uint32_t
-_zip_unicode_to_utf8(zip_uint32_t codepoint, zip_uint8_t *buf)
-{
+_zip_unicode_to_utf8(zip_uint32_t codepoint, zip_uint8_t *buf) {
if (codepoint < 0x0080) {
buf[0] = codepoint & 0xff;
return 1;
@@ -215,9 +195,7 @@
zip_uint8_t *
-_zip_cp437_to_utf8(const zip_uint8_t * const _cp437buf, zip_uint32_t len,
- zip_uint32_t *utf8_lenp, zip_error_t *error)
-{
+_zip_cp437_to_utf8(const zip_uint8_t *const _cp437buf, zip_uint32_t len, zip_uint32_t *utf8_lenp, zip_error_t *error) {
zip_uint8_t *cp437buf = (zip_uint8_t *)_cp437buf;
zip_uint8_t *utf8buf;
zip_uint32_t buflen, i, offset;
@@ -229,21 +207,20 @@
}
buflen = 1;
- for (i=0; i<len; i++)
+ for (i = 0; i < len; i++)
buflen += _zip_unicode_to_utf8_len(_cp437_to_unicode[cp437buf[i]]);
- if ((utf8buf=(zip_uint8_t*)malloc(buflen)) == NULL) {
+ if ((utf8buf = (zip_uint8_t *)malloc(buflen)) == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return NULL;
}
offset = 0;
- for (i=0; i<len; i++)
- offset += _zip_unicode_to_utf8(_cp437_to_unicode[cp437buf[i]],
- utf8buf+offset);
+ for (i = 0; i < len; i++)
+ offset += _zip_unicode_to_utf8(_cp437_to_unicode[cp437buf[i]], utf8buf + offset);
- utf8buf[buflen-1] = 0;
+ utf8buf[buflen - 1] = 0;
if (utf8_lenp)
- *utf8_lenp = buflen-1;
+ *utf8_lenp = buflen - 1;
return utf8buf;
}
diff --git a/lib/zipint.h b/lib/zipint.h
index d912b7d..830e399 100644
--- a/lib/zipint.h
+++ b/lib/zipint.h
@@ -49,63 +49,65 @@
#include "zip.h"
#define CENTRAL_MAGIC "PK\1\2"
-#define LOCAL_MAGIC "PK\3\4"
-#define EOCD_MAGIC "PK\5\6"
+#define LOCAL_MAGIC "PK\3\4"
+#define EOCD_MAGIC "PK\5\6"
#define DATADES_MAGIC "PK\7\10"
#define EOCD64LOC_MAGIC "PK\6\7"
-#define EOCD64_MAGIC "PK\6\6"
-#define CDENTRYSIZE 46u
-#define LENTRYSIZE 30
-#define MAXCOMLEN 65536
-#define MAXEXTLEN 65536
-#define EOCDLEN 22
-#define EOCD64LOCLEN 20
-#define EOCD64LEN 56
-#define CDBUFSIZE (MAXCOMLEN+EOCDLEN+EOCD64LOCLEN)
-#define BUFSIZE 8192
+#define EOCD64_MAGIC "PK\6\6"
+#define CDENTRYSIZE 46u
+#define LENTRYSIZE 30
+#define MAXCOMLEN 65536
+#define MAXEXTLEN 65536
+#define EOCDLEN 22
+#define EOCD64LOCLEN 20
+#define EOCD64LEN 56
+#define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
+#define BUFSIZE 8192
#define EFZIP64SIZE 28
#define EF_WINZIP_AES_SIZE 7
-#define ZIP_CM_REPLACED_DEFAULT (-2)
-#define ZIP_CM_WINZIP_AES 99 /* Winzip AES encrypted */
+#define ZIP_CM_REPLACED_DEFAULT (-2)
+#define ZIP_CM_WINZIP_AES 99 /* Winzip AES encrypted */
-#define ZIP_CM_IS_DEFAULT(x) ((x) == ZIP_CM_DEFAULT || (x) == ZIP_CM_REPLACED_DEFAULT)
-#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)(ZIP_CM_IS_DEFAULT(x) ? ZIP_CM_DEFLATE : (x)))
+#define ZIP_CM_IS_DEFAULT(x) ((x) == ZIP_CM_DEFAULT || (x) == ZIP_CM_REPLACED_DEFAULT)
+#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)(ZIP_CM_IS_DEFAULT(x) ? ZIP_CM_DEFLATE : (x)))
-#define ZIP_EF_UTF_8_COMMENT 0x6375
-#define ZIP_EF_UTF_8_NAME 0x7075
-#define ZIP_EF_WINZIP_AES 0x9901
-#define ZIP_EF_ZIP64 0x0001
+#define ZIP_EF_UTF_8_COMMENT 0x6375
+#define ZIP_EF_UTF_8_NAME 0x7075
+#define ZIP_EF_WINZIP_AES 0x9901
+#define ZIP_EF_ZIP64 0x0001
-#define ZIP_EF_IS_INTERNAL(id) ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_WINZIP_AES || (id) == ZIP_EF_ZIP64)
+#define ZIP_EF_IS_INTERNAL(id) ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_WINZIP_AES || (id) == ZIP_EF_ZIP64)
/* according to unzip-6.0's zipinfo.c, this corresponds to a regular file with rw permissions for everyone */
-#define ZIP_EXT_ATTRIB_DEFAULT (0100666u<<16)
+#define ZIP_EXT_ATTRIB_DEFAULT (0100666u << 16)
/* according to unzip-6.0's zipinfo.c, this corresponds to a directory with rwx permissions for everyone */
-#define ZIP_EXT_ATTRIB_DEFAULT_DIR (0040777u<<16)
+#define ZIP_EXT_ATTRIB_DEFAULT_DIR (0040777u << 16)
-#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
-#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
+#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
+#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
/* This section contains API that won't materialize like this. It's
placed in the internal section, pending cleanup. */
/* flags for compression and encryption sources */
-#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
-#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
+#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
+#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
typedef zip_source_t *(*zip_encryption_implementation)(zip_t *, zip_source_t *, zip_uint16_t, int, const char *);
zip_encryption_implementation _zip_get_encryption_implementation(zip_uint16_t method, int operation);
+// clang-format off
enum zip_compression_status {
ZIP_COMPRESSION_OK,
ZIP_COMPRESSION_END,
ZIP_COMPRESSION_ERROR,
ZIP_COMPRESSION_NEED_DATA
};
+// clang-format on
typedef enum zip_compression_status zip_compression_status_t;
struct zip_compression_algorithm {
@@ -168,30 +170,30 @@
/* directory entry: general purpose bit flags */
-#define ZIP_GPBF_ENCRYPTED 0x0001u /* is encrypted */
-#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u /* crc/size after file data */
-#define ZIP_GPBF_STRONG_ENCRYPTION 0x0040u /* uses strong encryption */
-#define ZIP_GPBF_ENCODING_UTF_8 0x0800u /* file name encoding is UTF-8 */
+#define ZIP_GPBF_ENCRYPTED 0x0001u /* is encrypted */
+#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u /* crc/size after file data */
+#define ZIP_GPBF_STRONG_ENCRYPTION 0x0040u /* uses strong encryption */
+#define ZIP_GPBF_ENCODING_UTF_8 0x0800u /* file name encoding is UTF-8 */
/* extra fields */
-#define ZIP_EF_LOCAL ZIP_FL_LOCAL /* include in local header */
-#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL /* include in central directory */
-#define ZIP_EF_BOTH (ZIP_EF_LOCAL|ZIP_EF_CENTRAL) /* include in both */
+#define ZIP_EF_LOCAL ZIP_FL_LOCAL /* include in local header */
+#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL /* include in central directory */
+#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
-#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
+#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
-#define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS|ZIP_FL_ENC_CP437|ZIP_FL_ENC_UTF_8)
+#define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
/* encoding type */
enum zip_encoding_type {
- ZIP_ENCODING_UNKNOWN, /* not yet analyzed */
- ZIP_ENCODING_ASCII, /* plain ASCII */
- ZIP_ENCODING_UTF8_KNOWN, /* is UTF-8 */
- ZIP_ENCODING_UTF8_GUESSED, /* possibly UTF-8 */
- ZIP_ENCODING_CP437, /* Code Page 437 */
- ZIP_ENCODING_ERROR /* should be UTF-8 but isn't */
+ ZIP_ENCODING_UNKNOWN, /* not yet analyzed */
+ ZIP_ENCODING_ASCII, /* plain ASCII */
+ ZIP_ENCODING_UTF8_KNOWN, /* is UTF-8 */
+ ZIP_ENCODING_UTF8_GUESSED, /* possibly UTF-8 */
+ ZIP_ENCODING_CP437, /* Code Page 437 */
+ ZIP_ENCODING_ERROR /* should be UTF-8 but isn't */
};
typedef enum zip_encoding_type zip_encoding_type_t;
@@ -211,107 +213,107 @@
/* zip archive, part of API */
struct zip {
- zip_source_t *src; /* data source for archive */
- unsigned int open_flags; /* flags passed to zip_open */
- zip_error_t error; /* error information */
+ zip_source_t *src; /* data source for archive */
+ unsigned int open_flags; /* flags passed to zip_open */
+ zip_error_t error; /* error information */
- unsigned int flags; /* archive global flags */
- unsigned int ch_flags; /* changed archive global flags */
+ unsigned int flags; /* archive global flags */
+ unsigned int ch_flags; /* changed archive global flags */
- char *default_password; /* password used when no other supplied */
+ char *default_password; /* password used when no other supplied */
- zip_string_t *comment_orig; /* archive comment */
- zip_string_t *comment_changes; /* changed archive comment */
- bool comment_changed; /* whether archive comment was changed */
+ zip_string_t *comment_orig; /* archive comment */
+ zip_string_t *comment_changes; /* changed archive comment */
+ bool comment_changed; /* whether archive comment was changed */
- zip_uint64_t nentry; /* number of entries */
- zip_uint64_t nentry_alloc; /* number of entries allocated */
- zip_entry_t *entry; /* entries */
+ zip_uint64_t nentry; /* number of entries */
+ zip_uint64_t nentry_alloc; /* number of entries allocated */
+ zip_entry_t *entry; /* entries */
- unsigned int nopen_source; /* number of open sources using archive */
- unsigned int nopen_source_alloc; /* number of sources allocated */
- zip_source_t **open_source; /* open sources using archive */
+ unsigned int nopen_source; /* number of open sources using archive */
+ unsigned int nopen_source_alloc; /* number of sources allocated */
+ zip_source_t **open_source; /* open sources using archive */
- zip_hash_t *names; /* hash table for name lookup */
+ zip_hash_t *names; /* hash table for name lookup */
- zip_progress_t *progress; /* progress callback for zip_close() */
+ zip_progress_t *progress; /* progress callback for zip_close() */
};
/* file in zip archive, part of API */
struct zip_file {
- zip_t *za; /* zip archive containing this file */
- zip_error_t error; /* error information */
+ zip_t *za; /* zip archive containing this file */
+ zip_error_t error; /* error information */
bool eof;
- zip_source_t *src; /* data source */
+ zip_source_t *src; /* data source */
};
/* zip archive directory entry (central or local) */
-#define ZIP_DIRENT_COMP_METHOD 0x0001u
-#define ZIP_DIRENT_FILENAME 0x0002u
-#define ZIP_DIRENT_COMMENT 0x0004u
-#define ZIP_DIRENT_EXTRA_FIELD 0x0008u
-#define ZIP_DIRENT_ATTRIBUTES 0x0010u
-#define ZIP_DIRENT_LAST_MOD 0x0020u
-#define ZIP_DIRENT_ENCRYPTION_METHOD 0x0040u
-#define ZIP_DIRENT_PASSWORD 0x0080u
-#define ZIP_DIRENT_ALL ZIP_UINT32_MAX
+#define ZIP_DIRENT_COMP_METHOD 0x0001u
+#define ZIP_DIRENT_FILENAME 0x0002u
+#define ZIP_DIRENT_COMMENT 0x0004u
+#define ZIP_DIRENT_EXTRA_FIELD 0x0008u
+#define ZIP_DIRENT_ATTRIBUTES 0x0010u
+#define ZIP_DIRENT_LAST_MOD 0x0020u
+#define ZIP_DIRENT_ENCRYPTION_METHOD 0x0040u
+#define ZIP_DIRENT_PASSWORD 0x0080u
+#define ZIP_DIRENT_ALL ZIP_UINT32_MAX
struct zip_dirent {
zip_uint32_t changed;
- bool local_extra_fields_read; /* whether we already read in local header extra fields */
- bool cloned; /* whether this instance is cloned, and thus shares non-changed strings */
+ bool local_extra_fields_read; /* whether we already read in local header extra fields */
+ bool cloned; /* whether this instance is cloned, and thus shares non-changed strings */
- bool crc_valid; /* if CRC is valid (sometimes not for encrypted archives) */
+ bool crc_valid; /* if CRC is valid (sometimes not for encrypted archives) */
- zip_uint16_t version_madeby; /* (c) version of creator */
- zip_uint16_t version_needed; /* (cl) version needed to extract */
- zip_uint16_t bitflags; /* (cl) general purpose bit flag */
- zip_int32_t comp_method; /* (cl) compression method used (uint16 and ZIP_CM_DEFAULT (-1)) */
- time_t last_mod; /* (cl) time of last modification */
- zip_uint32_t crc; /* (cl) CRC-32 of uncompressed data */
- zip_uint64_t comp_size; /* (cl) size of compressed data */
- zip_uint64_t uncomp_size; /* (cl) size of uncompressed data */
- zip_string_t *filename; /* (cl) file name (NUL-terminated) */
- zip_extra_field_t *extra_fields; /* (cl) extra fields, parsed */
- zip_string_t *comment; /* (c) file comment */
- zip_uint32_t disk_number; /* (c) disk number start */
- zip_uint16_t int_attrib; /* (c) internal file attributes */
- zip_uint32_t ext_attrib; /* (c) external file attributes */
- zip_uint64_t offset; /* (c) offset of local header */
+ zip_uint16_t version_madeby; /* (c) version of creator */
+ zip_uint16_t version_needed; /* (cl) version needed to extract */
+ zip_uint16_t bitflags; /* (cl) general purpose bit flag */
+ zip_int32_t comp_method; /* (cl) compression method used (uint16 and ZIP_CM_DEFAULT (-1)) */
+ time_t last_mod; /* (cl) time of last modification */
+ zip_uint32_t crc; /* (cl) CRC-32 of uncompressed data */
+ zip_uint64_t comp_size; /* (cl) size of compressed data */
+ zip_uint64_t uncomp_size; /* (cl) size of uncompressed data */
+ zip_string_t *filename; /* (cl) file name (NUL-terminated) */
+ zip_extra_field_t *extra_fields; /* (cl) extra fields, parsed */
+ zip_string_t *comment; /* (c) file comment */
+ zip_uint32_t disk_number; /* (c) disk number start */
+ zip_uint16_t int_attrib; /* (c) internal file attributes */
+ zip_uint32_t ext_attrib; /* (c) external file attributes */
+ zip_uint64_t offset; /* (c) offset of local header */
- zip_uint16_t compression_level; /* level of compression to use (never valid in orig) */
- zip_uint16_t encryption_method; /* encryption method, computed from other fields */
- char *password; /* file specific encryption password */
+ zip_uint16_t compression_level; /* level of compression to use (never valid in orig) */
+ zip_uint16_t encryption_method; /* encryption method, computed from other fields */
+ char *password; /* file specific encryption password */
};
/* zip archive central directory */
struct zip_cdir {
- zip_entry_t *entry; /* directory entries */
- zip_uint64_t nentry; /* number of entries */
- zip_uint64_t nentry_alloc; /* number of entries allocated */
+ zip_entry_t *entry; /* directory entries */
+ zip_uint64_t nentry; /* number of entries */
+ zip_uint64_t nentry_alloc; /* number of entries allocated */
- zip_uint64_t size; /* size of central directory */
- zip_uint64_t offset; /* offset of central directory in file */
- zip_string_t *comment; /* zip archive comment */
- bool is_zip64; /* central directory in zip64 format */
+ zip_uint64_t size; /* size of central directory */
+ zip_uint64_t offset; /* offset of central directory in file */
+ zip_string_t *comment; /* zip archive comment */
+ bool is_zip64; /* central directory in zip64 format */
};
struct zip_extra_field {
zip_extra_field_t *next;
- zip_flags_t flags; /* in local/central header */
- zip_uint16_t id; /* header id */
- zip_uint16_t size; /* data size */
+ zip_flags_t flags; /* in local/central header */
+ zip_uint16_t id; /* header id */
+ zip_uint16_t size; /* data size */
zip_uint8_t *data;
};
enum zip_source_write_state {
- ZIP_SOURCE_WRITE_CLOSED, /* write is not in progress */
- ZIP_SOURCE_WRITE_OPEN, /* write is in progress */
- ZIP_SOURCE_WRITE_FAILED, /* commit failed, only rollback allowed */
- ZIP_SOURCE_WRITE_REMOVED /* file was removed */
+ ZIP_SOURCE_WRITE_CLOSED, /* write is not in progress */
+ ZIP_SOURCE_WRITE_OPEN, /* write is in progress */
+ ZIP_SOURCE_WRITE_FAILED, /* commit failed, only rollback allowed */
+ ZIP_SOURCE_WRITE_REMOVED /* file was removed */
};
typedef enum zip_source_write_state zip_source_write_state_t;
@@ -323,19 +325,19 @@
} cb;
void *ud;
zip_error_t error;
- zip_int64_t supports; /* supported commands */
- unsigned int open_count; /* number of times source was opened (directly or as lower layer) */
- zip_source_write_state_t write_state; /* whether source is open for writing */
- bool source_closed; /* set if source archive is closed */
- zip_t *source_archive; /* zip archive we're reading from, NULL if not from archive */
+ zip_int64_t supports; /* supported commands */
+ unsigned int open_count; /* number of times source was opened (directly or as lower layer) */
+ zip_source_write_state_t write_state; /* whether source is open for writing */
+ bool source_closed; /* set if source archive is closed */
+ zip_t *source_archive; /* zip archive we're reading from, NULL if not from archive */
unsigned int refcount;
- bool eof; /* EOF reached */
- bool had_read_error; /* a previous ZIP_SOURCE_READ reported an error */
+ bool eof; /* EOF reached */
+ bool had_read_error; /* a previous ZIP_SOURCE_READ reported an error */
};
#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
-#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
+#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
/* entry in zip archive directory */
@@ -350,11 +352,11 @@
/* file or archive comment, or filename */
struct zip_string {
- zip_uint8_t *raw; /* raw string */
- zip_uint16_t length; /* length of raw string */
- enum zip_encoding_type encoding; /* autorecognized encoding */
- zip_uint8_t *converted; /* autoconverted string */
- zip_uint32_t converted_length; /* length of converted */
+ zip_uint8_t *raw; /* raw string */
+ zip_uint16_t length; /* length of raw string */
+ enum zip_encoding_type encoding; /* autorecognized encoding */
+ zip_uint8_t *converted; /* autoconverted string */
+ zip_uint32_t converted_length; /* length of converted */
};
@@ -373,24 +375,24 @@
struct zip_filelist {
zip_uint64_t idx;
-/* TODO const char *name; */
+ /* TODO const char *name; */
};
typedef struct zip_filelist zip_filelist_t;
-extern const char * const _zip_err_str[];
+extern const char *const _zip_err_str[];
extern const int _zip_nerr_str;
extern const int _zip_err_type[];
-#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
-#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
+#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
+#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
-#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
-#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
-#define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
+#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
+#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
+#define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
-#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
+#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
#ifdef HAVE_EXPLICIT_MEMSET
@@ -480,7 +482,7 @@
zip_dirent_t *_zip_get_dirent(zip_t *, zip_uint64_t, zip_flags_t, zip_error_t *);
enum zip_encoding_type _zip_guess_encoding(zip_string_t *, enum zip_encoding_type);
-zip_uint8_t *_zip_cp437_to_utf8(const zip_uint8_t * const, zip_uint32_t, zip_uint32_t *, zip_error_t *);
+zip_uint8_t *_zip_cp437_to_utf8(const zip_uint8_t *const, zip_uint32_t, zip_uint32_t *, zip_error_t *);
bool _zip_hash_add(zip_hash_t *hash, const zip_uint8_t *name, zip_uint64_t index, zip_flags_t flags, zip_error_t *error);
bool _zip_hash_delete(zip_hash_t *hash, const zip_uint8_t *key, zip_error_t *error);
diff --git a/lib/zipwin32.h b/lib/zipwin32.h
index db549e2..e989a0e 100644
--- a/lib/zipwin32.h
+++ b/lib/zipwin32.h
@@ -20,7 +20,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -46,24 +46,24 @@
struct _zip_source_win32_file_ops;
struct _zip_source_win32_read_file {
- zip_error_t error; /* last error information */
+ zip_error_t error; /* last error information */
zip_int64_t supports;
/* operations */
struct _zip_source_win32_file_ops *ops;
/* reading */
- void *fname; /* name of file to read from - ANSI (char *) or Unicode (wchar_t *) */
- void *h; /* HANDLE for file to read from */
- int closep; /* whether to close f on ZIP_CMD_FREE */
- struct zip_stat st; /* stat information passed in */
- zip_uint64_t start; /* start offset of data to read */
- zip_uint64_t end; /* end offset of data to read, 0 for up to EOF */
- zip_uint64_t current; /* current offset */
+ void *fname; /* name of file to read from - ANSI (char *) or Unicode (wchar_t *) */
+ void *h; /* HANDLE for file to read from */
+ int closep; /* whether to close f on ZIP_CMD_FREE */
+ struct zip_stat st; /* stat information passed in */
+ zip_uint64_t start; /* start offset of data to read */
+ zip_uint64_t end; /* end offset of data to read, 0 for up to EOF */
+ zip_uint64_t current; /* current offset */
/* writing */
- void *tmpname; /* name of temp file - ANSI (char *) or Unicode (wchar_t *) */
- void *hout; /* HANDLE for output file */
+ void *tmpname; /* name of temp file - ANSI (char *) or Unicode (wchar_t *) */
+ void *hout; /* HANDLE for output file */
};
typedef struct _zip_source_win32_read_file _zip_source_win32_read_file_t;