diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 6b88c9074738204d99f2dc536100a68a1656ea77..d8b40f397fae8d66ffd0c489744bfee0a010de43 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -68,7 +68,7 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1 } else if (strncmp(pToken->z, "0", 1) == 0 && pToken->n == 1) { // do nothing } else if (pToken->type == TK_INTEGER) { - useconds = tsosStr2int64(pToken->z); + useconds = taosStr2int64(pToken->z); } else { // strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm); if (taosParseTime(pToken->z, time, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) { diff --git a/src/os/inc/osDarwin.h b/src/os/inc/osDarwin.h index 7c206afe7a12e9be17ad997ee50625a0cce438e9..f8e3c65d63f6da7649a7ffc113b3f7ac17c66886 100644 --- a/src/os/inc/osDarwin.h +++ b/src/os/inc/osDarwin.h @@ -82,13 +82,11 @@ extern "C" { int tsem_destroy(tsem_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_SEMPHONE_PTHREAD // specific -#define htobe64 htonll typedef int(*__compar_fn_t)(const void *, const void *); // for send function in tsocket.c @@ -108,8 +106,6 @@ typedef int(*__compar_fn_t)(const void *, const void *); #define TAOS_OS_FUNC_PTHREAD_RWLOCK -int64_t tsosStr2int64(char *str); - #include "eok.h" void taos_block_sigalrm(void); diff --git a/src/os/inc/osDef.h b/src/os/inc/osDef.h index ac7aac0afa5175e1f43f148d6b7ea5ba9725cdac..7604100e0aefce4eea186188ad7a07ca22892ad3 100644 --- a/src/os/inc/osDef.h +++ b/src/os/inc/osDef.h @@ -111,7 +111,7 @@ extern "C" { #define threadlocal __declspec( thread ) #endif -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) #define PRIzu "ld" #endif diff --git a/src/os/inc/osMemory.h b/src/os/inc/osMemory.h index 2cf7e14d2f4bc9fc124cdf4de167c5b2cb93f4bb..27efd9f5051d9f87838980503ed60174de153ad4 100644 --- a/src/os/inc/osMemory.h +++ b/src/os/inc/osMemory.h @@ -43,9 +43,6 @@ void taosTMemset(void *ptr, int c); #define tmalloc(size) malloc(size) #define tcalloc(num, size) calloc(num, size) #define trealloc(ptr, size) realloc(ptr, size) -#define tstrdup(str) taosStrdupImp(str) -#define tstrndup(str, size) taosStrndupImp(str, size) -#define tgetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream) #define tfree(x) \ do { \ if (x) { \ @@ -71,15 +68,8 @@ void taosTMemset(void *ptr, int c); #define tcalloc(num, size) taosCallocMem(num, size, __FILE__, __LINE__) #define trealloc(ptr, size) taosReallocMem(ptr, size, __FILE__, __LINE__) #define tfree(ptr) taosFreeMem(ptr, __FILE__, __LINE__) - - // #undef tstrdup - // #undef tstrndup - // #undef tgetline - // #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__) - // #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__) - // #define tgetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__) #endif -#endif +#endif #ifdef __cplusplus } diff --git a/src/os/inc/osRand.h b/src/os/inc/osRand.h index 803c0688bb4a9c5fab117d8548206e70b5f152db..e08768c2cc6b379877fb8be7d3541c13bc431f98 100644 --- a/src/os/inc/osRand.h +++ b/src/os/inc/osRand.h @@ -20,9 +20,8 @@ extern "C" { #endif -// TAOS_OS_FUNC_RAND uint32_t taosRand(void); -void taosRandStr(char* str, int32_t size); +void taosRandStr(char* str, int32_t size); uint32_t taosSafeRand(void); #ifdef __cplusplus diff --git a/src/os/inc/osSocket.h b/src/os/inc/osSocket.h index cf75b74a9afa75caa15ec82e191d781159af944f..e60028337fbabadce01b09a812bd08f55b0a251e 100644 --- a/src/os/inc/osSocket.h +++ b/src/os/inc/osSocket.h @@ -74,6 +74,16 @@ int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op uint32_t taosInetAddr(char *ipAddr); const char *taosInetNtoa(struct in_addr ipInt); + +#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) + #define htobe64 htonll + #if defined(_TD_GO_DLL_) + uint64_t htonll(uint64_t val); + #endif +#elif defined(_TD_DARWIN_64) + #define htobe64 htonll +#endif + #ifdef __cplusplus } #endif diff --git a/src/os/inc/osString.h b/src/os/inc/osString.h index 97966ed412d0ae4ef4970de4dbb6d48c82130671..f2e8b381fe7d4f6d48bc30ec902c1ef576064e78 100644 --- a/src/os/inc/osString.h +++ b/src/os/inc/osString.h @@ -20,35 +20,30 @@ extern "C" { #endif -#ifndef TAOS_OS_FUNC_STRING_STRDUP - #define taosStrdupImp(str) strdup(str) - #define taosStrndupImp(str, size) strndup(str, size) -#endif - -#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 +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + #define tstrdup(str) _strdup(str) + #define tstrndup(str, size) _strndup(str, size) + int32_t tgetline(char **lineptr, size_t *n, FILE *stream); + int32_t twcslen(const wchar_t *wcs); +#else + #define tstrdup(str) strdup(str) + #define tstrndup(str, size) strndup(str, size) + #define tgetline(lineptr, n, stream) getline(lineptr, n , stream) #define twcslen wcslen -#endif +#endif -#define tstrncpy(dst, src, size) \ - do { \ - strncpy((dst), (src), (size)); \ - (dst)[(size)-1] = 0; \ +#define tstrncpy(dst, src, size) \ + do { \ + strncpy((dst), (src), (size)); \ + (dst)[(size)-1] = 0; \ } while (0) -#ifndef TAOS_OS_FUNC_STRING_STR2INT64 - int64_t tsosStr2int64(char *str); -#endif +int64_t taosStr2int64(char *str); // USE_LIBICONV int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); -bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int *len); -int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes); +bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t *len); +int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes); bool taosValidateEncodec(const char *encodec); char * taosCharsetReplace(char *charsetstr); diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index 5fd32711f9a0406f59bbb60f599ff4a6c24d65f3..f90ae6f059442722c4a4d458b37455ee1519881b 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -88,19 +88,6 @@ typedef SOCKET eventfd_t; #define EPOLLWAKEUP (1u << 29) #endif -#define TAOS_OS_FUNC_STRING_WCHAR - int twcslen(const wchar_t *wcs); -#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) char *stpcpy (char *dest, const char *src); char *stpncpy (char *dest, const char *src, size_t n); @@ -127,7 +114,6 @@ typedef int (*__compar_fn_t)(const void *, const void *); #define snprintf _snprintf #define in_addr_t unsigned long #define socklen_t int -#define htobe64 htonll struct tm *localtime_r(const time_t *timep, struct tm *result); char * strptime(const char *buf, const char *fmt, struct tm *tm); diff --git a/src/os/src/darwin/darwinString.c b/src/os/src/darwin/darwinString.c deleted file mode 100644 index 3042e78666c45a97236a45ea20eaf19706104f92..0000000000000000000000000000000000000000 --- a/src/os/src/darwin/darwinString.c +++ /dev/null @@ -1,22 +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" - -int64_t tsosStr2int64(char *str) { - char *endptr = NULL; - return strtoll(str, &endptr, 10); -} diff --git a/src/os/src/detail/osRand.c b/src/os/src/detail/osRand.c index b322a88684e63776b432d2f4025b3d16fc614861..0dda908bb35c68513dba150e8380846c36aa2893 100644 --- a/src/os/src/detail/osRand.c +++ b/src/os/src/detail/osRand.c @@ -16,8 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" -#ifndef TAOS_OS_FUNC_RAND - uint32_t taosRand(void) { return rand(); } uint32_t taosSafeRand(void) { @@ -38,8 +36,6 @@ uint32_t taosSafeRand(void) { return (uint32_t)seed; } -#endif - void taosRandStr(char* str, int32_t size) { const char* set = "abcdefghijklmnopqrstuvwxyz0123456789-_."; int32_t len = 39; diff --git a/src/os/src/detail/osString.c b/src/os/src/detail/osString.c index 59f47b4815badd8411b54ea997bf6b46f3a18a27..2c49797d83dd4bb53b2fef69091e28be7194461e 100644 --- a/src/os/src/detail/osString.c +++ b/src/os/src/detail/osString.c @@ -17,17 +17,17 @@ #include "os.h" #include "tglobal.h" -#ifndef TAOS_OS_FUNC_STRING_STR2INT64 -int64_t tsosStr2int64(char *str) { +int64_t taosStr2int64(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) { +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) + +int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t 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/windows/wGetline.c b/src/os/src/windows/wGetline.c index 3e8701e19b3ee420648bec984874416410cd14f1..b9d8ccf928b38a647de5655ed361f43f60d05778 100644 --- a/src/os/src/windows/wGetline.c +++ b/src/os/src/windows/wGetline.c @@ -40,10 +40,10 @@ 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; +int32_t getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int32_t offset) { + int32_t nchars_avail; /* Allocated but unused chars in *LINEPTR. */ + char * read_pos; /* Where we're reading into *LINEPTR. */ + int32_t ret; if (!lineptr || !n || !stream) { errno = EINVAL; @@ -59,12 +59,12 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) } } - nchars_avail = (int)(*n - offset); + nchars_avail = (int32_t)(*n - offset); read_pos = *lineptr + offset; for (;;) { - int save_errno; - register int c = getc(stream); + int32_t save_errno; + register int32_t c = getc(stream); save_errno = errno; @@ -79,7 +79,7 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) else *n += MIN_CHUNK; - nchars_avail = (int)(*n + *lineptr - read_pos); + nchars_avail = (int32_t)(*n + *lineptr - read_pos); *lineptr = realloc(*lineptr, *n); if (!*lineptr) { errno = ENOMEM; @@ -115,10 +115,8 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) /* Done - NUL terminate and return the number of chars read. */ *read_pos = '\0'; - ret = (int)(read_pos - (*lineptr + offset)); + ret = (int32_t)(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 +int32_t tgetline(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/windows/wGodll.c b/src/os/src/windows/wGodll.c deleted file mode 100644 index b270dab2f4364c014c0a0b8b28993d0299d11847..0000000000000000000000000000000000000000 --- a/src/os/src/windows/wGodll.c +++ /dev/null @@ -1,33 +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" - -#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 diff --git a/src/os/src/windows/wSocket.c b/src/os/src/windows/wSocket.c index 4e6ee15e772c5af56b4ebd11e74fc44dd57946f5..e152f40f03538c4a87fa2a55ade3e08dc741bf37 100644 --- a/src/os/src/windows/wSocket.c +++ b/src/os/src/windows/wSocket.c @@ -88,4 +88,10 @@ const char *taosInetNtoa(struct in_addr ipInt) { return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN); } -#endif \ No newline at end of file +#endif + +#if defined(_TD_GO_DLL_) + +uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(val >> 32); } + +#endif diff --git a/src/os/src/windows/wString.c b/src/os/src/windows/wString.c index 67237e655cd2916ec2ec80daa01e7a0f9ae0d3e3..96a604ae6e3bfb2088a376894c7083a9514ae67f 100644 --- a/src/os/src/windows/wString.c +++ b/src/os/src/windows/wString.c @@ -33,9 +33,9 @@ * If *stringp is NULL, strsep returns NULL. */ char *strsep(char **stringp, const char *delim) { - char *s; + char * s; const char *spanp; - int c, sc; + int32_t c, sc; char *tok; if ((s = *stringp) == NULL) return (NULL); @@ -75,13 +75,13 @@ char *getpass(const char *prefix) { return passwd; } -int twcslen(const wchar_t *wcs) { - int *wstr = (int *)wcs; +int32_t twcslen(const wchar_t *wcs) { + int32_t *wstr = (int32_t *)wcs; if (NULL == wstr) { return 0; } - int n = 0; + int32_t n = 0; while (1) { if (0 == *wstr++) { break; @@ -92,8 +92,8 @@ int twcslen(const wchar_t *wcs) { return n; } -int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) { - for (int i = 0; i < bytes; ++i) { +int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) { + for (int32_t 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); @@ -127,7 +127,6 @@ int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) { #endif } - /* Copy memory to memory until the specified number of bytes has been copied, return pointer to following byte. Overlap is NOT handled correctly. */