]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Support for libc variants without fseeko/ftello
authorVictor Zhang <csv@meta.com>
Thu, 2 Jan 2025 22:02:10 +0000 (14:02 -0800)
committerVictor Zhang <csv@meta.com>
Thu, 2 Jan 2025 22:02:10 +0000 (14:02 -0800)
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
contrib/seekable_format/zstdseek_decompress.c
programs/fileio_common.h
programs/util.h

index b43671cc216b0da6983287ac6a37f99f3d057e59..e03eadb662d4a54635e234b512db7b68360b763d 100644 (file)
@@ -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 ()
index 5ee6e0541a57a91249632991d51b36f891fa4189..7f49798754fcb4ee7e400ceea12185620de22f80 100644 (file)
 /* ************************************************************
 * 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
index 7a014ee4bb14632255d2e6285c6492d9e715c21c..f1eb8160b026a4b90736759b5ab101ff9be0457d 100644 (file)
@@ -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 */
index ec813968446a9bd94f5b5c6721ca955e3cf1de58..e66d95c0862b4a65c1c2ce6a23315c3fc73133ae 100644 (file)
 /*-************************************************************
 *  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