From 54c3d998a04a4002697a3a44293074cb01df54a5 Mon Sep 17 00:00:00 2001 From: Victor Zhang Date: Thu, 2 Jan 2025 14:02:10 -0800 Subject: [PATCH 1/4] Support for libc variants without fseeko/ftello Some older Android libc implementations don't support `fseeko` or `ftello`. This commit adds a new compile-time macro `LIBC_NO_FSEEKO` as well as a usage in CMake for old Android APIs. --- build/cmake/CMakeLists.txt | 12 ++++++++++++ contrib/seekable_format/zstdseek_decompress.c | 5 ++++- programs/fileio_common.h | 6 +++++- programs/util.h | 5 ++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index b43671cc21..e03eadb662 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -82,8 +82,19 @@ else () add_definitions(-DZSTD_LEGACY_SUPPORT=0) endif () +get_cmake_property(_variableNames VARIABLES) +list (SORT _variableNames) +foreach (_variableName ${_variableNames}) + message("${_variableName}=${${_variableName}}") +endforeach() + if (ANDROID) set(ZSTD_MULTITHREAD_SUPPORT_DEFAULT OFF) + # Old versions of bionic libc don't have fseeko/ftello + if ((NOT ${ANDROID_PLATFORM_LEVEL}) OR ${ANDROID_PLATFORM_LEVEL} VERSION_LESS 24) + message("Hi Android SDK") + add_compile_definitions(LIBC_NO_FSEEKO) + endif () else() set(ZSTD_MULTITHREAD_SUPPORT_DEFAULT ON) endif() @@ -153,6 +164,7 @@ if (ZSTD_BUILD_PROGRAMS) elseif(NOT ZSTD_BUILD_SHARED AND ZSTD_PROGRAMS_LINK_SHARED) message(SEND_ERROR "You need to build shared library to build zstd CLI") endif () + message("Building program") add_subdirectory(programs) endif () diff --git a/contrib/seekable_format/zstdseek_decompress.c b/contrib/seekable_format/zstdseek_decompress.c index 5ee6e0541a..7f49798754 100644 --- a/contrib/seekable_format/zstdseek_decompress.c +++ b/contrib/seekable_format/zstdseek_decompress.c @@ -77,7 +77,10 @@ /* ************************************************************ * Avoid fseek()'s 2GiB barrier with MSVC, macOS, *BSD, MinGW ***************************************************************/ -#if defined(_MSC_VER) && _MSC_VER >= 1400 +#if defined(LIBC_NO_FSEEKO) +/* Some older libc implementations don't include these functions (e.g. Bionic < 24) */ +#define LONG_SEEK fseek +#elif defined(_MSC_VER) && _MSC_VER >= 1400 # define LONG_SEEK _fseeki64 #elif !defined(__64BIT__) && (PLATFORM_POSIX_VERSION >= 200112L) /* No point defining Large file for 64 bit */ # define LONG_SEEK fseeko diff --git a/programs/fileio_common.h b/programs/fileio_common.h index 7a014ee4bb..f1eb8160b0 100644 --- a/programs/fileio_common.h +++ b/programs/fileio_common.h @@ -79,7 +79,11 @@ extern UTIL_time_t g_displayClock; /* Avoid fseek()'s 2GiB barrier with MSVC, macOS, *BSD, MinGW */ -#if defined(_MSC_VER) && _MSC_VER >= 1400 +#if defined(LIBC_NO_FSEEKO) +/* Some older libc implementations don't include these functions (e.g. Bionic < 24) */ +#define LONG_SEEK fseek +#define LONG_TELL ftell +#elif defined(_MSC_VER) && _MSC_VER >= 1400 # define LONG_SEEK _fseeki64 # define LONG_TELL _ftelli64 #elif !defined(__64BIT__) && (PLATFORM_POSIX_VERSION >= 200112L) /* No point defining Large file for 64 bit */ diff --git a/programs/util.h b/programs/util.h index ec81396844..e66d95c086 100644 --- a/programs/util.h +++ b/programs/util.h @@ -24,7 +24,10 @@ /*-************************************************************ * Fix fseek()'s 2GiB barrier with MSVC, macOS, *BSD, MinGW ***************************************************************/ -#if defined(_MSC_VER) && (_MSC_VER >= 1400) +#if defined(LIBC_NO_FSEEKO) +/* Some older libc implementations don't include these functions (e.g. Bionic < 24) */ +#define UTIL_fseek fseek +#elif defined(_MSC_VER) && (_MSC_VER >= 1400) # define UTIL_fseek _fseeki64 #elif !defined(__64BIT__) && (PLATFORM_POSIX_VERSION >= 200112L) /* No point defining Large file for 64 bit */ # define UTIL_fseek fseeko From 757e29e170565ac48ff7d893a4cc421e0450dd72 Mon Sep 17 00:00:00 2001 From: Victor Zhang Date: Thu, 2 Jan 2025 14:17:24 -0800 Subject: [PATCH 2/4] Oops --- build/cmake/CMakeLists.txt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index e03eadb662..b9003c8678 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -82,17 +82,11 @@ else () add_definitions(-DZSTD_LEGACY_SUPPORT=0) endif () -get_cmake_property(_variableNames VARIABLES) -list (SORT _variableNames) -foreach (_variableName ${_variableNames}) - message("${_variableName}=${${_variableName}}") -endforeach() - if (ANDROID) set(ZSTD_MULTITHREAD_SUPPORT_DEFAULT OFF) # Old versions of bionic libc don't have fseeko/ftello if ((NOT ${ANDROID_PLATFORM_LEVEL}) OR ${ANDROID_PLATFORM_LEVEL} VERSION_LESS 24) - message("Hi Android SDK") + message(STATUS "Setting compile definitions for old Android API") add_compile_definitions(LIBC_NO_FSEEKO) endif () else() @@ -164,7 +158,6 @@ if (ZSTD_BUILD_PROGRAMS) elseif(NOT ZSTD_BUILD_SHARED AND ZSTD_PROGRAMS_LINK_SHARED) message(SEND_ERROR "You need to build shared library to build zstd CLI") endif () - message("Building program") add_subdirectory(programs) endif () From 6b046f58410fe66ea300c31ffc92dbfb4c956bb1 Mon Sep 17 00:00:00 2001 From: Victor Zhang Date: Thu, 2 Jan 2025 15:05:58 -0800 Subject: [PATCH 3/4] PR feedback --- contrib/seekable_format/zstdseek_decompress.c | 2 +- programs/fileio_common.h | 4 ++-- programs/util.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/seekable_format/zstdseek_decompress.c b/contrib/seekable_format/zstdseek_decompress.c index 7f49798754..ab9088a106 100644 --- a/contrib/seekable_format/zstdseek_decompress.c +++ b/contrib/seekable_format/zstdseek_decompress.c @@ -79,7 +79,7 @@ ***************************************************************/ #if defined(LIBC_NO_FSEEKO) /* Some older libc implementations don't include these functions (e.g. Bionic < 24) */ -#define LONG_SEEK fseek +# define LONG_SEEK fseek #elif defined(_MSC_VER) && _MSC_VER >= 1400 # define LONG_SEEK _fseeki64 #elif !defined(__64BIT__) && (PLATFORM_POSIX_VERSION >= 200112L) /* No point defining Large file for 64 bit */ diff --git a/programs/fileio_common.h b/programs/fileio_common.h index f1eb8160b0..0440015069 100644 --- a/programs/fileio_common.h +++ b/programs/fileio_common.h @@ -81,8 +81,8 @@ extern UTIL_time_t g_displayClock; /* Avoid fseek()'s 2GiB barrier with MSVC, macOS, *BSD, MinGW */ #if defined(LIBC_NO_FSEEKO) /* Some older libc implementations don't include these functions (e.g. Bionic < 24) */ -#define LONG_SEEK fseek -#define LONG_TELL ftell +# define LONG_SEEK fseek +# define LONG_TELL ftell #elif defined(_MSC_VER) && _MSC_VER >= 1400 # define LONG_SEEK _fseeki64 # define LONG_TELL _ftelli64 diff --git a/programs/util.h b/programs/util.h index e66d95c086..3a83a50ae3 100644 --- a/programs/util.h +++ b/programs/util.h @@ -26,7 +26,7 @@ ***************************************************************/ #if defined(LIBC_NO_FSEEKO) /* Some older libc implementations don't include these functions (e.g. Bionic < 24) */ -#define UTIL_fseek fseek +# define UTIL_fseek fseek #elif defined(_MSC_VER) && (_MSC_VER >= 1400) # define UTIL_fseek _fseeki64 #elif !defined(__64BIT__) && (PLATFORM_POSIX_VERSION >= 200112L) /* No point defining Large file for 64 bit */ From dfb236b2aa58d3460945f5112e8d5388d7c4a666 Mon Sep 17 00:00:00 2001 From: Victor Zhang Date: Thu, 2 Jan 2025 15:10:40 -0800 Subject: [PATCH 4/4] chore: indentation alignment --- programs/fileio_common.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/programs/fileio_common.h b/programs/fileio_common.h index 0440015069..696626fe47 100644 --- a/programs/fileio_common.h +++ b/programs/fileio_common.h @@ -81,14 +81,14 @@ extern UTIL_time_t g_displayClock; /* Avoid fseek()'s 2GiB barrier with MSVC, macOS, *BSD, MinGW */ #if defined(LIBC_NO_FSEEKO) /* Some older libc implementations don't include these functions (e.g. Bionic < 24) */ -# define LONG_SEEK fseek -# define LONG_TELL ftell +# define LONG_SEEK fseek +# define LONG_TELL ftell #elif defined(_MSC_VER) && _MSC_VER >= 1400 # define LONG_SEEK _fseeki64 # define LONG_TELL _ftelli64 #elif !defined(__64BIT__) && (PLATFORM_POSIX_VERSION >= 200112L) /* No point defining Large file for 64 bit */ -# define LONG_SEEK fseeko -# define LONG_TELL ftello +# define LONG_SEEK fseeko +# define LONG_TELL ftello #elif defined(__MINGW32__) && !defined(__STRICT_ANSI__) && !defined(__NO_MINGW_LFS) && defined(__MSVCRT__) # define LONG_SEEK fseeko64 # define LONG_TELL ftello64