Skip to content

Commit 07be1ea

Browse files
author
Nigel Stewart
committed
lib: chunkio: cmake check for fallocate availability
1 parent b872ce2 commit 07be1ea

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/chunkio/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ if(CIO_BACKEND_FILESYSTEM)
6969
CIO_DEFINITION(CIO_HAVE_BACKEND_FILESYSTEM)
7070
endif()
7171

72+
include(CheckCSourceCompiles)
73+
74+
# fallocate support
75+
check_c_source_compiles("
76+
#include <fcntl.h>
77+
int main() {
78+
fallocate(0,0,0);
79+
return 0;
80+
}" CIO_HAVE_FALLOCATE)
81+
82+
if(CIO_HAVE_FALLOCATE)
83+
CIO_DEFINITION(CIO_HAVE_FALLOCATE)
84+
endif()
85+
7286
include_directories(
7387
include
7488
deps/

lib/chunkio/src/cio_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ int cio_file_fs_size_change(struct cio_file *cf, size_t new_size)
962962

963963
/* macOS does not have fallocate().
964964
* So, we should use ftruncate always. */
965-
#ifdef __linux__
965+
#if defined(CIO_HAVE_FALLOCATE)
966966
if (new_size > cf->alloc_size) {
967967
/*
968968
* To increase the file size we use fallocate() since this option

0 commit comments

Comments
 (0)