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

TD-4088

上级 18fdb96a
......@@ -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) {
......
......@@ -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);
......
......@@ -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
......
......@@ -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
}
......
......@@ -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
......
......@@ -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
......
......@@ -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);
......
......@@ -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);
......
/*
* 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 @@
#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;
......
......@@ -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
......
......@@ -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
/*
* 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) {
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
......@@ -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. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册