Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build-test-run-reusable-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
runs-on: ${{ inputs.runner }}
name : Test (Target ${{ inputs.target-platform }} - Host ${{ inputs.host-platform }})
needs: build
timeout-minutes: 15
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -62,7 +62,7 @@ jobs:
name: CoDeLibBuildArtifacts-target-${{ inputs.target-platform }}-host-${{ inputs.host-platform }}
path: CoDeLib/Build
- run: |
python -u Scripts/RunTest.py
python -u Scripts/RunTest.py --RunLongTests
- name: 'Upload test results'
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
url = https://github.com/madler/zlib.git
[submodule "External/minizip-ng"]
path = External/minizip-ng
url = https://github.com/zlib-ng/minizip-ng
url = https://github.com/enzoevers/minizip-ng
13 changes: 12 additions & 1 deletion CoDeLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
cmake_minimum_required(VERSION 3.28)
project(COMPRESSION_DECOMPRESSION_LIB VERSION 0.0.1 LANGUAGES C)

add_compile_definitions("$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")

# Required for FileUtils.c (and its tests) to use the correct versions of ftello and similar functions
add_compile_definitions(_FILE_OFFSET_BITS=64)
# The follwing may be interesting in the future
# add_compile_definitions(__USE_LARGEFILE64)
# add_compile_definitions(_LARGEFILE_SOURCE)
# add_compile_definitions(_LARGEFILE64_SOURCE)

include(FetchContent)
include(GNUInstallDirs)

