From 4558290e1ed28dd57b71084c4074e28df9f135a6 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Tue, 11 May 2021 09:07:23 +0800 Subject: [PATCH] add macro fc_fallocate --- HISTORY | 3 ++- src/common_define.h | 8 ++++++++ src/shared_func.c | 4 +--- src/shared_func.h | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/HISTORY b/HISTORY index b0d8acc..203bb65 100644 --- a/HISTORY +++ b/HISTORY @@ -1,8 +1,9 @@ -Version 1.50 2021-04-29 +Version 1.50 2021-05-11 * add function is_digital_string * add function fc_server_load_from_ini_context * set thread name as necessary + * add macro fc_fallocate Version 1.49 2021-04-17 * add macros: FC_ABS and FC_NEGATIVE diff --git a/src/common_define.h b/src/common_define.h index 3b2c3a2..5356491 100644 --- a/src/common_define.h +++ b/src/common_define.h @@ -35,6 +35,7 @@ typedef DWORD (WINAPI *ThreadEntranceFunc)(LPVOID lpThreadParameter); #else #include +#include #include #include #include @@ -383,6 +384,13 @@ static inline int fc_compare_int64(const int64_t n1, const int64_t n2) } } +#ifdef OS_LINUX +#define fc_fallocate(fd, size) fallocate(fd, 0, 0, size) +#else +#define fc_fallocate(fd, size) ftruncate(fd, size) +#endif + + #ifdef __cplusplus } #endif diff --git a/src/shared_func.c b/src/shared_func.c index 97b6133..7d81e7e 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -18,15 +18,13 @@ #include #include #include -#include #include #include +#include #include #include #include #include -#include -#include #include #include #include diff --git a/src/shared_func.h b/src/shared_func.h index 7d27003..dd66bc2 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -1068,6 +1068,7 @@ int fc_check_filename(const string_t *filename, const char *caption); */ bool is_digital_string(const char *str); + #ifdef __cplusplus } #endif