diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d64966861f3fe1a583af37834129749637f85c1..2e37a14143c3c7e2521692ac0e95d6753f372109 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 0000000000000000000000000000000000000000..b97c10a4b7ddc2ce1c99283538c76b49bf01e2b3 --- /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 e19c10f6b2658e506f3ffb16e604686f61de2696..1a1a5b5d785007692fcc5982558024f4bf05b893 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 0000000000000000000000000000000000000000..7ef259ba541582baf012e1de4dfbbf3c4f91d5ab --- /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 0000000000000000000000000000000000000000..e0c07fe3baf00be29f8ca202596ed5baf1f2377b --- /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 0000000000000000000000000000000000000000..ee6d0691550eb1ea9f9fe6cd7fee99a5a4ebfe20 --- /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 21b8b661df9809d8631cf1e7e915eb78c500671e..5e2bfc52e1cd9952a76ab2d3709161b9246419aa 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 0dcf554433a87204e2234efaaa75469e2bd75664..85ce0d0cd305d6fb5945bf151ca8637c11bae590 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 ef30796d787528aeb4ec37e1811e310f2d46993a..4dd3daba4dc13aa15a764206ab8fdb19b45e4dcc 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 a58e798d381803bdf2b4e91bbba4865c6baee11d..fd272b15a308222cf980b92b56b86780e232b1fa 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 7df9ad39bb72cee1a32c7a903c7df580b2ea9413..fcc96c19b46eb51da82ea5fcc0d87b7a4b90d742 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 703ba196efb14ebdae7fe2070c0b640ff2dde52b..b0e97e7b54902eb9c05f13486b8c44b40e533b9c 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 7fb9a2202d38760e5f1c760fe9d7f8eaa4096f46..9904170d61f152f6cbc047f52c65d0deb960edb8 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 6544c895486f74570783c53e86509c57d312ae4d..3faed855bad7fa42e23ceac0133d870501926a45 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 aec63f3322e2188b44986acaa1c4cb1b90ab1e91..d7cf05a59464a867f09f046e44dd6c8face37dcc 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 4718082ad12363333e9533745efdfdce7e34762b..4904eb9b514ca349cffc1be2e1574d706a3ccf4d 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 1e4ad95504e18dd2bf1dbc337f73156c8926e8c0..1344b5b58c4e3ae86d4a99ab9d6d56a391d0a87a 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 e52f349338f793b61d8bb9d0e5fb69b6ee548297..27906c262753f2bf02bd9cd09b4ca9227ba26bba 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 fb926610bd41d68113508584587587e8de620207..e506210cd2f54ca71dac0e77dec54338ef800aba 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 0fab7a941e7b6c78983ec81b7e055fe881952265..1052d108af43599ae2fb6706388a2ce9b4b2e115 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 25c748a8d88a99a10e120e6fc7992792b2fbd799..9bff7605097f20794b9a2d7b89e1127dc3a7d3b7 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 5c98db33d1007ff8f21872ca48096a108912724f..8ccbe9d78004760ab9f2377ede3a41dbfbe87f46 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 7a47639e75f2e18e6ed47a19066c0a69ea336503..08fa0a240903736007605d349f11b953c4aacc64 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 8c2fd7809d12feacb54d46b8a7db07b67d44c341..a9d925ac076b3345e5abf99a6e598c112c2a251f 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 72c18518e39894eb6d370051cfc8605c85a0eba3..7bdcf3cc6449fa11dd9e903134b2a593fb48ee0e 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 } }