From ba8d9a798e971811fe17a5ca029250e2ee358967 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 11 Mar 2022 19:39:20 +0800 Subject: [PATCH] Feature/sangshuduo/td 13063 3.0 windows (#10708) * [TD-13063]: 3.0 on Windows * add pthread in contrib * fix linux compile * fix osSemaphore * add gnu regex for Windows * fix compile error for Windows --- CMakeLists.txt | 33 +++------------------ cmake/cmake.define | 42 ++++++++++++++++++++++++++ cmake/cmake.options | 42 ++++++++++++++++++++++---- cmake/cmake.platform | 51 ++++++++++++++++++++++++++++++++ cmake/gnuregex_CMakeLists.txt.in | 13 ++++++++ cmake/pthread_CMakeLists.txt.in | 13 ++++++++ contrib/CMakeLists.txt | 16 +++++++++- include/common/tmsg.h | 5 ++++ include/common/trow.h | 3 +- include/os/os.h | 24 +++++++++------ include/os/osDef.h | 47 ++++++++++++++++++++++++----- include/os/osFile.h | 15 ++++++++++ include/os/osSemaphore.h | 5 ++-- include/os/osSocket.h | 2 +- include/os/osSysinfo.h | 7 +++++ include/os/osTime.h | 3 ++ source/common/CMakeLists.txt | 4 +++ source/os/CMakeLists.txt | 4 ++- source/os/src/osFile.c | 10 ++++++- source/os/src/osString.c | 3 +- source/os/src/osSysinfo.c | 15 +++++----- source/os/src/osSystem.c | 13 ++++---- source/util/CMakeLists.txt | 4 +++ source/util/src/tpagedbuf.c | 2 +- source/util/src/ttimer.c | 2 ++ 25 files changed, 306 insertions(+), 72 deletions(-) create mode 100644 cmake/cmake.define create mode 100644 cmake/cmake.platform create mode 100644 cmake/gnuregex_CMakeLists.txt.in create mode 100644 cmake/pthread_CMakeLists.txt.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d64966861..2e37a14143 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,40 +6,14 @@ project( DESCRIPTION "An open-source big data platform designed and optimized for the Internet of Things(IOT)" ) -IF ("${BUILD_TOOLS}" STREQUAL "") - IF (TD_LINUX) - IF (TD_ARM_32) - SET(BUILD_TOOLS "false") - ELSEIF (TD_ARM_64) - SET(BUILD_TOOLS "false") - ELSE () - SET(BUILD_TOOLS "false") - ENDIF () - ELSEIF (TD_DARWIN) - SET(BUILD_TOOLS "false") - ELSE () - SET(BUILD_TOOLS "false") - ENDIF () -ENDIF () - -IF ("${BUILD_TOOLS}" MATCHES "false") - MESSAGE("${Yellow} Will _not_ build taos_tools! ${ColourReset}") - SET(TD_TAOS_TOOLS FALSE) -ELSE () - MESSAGE("") - MESSAGE("${Green} Will build taos_tools! ${ColourReset}") - MESSAGE("") - SET(TD_TAOS_TOOLS TRUE) -ENDIF () - set(CMAKE_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/cmake") set(CMAKE_CONTRIB_DIR "${CMAKE_SOURCE_DIR}/contrib") + +include(${CMAKE_SUPPORT_DIR}/cmake.platform) +include(${CMAKE_SUPPORT_DIR}/cmake.define) include(${CMAKE_SUPPORT_DIR}/cmake.options) include(${CMAKE_SUPPORT_DIR}/cmake.version) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3") - # contrib add_subdirectory(contrib) @@ -52,6 +26,7 @@ if(${BUILD_TEST}) include(CTest) enable_testing() endif(${BUILD_TEST}) + add_subdirectory(source) add_subdirectory(tools) add_subdirectory(tests) diff --git a/cmake/cmake.define b/cmake/cmake.define new file mode 100644 index 0000000000..b97c10a4b7 --- /dev/null +++ b/cmake/cmake.define @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 3.16) + +IF ("${BUILD_TOOLS}" STREQUAL "") + IF (TD_LINUX) + IF (TD_ARM_32) + SET(BUILD_TOOLS "false") + ELSEIF (TD_ARM_64) + SET(BUILD_TOOLS "false") + ELSE () + SET(BUILD_TOOLS "false") + ENDIF () + ELSEIF (TD_DARWIN) + SET(BUILD_TOOLS "false") + ELSE () + SET(BUILD_TOOLS "false") + ENDIF () +ENDIF () + +IF ("${BUILD_TOOLS}" MATCHES "false") + MESSAGE("${Yellow} Will _not_ build taos_tools! ${ColourReset}") + SET(TD_TAOS_TOOLS FALSE) +ELSE () + MESSAGE("") + MESSAGE("${Green} Will build taos_tools! ${ColourReset}") + MESSAGE("") + SET(TD_TAOS_TOOLS TRUE) +ENDIF () + +IF (TD_WINDOWS) + MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}") + SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE) + SET(COMMON_FLAGS "/nologo /WX /wd4018 /wd4999 /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-") + + IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900)) + SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18") + ENDIF () + +ELSE () + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3") + +ENDIF () diff --git a/cmake/cmake.options b/cmake/cmake.options index e19c10f6b2..1a1a5b5d78 100644 --- a/cmake/cmake.options +++ b/cmake/cmake.options @@ -1,12 +1,35 @@ # ========================================================= # Deps options # ========================================================= + +IF(${TD_WINDOWS}) + + MESSAGE("build pthread Win32") + option( + BUILD_PTHREAD + "If build pthread on Windows" + ON + ) + + MESSAGE("build gnu regex for Windows") + option( + BUILD_GNUREGEX + "If build gnu regex on Windows" + ON + ) + +ENDIF () + +IF(${TD_LINUX} MATCHES TRUE) + option( BUILD_TEST "If build unit tests using googletest" ON ) +ENDIF () + option( BUILD_WITH_LEVELDB "If build with leveldb" @@ -25,11 +48,16 @@ option( OFF ) -option( - BUILD_WITH_BDB - "If build with BerkleyDB" - ON -) +IF(${TD_WINDOWS}) + MESSAGE("Not build BDB on Windows") +ELSE () + option( + BUILD_WITH_BDB + "If build with BerkleyDB" + ON + ) + +ENDIF () option( BUILD_WITH_LUCENE @@ -68,12 +96,16 @@ option( OFF ) +IF(${TD_LINUX} MATCHES TRUE) + option( BUILD_DEPENDENCY_TESTS "If build dependency tests" ON ) +ENDIF () + option( BUILD_DOCS "If use doxygen build documents" diff --git a/cmake/cmake.platform b/cmake/cmake.platform new file mode 100644 index 0000000000..7ef259ba54 --- /dev/null +++ b/cmake/cmake.platform @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.16) + +MESSAGE("Current system is ${CMAKE_SYSTEM_NAME}") + +# init +SET(TD_LINUX FALSE) +SET(TD_WINDOWS FALSE) +SET(TD_DARWIN FALSE) + +IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + + SET(TD_LINUX TRUE) + SET(OSTYPE "Linux") + ADD_DEFINITIONS("-DLINUX") + + IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8) + SET(TD_LINUX_64 TRUE) + ELSE () + SET(TD_LINUX_32 TRUE) + ENDIF () + +ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + + SET(TD_DARWIN TRUE) + SET(OSTYPE "macOS") + ADD_DEFINITIONS("-DDARWIN") + IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64") + MESSAGE("Current system arch is arm64") + SET(TD_DARWIN_64 TRUE) + ADD_DEFINITIONS("-D_TD_DARWIN_64") + ENDIF () + + ADD_DEFINITIONS("-DHAVE_UNISTD_H") + +ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + + SET(TD_WINDOWS TRUE) + SET(OSTYPE "Windows") + ADD_DEFINITIONS("-DWINDOWS") + + IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8) + SET(TD_WINDOWS_64 TRUE) + ADD_DEFINITIONS("-D_TD_WINDOWS_64") + ELSE () + SET(TD_WINDOWS_32 TRUE) + ADD_DEFINITIONS("-D_TD_WINDOWS_32") + ENDIF () +ENDIF() + +MESSAGE("C Compiler ID: ${CMAKE_C_COMPILER_ID}") +MESSAGE("CXX Compiler ID: ${CMAKE_CXX_COMPILER_ID}") diff --git a/cmake/gnuregex_CMakeLists.txt.in b/cmake/gnuregex_CMakeLists.txt.in new file mode 100644 index 0000000000..e0c07fe3ba --- /dev/null +++ b/cmake/gnuregex_CMakeLists.txt.in @@ -0,0 +1,13 @@ + +# gnuregex +ExternalProject_Add(gnuregex + URL https://launchpad.net/gnuregex/trunk/2.9/+download/libgnurx-src-2.9.zip + DOWNLOAD_NAME libgnurx-src.zip + SOURCE_DIR "${CMAKE_CONTRIB_DIR}/gnuregex" + BINARY_DIR "" + #BUILD_IN_SOURCE TRUE + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) diff --git a/cmake/pthread_CMakeLists.txt.in b/cmake/pthread_CMakeLists.txt.in new file mode 100644 index 0000000000..ee6d069155 --- /dev/null +++ b/cmake/pthread_CMakeLists.txt.in @@ -0,0 +1,13 @@ + +# pthread +ExternalProject_Add(pthread + GIT_REPOSITORY https://github.com/GerHobbelt/pthread-win32 + GIT_TAG v3.0.3.1 + SOURCE_DIR "${CMAKE_CONTRIB_DIR}/pthread-win32" + BINARY_DIR "" + #BUILD_IN_SOURCE TRUE + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 21b8b661df..5e2bfc52e1 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -9,6 +9,16 @@ endfunction(cat IN_FILE OUT_FILE) set(CONTRIB_TMP_FILE "${CMAKE_BINARY_DIR}/deps_tmp_CMakeLists.txt.in") configure_file("${CMAKE_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) +# pthread +if(${BUILD_PTHREAD}) + cat("${CMAKE_SUPPORT_DIR}/pthread_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) +endif() + +# gnu regex +if(${BUILD_GNUREGEX}) + cat("${CMAKE_SUPPORT_DIR}/gnuregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) +endif() + # googletest if(${BUILD_TEST}) cat("${CMAKE_SUPPORT_DIR}/gtest_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) @@ -193,7 +203,10 @@ endif(${BUILD_WITH_TRAFT}) # LIBUV if(${BUILD_WITH_UV}) - add_compile_options(-Wno-sign-compare) + if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") + MESSAGE("Windows need set no-sign-compare") + add_compile_options(-Wno-sign-compare) + endif () add_subdirectory(libuv) endif(${BUILD_WITH_UV}) @@ -224,6 +237,7 @@ if(${BUILD_WITH_SQLITE}) ) endif(${BUILD_WITH_SQLITE}) +# pthread # ================================================================================================ diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 0dcf554433..85ce0d0cd3 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1356,6 +1356,7 @@ typedef struct SVCreateTbReq { } SVCreateTbReq, SVUpdateTbReq; typedef struct { + int tmp; // TODO: to avoid compile error } SVCreateTbRsp, SVUpdateTbRsp; int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq); @@ -1367,6 +1368,7 @@ typedef struct { } SVCreateTbBatchReq; typedef struct { + int tmp; // TODO: to avoid compile error } SVCreateTbBatchRsp; int32_t tSerializeSVCreateTbBatchReq(void** buf, SVCreateTbBatchReq* pReq); @@ -1380,6 +1382,7 @@ typedef struct { } SVDropTbReq; typedef struct { + int tmp; // TODO: to avoid compile error } SVDropTbRsp; int32_t tSerializeSVDropTbReq(void** buf, SVDropTbReq* pReq); @@ -1930,7 +1933,9 @@ typedef struct { int64_t ver; // use a general definition char indexName[TSDB_INDEX_NAME_LEN]; } SVDropTSmaReq; + typedef struct { + int tmp; // TODO: to avoid compile error } SVCreateTSmaRsp, SVDropTSmaRsp; int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq); diff --git a/include/common/trow.h b/include/common/trow.h index ef30796d78..4dd3daba4d 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -103,6 +103,7 @@ typedef struct { typedef struct { // TODO + int tmp; // TODO: to avoid compile error } STpRow; // tuple #pragma pack(push, 1) @@ -1098,4 +1099,4 @@ const STSRow *tRowBatchIterNext(STSRowBatchIter *pRowBatchIter); } #endif -#endif /*_TD_COMMON_ROW_H_*/ \ No newline at end of file +#endif /*_TD_COMMON_ROW_H_*/ diff --git a/include/os/os.h b/include/os/os.h index a58e798d38..fd272b15a3 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -22,7 +22,22 @@ extern "C" { #include #include + +#if !defined(WINDOWS) +#include #include +#include +#include +#include +#include + +#include +#include +#include +#include + +#endif + #include #include #include @@ -30,8 +45,6 @@ extern "C" { #include #include #include -#include -#include #include #include #include @@ -43,16 +56,9 @@ extern "C" { #include #include #include -#include -#include -#include #include #include -#include -#include -#include -#include #include "osAtomic.h" #include "osDef.h" diff --git a/include/os/osDef.h b/include/os/osDef.h index 7df9ad39bb..fcc96c19b4 100644 --- a/include/os/osDef.h +++ b/include/os/osDef.h @@ -49,7 +49,7 @@ extern "C" { #endif -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#if defined(WINDOWS) char *stpcpy (char *dest, const char *src); char *stpncpy (char *dest, const char *src, size_t n); @@ -63,14 +63,46 @@ extern "C" { #define strtok_r strtok_s #define snprintf _snprintf #define in_addr_t unsigned long - #define socklen_t int +// #define socklen_t int char * strsep(char **stringp, const char *delim); char * getpass(const char *prefix); char * strndup(const char *s, size_t n); - -#endif + int gettimeofday(struct timeval *ptv, void *pTimeZone); + // for send function in tsocket.c + #define MSG_NOSIGNAL 0 + #define SO_NO_CHECK 0x1234 + #define SOL_TCP 0x1234 + + #define SHUT_RDWR SD_BOTH + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + + #define LOCK_EX 1 + #define LOCK_NB 2 + #define LOCK_UN 3 + + #ifndef PATH_MAX + #define PATH_MAX 256 + #endif + + typedef struct { + int we_wordc; + char *we_wordv[1]; + int we_offs; + char wordPos[1025]; + } wordexp_t; + int wordexp(char *words, wordexp_t *pwordexp, int flags); + void wordfree(wordexp_t *pwordexp); + + #define openlog(a, b, c) + #define closelog() + #define LOG_ERR 0 + #define LOG_INFO 1 + void syslog(int unused, const char *format, ...); +#endif // WINDOWS + #ifndef WINDOWS #ifndef O_BINARY #define O_BINARY 0 @@ -164,7 +196,7 @@ extern "C" { #define PRIzu "zu" #endif -#if defined(_TD_LINUX_64) || defined(_TD_LINUX_32) || defined(_TD_MIPS_64) || defined(_TD_ARM_32) || defined(_TD_ARM_64) || defined(_TD_DARWIN_64) +#if !defined(WINDOWS) #if defined(_TD_DARWIN_64) // MacOS #if !defined(_GNU_SOURCE) @@ -179,8 +211,7 @@ extern "C" { #endif #else // Windows -// #define setThreadName(name) -#define setThreadName(name) do { prctl(PR_SET_NAME, (name)); } while (0) + #define setThreadName(name) #endif #if defined(_WIN32) @@ -197,4 +228,4 @@ extern "C" { } #endif -#endif /*_TD_OS_DEF_H_*/ \ No newline at end of file +#endif /*_TD_OS_DEF_H_*/ diff --git a/include/os/osFile.h b/include/os/osFile.h index 703ba196ef..b0e97e7b54 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -22,6 +22,15 @@ extern "C" { #include "osSocket.h" +#if defined(WINDOWS) +typedef int32_t FileFd; +typedef SOCKET SocketFd; +#else +typedef int32_t FileFd; +typedef int32_t SocketFd; +#endif + +int64_t taosRead(FileFd fd, void *buf, int64_t count); // If the error is in a third-party library, place this header file under the third-party library header file. #ifndef ALLOW_FORBID_FUNC #define open OPEN_FUNC_TAOS_FORBID @@ -76,7 +85,13 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count); int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset); int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count); void taosFprintfFile(TdFilePtr pFile, const char *format, ...); + +#if defined(WINDOWS) +#define __restrict__ +#endif // WINDOWS + int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf); + int32_t taosEOFFile(TdFilePtr pFile); int64_t taosCloseFile(TdFilePtr *ppFile); diff --git a/include/os/osSemaphore.h b/include/os/osSemaphore.h index 7fb9a2202d..9904170d61 100644 --- a/include/os/osSemaphore.h +++ b/include/os/osSemaphore.h @@ -16,12 +16,13 @@ #ifndef _TD_OS_SEMPHONE_H_ #define _TD_OS_SEMPHONE_H_ -#include - #ifdef __cplusplus extern "C" { #endif +#include +#include + #if defined (_TD_DARWIN_64) typedef struct tsem_s *tsem_t; int tsem_init(tsem_t *sem, int pshared, unsigned int value); diff --git a/include/os/osSocket.h b/include/os/osSocket.h index 6544c89548..3faed855ba 100644 --- a/include/os/osSocket.h +++ b/include/os/osSocket.h @@ -27,7 +27,7 @@ #define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID #endif -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#if defined(WINDOWS) #include "winsock2.h" #include #include diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index aec63f3322..d7cf05a594 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -52,6 +52,13 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen); char *taosGetCmdlineByPID(int32_t pid); void taosSetCoreDump(bool enable); +#if defined(WINDOWS) + +#define _UTSNAME_LENGTH 65 +#define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH + +#endif // WINDOWS + typedef struct { char sysname[_UTSNAME_MACHINE_LENGTH]; char nodename[_UTSNAME_MACHINE_LENGTH]; diff --git a/include/os/osTime.h b/include/os/osTime.h index 4718082ad1..4904eb9b51 100644 --- a/include/os/osTime.h +++ b/include/os/osTime.h @@ -30,6 +30,9 @@ extern "C" { #endif #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + + #define CLOCK_REALTIME 0 + #ifdef _TD_GO_DLL_ #define MILLISECOND_PER_SECOND (1000LL) #else diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt index 1e4ad95504..1344b5b58c 100644 --- a/source/common/CMakeLists.txt +++ b/source/common/CMakeLists.txt @@ -4,6 +4,10 @@ target_include_directories( common PUBLIC "${CMAKE_SOURCE_DIR}/include/common" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +IF(${TD_WINDOWS}) + PRIVATE "${CMAKE_SOURCE_DIR}/contrib/pthread-win32" + PRIVATE "${CMAKE_SOURCE_DIR}/contrib/gnuregex" +ENDIF () ) target_link_libraries( common diff --git a/source/os/CMakeLists.txt b/source/os/CMakeLists.txt index e52f349338..27906c2627 100644 --- a/source/os/CMakeLists.txt +++ b/source/os/CMakeLists.txt @@ -3,7 +3,9 @@ add_library(os STATIC ${OS_SRC}) target_include_directories( os PUBLIC "${CMAKE_SOURCE_DIR}/include/os" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" + PRIVATE "${CMAKE_SOURCE_DIR}/include" + PRIVATE "${CMAKE_SOURCE_DIR}/include/util" + PRIVATE "${CMAKE_SOURCE_DIR}/contrib/pthread-win32" ) target_link_libraries( os pthread dl rt m diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index fb926610bd..e506210cd2 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -735,6 +735,7 @@ void taosFprintfFile(TdFilePtr pFile, const char *format, ...) { fflush(pFile->fp); } +#if !defined(WINDOWS) void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) { if (pFile == NULL) { return NULL; @@ -744,6 +745,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) { void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, pFile->fd, 0); return ptr; } +#endif bool taosValidFile(TdFilePtr pFile) { return pFile != NULL; } @@ -773,6 +775,9 @@ int32_t taosEOFFile(TdFilePtr pFile) { return feof(pFile->fp); } + +#if !defined(WINDOWS) + bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { int flags = 0; @@ -790,4 +795,7 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { return access(pathname, flags) == 0; } -bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); }; \ No newline at end of file + +bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); }; + +#endif // WINDOWS diff --git a/source/os/src/osString.c b/source/os/src/osString.c index 0fab7a941e..1052d108af 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" +#include "tdef.h" #include #include @@ -360,4 +361,4 @@ int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes, int8_t ncha return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / ncharSize); } -#endif \ No newline at end of file +#endif diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 25c748a8d8..9bff760509 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" +#include "taoserror.h" #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) @@ -374,12 +375,12 @@ int32_t taosGetCpuCores(float *numOfCores) { int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) { #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) - *sysCpuUsage = 0; - *procCpuUsage = 0; + *cpu_system = 0; + *cpu_engine = 0; return 0; #elif defined(_TD_DARWIN_64) - *sysCpuUsage = 0; - *procCpuUsage = 0; + *cpu_system = 0; + *cpu_engine = 0; return 0; #else static uint64_t lastSysUsed = 0; @@ -514,7 +515,7 @@ int32_t taosGetSysMemory(int64_t *usedKB) { } int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#if defined(WINDOWS) unsigned _int64 i64FreeBytesToCaller; unsigned _int64 i64TotalBytes; unsigned _int64 i64FreeBytes; @@ -522,7 +523,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { BOOL fResult = GetDiskFreeSpaceExA(dataDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes); if (fResult) { - diskSize->tsize = (int64_t)(i64TotalBytes); + diskSize->total = (int64_t)(i64TotalBytes); diskSize->avail = (int64_t)(i64FreeBytesToCaller); diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes); return 0; @@ -538,7 +539,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; } else { - diskSize->tsize = info.f_blocks * info.f_frsize; + diskSize->total = info.f_blocks * info.f_frsize; diskSize->avail = info.f_bavail * info.f_frsize; diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize; return 0; diff --git a/source/os/src/osSystem.c b/source/os/src/osSystem.c index 5c98db33d1..8ccbe9d780 100644 --- a/source/os/src/osSystem.c +++ b/source/os/src/osSystem.c @@ -17,7 +17,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#if defined(WINDOWS) #elif defined(_TD_DARWIN_64) #else #include @@ -25,10 +25,12 @@ #include #endif +#if !defined(WINDOWS) struct termios oldtio; +#endif int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize) { -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#if defined(WINDOWS) FILE *fp; if (cmd == NULL) { // printf("taosSystem cmd is NULL!"); @@ -51,6 +53,7 @@ int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize) { } return 0; + } #elif defined(_TD_DARWIN_64) printf("no support funtion"); return -1; @@ -82,7 +85,7 @@ int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize) { } void* taosLoadDll(const char* filename) { -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#if defined(WINDOWS) return NULL; #elif defined(_TD_DARWIN_64) return NULL; @@ -252,7 +255,7 @@ void setTerminalMode() { } int32_t getOldTerminalMode() { -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#if defined(WINDOWS) #elif defined(_TD_DARWIN_64) /* Make sure stdin is a terminal. */ @@ -295,4 +298,4 @@ void resetTerminalMode() { exit(EXIT_FAILURE); } #endif -} \ No newline at end of file +} diff --git a/source/util/CMakeLists.txt b/source/util/CMakeLists.txt index 7a47639e75..08fa0a2409 100644 --- a/source/util/CMakeLists.txt +++ b/source/util/CMakeLists.txt @@ -5,6 +5,10 @@ target_include_directories( util PUBLIC "${CMAKE_SOURCE_DIR}/include/util" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +IF(${TD_WINDOWS}) + PRIVATE "${CMAKE_SOURCE_DIR}/contrib/pthread-win32" + PRIVATE "${CMAKE_SOURCE_DIR}/contrib/gnuregex" +ENDIF () ) target_link_libraries( util diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 8c2fd7809d..a9d925ac07 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -351,7 +351,7 @@ static void lruListMoveToFront(SList* pList, SPageInfo* pi) { static SPageInfo* getPageInfoFromPayload(void* page) { int32_t offset = offsetof(SPageInfo, pData); - char* p = page - offset; + char* p = (char *)page - offset; SPageInfo* ppi = ((SPageInfo**)p)[0]; return ppi; diff --git a/source/util/src/ttimer.c b/source/util/src/ttimer.c index 72c18518e3..7bdcf3cc64 100644 --- a/source/util/src/ttimer.c +++ b/source/util/src/ttimer.c @@ -628,6 +628,8 @@ void taosTmrCleanUp(void* handle) { tmrCtrls = NULL; unusedTmrCtrl = NULL; +#if !defined(WINDOWS) tmrModuleInit = PTHREAD_ONCE_INIT; // to support restart +#endif } } -- GitLab