Fixed formatting.

This commit is contained in:
Nathan Moinvaziri 2018-09-18 20:25:48 -07:00
parent dacd44383d
commit 5469018dbc
5 changed files with 53 additions and 43 deletions

View File

@ -20,14 +20,14 @@
#ifdef HAVE_GETRANDOM
# include <sys/random.h>
#endif
#if defined unix || defined __APPLE__
#if defined(unix) || defined(__APPLE__)
# include <unistd.h>
# include <utime.h>
# define HAVE_ARC4RANDOM_BUF
#endif
#if defined(HAVE_LIBBSD) && \
!defined(MZ_ZIP_NO_COMPRESSION) && \
!defined(MZ_ZIP_NO_ENCRYPTION)
#if defined(HAVE_LIBBSD) && \
!defined(MZ_ZIP_NO_COMPRESSION) && \
!defined(MZ_ZIP_NO_ENCRYPTION)
# include <bsd/stdlib.h> // arc4random_buf
#else
# include <stdlib.h>
@ -266,15 +266,18 @@ int32_t mz_posix_is_dir(const char *path)
return MZ_EXIST_ERROR;
}
uint64_t mz_posix_ms_time(void) {
uint64_t mz_posix_ms_time(void)
{
struct timespec ts;
#ifdef __APPLE__
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
ts.tv_sec = mts.tv_sec;
ts.tv_nsec = mts.tv_nsec;
#else

View File

@ -30,21 +30,21 @@ extern "C" {
/***************************************************************************/
int32_t mz_posix_rand(uint8_t *buf, int32_t size);
int32_t mz_posix_rename(const char *source_path, const char *target_path);
int32_t mz_posix_delete(const char *path);
int32_t mz_posix_file_exists(const char *path);
int64_t mz_posix_get_file_size(const char *path);
int32_t mz_posix_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
int32_t mz_posix_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
int32_t mz_posix_get_file_attribs(const char *path, uint32_t *attributes);
int32_t mz_posix_set_file_attribs(const char *path, uint32_t attributes);
int32_t mz_posix_make_dir(const char *path);
DIR* mz_posix_open_dir(const char *path);
int32_t mz_posix_rand(uint8_t *buf, int32_t size);
int32_t mz_posix_rename(const char *source_path, const char *target_path);
int32_t mz_posix_delete(const char *path);
int32_t mz_posix_file_exists(const char *path);
int64_t mz_posix_get_file_size(const char *path);
int32_t mz_posix_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
int32_t mz_posix_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
int32_t mz_posix_get_file_attribs(const char *path, uint32_t *attributes);
int32_t mz_posix_set_file_attribs(const char *path, uint32_t attributes);
int32_t mz_posix_make_dir(const char *path);
DIR* mz_posix_open_dir(const char *path);
struct
dirent* mz_posix_read_dir(DIR *dir);
int32_t mz_posix_close_dir(DIR *dir);
int32_t mz_posix_is_dir(const char *path);
dirent* mz_posix_read_dir(DIR *dir);
int32_t mz_posix_close_dir(DIR *dir);
int32_t mz_posix_is_dir(const char *path);
uint64_t mz_posix_ms_time(void);
/***************************************************************************/

View File

@ -382,12 +382,17 @@ int32_t mz_win32_is_dir(const char *path)
return MZ_EXIST_ERROR;
}
uint64_t mz_win32_ms_time(void) {
uint64_t mz_win32_ms_time(void)
{
SYSTEMTIME system_time;
GetSystemTime(&system_time);
FILETIME file_time;
uint64_t quad_file_time = 0;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
return ((((ULONGLONG) file_time.dwHighDateTime) << 32) + file_time.dwLowDateTime)/10000 - 11644473600000;
quad_file_time = file_time.dwLowDateTime;
quad_file_time |= ((uint64_t)file_time.dwHighDateTime << 32);
return quad_file_time / 10000 - 11644473600000LL;
}

View File

@ -31,21 +31,21 @@ typedef void* DIR;
/***************************************************************************/
int32_t mz_win32_rand(uint8_t *buf, int32_t size);
int32_t mz_win32_rename(const char *source_path, const char *target_path);
int32_t mz_win32_delete(const char *path);
int32_t mz_win32_file_exists(const char *path);
int64_t mz_win32_get_file_size(const char *path);
int32_t mz_win32_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
int32_t mz_win32_get_file_attribs(const char *path, uint32_t *attributes);
int32_t mz_win32_set_file_attribs(const char *path, uint32_t attributes);
int32_t mz_win32_make_dir(const char *path);
DIR* mz_win32_open_dir(const char *path);
int32_t mz_win32_rand(uint8_t *buf, int32_t size);
int32_t mz_win32_rename(const char *source_path, const char *target_path);
int32_t mz_win32_delete(const char *path);
int32_t mz_win32_file_exists(const char *path);
int64_t mz_win32_get_file_size(const char *path);
int32_t mz_win32_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
int32_t mz_win32_get_file_attribs(const char *path, uint32_t *attributes);
int32_t mz_win32_set_file_attribs(const char *path, uint32_t attributes);
int32_t mz_win32_make_dir(const char *path);
DIR* mz_win32_open_dir(const char *path);
struct
dirent* mz_win32_read_dir(DIR *dir);
int32_t mz_win32_close_dir(DIR *dir);
int32_t mz_win32_is_dir(const char *path);
dirent* mz_win32_read_dir(DIR *dir);
int32_t mz_win32_close_dir(DIR *dir);
int32_t mz_win32_is_dir(const char *path);
uint64_t mz_win32_ms_time(void);
/***************************************************************************/

View File

@ -27,6 +27,10 @@
/***************************************************************************/
#define MZ_DEFAULT_PROGRESS_INTERVAL (1000u)
/***************************************************************************/
typedef struct mz_zip_reader_s {
void *zip_handle;
void *file_stream;
@ -57,8 +61,6 @@ typedef struct mz_zip_reader_s {
/***************************************************************************/
#define DEFAULT_PROGRESS_INTERVAL 1000u
int32_t mz_zip_reader_is_open(void *handle)
{
mz_zip_reader *reader = (mz_zip_reader *)handle;
@ -441,7 +443,7 @@ int32_t mz_zip_reader_entry_save(void *handle, void *stream, mz_stream_write_cb
// Update progress if enough time have passed
current_time = mz_os_ms_time();
if (current_time - update_time > reader->progress_cb_interval_ms)
if ((current_time - update_time) > reader->progress_cb_interval_ms)
{
if (reader->progress_cb != NULL)
reader->progress_cb(handle, reader->progress_userdata, reader->file_info, current_pos);
@ -709,7 +711,7 @@ void *mz_zip_reader_create(void **handle)
if (reader != NULL)
{
memset(reader, 0, sizeof(mz_zip_reader));
reader->progress_cb_interval_ms = DEFAULT_PROGRESS_INTERVAL;
reader->progress_cb_interval_ms = MZ_DEFAULT_PROGRESS_INTERVAL;
*handle = reader;
}
@ -1037,7 +1039,7 @@ int32_t mz_zip_writer_add(void *handle, void *stream, mz_stream_read_cb read_cb)
// Update progress if enough time have passed
current_time = mz_os_ms_time();
if (current_time - update_time > writer->progress_cb_interval_ms)
if ((current_time - update_time) > writer->progress_cb_interval_ms)
{
if (writer->progress_cb != NULL)
writer->progress_cb(handle, writer->progress_userdata, &writer->file_info, current_pos);
@ -1381,7 +1383,7 @@ void *mz_zip_writer_create(void **handle)
writer->compress_method = MZ_COMPRESS_METHOD_DEFLATE;
writer->compress_level = MZ_COMPRESS_LEVEL_BEST;
writer->progress_cb_interval_ms = DEFAULT_PROGRESS_INTERVAL;
writer->progress_cb_interval_ms = MZ_DEFAULT_PROGRESS_INTERVAL;
*handle = writer;
}