Skip to content

Commit 734de4b

Browse files
committed
Enable Large File Support
This enables 64-bit off_t where it's opt-in (e.g. glibc) on 32-bit platforms. Crib the CMake module from libpcap as well to handle CMake, while we use AC_SYS_LARGEFILE for autotools. Bug: https://bugs.gentoo.org/911176 Signed-off-by: Sam James <[email protected]>
1 parent 80aedf3 commit 734de4b

File tree

4 files changed

+168
-1
lines changed

4 files changed

+168
-1
lines changed

CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,19 @@ cmake_pop_check_state()
632632
# so we use check_struct_has_member() and look for ss_family.
633633
#
634634

635+
#
636+
# Large file support on UN*X, a/k/a LFS.
637+
#
638+
if(NOT WIN32)
639+
include(FindLFS)
640+
if(LFS_FOUND)
641+
#
642+
# Add the required #defines.
643+
#
644+
add_definitions(${LFS_DEFINITIONS})
645+
endif()
646+
endif()
647+
635648
######################################
636649
# External dependencies
637650
######################################

Makefile.in

+1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ EXTRA_DIST = \
349349
atime.awk \
350350
bpf_dump.c \
351351
cmake/Modules/FindCRYPTO.cmake \
352+
cmake/Modules/FindLFS.cmake \
352353
cmake/Modules/FindPCAP.cmake \
353354
cmake/Modules/FindSMI.cmake \
354355
cmake_uninstall.cmake.in \

