]> granicus.if.org Git - transmission/commitdiff
Define one of LFS macros instead of using xxx64 functions directly.
authorMike Gelfand <mikedld@mikedld.com>
Tue, 10 Mar 2015 22:31:09 +0000 (22:31 +0000)
committerMike Gelfand <mikedld@mikedld.com>
Tue, 10 Mar 2015 22:31:09 +0000 (22:31 +0000)
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
cmake/LargeFileSupport.cmake [new file with mode: 0644]
configure.ac
libtransmission/file-posix.c

index 5f7ab8a7ea28b2b2c048339d8263efbdf88ff5be..a48ffd48393413b7b79844d0f999d1702350ae8b 100644 (file)
@@ -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 (file)
index 0000000..01225e7
--- /dev/null
@@ -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 <sys/types.h>
+        #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()
index 76272089ff67477984093a7d286d02ccd93eeede..a02f7a122fb7a9940414796c80418baa58184243 100644 (file)
@@ -182,7 +182,6 @@ AC_SUBST(CRYPTO_LIBS)
 
 
 AC_SYS_LARGEFILE
-AC_CHECK_FUNCS([lseek64])
 
 AC_FUNC_GETMNTENT
 
index 2108f84d5c4e240574b1639f5d2464d11634cb0a..d9469f392737e746f3b7a2b44f14423a0d8bbc04 100644 (file)
  #define _DARWIN_C_SOURCE
 #endif
 
-#if !defined (_LARGEFILE64_SOURCE)
- #define _LARGEFILE64_SOURCE
-#endif
-
 #include <assert.h>
 #include <dirent.h>
 #include <errno.h>
  #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;