提交 8089a23c 编写于 作者: S slguan

[TD-992]

上级 a0c3a007
......@@ -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"
......
......@@ -71,21 +71,21 @@ extern "C" {
#include <fcntl.h>
#include <sys/utsname.h>
#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
......
......@@ -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
......
......@@ -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();
......
......@@ -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) \
#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)
......
......@@ -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
......
......@@ -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
......
/*
* 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/>.
*/
#ifndef TDENGINE_PLATFORM_WINDOWS32_H
#define TDENGINE_PLATFORM_WINDOWS32_H
#include <assert.h>
#include <ctype.h>
#include <direct.h>
#include <errno.h>
#include <fcntl.h>
#include <float.h>
#include <locale.h>
#include <intrin.h>
#include <io.h>
#include <math.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <inttypes.h>
#include "winsock2.h"
#include <WS2tcpip.h>
#include <winbase.h>
#include <Winsock2.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
......@@ -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;
......
......@@ -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(); }
......
......@@ -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
......
......@@ -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,
......
......@@ -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
......
......@@ -40,30 +40,20 @@ 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 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)
{
if (!lineptr || !n || !stream) {
errno = EINVAL;
return -1;
}
if (!*lineptr)
{
if (!*lineptr) {
*n = MIN_CHUNK;
*lineptr = malloc(*n);
if (!*lineptr)
{
if (!*lineptr) {
errno = ENOMEM;
return -1;
}
......@@ -72,8 +62,7 @@ int offset;
nchars_avail = (int)(*n - offset);
read_pos = *lineptr + offset;
for (;;)
{
for (;;) {
int save_errno;
register int c = getc(stream);
......@@ -84,8 +73,7 @@ int offset;
NUL-terminate the line buffer. */
assert((*lineptr + *n) == (read_pos + nchars_avail));
if (nchars_avail < 2)
{
if (nchars_avail < 2) {
if (*n > MIN_CHUNK)
*n *= 2;
else
......@@ -93,8 +81,7 @@ int offset;
nchars_avail = (int)(*n + *lineptr - read_pos);
*lineptr = realloc(*lineptr, *n);
if (!*lineptr)
{
if (!*lineptr) {
errno = ENOMEM;
return -1;
}
......@@ -102,8 +89,7 @@ int offset;
assert((*lineptr + *n) == (read_pos + nchars_avail));
}
if (ferror(stream))
{
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. */
......@@ -111,8 +97,7 @@ int offset;
return -1;
}
if (c == EOF)
{
if (c == EOF) {
/* Return partial line, if any. */
if (read_pos == *lineptr)
return -1;
......@@ -123,8 +108,7 @@ int offset;
*read_pos++ = c;
nchars_avail--;
if (c == terminator)
/* Return the line. */
if (c == terminator) /* Return the line. */
break;
}
......@@ -135,11 +119,6 @@ int offset;
return ret;
}
int
getline(lineptr, n, stream)
char **lineptr;
size_t *n;
FILE *stream;
{
int taosGetlineImp(char **lineptr, size_t *n, FILE *stream) {
return getstr(lineptr, n, stream, '\n', 0);
}
\ No newline at end of file
......@@ -27,8 +27,7 @@ int64_t tsosStr2int64(char *str) {
return strtoll(str, &endptr, 10);
}
uint64_t htonll(uint64_t val)
{
uint64_t htonll(uint64_t val) {
return (((uint64_t) htonl(val)) << 32) + htonl(val >> 32);
}
#endif
......@@ -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++;
}
uint64_t htonll(uint64_t val)
{
return (((uint64_t) htonl(val)) << 32) + htonl(val >> 32);
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
}
......@@ -114,3 +114,5 @@ int fsync(int filedes) {
int sigaction(int sig, struct sigaction *d, void *p) {
return 0;
}
void taosSetCoreDump() {}
\ 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 "tconfig.h"
#include "tglobal.h"
#include "tulog.h"
#include "tsystem.h"
void taosSetCoreDump() {}
\ 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"
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);
}
/*
* 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/>.
*/
#include <winsock2.h>
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++;
}
/*
* 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"
/*
* 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
/*
* 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 "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
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册