cmake/Modules/FindLFS.cmake

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# CMake support for large files
2+
#
3+
# Copyright (C) 2016 Julian Andres Klode <[email protected]>.
4+
#
5+
# Permission is hereby granted, free of charge, to any person
6+
# obtaining a copy of this software and associated documentation files
7+
# (the "Software"), to deal in the Software without restriction,
8+
# including without limitation the rights to use, copy, modify, merge,
9+
# publish, distribute, sublicense, and/or sell copies of the Software,
10+
# and to permit persons to whom the Software is furnished to do so,
11+
# subject to the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be
14+
# included in all copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20+
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21+
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
# This defines the following variables
26+
#
27+
# LFS_DEFINITIONS - List of definitions to pass to add_definitions()
28+
# LFS_COMPILE_OPTIONS - List of definitions to pass to add_compile_options()
29+
# LFS_LIBRARIES - List of libraries and linker flags
30+
# LFS_FOUND - If there is Large files support
31+
#
32+
33+
include(CheckCSourceCompiles)
34+
include(FindPackageHandleStandardArgs)
35+
include(CMakePushCheckState)
36+
37+
# Test program to check for LFS. Requires that off_t has at least 8 byte large
38+
set(_lfs_test_source
39+
"
40+
#include <sys/types.h>
41+
typedef char my_static_assert[sizeof(off_t) >= 8 ? 1 : -1];
42+
int main(void) { return 0; }
43+
"
44+
)
45+
46+
# Check if the given options are needed
47+
#
48+
# This appends to the variables _lfs_cppflags, _lfs_cflags, and _lfs_ldflags,
49+
# it also sets LFS_FOUND to 1 if it works.
50+
function(_lfs_check_compiler_option var options definitions libraries)
51+
cmake_push_check_state()
52+
set(CMAKE_REQUIRED_QUIET 1)
53+
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${options})
54+
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ${definitions})
55+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_DEFINITIONS} ${libraries})
56+
57+
message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries}")
58+
check_c_source_compiles("${_lfs_test_source}" ${var})
59+
cmake_pop_check_state()
60+
61+
if(${var})
62+
message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries} - found")
63+
set(_lfs_cppflags ${_lfs_cppflags} ${definitions} PARENT_SCOPE)
64+
set(_lfs_cflags ${_lfs_cflags} ${options} PARENT_SCOPE)
65+
set(_lfs_ldflags ${_lfs_ldflags} ${libraries} PARENT_SCOPE)
66+
set(LFS_FOUND TRUE PARENT_SCOPE)
67+
else()
68+
message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries} - not found")
69+
endif()
70+
endfunction()
71+
72+
# Check for the availability of LFS.
73+
# The cases handled are:
74+
#
75+
# * Native LFS
76+
# * Output of getconf LFS_CFLAGS; getconf LFS_LIBS; getconf LFS_LDFLAGS
77+
# * Preprocessor flag -D_FILE_OFFSET_BITS=64
78+
# * Preprocessor flag -D_LARGE_FILES
79+
#
80+
function(_lfs_check)
81+
set(_lfs_cflags)
82+
set(_lfs_cppflags)
83+
set(_lfs_ldflags)
84+
set(_lfs_libs)
85+
cmake_push_check_state()
86+
set(CMAKE_REQUIRED_QUIET 1)
87+
message(STATUS "Looking for native LFS support")
88+
check_c_source_compiles("${_lfs_test_source}" lfs_native)
89+
cmake_pop_check_state()
90+
if (lfs_native)
91+
message(STATUS "Looking for native LFS support - found")
92+
set(LFS_FOUND TRUE)
93+
else()
94+
message(STATUS "Looking for native LFS support - not found")
95+
endif()
96+
97+
if (NOT LFS_FOUND)
98+
# Check using getconf. If getconf fails, don't worry, the check in
99+
# _lfs_check_compiler_option will fail as well.
100+
execute_process(COMMAND getconf LFS_CFLAGS
101+
OUTPUT_VARIABLE _lfs_cflags_raw
102+
OUTPUT_STRIP_TRAILING_WHITESPACE
103+
ERROR_QUIET)
104+
execute_process(COMMAND getconf LFS_LIBS
105+
OUTPUT_VARIABLE _lfs_libs_tmp
106+
OUTPUT_STRIP_TRAILING_WHITESPACE
107+
ERROR_QUIET)
108+
execute_process(COMMAND getconf LFS_LDFLAGS
109+
OUTPUT_VARIABLE _lfs_ldflags_tmp
110+
OUTPUT_STRIP_TRAILING_WHITESPACE
111+
ERROR_QUIET)
112+
113+
separate_arguments(_lfs_cflags_raw)
114+
separate_arguments(_lfs_ldflags_tmp)
115+
separate_arguments(_lfs_libs_tmp)
116+
117+
# Move -D flags to the place they are supposed to be
118+
foreach(flag ${_lfs_cflags_raw})
119+
if (flag MATCHES "-D.*")
120+
list(APPEND _lfs_cppflags_tmp ${flag})
121+
else()
122+
list(APPEND _lfs_cflags_tmp ${flag})
123+
endif()
124+
endforeach()
125+
126+
# Check if the flags we received (if any) produce working LFS support
127+
_lfs_check_compiler_option(lfs_getconf_works
128+
"${_lfs_cflags_tmp}"
129+
"${_lfs_cppflags_tmp}"
130+
"${_lfs_libs_tmp};${_lfs_ldflags_tmp}")
131+
endif()
132+
133+
if(NOT LFS_FOUND) # IRIX stuff
134+
_lfs_check_compiler_option(lfs_need_n32 "-n32" "" "")
135+
endif()
136+
if(NOT LFS_FOUND) # Linux and friends
137+
_lfs_check_compiler_option(lfs_need_file_offset_bits "" "-D_FILE_OFFSET_BITS=64" "")
138+
endif()
139+
if(NOT LFS_FOUND) # AIX
140+
_lfs_check_compiler_option(lfs_need_large_files "" "-D_LARGE_FILES=1" "")
141+
endif()
142+
143+
set(LFS_DEFINITIONS ${_lfs_cppflags} CACHE STRING "Extra definitions for large file support")
144+
set(LFS_COMPILE_OPTIONS ${_lfs_cflags} CACHE STRING "Extra definitions for large file support")
145+
set(LFS_LIBRARIES ${_lfs_libs} ${_lfs_ldflags} CACHE STRING "Extra definitions for large file support")
146+
set(LFS_FOUND ${LFS_FOUND} CACHE INTERNAL "Found LFS")
147+
endfunction()
148+
149+
if (NOT LFS_FOUND)
150+
_lfs_check()
151+
endif()
152+
153+
find_package_handle_standard_args(LFS "Could not find LFS. Set LFS_DEFINITIONS, LFS_COMPILE_OPTIONS, LFS_LIBRARIES." LFS_FOUND)

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if test "$ac_cv_prog_cc_c99" = "no"; then
3030
fi
3131
AC_LBL_C_INIT(V_CCOPT, V_INCLS)
3232
AC_C_INLINE
33-
33+
AC_SYS_LARGEFILE
3434
AC_CHECK_HEADERS(fcntl.h rpc/rpc.h rpc/rpcent.h net/if.h)
3535

3636
case "$host_os" in

0 commit comments

Comments
 (0)