mirror of
https://github.com/QuasarApp/zip.git
synced 2025-04-27 04:54:30 +00:00
Exports symbols of API and hides others symbols (#178)
* exports symbols of API and hides others symbols * fix sanitizers in tests * add export macro in public header
This commit is contained in:
parent
3c0319673c
commit
e43ba3b98f
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -55,7 +55,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Configure
|
||||
run: cmake -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE .
|
||||
run: cmake .
|
||||
- name: Build
|
||||
run: |
|
||||
cmake --build . --config "Debug"
|
||||
@ -68,7 +68,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Configure
|
||||
run: cmake -G "MinGW Makefiles" -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE .
|
||||
run: cmake -G "MinGW Makefiles" .
|
||||
- name: Build
|
||||
run: |
|
||||
mingw32-make
|
||||
|
@ -11,20 +11,18 @@ option(ZIP_STATIC_PIC "Build static zip with PIC" ON)
|
||||
# zip
|
||||
set(SRC src/miniz.h src/zip.h src/zip.c)
|
||||
|
||||
# this is the "object library" target: compiles the sources only once
|
||||
add_library(OBJLIB OBJECT ${SRC})
|
||||
# shared libraries need PIC
|
||||
if(BUILD_SHARED_LIBS OR ZIP_STATIC_PIC)
|
||||
set_property(TARGET OBJLIB PROPERTY POSITION_INDEPENDENT_CODE 1)
|
||||
add_library(${PROJECT_NAME} ${SRC})
|
||||
|
||||
if(ZIP_STATIC_PIC)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE 1)
|
||||
endif()
|
||||
|
||||
# static and shared libraries built from the same object files
|
||||
if (BUILD_SHARED_LIBS)
|
||||
add_library(${PROJECT_NAME} SHARED $<TARGET_OBJECTS:OBJLIB>)
|
||||
include(GenerateExportHeader)
|
||||
generate_export_header(${PROJECT_NAME})
|
||||
else()
|
||||
add_library(${PROJECT_NAME} STATIC $<TARGET_OBJECTS:OBJLIB>)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY C_VISIBILITY_PRESET hidden)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PUBLIC ZIP_SHARED
|
||||
PRIVATE ZIP_BUILD_SHARED
|
||||
)
|
||||
endif()
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
@ -36,8 +34,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
if (NOT CMAKE_DISABLE_TESTING)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
find_package(Sanitizers)
|
||||
add_sanitizers(${PROJECT_NAME} ${test_out})
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
|
88
src/zip.h
88
src/zip.h
@ -15,6 +15,20 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef ZIP_SHARED
|
||||
# define ZIP_EXPORT
|
||||
#else
|
||||
# ifdef _WIN32
|
||||
# ifdef ZIP_BUILD_SHARED
|
||||
# define ZIP_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define ZIP_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define ZIP_EXPORT __attribute__ ((visibility ("default")))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -88,7 +102,7 @@ typedef long ssize_t; /* byte count or error */
|
||||
* @return error message string coresponding to errnum or NULL if error is not
|
||||
* found.
|
||||
*/
|
||||
extern const char *zip_strerror(int errnum);
|
||||
extern ZIP_EXPORT const char *zip_strerror(int errnum);
|
||||
|
||||
/**
|
||||
* @struct zip_t
|
||||
@ -110,14 +124,15 @@ struct zip_t;
|
||||
*
|
||||
* @return the zip archive handler or NULL on error
|
||||
*/
|
||||
extern struct zip_t *zip_open(const char *zipname, int level, char mode);
|
||||
extern ZIP_EXPORT struct zip_t *zip_open(const char *zipname, int level,
|
||||
char mode);
|
||||
|
||||
/**
|
||||
* Closes the zip archive, releases resources - always finalize.
|
||||
*
|
||||
* @param zip zip archive handler.
|
||||
*/
|
||||
extern void zip_close(struct zip_t *zip);
|
||||
extern ZIP_EXPORT void zip_close(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Determines if the archive has a zip64 end of central directory headers.
|
||||
@ -127,7 +142,7 @@ extern void zip_close(struct zip_t *zip);
|
||||
* @return the return code - 1 (true), 0 (false), negative number (< 0) on
|
||||
* error.
|
||||
*/
|
||||
extern int zip_is64(struct zip_t *zip);
|
||||
extern ZIP_EXPORT int zip_is64(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Opens an entry by name in the zip archive.
|
||||
@ -141,7 +156,7 @@ extern int zip_is64(struct zip_t *zip);
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_entry_open(struct zip_t *zip, const char *entryname);
|
||||
extern ZIP_EXPORT int zip_entry_open(struct zip_t *zip, const char *entryname);
|
||||
|
||||
/**
|
||||
* Opens a new entry by index in the zip archive.
|
||||
@ -153,7 +168,7 @@ extern int zip_entry_open(struct zip_t *zip, const char *entryname);
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_entry_openbyindex(struct zip_t *zip, int index);
|
||||
extern ZIP_EXPORT int zip_entry_openbyindex(struct zip_t *zip, int index);
|
||||
|
||||
/**
|
||||
* Closes a zip entry, flushes buffer and releases resources.
|
||||
@ -162,7 +177,7 @@ extern int zip_entry_openbyindex(struct zip_t *zip, int index);
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_entry_close(struct zip_t *zip);
|
||||
extern ZIP_EXPORT int zip_entry_close(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Returns a local name of the current zip entry.
|
||||
@ -178,7 +193,7 @@ extern int zip_entry_close(struct zip_t *zip);
|
||||
*
|
||||
* @return the pointer to the current zip entry name, or NULL on error.
|
||||
*/
|
||||
extern const char *zip_entry_name(struct zip_t *zip);
|
||||
extern ZIP_EXPORT const char *zip_entry_name(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Returns an index of the current zip entry.
|
||||
@ -187,7 +202,7 @@ extern const char *zip_entry_name(struct zip_t *zip);
|
||||
*
|
||||
* @return the index on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_entry_index(struct zip_t *zip);
|
||||
extern ZIP_EXPORT int zip_entry_index(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Determines if the current zip entry is a directory entry.
|
||||
@ -197,7 +212,7 @@ extern int zip_entry_index(struct zip_t *zip);
|
||||
* @return the return code - 1 (true), 0 (false), negative number (< 0) on
|
||||
* error.
|
||||
*/
|
||||
extern int zip_entry_isdir(struct zip_t *zip);
|
||||
extern ZIP_EXPORT int zip_entry_isdir(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Returns an uncompressed size of the current zip entry.
|
||||
@ -206,7 +221,7 @@ extern int zip_entry_isdir(struct zip_t *zip);
|
||||
*
|
||||
* @return the uncompressed size in bytes.
|
||||
*/
|
||||
extern unsigned long long zip_entry_size(struct zip_t *zip);
|
||||
extern ZIP_EXPORT unsigned long long zip_entry_size(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Returns CRC-32 checksum of the current zip entry.
|
||||
@ -215,7 +230,7 @@ extern unsigned long long zip_entry_size(struct zip_t *zip);
|
||||
*
|
||||
* @return the CRC-32 checksum.
|
||||
*/
|
||||
extern unsigned int zip_entry_crc32(struct zip_t *zip);
|
||||
extern ZIP_EXPORT unsigned int zip_entry_crc32(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Compresses an input buffer for the current zip entry.
|
||||
@ -226,7 +241,8 @@ extern unsigned int zip_entry_crc32(struct zip_t *zip);
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_entry_write(struct zip_t *zip, const void *buf, size_t bufsize);
|
||||
extern ZIP_EXPORT int zip_entry_write(struct zip_t *zip, const void *buf,
|
||||
size_t bufsize);
|
||||
|
||||
/**
|
||||
* Compresses a file for the current zip entry.
|
||||
@ -236,7 +252,7 @@ extern int zip_entry_write(struct zip_t *zip, const void *buf, size_t bufsize);
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_entry_fwrite(struct zip_t *zip, const char *filename);
|
||||
extern ZIP_EXPORT int zip_entry_fwrite(struct zip_t *zip, const char *filename);
|
||||
|
||||
/**
|
||||
* Extracts the current zip entry into output buffer.
|
||||
@ -253,7 +269,8 @@ extern int zip_entry_fwrite(struct zip_t *zip, const char *filename);
|
||||
* @return the return code - the number of bytes actually read on success.
|
||||
* Otherwise a -1 on error.
|
||||
*/
|
||||
extern ssize_t zip_entry_read(struct zip_t *zip, void **buf, size_t *bufsize);
|
||||
extern ZIP_EXPORT ssize_t zip_entry_read(struct zip_t *zip, void **buf,
|
||||
size_t *bufsize);
|
||||
|
||||
/**
|
||||
* Extracts the current zip entry into a memory buffer using no memory
|
||||
@ -271,8 +288,8 @@ extern ssize_t zip_entry_read(struct zip_t *zip, void **buf, size_t *bufsize);
|
||||
* @return the return code - the number of bytes actually read on success.
|
||||
* Otherwise a -1 on error (e.g. bufsize is not large enough).
|
||||
*/
|
||||
extern ssize_t zip_entry_noallocread(struct zip_t *zip, void *buf,
|
||||
size_t bufsize);
|
||||
extern ZIP_EXPORT ssize_t zip_entry_noallocread(struct zip_t *zip, void *buf,
|
||||
size_t bufsize);
|
||||
|
||||
/**
|
||||
* Extracts the current zip entry into output file.
|
||||
@ -282,7 +299,7 @@ extern ssize_t zip_entry_noallocread(struct zip_t *zip, void *buf,
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_entry_fread(struct zip_t *zip, const char *filename);
|
||||
extern ZIP_EXPORT int zip_entry_fread(struct zip_t *zip, const char *filename);
|
||||
|
||||
/**
|
||||
* Extracts the current zip entry using a callback function (on_extract).
|
||||
@ -294,7 +311,7 @@ extern int zip_entry_fread(struct zip_t *zip, const char *filename);
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int
|
||||
extern ZIP_EXPORT int
|
||||
zip_entry_extract(struct zip_t *zip,
|
||||
size_t (*on_extract)(void *arg, unsigned long long offset,
|
||||
const void *data, size_t size),
|
||||
@ -308,7 +325,7 @@ zip_entry_extract(struct zip_t *zip,
|
||||
* @return the return code - the number of entries on success, negative number
|
||||
* (< 0) on error.
|
||||
*/
|
||||
extern int zip_entries_total(struct zip_t *zip);
|
||||
extern ZIP_EXPORT int zip_entries_total(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Deletes zip archive entries.
|
||||
@ -318,8 +335,8 @@ extern int zip_entries_total(struct zip_t *zip);
|
||||
* @param len the number of entries to be deleted.
|
||||
* @return the number of deleted entries, or negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_entries_delete(struct zip_t *zip, char *const entries[],
|
||||
size_t len);
|
||||
extern ZIP_EXPORT int zip_entries_delete(struct zip_t *zip,
|
||||
char *const entries[], size_t len);
|
||||
|
||||
/**
|
||||
* Extracts a zip archive stream into directory.
|
||||
@ -338,10 +355,10 @@ extern int zip_entries_delete(struct zip_t *zip, char *const entries[],
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_stream_extract(const char *stream, size_t size, const char *dir,
|
||||
int (*on_extract)(const char *filename,
|
||||
void *arg),
|
||||
void *arg);
|
||||
extern ZIP_EXPORT int
|
||||
zip_stream_extract(const char *stream, size_t size, const char *dir,
|
||||
int (*on_extract)(const char *filename, void *arg),
|
||||
void *arg);
|
||||
|
||||
/**
|
||||
* Opens zip archive stream into memory.
|
||||
@ -351,8 +368,8 @@ extern int zip_stream_extract(const char *stream, size_t size, const char *dir,
|
||||
*
|
||||
* @return the zip archive handler or NULL on error
|
||||
*/
|
||||
extern struct zip_t *zip_stream_open(const char *stream, size_t size, int level,
|
||||
char mode);
|
||||
extern ZIP_EXPORT struct zip_t *zip_stream_open(const char *stream, size_t size,
|
||||
int level, char mode);
|
||||
|
||||
/**
|
||||
* Copy zip archive stream output buffer.
|
||||
@ -363,7 +380,8 @@ extern struct zip_t *zip_stream_open(const char *stream, size_t size, int level,
|
||||
*
|
||||
* @return copy size
|
||||
*/
|
||||
extern ssize_t zip_stream_copy(struct zip_t *zip, void **buf, ssize_t *bufsize);
|
||||
extern ZIP_EXPORT ssize_t zip_stream_copy(struct zip_t *zip, void **buf,
|
||||
ssize_t *bufsize);
|
||||
|
||||
/**
|
||||
* Close zip archive releases resources.
|
||||
@ -372,7 +390,7 @@ extern ssize_t zip_stream_copy(struct zip_t *zip, void **buf, ssize_t *bufsize);
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
extern void zip_stream_close(struct zip_t *zip);
|
||||
extern ZIP_EXPORT void zip_stream_close(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Creates a new archive and puts files into a single zip archive.
|
||||
@ -383,7 +401,8 @@ extern void zip_stream_close(struct zip_t *zip);
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_create(const char *zipname, const char *filenames[], size_t len);
|
||||
extern ZIP_EXPORT int zip_create(const char *zipname, const char *filenames[],
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* Extracts a zip archive file into directory.
|
||||
@ -401,9 +420,10 @@ extern int zip_create(const char *zipname, const char *filenames[], size_t len);
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_extract(const char *zipname, const char *dir,
|
||||
int (*on_extract_entry)(const char *filename, void *arg),
|
||||
void *arg);
|
||||
extern ZIP_EXPORT int zip_extract(const char *zipname, const char *dir,
|
||||
int (*on_extract_entry)(const char *filename,
|
||||
void *arg),
|
||||
void *arg);
|
||||
|
||||
/** @} */
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,38 +1,40 @@
|
||||
cmake_minimum_required(VERSION 3.4)
|
||||
|
||||
find_package(Sanitizers)
|
||||
|
||||
# tests
|
||||
set(test_write_out test_write.out)
|
||||
add_executable(${test_write_out} test_write.c)
|
||||
target_link_libraries(${test_write_out} zip)
|
||||
add_test(NAME ${test_write_out} COMMAND ${test_write_out})
|
||||
set(test_write_out ${test_write_out} PARENT_SCOPE)
|
||||
add_sanitizers(${test_write_out})
|
||||
|
||||
set(test_append_out test_append.out)
|
||||
add_executable(${test_append_out} test_append.c)
|
||||
target_link_libraries(${test_append_out} zip)
|
||||
add_test(NAME ${test_append_out} COMMAND ${test_append_out})
|
||||
set(test_append_out ${test_append_out} PARENT_SCOPE)
|
||||
add_sanitizers(${test_append_out})
|
||||
|
||||
set(test_read_out test_read.out)
|
||||
add_executable(${test_read_out} test_read.c)
|
||||
target_link_libraries(${test_read_out} zip)
|
||||
add_test(NAME ${test_read_out} COMMAND ${test_read_out})
|
||||
set(test_read_out ${test_read_out} PARENT_SCOPE)
|
||||
add_sanitizers(${test_read_out})
|
||||
|
||||
set(test_extract_out test_extract.out)
|
||||
add_executable(${test_extract_out} test_extract.c)
|
||||
target_link_libraries(${test_extract_out} zip)
|
||||
add_test(NAME ${test_extract_out} COMMAND ${test_extract_out})
|
||||
set(test_extract_out ${test_extract_out} PARENT_SCOPE)
|
||||
add_sanitizers(${test_extract_out})
|
||||
|
||||
set(test_entry_out test_entry.out)
|
||||
add_executable(${test_entry_out} test_entry.c)
|
||||
target_link_libraries(${test_entry_out} zip)
|
||||
add_test(NAME ${test_entry_out} COMMAND ${test_entry_out})
|
||||
set(test_entry_out ${test_entry_out} PARENT_SCOPE)
|
||||
add_sanitizers(${test_entry_out})
|
||||
|
||||
set(test_permissions_out test_permissions.out)
|
||||
add_executable(${test_permissions_out} test_permissions.c)
|
||||
target_link_libraries(${test_permissions_out} zip)
|
||||
add_test(NAME ${test_permissions_out} COMMAND ${test_permissions_out})
|
||||
set(test_permissions_out ${test_permissions_out} PARENT_SCOPE)
|
||||
add_sanitizers(${test_permissions_out})
|
||||
|
Loading…
x
Reference in New Issue
Block a user