提交 ac3d6440 编写于 作者: S Shengliang Guan

TD-4088

上级 18fdb96a
...@@ -68,7 +68,7 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1 ...@@ -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) { } else if (strncmp(pToken->z, "0", 1) == 0 && pToken->n == 1) {
// do nothing // do nothing
} else if (pToken->type == TK_INTEGER) { } else if (pToken->type == TK_INTEGER) {
useconds = tsosStr2int64(pToken->z); useconds = taosStr2int64(pToken->z);
} else { } else {
// strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm); // 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) { if (taosParseTime(pToken->z, time, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) {
......
...@@ -82,13 +82,11 @@ extern "C" { ...@@ -82,13 +82,11 @@ extern "C" {
int tsem_destroy(tsem_t *sem); int tsem_destroy(tsem_t *sem);
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT #define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
#define TAOS_OS_FUNC_STRING_STR2INT64
#define TAOS_OS_FUNC_SYSINFO #define TAOS_OS_FUNC_SYSINFO
#define TAOS_OS_FUNC_TIMER #define TAOS_OS_FUNC_TIMER
#define TAOS_OS_FUNC_SEMPHONE_PTHREAD #define TAOS_OS_FUNC_SEMPHONE_PTHREAD
// specific // specific
#define htobe64 htonll
typedef int(*__compar_fn_t)(const void *, const void *); typedef int(*__compar_fn_t)(const void *, const void *);
// for send function in tsocket.c // for send function in tsocket.c
...@@ -108,8 +106,6 @@ typedef int(*__compar_fn_t)(const void *, const void *); ...@@ -108,8 +106,6 @@ typedef int(*__compar_fn_t)(const void *, const void *);
#define TAOS_OS_FUNC_PTHREAD_RWLOCK #define TAOS_OS_FUNC_PTHREAD_RWLOCK
int64_t tsosStr2int64(char *str);
#include "eok.h" #include "eok.h"
void taos_block_sigalrm(void); void taos_block_sigalrm(void);
......
...@@ -111,7 +111,7 @@ extern "C" { ...@@ -111,7 +111,7 @@ extern "C" {
#define threadlocal __declspec( thread ) #define threadlocal __declspec( thread )
#endif #endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
#define PRIzu "ld" #define PRIzu "ld"
#endif #endif
......
...@@ -43,9 +43,6 @@ void taosTMemset(void *ptr, int c); ...@@ -43,9 +43,6 @@ void taosTMemset(void *ptr, int c);
#define tmalloc(size) malloc(size) #define tmalloc(size) malloc(size)
#define tcalloc(num, size) calloc(num, size) #define tcalloc(num, size) calloc(num, size)
#define trealloc(ptr, size) realloc(ptr, 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) \ #define tfree(x) \
do { \ do { \
if (x) { \ if (x) { \
...@@ -71,15 +68,8 @@ void taosTMemset(void *ptr, int c); ...@@ -71,15 +68,8 @@ void taosTMemset(void *ptr, int c);
#define tcalloc(num, size) taosCallocMem(num, size, __FILE__, __LINE__) #define tcalloc(num, size) taosCallocMem(num, size, __FILE__, __LINE__)
#define trealloc(ptr, size) taosReallocMem(ptr, size, __FILE__, __LINE__) #define trealloc(ptr, size) taosReallocMem(ptr, size, __FILE__, __LINE__)
#define tfree(ptr) taosFreeMem(ptr, __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 #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -20,9 +20,8 @@ ...@@ -20,9 +20,8 @@
extern "C" { extern "C" {
#endif #endif
// TAOS_OS_FUNC_RAND
uint32_t taosRand(void); uint32_t taosRand(void);
void taosRandStr(char* str, int32_t size); void taosRandStr(char* str, int32_t size);
uint32_t taosSafeRand(void); uint32_t taosSafeRand(void);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -74,6 +74,16 @@ int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op ...@@ -74,6 +74,16 @@ int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op
uint32_t taosInetAddr(char *ipAddr); uint32_t taosInetAddr(char *ipAddr);
const char *taosInetNtoa(struct in_addr ipInt); 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 #ifdef __cplusplus
} }
#endif #endif
......
...@@ -20,35 +20,30 @@ ...@@ -20,35 +20,30 @@
extern "C" { extern "C" {
#endif #endif
#ifndef TAOS_OS_FUNC_STRING_STRDUP #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define taosStrdupImp(str) strdup(str) #define tstrdup(str) _strdup(str)
#define taosStrndupImp(str, size) strndup(str, size) #define tstrndup(str, size) _strndup(str, size)
#endif int32_t tgetline(char **lineptr, size_t *n, FILE *stream);
int32_t twcslen(const wchar_t *wcs);
#ifndef TAOS_OS_FUNC_STRING_GETLINE #else
#define taosGetlineImp(lineptr, n, stream) getline(lineptr, n , stream) #define tstrdup(str) strdup(str)
#else #define tstrndup(str, size) strndup(str, size)
int taosGetlineImp(char **lineptr, size_t *n, FILE *stream); #define tgetline(lineptr, n, stream) getline(lineptr, n , stream)
#endif
#ifndef TAOS_OS_FUNC_STRING_WCHAR
#define twcslen wcslen #define twcslen wcslen
#endif #endif
#define tstrncpy(dst, src, size) \ #define tstrncpy(dst, src, size) \
do { \ do { \
strncpy((dst), (src), (size)); \ strncpy((dst), (src), (size)); \
(dst)[(size)-1] = 0; \ (dst)[(size)-1] = 0; \
} while (0) } while (0)
#ifndef TAOS_OS_FUNC_STRING_STR2INT64 int64_t taosStr2int64(char *str);
int64_t tsosStr2int64(char *str);
#endif
// USE_LIBICONV // USE_LIBICONV
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); 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); bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t *len);
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes); int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes);
bool taosValidateEncodec(const char *encodec); bool taosValidateEncodec(const char *encodec);
char * taosCharsetReplace(char *charsetstr); char * taosCharsetReplace(char *charsetstr);
......
...@@ -88,19 +88,6 @@ typedef SOCKET eventfd_t; ...@@ -88,19 +88,6 @@ typedef SOCKET eventfd_t;
#define EPOLLWAKEUP (1u << 29) #define EPOLLWAKEUP (1u << 29)
#endif #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 *stpcpy (char *dest, const char *src);
char *stpncpy (char *dest, const char *src, size_t n); char *stpncpy (char *dest, const char *src, size_t n);
...@@ -127,7 +114,6 @@ typedef int (*__compar_fn_t)(const void *, const void *); ...@@ -127,7 +114,6 @@ typedef int (*__compar_fn_t)(const void *, const void *);
#define snprintf _snprintf #define snprintf _snprintf
#define in_addr_t unsigned long #define in_addr_t unsigned long
#define socklen_t int #define socklen_t int
#define htobe64 htonll
struct tm *localtime_r(const time_t *timep, struct tm *result); struct tm *localtime_r(const time_t *timep, struct tm *result);
char * strptime(const char *buf, const char *fmt, struct tm *tm); char * strptime(const char *buf, const char *fmt, struct tm *tm);
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
int64_t tsosStr2int64(char *str) {
char *endptr = NULL;
return strtoll(str, &endptr, 10);
}
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#ifndef TAOS_OS_FUNC_RAND
uint32_t taosRand(void) { return rand(); } uint32_t taosRand(void) { return rand(); }
uint32_t taosSafeRand(void) { uint32_t taosSafeRand(void) {
...@@ -38,8 +36,6 @@ uint32_t taosSafeRand(void) { ...@@ -38,8 +36,6 @@ uint32_t taosSafeRand(void) {
return (uint32_t)seed; return (uint32_t)seed;
} }
#endif
void taosRandStr(char* str, int32_t size) { void taosRandStr(char* str, int32_t size) {
const char* set = "abcdefghijklmnopqrstuvwxyz0123456789-_."; const char* set = "abcdefghijklmnopqrstuvwxyz0123456789-_.";
int32_t len = 39; int32_t len = 39;
......
...@@ -17,17 +17,17 @@ ...@@ -17,17 +17,17 @@
#include "os.h" #include "os.h"
#include "tglobal.h" #include "tglobal.h"
#ifndef TAOS_OS_FUNC_STRING_STR2INT64 int64_t taosStr2int64(char *str) {
int64_t tsosStr2int64(char *str) {
char *endptr = NULL; char *endptr = NULL;
return strtoll(str, &endptr, 10); return strtoll(str, &endptr, 10);
} }
#endif
#ifndef TAOS_OS_FUNC_STRING_WCHAR #if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) {
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); return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / TSDB_NCHAR_SIZE);
} }
#endif #endif
#ifdef USE_LIBICONV #ifdef USE_LIBICONV
......
...@@ -40,10 +40,10 @@ null terminator), or -1 on error or EOF. On a -1 return, the caller ...@@ -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 should check feof(), if not then errno has been set to indicate
the error. */ the error. */
int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) { int32_t getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int32_t offset) {
int nchars_avail; /* Allocated but unused chars in *LINEPTR. */ int32_t nchars_avail; /* Allocated but unused chars in *LINEPTR. */
char *read_pos; /* Where we're reading into *LINEPTR. */ char * read_pos; /* Where we're reading into *LINEPTR. */
int ret; int32_t ret;
if (!lineptr || !n || !stream) { if (!lineptr || !n || !stream) {
errno = EINVAL; errno = EINVAL;
...@@ -59,12 +59,12 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) ...@@ -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; read_pos = *lineptr + offset;
for (;;) { for (;;) {
int save_errno; int32_t save_errno;
register int c = getc(stream); register int32_t c = getc(stream);
save_errno = errno; save_errno = errno;
...@@ -79,7 +79,7 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) ...@@ -79,7 +79,7 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset)
else else
*n += MIN_CHUNK; *n += MIN_CHUNK;
nchars_avail = (int)(*n + *lineptr - read_pos); nchars_avail = (int32_t)(*n + *lineptr - read_pos);
*lineptr = realloc(*lineptr, *n); *lineptr = realloc(*lineptr, *n);
if (!*lineptr) { if (!*lineptr) {
errno = ENOMEM; errno = ENOMEM;
...@@ -115,10 +115,8 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) ...@@ -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. */ /* Done - NUL terminate and return the number of chars read. */
*read_pos = '\0'; *read_pos = '\0';
ret = (int)(read_pos - (*lineptr + offset)); ret = (int32_t)(read_pos - (*lineptr + offset));
return ret; return ret;
} }
int taosGetlineImp(char **lineptr, size_t *n, FILE *stream) { int32_t tgetline(char **lineptr, size_t *n, FILE *stream) { return getstr(lineptr, n, stream, '\n', 0); }
return getstr(lineptr, n, stream, '\n', 0); \ No newline at end of file
}
\ No newline at end of file
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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
...@@ -88,4 +88,10 @@ const char *taosInetNtoa(struct in_addr ipInt) { ...@@ -88,4 +88,10 @@ const char *taosInetNtoa(struct in_addr ipInt) {
return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN); return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN);
} }
#endif #endif
\ No newline at end of file
#if defined(_TD_GO_DLL_)
uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(val >> 32); }
#endif
...@@ -33,9 +33,9 @@ ...@@ -33,9 +33,9 @@
* If *stringp is NULL, strsep returns NULL. * If *stringp is NULL, strsep returns NULL.
*/ */
char *strsep(char **stringp, const char *delim) { char *strsep(char **stringp, const char *delim) {
char *s; char * s;
const char *spanp; const char *spanp;
int c, sc; int32_t c, sc;
char *tok; char *tok;
if ((s = *stringp) == NULL) if ((s = *stringp) == NULL)
return (NULL); return (NULL);
...@@ -75,13 +75,13 @@ char *getpass(const char *prefix) { ...@@ -75,13 +75,13 @@ char *getpass(const char *prefix) {
return passwd; return passwd;
} }
int twcslen(const wchar_t *wcs) { int32_t twcslen(const wchar_t *wcs) {
int *wstr = (int *)wcs; int32_t *wstr = (int32_t *)wcs;
if (NULL == wstr) { if (NULL == wstr) {
return 0; return 0;
} }
int n = 0; int32_t n = 0;
while (1) { while (1) {
if (0 == *wstr++) { if (0 == *wstr++) {
break; break;
...@@ -92,8 +92,8 @@ int twcslen(const wchar_t *wcs) { ...@@ -92,8 +92,8 @@ int twcslen(const wchar_t *wcs) {
return n; return n;
} }
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) { int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) {
for (int i = 0; i < bytes; ++i) { for (int32_t i = 0; i < bytes; ++i) {
int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4); int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4);
int32_t f2 = *(int32_t *)((char *)f2_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) { ...@@ -127,7 +127,6 @@ int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) {
#endif #endif
} }
/* Copy memory to memory until the specified number of bytes /* Copy memory to memory until the specified number of bytes
has been copied, return pointer to following byte. has been copied, return pointer to following byte.
Overlap is NOT handled correctly. */ Overlap is NOT handled correctly. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册