Expand All @@ -20,19 +29,21 @@ set(COMMON_HEADERS
${CoDeLib_PUBLIC_INCLUDE_PATH}/IDeflate.h
${CoDeLib_PUBLIC_INCLUDE_PATH}/IInflate.h
${CoDeLib_PUBLIC_INCLUDE_PATH}/IUnZip.h
${CoDeLib_PUBLIC_INCLUDE_PATH}/IZip.h
)
install(FILES ${COMMON_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CoDeLib)

add_subdirectory(Deflate_zlib)
add_subdirectory(Inflate_zlib)
add_subdirectory(FileUtils)
add_subdirectory(UnZip_minizip)
add_subdirectory(Zip_minizip)
add_subdirectory(RaiiString)
add_subdirectory(ZipContentInfo)
add_subdirectory(Test)

install(
TARGETS CoDeLib Deflate_zlib Inflate_zlib UnZip_minizip RaiiString ZipContentInfo FileUtils
TARGETS CoDeLib Deflate_zlib Inflate_zlib UnZip_minizip Zip_minizip RaiiString ZipContentInfo FileUtils
EXPORT CoDeLibTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
6 changes: 5 additions & 1 deletion CoDeLib/CustomDeflate.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
# refs

- https://pnrsolution.org/Datacenter/Vol4/Issue1/58.pdf
- https://nachtimwald.com/2019/09/08/making-minizip-easier-to-use/
- https://nachtimwald.com/2019/09/08/making-minizip-easier-to-use/
- https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT
- https://github.com/zlib-ng/minizip-ng/blob/cf5404bb714ee11ca2fdc3168d9770a11ec8b576/test/fuzz/zip_fuzzer.c#L100
- https://stackoverflow.com/questions/12609747/traversing-a-filesystem-with-fts3
- https://man7.org/linux/man-pages/man3/alloca.3.html
50 changes: 37 additions & 13 deletions CoDeLib/FileUtils/src/FileUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <assert.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -278,7 +277,7 @@ size_t ExtractLastPartOfPath(const char *const pPath, char *const pDestBuffer,
return SIZE_MAX;
}

const size_t pathLenght = strnlen(pPath, MAX_PATH_LENGTH_WTH_TERMINATOR);
size_t pathLenght = strnlen(pPath, MAX_PATH_LENGTH_WTH_TERMINATOR);
if (pathLenght == 0 || pathLenght == MAX_PATH_LENGTH_WTH_TERMINATOR) {
return SIZE_MAX;
}
Expand All @@ -287,11 +286,25 @@ size_t ExtractLastPartOfPath(const char *const pPath, char *const pDestBuffer,
return SIZE_MAX;
}

char lastChar = pPath[pathLenght - 1];
bool isDir = lastChar == '/' || lastChar == '\\';

if (isDir) {
// Ignore empty sections of the path
for (size_t i = pathLenght - 2; i > 0; --i) {
if (pPath[i] == '/' || pPath[i] == '\\') {
// Assigning again because this may be different from the last
lastChar = pPath[i];
pathLenght--;
} else {
break;
}
}
}

char *pLocalPath = (char *)calloc(pathLenght + 1, sizeof(char));
memcpy(pLocalPath, pPath, pathLenght + 1);

const char lastChar = pLocalPath[pathLenght - 1];
bool isDir = lastChar == '/' || lastChar == '\\';
pLocalPath[pathLenght] = '\0';

if (isDir) {
// Remove the last separator to make getting the file or directory name
Expand Down Expand Up @@ -341,29 +354,40 @@ size_t ExtractLastPartOfPath(const char *const pPath, char *const pDestBuffer,
return startIndexOfNameInPath;
}

void OpenFileWithMode(FILE **pInFile, RaiiString *pFullPath, char *pOpenMode) {
void OpenFileWithMode(FILE **pInFile, const RaiiString *const pFullPath,
const char *const pOpenMode) {
*pInFile = fopen(pFullPath->pString, pOpenMode);
if (*pInFile == NULL) {
printf("Failed to open file: %s\n", pFullPath->pString);
exit(1);
}
}

size_t GetFileSizeInBytes(FILE *pFile) {
fseek(pFile, 0, SEEK_END);
const size_t fileSize = ftell(pFile);
uint64_t GetFileSizeInBytes(FILE *pFile) {
if (pFile == NULL) {
return 0;
}

fseeko(pFile, 0, SEEK_END);
const off_t fileSize = ftello(pFile);
rewind(pFile);

if (fileSize == -1) {
printf("Failed to get file size: %s\n", strerror(errno));
return 0;
}

return fileSize;
}

bool FilesAreEqual(FILE *pFile1, FILE *pFile2) {
const size_t fileSize1 = GetFileSizeInBytes(pFile1);
const size_t fileSize2 = GetFileSizeInBytes(pFile2);
const uint64_t fileSize1 = GetFileSizeInBytes(pFile1);
const uint64_t fileSize2 = GetFileSizeInBytes(pFile2);

if (fileSize1 != fileSize2) {
printf("File sizes not equal:\n");
printf(" fileSize1: %lu\n", (unsigned long)fileSize1);
printf(" fileSize2: %lu\n", (unsigned long)fileSize2);
printf(" fileSize1: %llu\n", (unsigned long long)fileSize1);
printf(" fileSize2: %llu\n", (unsigned long long)fileSize2);
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions CoDeLib/RaiiString/src/RaiiString.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ RaiiString RaiiStringCreateFromCString(const char *pCString) {

RaiiString newRaiistring = {NULL, 0};

if (lengthWithoutTermination == 0 ||
lengthWithoutTermination == MAX_CSTRING_INCLUDING_TERMINATION_LENGTH) {
if (lengthWithoutTermination == MAX_CSTRING_INCLUDING_TERMINATION_LENGTH) {
return newRaiistring;
}

Expand Down
3 changes: 3 additions & 0 deletions CoDeLib/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ add_executable(CoDeLib_Test
src/TestDeflateInflateZlib.c
src/TestFileUtils.c
src/TestUnZipMinizip.c
src/TestZipMinizip.c
src/TestUnZipMinizipInflateZlib.c
src/TestZipMinizipUnZipMinizip.c
src/TestZipContentInfo.c
)

Expand All @@ -27,6 +29,7 @@ target_link_libraries(CoDeLib_Test PRIVATE Deflate_zlib)
target_link_libraries(CoDeLib_Test PRIVATE Inflate_zlib)
target_link_libraries(CoDeLib_Test PRIVATE FileUtils)
target_link_libraries(CoDeLib_Test PRIVATE UnZip_minizip)
target_link_libraries(CoDeLib_Test PRIVATE Zip_minizip)
target_link_libraries(CoDeLib_Test PRIVATE RaiiString)
target_link_libraries(CoDeLib_Test PRIVATE ZipContentInfo)

Expand Down
Loading