mirror of
https://github.com/QuasarApp/zip.git
synced 2025-04-28 21:34:32 +00:00
[CMakeLists.txt] Set C89; [src/zip.c] C89-compatibility (resolves: "GCC does not allow variable declarations in for loop initializers before C99") (#212)
This commit is contained in:
parent
326d8c2e33
commit
58bde05a12
@ -39,6 +39,7 @@ if (NOT CMAKE_DISABLE_TESTING)
|
|||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 90)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
# Use secure functions by default and suppress warnings about "deprecated" functions
|
# Use secure functions by default 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=1")
|
||||||
@ -47,7 +48,7 @@ if (MSVC)
|
|||||||
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
|
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
|
||||||
"${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
|
||||||
"${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wextra -Werror -pedantic -Wno-deprecated")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -pedantic")
|
||||||
endif (MSVC)
|
endif (MSVC)
|
||||||
|
|
||||||
####
|
####
|
||||||
|
29
src/zip.c
29
src/zip.c
@ -422,12 +422,15 @@ static ssize_t zip_entry_mark(struct zip_t *zip,
|
|||||||
}
|
}
|
||||||
|
|
||||||
mz_bool name_matches = MZ_FALSE;
|
mz_bool name_matches = MZ_FALSE;
|
||||||
for (int j = 0; j < (const int)len; ++j) {
|
{
|
||||||
|
size_t j;
|
||||||
|
for (j = 0; j < len; ++j) {
|
||||||
if (zip_name_match(zip->entry.name, entries[j])) {
|
if (zip_name_match(zip->entry.name, entries[j])) {
|
||||||
name_matches = MZ_TRUE;
|
name_matches = MZ_TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (name_matches) {
|
if (name_matches) {
|
||||||
entry_mark[i].type = MZ_DELETE;
|
entry_mark[i].type = MZ_DELETE;
|
||||||
} else {
|
} else {
|
||||||
@ -459,8 +462,8 @@ static ssize_t zip_entry_mark(struct zip_t *zip,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int zip_index_next(mz_uint64 *local_header_ofs_array, int cur_index) {
|
static int zip_index_next(mz_uint64 *local_header_ofs_array, int cur_index) {
|
||||||
int new_index = 0;
|
int new_index = 0, i;
|
||||||
for (int i = cur_index - 1; i >= 0; --i) {
|
for (i = cur_index - 1; i >= 0; --i) {
|
||||||
if (local_header_ofs_array[cur_index] > local_header_ofs_array[i]) {
|
if (local_header_ofs_array[cur_index] > local_header_ofs_array[i]) {
|
||||||
new_index = i + 1;
|
new_index = i + 1;
|
||||||
return new_index;
|
return new_index;
|
||||||
@ -474,7 +477,8 @@ static int zip_sort(mz_uint64 *local_header_ofs_array, int cur_index) {
|
|||||||
|
|
||||||
if (nxt_index != cur_index) {
|
if (nxt_index != cur_index) {
|
||||||
mz_uint64 temp = local_header_ofs_array[cur_index];
|
mz_uint64 temp = local_header_ofs_array[cur_index];
|
||||||
for (int i = cur_index; i > nxt_index; i--) {
|
int i;
|
||||||
|
for (i = cur_index; i > nxt_index; i--) {
|
||||||
local_header_ofs_array[i] = local_header_ofs_array[i - 1];
|
local_header_ofs_array[i] = local_header_ofs_array[i - 1];
|
||||||
}
|
}
|
||||||
local_header_ofs_array[nxt_index] = temp;
|
local_header_ofs_array[nxt_index] = temp;
|
||||||
@ -484,7 +488,8 @@ static int zip_sort(mz_uint64 *local_header_ofs_array, int cur_index) {
|
|||||||
|
|
||||||
static int zip_index_update(struct zip_entry_mark_t *entry_mark, int last_index,
|
static int zip_index_update(struct zip_entry_mark_t *entry_mark, int last_index,
|
||||||
int nxt_index) {
|
int nxt_index) {
|
||||||
for (int j = 0; j < last_index; j++) {
|
int j;
|
||||||
|
for (j = 0; j < last_index; j++) {
|
||||||
if (entry_mark[j].file_index >= nxt_index) {
|
if (entry_mark[j].file_index >= nxt_index) {
|
||||||
entry_mark[j].file_index += 1;
|
entry_mark[j].file_index += 1;
|
||||||
}
|
}
|
||||||
@ -637,19 +642,25 @@ static int zip_central_dir_move(mz_zip_internal_state *pState, int begin,
|
|||||||
if (l_size == 0) {
|
if (l_size == 0) {
|
||||||
memmove(pState->m_central_dir.m_p, next, r_size);
|
memmove(pState->m_central_dir.m_p, next, r_size);
|
||||||
pState->m_central_dir.m_p = MZ_REALLOC(pState->m_central_dir.m_p, r_size);
|
pState->m_central_dir.m_p = MZ_REALLOC(pState->m_central_dir.m_p, r_size);
|
||||||
for (int i = end; i < entry_num; i++) {
|
{
|
||||||
|
int i;
|
||||||
|
for (i = end; i < entry_num; i++) {
|
||||||
MZ_ZIP_ARRAY_ELEMENT(&pState->m_central_dir_offsets, mz_uint32, i) -=
|
MZ_ZIP_ARRAY_ELEMENT(&pState->m_central_dir_offsets, mz_uint32, i) -=
|
||||||
d_size;
|
d_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (l_size * r_size != 0) {
|
if (l_size * r_size != 0) {
|
||||||
memmove(deleted, next, r_size);
|
memmove(deleted, next, r_size);
|
||||||
for (int i = end; i < entry_num; i++) {
|
{
|
||||||
|
int i;
|
||||||
|
for (i = end; i < entry_num; i++) {
|
||||||
MZ_ZIP_ARRAY_ELEMENT(&pState->m_central_dir_offsets, mz_uint32, i) -=
|
MZ_ZIP_ARRAY_ELEMENT(&pState->m_central_dir_offsets, mz_uint32, i) -=
|
||||||
d_size;
|
d_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pState->m_central_dir.m_size = l_size + r_size;
|
pState->m_central_dir.m_size = l_size + r_size;
|
||||||
return 0;
|
return 0;
|
||||||
@ -688,8 +699,8 @@ static int zip_central_dir_delete(mz_zip_internal_state *pState,
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
end = i;
|
end = i;
|
||||||
int k = 0;
|
int k = 0, j;
|
||||||
for (int j = end; j < entry_num; j++) {
|
for (j = end; j < entry_num; j++) {
|
||||||
MZ_ZIP_ARRAY_ELEMENT(&pState->m_central_dir_offsets, mz_uint32,
|
MZ_ZIP_ARRAY_ELEMENT(&pState->m_central_dir_offsets, mz_uint32,
|
||||||
begin + k) =
|
begin + k) =
|
||||||
(mz_uint32)MZ_ZIP_ARRAY_ELEMENT(&pState->m_central_dir_offsets,
|
(mz_uint32)MZ_ZIP_ARRAY_ELEMENT(&pState->m_central_dir_offsets,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user