4
0
mirror of https://github.com/QuasarApp/zip.git synced 2025-05-05 00:29:34 +00:00

Suppress MSVC warnings

This commit is contained in:
Kuba Podgórski 2017-02-14 23:15:19 +01:00 committed by GitHub
parent 8cac9e042f
commit c02431f3a0
3 changed files with 25 additions and 8 deletions

4
.gitignore vendored

@ -28,3 +28,7 @@
*.i*86
*.x86_64
*.hex
/build/
*.swp

@ -1,6 +1,13 @@
cmake_minimum_required(VERSION 2.8)
project(zip)
if (MSVC)
# Use secure functions by defaualt and suppress warnings about "deprecated" functions
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_NONSTDC_NO_WARNINGS=1 /D _CRT_SECURE_NO_WARNINGS=1")
endif (MSVC)
set(SRC src/miniz.h src/zip.h src/zip.c)
add_library(${CMAKE_PROJECT_NAME} ${SRC})

@ -13,14 +13,23 @@
#include <errno.h>
#include <sys/stat.h>
#include <time.h>
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
/* Win32, OS/2, DOS */
#if defined _WIN32 || defined __WIN32__
/* Win32, DOS */
#include <direct.h>
#define MKDIR(DIRNAME) _mkdir(DIRNAME)
#define STRCLONE(STR) ((STR) ? _strdup(STR) : NULL)
#define HAS_DEVICE(P) \
((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) && \
(P)[1] == ':')
#define FILESYSTEM_PREFIX_LEN(P) (HAS_DEVICE(P) ? 2 : 0)
#define ISSLASH(C) ((C) == '/' || (C) == '\\')
#else
#define MKDIR(DIRNAME) mkdir(DIRNAME, 0755)
#define STRCLONE(STR) ((STR) ? strdup(STR) : NULL)
#endif
#ifndef FILESYSTEM_PREFIX_LEN
@ -38,7 +47,6 @@
ptr = NULL; \
} \
} while (0)
#define strclone(ptr) ((ptr) ? strdup(ptr) : NULL)
static char *basename(const char *name) {
char const *p;
@ -59,14 +67,13 @@ static char *basename(const char *name) {
}
static int mkpath(const char *path) {
const int mode = 0755;
char const *p;
char npath[MAX_PATH + 1] = {0};
int len = 0;
for (p = path; *p && len < MAX_PATH; p++) {
if (ISSLASH(*p) && len > 0) {
if (mkdir(npath, mode) == -1)
if (MKDIR(npath) == -1)
if (errno != EEXIST) return -1;
}
npath[len++] = *p;
@ -165,7 +172,7 @@ int zip_entry_open(struct zip_t *zip, const char *entryname) {
return -1;
}
zip->entry.name = strclone(entryname);
zip->entry.name = STRCLONE(entryname);
if (!zip->entry.name) {
// Cannot parse zip entry name
return -1;
@ -460,7 +467,7 @@ int zip_extract(const char *zipname, const char *dir,
strcpy(path, dir);
if (!ISSLASH(path[dirlen - 1])) {
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
#if defined _WIN32 || defined __WIN32__
path[dirlen] = '\\';
#else
path[dirlen] = '/';
@ -476,7 +483,6 @@ int zip_extract(const char *zipname, const char *dir,
status = -1;
break;
}
strncpy(&path[dirlen], info.m_filename, MAX_PATH - dirlen);
if (mkpath(path) < 0) {
// Cannot make a path