This commit is contained in:
Hugues Delorme 2015-04-03 15:16:18 +02:00
commit b92c0502e9
5 changed files with 31 additions and 60 deletions

View File

@ -62,26 +62,45 @@ if(NOT BUILD_STRICT_C90)
check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H) check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H)
# Check POSIX features # 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/types.h GMIO_HAVE_SYS_TYPES_H)
check_include_files(sys/stat.h GMIO_HAVE_SYS_STAT_H) check_include_files(sys/stat.h GMIO_HAVE_SYS_STAT_H)
check_function_exists(fileno GMIO_HAVE_POSIX_FILENO_FUNC) 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) if(WIN32)
check_function_exists(_fstat64 GMIO_HAVE_WIN__FSTAT64_FUNC) check_function_exists(_fstat64 GMIO_HAVE_WIN__FSTAT64_FUNC)
endif() endif()
# Have BSD-like alloca() function ? # Check sizeof(struct stat[64])
check_c_source_compiles( set(CMAKE_EXTRA_INCLUDE_FILES sys/stat.h)
"#include <alloca.h> if(GMIO_HAVE_WIN__FSTAT64_FUNC)
int main() { void* ptr = alloca(256); return 0; }" check_type_size("((struct _stat64*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE)
GMIO_HAVE_BSD_ALLOCA_FUNC) 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)
# Have Win32 _alloca() function ? if(GMIO_HAVE_SYS_STAT_H
if(WIN32) AND NOT(GMIO_SIZEOF_STRUCT_STAT_ST_SIZE STREQUAL "0") # Not arch-dependent size
check_c_source_compiles( AND NOT(GMIO_SIZEOF_STRUCT_STAT_ST_SIZE EQUAL 8))
"#include <malloc.h> message(WARNING "<sys/stat.h> does not provide 64b variant of fstat(), you may encounter problems with files > 2GB")
int main() { void* ptr = _alloca(256); return 0; }"
GMIO_HAVE_WIN__ALLOCA_FUNC)
endif() endif()
# Have builtin byte swap functions ? # Have builtin byte swap functions ?

View File

@ -17,14 +17,6 @@
#include <stdlib.h> #include <stdlib.h>
#if defined(GMIO_HAVE_BSD_ALLOCA_FUNC)
# include <alloca.h>
#elif defined(GMIO_HAVE_WIN__ALLOCA_FUNC)
# include "error.h"
# include <windows.h>
# include <malloc.h>
#endif
GMIO_INLINE gmio_buffer_t gmio_buffer_null() GMIO_INLINE gmio_buffer_t gmio_buffer_null()
{ {
gmio_buffer_t buff = { 0 }; gmio_buffer_t buff = { 0 };
@ -56,30 +48,6 @@ gmio_buffer_t gmio_buffer_realloc(void* ptr, size_t size)
return gmio_buffer(realloc(ptr, size), size, &free); return gmio_buffer(realloc(ptr, size), size, &free);
} }
gmio_buffer_t gmio_buffer_alloca(size_t size)
{
#if defined(GMIO_HAVE_BSD_ALLOCA_FUNC)
return gmio_buffer(alloca(size), size, NULL);
#elif defined(GMIO_HAVE_WIN__ALLOCA_FUNC)
# ifdef _MSC_VER
__try {
return gmio_buffer(_alloca(size), size, NULL);
}
__except(GetExceptionCode() == STATUS_STACK_OVERFLOW) {
/* The stack overflowed */
if (_resetstkoflw() == 0)
exit(GMIO_ERROR_UNKNOWN);
return gmio_buffer_null();
}
# else
return gmio_buffer(_alloca(size), size, NULL);
# endif /* _MSC_VER */
#else
GMIO_UNUSED(size);
return gmio_buffer_null();
#endif
}
void gmio_buffer_deallocate(gmio_buffer_t *buffer) void gmio_buffer_deallocate(gmio_buffer_t *buffer)
{ {
if (buffer != NULL && buffer->deallocate_func != NULL) if (buffer != NULL && buffer->deallocate_func != NULL)

View File

@ -57,9 +57,6 @@ GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_calloc(size_t num, size_t size);
/*! Returns a gmio_buffer object allocated with standard \c realloc() */ /*! Returns a gmio_buffer object allocated with standard \c realloc() */
GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_realloc(void* ptr, size_t size); GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_realloc(void* ptr, size_t size);
/*! Returns a gmio_buffer object allocated with OS-specific \c alloca() */
GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_alloca(size_t size);
/*! Safe and convenient call to gmio_buffer::deallocate_func() */ /*! Safe and convenient call to gmio_buffer::deallocate_func() */
GMIO_LIB_EXPORT void gmio_buffer_deallocate(gmio_buffer_t* buffer); GMIO_LIB_EXPORT void gmio_buffer_deallocate(gmio_buffer_t* buffer);

View File

@ -37,10 +37,6 @@
#cmakedefine GMIO_HAVE_POSIX_FSTAT64_FUNC #cmakedefine GMIO_HAVE_POSIX_FSTAT64_FUNC
#cmakedefine GMIO_HAVE_WIN__FSTAT64_FUNC #cmakedefine GMIO_HAVE_WIN__FSTAT64_FUNC
/* alloca()-like */
#cmakedefine GMIO_HAVE_BSD_ALLOCA_FUNC
#cmakedefine GMIO_HAVE_WIN__ALLOCA_FUNC
/* Compiler byte-swap functions */ /* Compiler byte-swap functions */
#cmakedefine GMIO_HAVE_GCC_BUILTIN_BSWAP16_FUNC #cmakedefine GMIO_HAVE_GCC_BUILTIN_BSWAP16_FUNC
#cmakedefine GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC #cmakedefine GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC

View File

@ -20,15 +20,6 @@
#include <stdlib.h> #include <stdlib.h>
#if defined(GMIO_HAVE_SYS_TYPES_H) && defined(GMIO_HAVE_SYS_STAT_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/types.h>
# include <sys/stat.h> # include <sys/stat.h>