cmake: on UNIX systems force 64b overrides of stat(), fstat(), ...

This commit is contained in:
Hugues Delorme 2015-04-03 15:12:58 +02:00
parent 4fe921c11a
commit 0f5141979a
2 changed files with 34 additions and 10 deletions

View File

@ -62,14 +62,47 @@ if(NOT BUILD_STRICT_C90)
check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H)
# Check POSIX features
if(UNIX)
# See:
# http://linux.die.net/man/2/fstat64
# https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fstat.2.html
# https://www.gnu.org/software/libc/manual/html_mono/libc.html#Feature-Test-Macros
if(APPLE)
add_definitions(-D_DARWIN_USE_64_BIT_INODE)
else()
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
endif()
endif()
check_include_files(sys/types.h GMIO_HAVE_SYS_TYPES_H)
check_include_files(sys/stat.h GMIO_HAVE_SYS_STAT_H)
check_function_exists(fileno GMIO_HAVE_POSIX_FILENO_FUNC)
check_function_exists(fstat64 GMIO_HAVE_POSIX_FSTAT64_FUNC)
# Have POSIX fstat64() ?
check_c_source_compiles(
"#include <sys/stat.h>
int main() { fstat64(0, NULL); return 0; }"
GMIO_HAVE_POSIX_FSTAT64_FUNC)
if(WIN32)
check_function_exists(_fstat64 GMIO_HAVE_WIN__FSTAT64_FUNC)
endif()
# Check sizeof(struct stat[64])
set(CMAKE_EXTRA_INCLUDE_FILES sys/stat.h)
if(GMIO_HAVE_WIN__FSTAT64_FUNC)
check_type_size("((struct _stat64*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE)
elsif(GMIO_HAVE_POSIX_FSTAT64_FUNC)
check_type_size("((struct stat64*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE)
else()
check_type_size("((struct stat*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE)
endif()
set(CMAKE_EXTRA_INCLUDE_FILES)
if(GMIO_HAVE_SYS_STAT_H
AND NOT(GMIO_SIZEOF_STRUCT_STAT_ST_SIZE STREQUAL "0") # Not arch-dependent size
AND NOT(GMIO_SIZEOF_STRUCT_STAT_ST_SIZE EQUAL 8))
message(WARNING "<sys/stat.h> does not provide 64b variant of fstat(), you may encounter problems with files > 2GB")
endif()
# Have BSD-like alloca() function ?
check_c_source_compiles(
"#include <alloca.h>

View File

@ -20,15 +20,6 @@
#include <stdlib.h>
#if defined(GMIO_HAVE_SYS_TYPES_H) && defined(GMIO_HAVE_SYS_STAT_H)
/* For some platforms maybe it's better to override stat(), fstat(), etc. with
* 64bit variants. See:
* http://linux.die.net/man/2/fstat64
* #define _FILE_OFFSET_BITS 64
* https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fstat.2.html
* #define _DARWIN_USE_64_BIT_INODE
*/
# include <sys/types.h>
# include <sys/stat.h>