From a2037bdbbdeebcc0ddcc8c8b9211d3d773b00c3b Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Tue, 10 Mar 2015 22:31:09 +0000 Subject: [PATCH] Define one of LFS macros instead of using xxx64 functions directly. There're too many functions and types to consider, and benefits of not using LFS macros aren't that big (I was thinking of using fts(3) but that may not happen soon or at all). --- CMakeLists.txt | 3 ++- cmake/LargeFileSupport.cmake | 33 +++++++++++++++++++++++++++++++++ configure.ac | 1 - libtransmission/file-posix.c | 20 ++++---------------- 4 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 cmake/LargeFileSupport.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f7ab8a7e..a48ffd483 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -351,6 +351,8 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NEEDED_CXX_COMPILER_FLAGS_STRING}") endif() +include(LargeFileSupport) + set(NEEDED_HEADERS stdbool.h sys/statvfs.h @@ -377,7 +379,6 @@ set(NEEDED_FUNCTIONS htonll iconv_open localtime_r - lseek64 memmem mkdtemp ntohll diff --git a/cmake/LargeFileSupport.cmake b/cmake/LargeFileSupport.cmake new file mode 100644 index 000000000..01225e708 --- /dev/null +++ b/cmake/LargeFileSupport.cmake @@ -0,0 +1,33 @@ +# Based on AC_SYS_LARGEFILE + +if(NOT DEFINED NO_LFS_MACROS_REQUIRED) + include(CheckCSourceCompiles) + + # Check that off_t can represent 2**63 - 1 correctly. + # We can't simply define LARGE_OFF_T to be 9223372036854775807, + # since some C++ compilers masquerading as C compilers + # incorrectly reject 9223372036854775807. + set(LFS_TEST_PROGRAM " + #include + #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; + int main() { return 0; } + ") + + check_c_source_compiles("${LFS_TEST_PROGRAM}" NO_LFS_MACROS_REQUIRED) + if(NOT NO_LFS_MACROS_REQUIRED) + if(NOT DEFINED FILE_OFFSET_BITS_LFS_MACRO_REQUIRED) + check_c_source_compiles("#define _FILE_OFFSET_BITS 64 ${LFS_TEST_PROGRAM}" FILE_OFFSET_BITS_LFS_MACRO_REQUIRED) + if(FILE_OFFSET_BITS_LFS_MACRO_REQUIRED) + add_definitions(-D_FILE_OFFSET_BITS=64) + elseif(NOT DEFINED LARGE_FILES_LFS_MACRO_REQUIRED) + check_c_source_compiles("#define _LARGE_FILES 1 ${LFS_TEST_PROGRAM}" LARGE_FILES_LFS_MACRO_REQUIRED) + if(LARGE_FILES_LFS_MACRO_REQUIRED) + add_definitions(-D_LARGE_FILES=1) + endif() + endif() + endif() + endif() + + unset(LFS_TEST_PROGRAM) +endif() diff --git a/configure.ac b/configure.ac index 76272089f..a02f7a122 100644 --- a/configure.ac +++ b/configure.ac @@ -182,7 +182,6 @@ AC_SUBST(CRYPTO_LIBS) AC_SYS_LARGEFILE -AC_CHECK_FUNCS([lseek64]) AC_FUNC_GETMNTENT diff --git a/libtransmission/file-posix.c b/libtransmission/file-posix.c index 2108f84d5..d9469f392 100644 --- a/libtransmission/file-posix.c +++ b/libtransmission/file-posix.c @@ -23,10 +23,6 @@ #define _DARWIN_C_SOURCE #endif -#if !defined (_LARGEFILE64_SOURCE) - #define _LARGEFILE64_SOURCE -#endif - #include #include #include @@ -68,14 +64,6 @@ #define PATH_MAX 4096 #endif -#ifdef HAVE_LSEEK64 - #define tr_off_t off64_t - #define tr_lseek lseek64 -#else - #define tr_off_t off_t - #define tr_lseek lseek -#endif - /* don't use pread/pwrite on old versions of uClibc because they're buggy. * https://trac.transmissionbt.com/ticket/3826 */ #ifdef __UCLIBC__ @@ -542,7 +530,7 @@ tr_sys_file_seek (tr_sys_file_t handle, tr_error ** error) { bool ret = false; - tr_off_t my_new_offset; + off_t my_new_offset; TR_STATIC_ASSERT (TR_SEEK_SET == SEEK_SET, "values should match"); TR_STATIC_ASSERT (TR_SEEK_CUR == SEEK_CUR, "values should match"); @@ -553,7 +541,7 @@ tr_sys_file_seek (tr_sys_file_t handle, assert (handle != TR_BAD_SYS_FILE); assert (origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END); - my_new_offset = tr_lseek (handle, offset, origin); + my_new_offset = lseek (handle, offset, origin); if (my_new_offset != -1) { @@ -624,7 +612,7 @@ tr_sys_file_read_at (tr_sys_file_t handle, #else - if (tr_lseek (handle, offset, SEEK_SET) != -1) + if (lseek (handle, offset, SEEK_SET) != -1) my_bytes_read = read (handle, buffer, size); else my_bytes_read = -1; @@ -700,7 +688,7 @@ tr_sys_file_write_at (tr_sys_file_t handle, #else - if (tr_lseek (handle, offset, SEEK_SET) != -1) + if (lseek (handle, offset, SEEK_SET) != -1) my_bytes_written = write (handle, buffer, size); else my_bytes_written = -1;