diff --git a/src/os/inc/os.h b/src/os/inc/os.h index 9996f7d92a5d73f7d1707fd75d3a076f30c84b8b..700b29ce98adff5e0e33ab1bfb8bfca6cb12f72f 100644 --- a/src/os/inc/os.h +++ b/src/os/inc/os.h @@ -21,7 +21,7 @@ extern "C" { #endif #ifdef _TD_DARWIN_64 -#include "osDarwin64.h" +#include "osDarwin.h" #endif #ifdef _TD_LINUX_64 @@ -36,12 +36,8 @@ extern "C" { #include "osAlpine.h" #endif -#ifdef _TD_WINDOWS_64 -#include "osWindows64.h" -#endif - -#ifdef _TD_WINDOWS_32 -#include "osWindows32.h" +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#include "osWindows.h" #endif #include "osAtomic.h" diff --git a/src/os/inc/osDarwin64.h b/src/os/inc/osDarwin.h similarity index 83% rename from src/os/inc/osDarwin64.h rename to src/os/inc/osDarwin.h index cda987f6d5c8aa6ace2217a6857ad45e4a627be8..8628a0f3ac266605d40e81cdd64b38458201b3e5 100644 --- a/src/os/inc/osDarwin64.h +++ b/src/os/inc/osDarwin.h @@ -71,21 +71,21 @@ extern "C" { #include #include -#define TAOS_OS_FUNC_FILE_TSENDIFLE -#define taosFSendFile(outfile, infile, offset, count) taosFSendFileImp(outfile, infile, offset, size) -#define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) +#define TAOS_OS_FUNC_FILE_SENDIFLE + #define taosFSendFile(outfile, infile, offset, count) taosFSendFileImp(outfile, infile, offset, size) + #define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) #define TAOS_OS_FUNC_SEMPHONE -#define tsem_t dispatch_semaphore_t -int tsem_init(dispatch_semaphore_t *sem, int pshared, unsigned int value); -int tsem_wait(dispatch_semaphore_t *sem); -int tsem_post(dispatch_semaphore_t *sem); -int tsem_destroy(dispatch_semaphore_t *sem); + #define tsem_t dispatch_semaphore_t + int tsem_init(dispatch_semaphore_t *sem, int pshared, unsigned int value); + int tsem_wait(dispatch_semaphore_t *sem); + int tsem_post(dispatch_semaphore_t *sem); + int tsem_destroy(dispatch_semaphore_t *sem); #define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT +#define TAOS_OS_FUNC_STRING_STR2INT64 #define TAOS_OS_FUNC_SYSINFO #define TAOS_OS_FUNC_TIMER -#define TAOS_OS_FUNC_STRING_STR2INT64 // specific #define htobe64 htonll diff --git a/src/os/inc/osFile.h b/src/os/inc/osFile.h index 8ff00893926b833bfb20e7f191faddb7da8f26b9..6e48e80ca4966b43dda90ddd5a4d7261f144acfc 100644 --- a/src/os/inc/osFile.h +++ b/src/os/inc/osFile.h @@ -26,7 +26,7 @@ ssize_t taosTWriteImp(int fd, void *buf, size_t count); ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size); int taosFSendFileImp(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count); -#ifndef TAOS_OS_FUNC_FILE_TSENDIFLE +#ifndef TAOS_OS_FUNC_FILE_SENDIFLE #define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) #define taosFSendFile(outfile, infile, offset, count) taosTSendFileImp(fileno(outfile), fileno(infile), offset, size) #endif diff --git a/src/os/inc/osSemphone.h b/src/os/inc/osSemphone.h index c001f95d8962062455d14f764d392e3b738715d3..300f1e8ef1bca311e14fc220ca72bedd8a5f4152 100644 --- a/src/os/inc/osSemphone.h +++ b/src/os/inc/osSemphone.h @@ -28,7 +28,7 @@ extern "C" { #define tsem_destroy sem_destroy #endif -// TAOS_OS_FUNC_PTHREAD +// TAOS_OS_FUNC_SEMPHONE_PTHREAD bool taosCheckPthreadValid(pthread_t thread); int64_t taosGetPthreadId(); diff --git a/src/os/inc/osSocket.h b/src/os/inc/osSocket.h index 749d3906f5cd6d7393280c8912c466cfe2001170..10fed022bb9cafbb7c613473fab6b9c4b9e5d277 100644 --- a/src/os/inc/osSocket.h +++ b/src/os/inc/osSocket.h @@ -20,17 +20,19 @@ extern "C" { #endif -#define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags) -#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen) -#define taosReadSocket(fd, buf, len) read(fd, buf, len) -#define taosWriteSocket(fd, buf, len) write(fd, buf, len) -#define taosCloseSocket(x) \ - { \ - if (FD_VALID(x)) { \ - close(x); \ - x = FD_INITIALIZER; \ - } \ - } +#ifndef TAOS_OS_FUNC_SOCKET_OP + #define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags) + #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen) + #define taosReadSocket(fd, buf, len) read(fd, buf, len) + #define taosWriteSocket(fd, buf, len) write(fd, buf, len) + #define taosCloseSocket(x) \ + { \ + if (FD_VALID(x)) { \ + close(x); \ + x = FD_INITIALIZER; \ + } \ + } +#endif #define taosClose(x) taosCloseSocket(x) diff --git a/src/os/inc/osString.h b/src/os/inc/osString.h index 9d0a7b335259349bd3bae7c2de98a109d587e29f..1e1953c81ddaf42a86ed8c04965dcbf46792db12 100644 --- a/src/os/inc/osString.h +++ b/src/os/inc/osString.h @@ -27,6 +27,8 @@ extern "C" { #ifndef TAOS_OS_FUNC_STRING_GETLINE #define taosGetlineImp(lineptr, n, stream) getline(lineptr, n , stream) +#else + int taosGetlineImp(char **lineptr, size_t *n, FILE *stream); #endif #ifndef TAOS_OS_FUNC_STRING_WCHAR diff --git a/src/os/inc/osWindows64.h b/src/os/inc/osWindows.h similarity index 96% rename from src/os/inc/osWindows64.h rename to src/os/inc/osWindows.h index 3a42978ff214181780ea1415a755893ca2f503bf..b44a41832e2fdcd17e72e3b754fa0a42c39b3775 100644 --- a/src/os/inc/osWindows64.h +++ b/src/os/inc/osWindows.h @@ -48,16 +48,7 @@ extern "C" { #endif -#define TAOS_OS_FUNC_STRING_WCHAR -#define TAOS_OS_FUNC_FILE -#define TAOS_OS_FUNC_SLEEP -#define TAOS_OS_FUNC_TIMER -#define TAOS_OS_FUNC_SOCKET -#define TAOS_OS_FUNC_PTHREAD - -#define TAOS_OS_FUNC_FILEOP - #define taosFSendFile(outfile, infile, offset, count) taosFSendFileImp(outfile, infile, offset, size) - #define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) +#define TAOS_OS_FUNC_ATOMIC #define TAOS_OS_FUNC_LZ4 int32_t BUILDIN_CLZL(uint64_t val); @@ -65,13 +56,13 @@ extern "C" { int32_t BUILDIN_CTZL(uint64_t val); int32_t BUILDIN_CTZ(uint32_t val); -#define TAOS_OS_FUNC_STRING_STR2INT64 - #ifdef _TD_GO_DLL_ - int64_t tsosStr2int64(char *str); - uint64_t htonll(uint64_t val); - #else - #define tsosStr2int64 _atoi64 - #endif +#define TAOS_OS_FUNC_DIR + +#define TAOS_OS_FUNC_FILE +#define TAOS_OS_FUNC_FILE_SENDIFLE + #define taosFSendFile(outfile, infile, offset, count) taosFSendFileImp(outfile, infile, offset, size) + #define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) +#define TAOS_OS_FUNC_FILE_GETTMPFILEPATH #define TAOS_OS_FUNC_MATH #define SWAP(a, b, c) \ @@ -80,26 +71,60 @@ extern "C" { (a) = (c)(b); \ (b) = __tmp; \ } while (0) - #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) -#define TAOS_OS_FUNC_NETWORK +#define TAOS_OS_FUNC_SEMPHONE_PTHREAD + +#define TAOS_OS_FUNC_SOCKET +#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT +#define TAOS_OS_FUNC_SOCKET_OP #define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags) #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen) #define taosWriteSocket(fd, buf, len) send(fd, buf, len, 0) #define taosReadSocket(fd, buf, len) recv(fd, buf, len, 0) #define taosCloseSocket(fd) closesocket(fd) -#define TAOS_OS_DEF_TIME +#define TAOS_OS_FUNC_STRING_WCHAR +#define TAOS_OS_FUNC_STRING_GETLINE +#define TAOS_OS_FUNC_STRING_STR2INT64 + #ifdef _TD_GO_DLL_ + int64_t tsosStr2int64(char *str); + uint64_t htonll(uint64_t val); + #else + #define tsosStr2int64 _atoi64 + #endif +#define TAOS_OS_FUNC_STRING_STRDUP + #define taosStrdupImp(str) _strdup(str) + #define taosStrndupImp(str, size) _strndup(str, size) + +#define TAOS_OS_FUNC_SYSINFO + +#define TAOS_OS_FUNC_TIME_DEF #ifdef _TD_GO_DLL_ #define MILLISECOND_PER_SECOND (1000LL) #else #define MILLISECOND_PER_SECOND (1000i64) #endif +#define TAOS_OS_FUNC_TIMER_SLEEP +#define TAOS_OS_FUNC_TIMER + +// specific typedef int (*__compar_fn_t)(const void *, const void *); -int getline(char **lineptr, size_t *n, FILE *stream); +#define ssize_t int +#define bzero(ptr, size) memset((ptr), 0, (size)) +#define mkdir(pathname, mode) _mkdir(pathname) +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#define wcsncasecmp _wcsnicmp +#define strtok_r strtok_s +#define snprintf _snprintf +#define in_addr_t unsigned long +#define socklen_t int +#define htobe64 htonll +#define twrite write + int gettimeofday(struct timeval *tv, struct timezone *tz); struct tm *localtime_r(const time_t *timep, struct tm *result); char * strptime(const char *buf, const char *fmt, struct tm *tm); @@ -109,9 +134,6 @@ int flock(int fd, int option); int fsync(int filedes); char * strndup(const char *s, size_t n); -#define strdup _strdup -#define ssize_t int - // for function open in stat.h #define S_IRWXU _S_IREAD #define S_IRWXG _S_IWRITE @@ -135,19 +157,6 @@ char * strndup(const char *s, size_t n); #define LOCK_NB 2 #define LOCK_UN 3 -#define bzero(ptr, size) memset((ptr), 0, (size)) -#define mkdir(pathname, mode) _mkdir(pathname) -#define strcasecmp _stricmp -#define strncasecmp _strnicmp -#define wcsncasecmp _wcsnicmp -#define strtok_r strtok_s - -#define snprintf _snprintf -#define in_addr_t unsigned long -#define socklen_t int -#define htobe64 htonll -#define twrite write - #ifndef PATH_MAX #define PATH_MAX 256 #endif diff --git a/src/os/inc/osWindows32.h b/src/os/inc/osWindows32.h deleted file mode 100644 index 4744d4beb55d533d48c6631ee3e0ae2f390cff6b..0000000000000000000000000000000000000000 --- a/src/os/inc/osWindows32.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Copyright (c) 2019 TAOS Data, Inc. -* -* This program is free software: you can use, redistribute, and/or modify -* it under the terms of the GNU Affero General Public License, version 3 -* or later ("AGPL"), as published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU Affero General Public License -* along with this program. If not, see . -*/ - -#ifndef TDENGINE_PLATFORM_WINDOWS32_H -#define TDENGINE_PLATFORM_WINDOWS32_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "winsock2.h" -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif -#endif \ No newline at end of file diff --git a/src/os/src/darwin64/CMakeLists.txt b/src/os/src/darwin/CMakeLists.txt similarity index 100% rename from src/os/src/darwin64/CMakeLists.txt rename to src/os/src/darwin/CMakeLists.txt diff --git a/src/os/src/darwin64/darwinEnv.c b/src/os/src/darwin/darwinEnv.c similarity index 100% rename from src/os/src/darwin64/darwinEnv.c rename to src/os/src/darwin/darwinEnv.c diff --git a/src/os/src/darwin64/darwinFile.c b/src/os/src/darwin/darwinFile.c similarity index 100% rename from src/os/src/darwin64/darwinFile.c rename to src/os/src/darwin/darwinFile.c diff --git a/src/os/src/darwin64/darwinSemphone.c b/src/os/src/darwin/darwinSemphone.c similarity index 100% rename from src/os/src/darwin64/darwinSemphone.c rename to src/os/src/darwin/darwinSemphone.c diff --git a/src/os/src/darwin64/darwinSocket.c b/src/os/src/darwin/darwinSocket.c similarity index 100% rename from src/os/src/darwin64/darwinSocket.c rename to src/os/src/darwin/darwinSocket.c diff --git a/src/os/src/darwin64/darwinString.c b/src/os/src/darwin/darwinString.c similarity index 100% rename from src/os/src/darwin64/darwinString.c rename to src/os/src/darwin/darwinString.c diff --git a/src/os/src/darwin64/darwinSysInfo.c b/src/os/src/darwin/darwinSysInfo.c similarity index 100% rename from src/os/src/darwin64/darwinSysInfo.c rename to src/os/src/darwin/darwinSysInfo.c diff --git a/src/os/src/darwin64/darwinTimer.c b/src/os/src/darwin/darwinTimer.c similarity index 100% rename from src/os/src/darwin64/darwinTimer.c rename to src/os/src/darwin/darwinTimer.c diff --git a/src/os/src/detail/osFile.c b/src/os/src/detail/osFile.c index 1cd74456586f2d2b1a811af3119e95c4f31f800c..ad6be83e41162666d20b6dee9e361872d45380de 100644 --- a/src/os/src/detail/osFile.c +++ b/src/os/src/detail/osFile.c @@ -109,7 +109,7 @@ ssize_t taosTWriteImp(int fd, void *buf, size_t n) { return n; } -#ifndef TAOS_OS_FUNC_FILE_TSENDIFLE +#ifndef TAOS_OS_FUNC_FILE_SENDIFLE ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) { size_t leftbytes = size; ssize_t sentbytes; diff --git a/src/os/src/detail/osSemphone.c b/src/os/src/detail/osSemphone.c index 18207dc12e937dc6f6a49d8778465a395c8d9078..82b916b4d73080c55da69ac090d9b5b56e23685b 100644 --- a/src/os/src/detail/osSemphone.c +++ b/src/os/src/detail/osSemphone.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#ifndef TAOS_OS_FUNC_PTHREAD +#ifndef TAOS_OS_FUNC_SEMPHONE_PTHREAD bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; } int64_t taosGetPthreadId() { return (int64_t)pthread_self(); } diff --git a/src/os/src/detail/osString.c b/src/os/src/detail/osString.c index 6a613e89fca37c197e0b72e2e8cb0a8eb4e549df..b4b8c9a29429bb619b336fd91e4fb5b352fe35ed 100644 --- a/src/os/src/detail/osString.c +++ b/src/os/src/detail/osString.c @@ -19,20 +19,16 @@ #include "taosdef.h" #ifndef TAOS_OS_FUNC_STRING_STR2INT64 - int64_t tsosStr2int64(char *str) { char *endptr = NULL; return strtoll(str, &endptr, 10); } - #endif #ifndef TAOS_OS_FUNC_STRING_WCHAR - -int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes) { +int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) { return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / TSDB_NCHAR_SIZE); } - #endif #ifdef USE_LIBICONV diff --git a/src/os/src/detail/osTimer.c b/src/os/src/detail/osTimer.c index bea5a718de8b4c6b43962d1cdb278053d8f85da3..c425d1732e7e03b23c7c26655667cc4d0d9beb7f 100644 --- a/src/os/src/detail/osTimer.c +++ b/src/os/src/detail/osTimer.c @@ -102,7 +102,7 @@ void taosUninitTimer() { #endif -#ifndef TAOS_OS_FUNC_SLEEP +#ifndef TAOS_OS_FUNC_TIMER_SLEEP /* to make taosMsleep work, signal SIGALRM shall be blocked in the calling thread, diff --git a/src/os/src/windows64/CMakeLists.txt b/src/os/src/windows/CMakeLists.txt similarity index 100% rename from src/os/src/windows64/CMakeLists.txt rename to src/os/src/windows/CMakeLists.txt diff --git a/src/os/src/windows64/w64Atomic.c b/src/os/src/windows/w64Atomic.c similarity index 100% rename from src/os/src/windows64/w64Atomic.c rename to src/os/src/windows/w64Atomic.c diff --git a/src/os/src/windows64/w64Env.c b/src/os/src/windows/w64Env.c similarity index 100% rename from src/os/src/windows64/w64Env.c rename to src/os/src/windows/w64Env.c diff --git a/src/os/src/windows64/w64FileOp.c b/src/os/src/windows/w64File.c similarity index 73% rename from src/os/src/windows64/w64FileOp.c rename to src/os/src/windows/w64File.c index 54f7938ddefae8e9bc49e286f52f21504dd49658..54a95297ac092a8df8ec262df98f53d32c05dc9d 100644 --- a/src/os/src/windows64/w64FileOp.c +++ b/src/os/src/windows/w64File.c @@ -15,11 +15,28 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "taosdef.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" + +void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) { + const char* tdengineTmpFileNamePrefix = "tdengine-"; + char tmpPath[PATH_MAX]; + + char *tmpDir = getenv("tmp"); + if (tmpDir == NULL) { + tmpDir = ""; + } + + strcpy(tmpPath, tmpDir); + strcat(tmpPath, tdengineTmpFileNamePrefix); + if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) { + strcat(tmpPath, fileNamePrefix); + strcat(tmpPath, "-%d-%s"); + } + + char rand[8] = {0}; + taosRandStr(rand, tListLen(rand) - 1); + snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand); +} + #define _SEND_FILE_STEP_ 1000 diff --git a/src/os/src/windows/w64Getline.c b/src/os/src/windows/w64Getline.c new file mode 100644 index 0000000000000000000000000000000000000000..3e8701e19b3ee420648bec984874416410cd14f1 --- /dev/null +++ b/src/os/src/windows/w64Getline.c @@ -0,0 +1,124 @@ +/* getline.c -- Replacement for GNU C library function getline + +Copyright (C) 1993 Free Software Foundation, Inc. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. */ + +/* Written by Jan Brittenson, bson@gnu.ai.mit.edu. */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#if STDC_HEADERS +#include +#else +char *malloc(), *realloc(); +#endif + +/* Always add at least this many bytes when extending the buffer. */ +#define MIN_CHUNK 64 + +/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR ++ OFFSET (and null-terminate it). *LINEPTR is a pointer returned from +malloc (or NULL), pointing to *N characters of space. It is realloc'd +as necessary. Return the number of characters read (not including the +null terminator), or -1 on error or EOF. On a -1 return, the caller +should check feof(), if not then errno has been set to indicate +the error. */ + +int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) { + int nchars_avail; /* Allocated but unused chars in *LINEPTR. */ + char *read_pos; /* Where we're reading into *LINEPTR. */ + int ret; + + if (!lineptr || !n || !stream) { + errno = EINVAL; + return -1; + } + + if (!*lineptr) { + *n = MIN_CHUNK; + *lineptr = malloc(*n); + if (!*lineptr) { + errno = ENOMEM; + return -1; + } + } + + nchars_avail = (int)(*n - offset); + read_pos = *lineptr + offset; + + for (;;) { + int save_errno; + register int c = getc(stream); + + save_errno = errno; + + /* We always want at least one char left in the buffer, since we + always (unless we get an error while reading the first char) + NUL-terminate the line buffer. */ + + assert((*lineptr + *n) == (read_pos + nchars_avail)); + if (nchars_avail < 2) { + if (*n > MIN_CHUNK) + *n *= 2; + else + *n += MIN_CHUNK; + + nchars_avail = (int)(*n + *lineptr - read_pos); + *lineptr = realloc(*lineptr, *n); + if (!*lineptr) { + errno = ENOMEM; + return -1; + } + read_pos = *n - nchars_avail + *lineptr; + assert((*lineptr + *n) == (read_pos + nchars_avail)); + } + + if (ferror(stream)) { + /* Might like to return partial line, but there is no + place for us to store errno. And we don't want to just + lose errno. */ + errno = save_errno; + return -1; + } + + if (c == EOF) { + /* Return partial line, if any. */ + if (read_pos == *lineptr) + return -1; + else + break; + } + + *read_pos++ = c; + nchars_avail--; + + if (c == terminator) /* Return the line. */ + break; + } + + /* Done - NUL terminate and return the number of chars read. */ + *read_pos = '\0'; + + ret = (int)(read_pos - (*lineptr + offset)); + return ret; +} + +int taosGetlineImp(char **lineptr, size_t *n, FILE *stream) { + return getstr(lineptr, n, stream, '\n', 0); +} \ No newline at end of file diff --git a/src/os/src/windows64/w64Godll.c b/src/os/src/windows/w64Godll.c similarity index 89% rename from src/os/src/windows64/w64Godll.c rename to src/os/src/windows/w64Godll.c index b0267c4aaccde131d4e06da068b78e1a116c3826..b270dab2f4364c014c0a0b8b28993d0299d11847 100644 --- a/src/os/src/windows64/w64Godll.c +++ b/src/os/src/windows/w64Godll.c @@ -27,8 +27,7 @@ int64_t tsosStr2int64(char *str) { return strtoll(str, &endptr, 10); } -uint64_t htonll(uint64_t val) -{ - return (((uint64_t) htonl(val)) << 32) + htonl(val >> 32); +uint64_t htonll(uint64_t val) { + return (((uint64_t) htonl(val)) << 32) + htonl(val >> 32); } -#endif \ No newline at end of file +#endif diff --git a/src/os/src/windows64/w64Lz4.c b/src/os/src/windows/w64Lz4.c similarity index 100% rename from src/os/src/windows64/w64Lz4.c rename to src/os/src/windows/w64Lz4.c diff --git a/src/os/src/windows64/w64PThread.c b/src/os/src/windows/w64Semphone.c similarity index 100% rename from src/os/src/windows64/w64PThread.c rename to src/os/src/windows/w64Semphone.c diff --git a/src/os/src/windows64/w64Socket.c b/src/os/src/windows/w64Socket.c similarity index 100% rename from src/os/src/windows64/w64Socket.c rename to src/os/src/windows/w64Socket.c diff --git a/src/os/src/windows64/w64Util.c b/src/os/src/windows/w64String.c similarity index 67% rename from src/os/src/windows64/w64Util.c rename to src/os/src/windows/w64String.c index 1a9f71b3c34d95e26b2b4df2d5a4f79747df496a..8057c89a5595d1eefa87b41c760d1fa57acf0ac4 100644 --- a/src/os/src/windows64/w64Util.c +++ b/src/os/src/windows/w64String.c @@ -21,7 +21,6 @@ #include "tulog.h" #include "tutil.h" - /* * Get next token from string *stringp, where tokens are possibly-empty * strings separated by characters from delim. @@ -67,29 +66,6 @@ char *getpass(const char *prefix) { return passwd; } -int flock(int fd, int option) { - return 0; -} - -int fsync(int filedes) { - return 0; -} - -int sigaction(int sig, struct sigaction *d, void *p) { - return 0; -} - -int wordexp(const char *words, wordexp_t *pwordexp, int flags) { - pwordexp->we_offs = 0; - pwordexp->we_wordc = 1; - pwordexp->we_wordv = (char **)(pwordexp->wordPos); - pwordexp->we_wordv[0] = (char *)words; - return 0; -} - -void wordfree(wordexp_t *pwordexp) {} - - char *strndup(const char *s, size_t n) { int len = strlen(s); if (len >= n) { @@ -102,16 +78,54 @@ char *strndup(const char *s, size_t n) { return r; } -void taosSetCoreDump() {} +size_t twcslen(const wchar_t *wcs) { + int *wstr = (int *)wcs; + if (NULL == wstr) { + return 0; + } -#ifdef _TD_GO_DLL_ -int64_t tsosStr2int64(char *str) { - char *endptr = NULL; - return strtoll(str, &endptr, 10); + size_t n = 0; + while (1) { + if (0 == *wstr++) { + break; + } + n++; + } + + return n; } -uint64_t htonll(uint64_t val) -{ - return (((uint64_t) htonl(val)) << 32) + htonl(val >> 32); +int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) { + for (int i = 0; i < bytes; ++i) { + int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4); + int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i * 4); + + if ((f1 == 0 && f2 != 0) || (f1 != 0 && f2 == 0)) { + return f1 - f2; + } else if (f1 == 0 && f2 == 0) { + return 0; + } + + if (f1 != f2) { + return f1 - f2; + } + } + + return 0; + +#if 0 + int32_t ucs4_max_len = bytes + 4; + char *f1_mbs = calloc(bytes, 1); + char *f2_mbs = calloc(bytes, 1); + if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) { + return -1; + } + if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) { + return -1; + } + int32_t ret = strcmp(f1_mbs, f2_mbs); + free(f1_mbs); + free(f2_mbs); + return ret; +#endif } -#endif \ No newline at end of file diff --git a/src/os/src/windows64/w64Strptime.c b/src/os/src/windows/w64Strptime.c similarity index 100% rename from src/os/src/windows64/w64Strptime.c rename to src/os/src/windows/w64Strptime.c diff --git a/src/os/src/windows64/w64Sysinfo.c b/src/os/src/windows/w64Sysinfo.c similarity index 99% rename from src/os/src/windows64/w64Sysinfo.c rename to src/os/src/windows/w64Sysinfo.c index 950230e56754952b194d41e84675cbecfe71c237..0a680ac0b7d47f65017d5027569fee4f2f54f508 100644 --- a/src/os/src/windows64/w64Sysinfo.c +++ b/src/os/src/windows/w64Sysinfo.c @@ -113,4 +113,6 @@ int fsync(int filedes) { int sigaction(int sig, struct sigaction *d, void *p) { return 0; -} \ No newline at end of file +} + +void taosSetCoreDump() {} \ No newline at end of file diff --git a/src/os/src/windows64/w64Time.c b/src/os/src/windows/w64Time.c similarity index 100% rename from src/os/src/windows64/w64Time.c rename to src/os/src/windows/w64Time.c diff --git a/src/os/src/windows64/w64Timer.c b/src/os/src/windows/w64Timer.c similarity index 100% rename from src/os/src/windows64/w64Timer.c rename to src/os/src/windows/w64Timer.c diff --git a/src/os/src/windows64/w64Wordexp.c b/src/os/src/windows/w64Wordexp.c similarity index 100% rename from src/os/src/windows64/w64Wordexp.c rename to src/os/src/windows/w64Wordexp.c diff --git a/src/os/src/windows64/w64Coredump.c b/src/os/src/windows64/w64Coredump.c deleted file mode 100644 index 95490e7ad0111517633f6ad8439d7e9697864a2a..0000000000000000000000000000000000000000 --- a/src/os/src/windows64/w64Coredump.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" -#include "tconfig.h" -#include "tglobal.h" -#include "tulog.h" -#include "tsystem.h" - -void taosSetCoreDump() {} \ No newline at end of file diff --git a/src/os/src/windows64/w64File.c b/src/os/src/windows64/w64File.c deleted file mode 100644 index 5cfcc8f79c977ee675a90e9d536677212bf6697b..0000000000000000000000000000000000000000 --- a/src/os/src/windows64/w64File.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" - -void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) { - const char* tdengineTmpFileNamePrefix = "tdengine-"; - char tmpPath[PATH_MAX]; - - char *tmpDir = getenv("tmp"); - if (tmpDir == NULL) { - tmpDir = ""; - } - - strcpy(tmpPath, tmpDir); - strcat(tmpPath, tdengineTmpFileNamePrefix); - if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) { - strcat(tmpPath, fileNamePrefix); - strcat(tmpPath, "-%d-%s"); - } - - char rand[8] = {0}; - taosRandStr(rand, tListLen(rand) - 1); - snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand); -} diff --git a/src/os/src/windows64/w64Getline.c b/src/os/src/windows64/w64Getline.c deleted file mode 100644 index 1dd56fd54781d709255637764e2779d7f039c984..0000000000000000000000000000000000000000 --- a/src/os/src/windows64/w64Getline.c +++ /dev/null @@ -1,145 +0,0 @@ -/* getline.c -- Replacement for GNU C library function getline - -Copyright (C) 1993 Free Software Foundation, Inc. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. */ - -/* Written by Jan Brittenson, bson@gnu.ai.mit.edu. */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#if STDC_HEADERS -#include -#else -char *malloc(), *realloc(); -#endif - -/* Always add at least this many bytes when extending the buffer. */ -#define MIN_CHUNK 64 - -/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR -+ OFFSET (and null-terminate it). *LINEPTR is a pointer returned from -malloc (or NULL), pointing to *N characters of space. It is realloc'd -as necessary. Return the number of characters read (not including the -null terminator), or -1 on error or EOF. On a -1 return, the caller -should check feof(), if not then errno has been set to indicate -the error. */ - -int -getstr(lineptr, n, stream, terminator, offset) -char **lineptr; -size_t *n; -FILE *stream; -char terminator; -int offset; -{ - int nchars_avail; /* Allocated but unused chars in *LINEPTR. */ - char *read_pos; /* Where we're reading into *LINEPTR. */ - int ret; - - if (!lineptr || !n || !stream) - { - errno = EINVAL; - return -1; - } - - if (!*lineptr) - { - *n = MIN_CHUNK; - *lineptr = malloc(*n); - if (!*lineptr) - { - errno = ENOMEM; - return -1; - } - } - - nchars_avail = (int)(*n - offset); - read_pos = *lineptr + offset; - - for (;;) - { - int save_errno; - register int c = getc(stream); - - save_errno = errno; - - /* We always want at least one char left in the buffer, since we - always (unless we get an error while reading the first char) - NUL-terminate the line buffer. */ - - assert((*lineptr + *n) == (read_pos + nchars_avail)); - if (nchars_avail < 2) - { - if (*n > MIN_CHUNK) - *n *= 2; - else - *n += MIN_CHUNK; - - nchars_avail = (int)(*n + *lineptr - read_pos); - *lineptr = realloc(*lineptr, *n); - if (!*lineptr) - { - errno = ENOMEM; - return -1; - } - read_pos = *n - nchars_avail + *lineptr; - assert((*lineptr + *n) == (read_pos + nchars_avail)); - } - - if (ferror(stream)) - { - /* Might like to return partial line, but there is no - place for us to store errno. And we don't want to just - lose errno. */ - errno = save_errno; - return -1; - } - - if (c == EOF) - { - /* Return partial line, if any. */ - if (read_pos == *lineptr) - return -1; - else - break; - } - - *read_pos++ = c; - nchars_avail--; - - if (c == terminator) - /* Return the line. */ - break; - } - - /* Done - NUL terminate and return the number of chars read. */ - *read_pos = '\0'; - - ret = (int)(read_pos - (*lineptr + offset)); - return ret; -} - -int -getline(lineptr, n, stream) -char **lineptr; -size_t *n; -FILE *stream; -{ - return getstr(lineptr, n, stream, '\n', 0); -} \ No newline at end of file diff --git a/src/os/src/windows64/w64Msghdr.c b/src/os/src/windows64/w64Msghdr.c deleted file mode 100644 index 9d1924f311ccf676f9aad141df6b8feaac32e356..0000000000000000000000000000000000000000 --- a/src/os/src/windows64/w64Msghdr.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include - -void taosFreeMsgHdr(void *hdr) { - WSAMSG *msgHdr = (WSAMSG *)hdr; - free(msgHdr->lpBuffers); -} - -int taosMsgHdrSize(void *hdr) { - WSAMSG *msgHdr = (WSAMSG *)hdr; - return msgHdr->dwBufferCount; -} - -void taosSendMsgHdr(void *hdr, int fd) { - WSAMSG *msgHdr = (WSAMSG *)hdr; - DWORD len; - - WSASendMsg(fd, msgHdr, 0, &len, 0, 0); - msgHdr->dwBufferCount = 0; -} - -void taosInitMsgHdr(void **hdr, void *dest, int maxPkts) { - WSAMSG *msgHdr = (WSAMSG *)malloc(sizeof(WSAMSG)); - memset(msgHdr, 0, sizeof(WSAMSG)); - *hdr = msgHdr; - - // see ws2def.h - // the size of LPSOCKADDR and sockaddr_in * is same, so it's safe - msgHdr->name = (LPSOCKADDR)dest; - msgHdr->namelen = sizeof(struct sockaddr_in); - int size = sizeof(WSABUF) * maxPkts; - msgHdr->lpBuffers = (LPWSABUF)malloc(size); - memset(msgHdr->lpBuffers, 0, size); - msgHdr->dwBufferCount = 0; -} - -void taosSetMsgHdrData(void *hdr, char *data, int dataLen) { - WSAMSG *msgHdr = (WSAMSG *)hdr; - msgHdr->lpBuffers[msgHdr->dwBufferCount].buf = data; - msgHdr->lpBuffers[msgHdr->dwBufferCount].len = dataLen; - msgHdr->dwBufferCount++; -} diff --git a/src/os/src/windows64/w64String.c b/src/os/src/windows64/w64String.c deleted file mode 100644 index 0b392466fa91a23bc4011baede957f21a2452b2d..0000000000000000000000000000000000000000 --- a/src/os/src/windows64/w64String.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" -#include "taosdef.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - - -/* - * Get next token from string *stringp, where tokens are possibly-empty - * strings separated by characters from delim. - * - * Writes NULs into the string at *stringp to end tokens. - * delim need not remain constant from call to call. - * On return, *stringp points past the last NUL written (if there might - * be further tokens), or is NULL (if there are definitely no moretokens). - * - * If *stringp is NULL, strsep returns NULL. - */ -char *strsep(char **stringp, const char *delim) { - char *s; - const char *spanp; - int c, sc; - char *tok; - if ((s = *stringp) == NULL) - return (NULL); - for (tok = s;;) { - c = *s++; - spanp = delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - *stringp = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ -} - -char *getpass(const char *prefix) { - static char passwd[TSDB_KEY_LEN] = {0}; - - printf("%s", prefix); - scanf("%s", passwd); - - char n = getchar(); - return passwd; -} - -char *strndup(const char *s, size_t n) { - int len = strlen(s); - if (len >= n) { - len = n; - } - - char *r = calloc(len + 1, 1); - memcpy(r, s, len); - r[len] = 0; - return r; -} - -#ifdef _TD_GO_DLL_ -int64_t tsosStr2int64(char *str) { - char *endptr = NULL; - return strtoll(str, &endptr, 10); -} - -uint64_t htonll(uint64_t val) -{ - return (((uint64_t) htonl(val)) << 32) + htonl(val >> 32); -} -#endif \ No newline at end of file diff --git a/src/os/src/windows64/w64Wchar.c b/src/os/src/windows64/w64Wchar.c deleted file mode 100644 index d5930d1de9856860af154776f78bd6f1d347f366..0000000000000000000000000000000000000000 --- a/src/os/src/windows64/w64Wchar.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" -#include "tglobal.h" -#include "tulog.h" - -size_t twcslen(const wchar_t *wcs) { - int *wstr = (int *)wcs; - if (NULL == wstr) { - return 0; - } - - size_t n = 0; - while (1) { - if (0 == *wstr++) { - break; - } - n++; - } - - return n; -} - -int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) { - for (int i = 0; i < bytes; ++i) { - int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4); - int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i * 4); - - if ((f1 == 0 && f2 != 0) || (f1 != 0 && f2 == 0)) { - return f1 - f2; - } else if (f1 == 0 && f2 == 0) { - return 0; - } - - if (f1 != f2) { - return f1 - f2; - } - } - - return 0; - -#if 0 - int32_t ucs4_max_len = bytes + 4; - char *f1_mbs = calloc(bytes, 1); - char *f2_mbs = calloc(bytes, 1); - if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) { - return -1; - } - if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) { - return -1; - } - int32_t ret = strcmp(f1_mbs, f2_mbs); - free(f1_mbs); - free(f2_mbs); - return ret; -#endif -}