[TD-992]
This commit is contained in:
parent
64d818516b
commit
999dc0af1b
|
@ -334,7 +334,7 @@ void tscSaveSubscriptionProgress(void* sub) {
|
|||
|
||||
char path[256];
|
||||
sprintf(path, "%s/subscribe", tsDataDir);
|
||||
if (tmkdir(path, 0777) != 0) {
|
||||
if (taosMkDir(path, 0777) != 0) {
|
||||
tscError("failed to create subscribe dir: %s", path);
|
||||
}
|
||||
|
||||
|
|
|
@ -205,7 +205,6 @@ ssize_t tread(int fd, void *buf, size_t count);
|
|||
|
||||
ssize_t twrite(int fd, void *buf, size_t n);
|
||||
|
||||
char *taosCharsetReplace(char *charsetstr);
|
||||
|
||||
bool taosCheckPthreadValid(pthread_t thread);
|
||||
|
||||
|
@ -219,8 +218,6 @@ int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optle
|
|||
|
||||
void taosPrintOsInfo();
|
||||
|
||||
char *taosCharsetReplace(char *charsetstr);
|
||||
|
||||
void taosPrintOsInfo();
|
||||
|
||||
void taosGetSystemInfo();
|
||||
|
|
|
@ -20,6 +20,89 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define tclose(x) taosCloseSocket(x)
|
||||
#define tfree(x) \
|
||||
do { \
|
||||
if (x) { \
|
||||
free((void *)(x)); \
|
||||
x = 0; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define tstrncpy(dst, src, size) \
|
||||
do { \
|
||||
strncpy((dst), (src), (size)); \
|
||||
(dst)[(size)-1] = 0; \
|
||||
} while (0);
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO (2)
|
||||
#endif
|
||||
|
||||
#define FD_VALID(x) ((x) > STDERR_FILENO)
|
||||
#define FD_INITIALIZER ((int32_t)-1)
|
||||
|
||||
#define WCHAR wchar_t
|
||||
|
||||
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
|
||||
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define ASSERT(x) assert(x)
|
||||
#else
|
||||
#define ASSERT(x)
|
||||
#endif
|
||||
|
||||
#ifdef UNUSED
|
||||
#undefine UNUSED
|
||||
#endif
|
||||
#define UNUSED(x) ((void)(x))
|
||||
|
||||
#ifdef UNUSED_FUNC
|
||||
#undefine UNUSED_FUNC
|
||||
#endif
|
||||
|
||||
#ifdef UNUSED_PARAM
|
||||
#undef UNUSED_PARAM
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define UNUSED_PARAM(x) _UNUSED##x __attribute__((unused))
|
||||
#define UNUSED_FUNC __attribute__((unused))
|
||||
#else
|
||||
#define UNUSED_PARAM(x) x
|
||||
#define UNUSED_FUNC
|
||||
#endif
|
||||
|
||||
#ifdef tListLen
|
||||
#undefine tListLen
|
||||
#endif
|
||||
#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define FORCE_INLINE inline __attribute__((always_inline))
|
||||
#else
|
||||
#define FORCE_INLINE
|
||||
#endif
|
||||
|
||||
#define DEFAULT_UNICODE_ENCODEC "UCS-4LE"
|
||||
|
||||
#define DEFAULT_COMP(x, y) \
|
||||
do { \
|
||||
if ((x) == (y)) { \
|
||||
return 0; \
|
||||
} else { \
|
||||
return (x) < (y) ? -1 : 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1)))
|
||||
|
||||
// align to 8bytes
|
||||
#define ALIGN8(n) ALIGN_NUM(n, 8)
|
||||
|
||||
#define POW2(x) ((x) * (x))
|
||||
|
||||
#ifndef TAOS_OS_FUNC_MATH
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
|
@ -46,6 +129,12 @@ extern "C" {
|
|||
#ifndef TAOS_OS_DEF_TIME
|
||||
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
|
||||
#endif
|
||||
#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60)
|
||||
#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60)
|
||||
#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24)
|
||||
#define MILLISECOND_PER_WEEK (MILLISECOND_PER_DAY * 7)
|
||||
#define MILLISECOND_PER_MONTH (MILLISECOND_PER_DAY * 30)
|
||||
#define MILLISECOND_PER_YEAR (MILLISECOND_PER_DAY * 365)
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SEMPHONE
|
||||
#define tsem_t sem_t
|
||||
|
@ -144,24 +233,13 @@ extern "C" {
|
|||
ssize_t taosTReadImp(int fd, void *buf, size_t count);
|
||||
ssize_t taosTWriteImp(int fd, void *buf, size_t count);
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size);
|
||||
#ifndef TAOS_OS_FUNC_FILE
|
||||
#ifndef TAOS_OS_FUNC_FILE_OP
|
||||
#define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count)
|
||||
#define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count)
|
||||
#define taosLSeek(fd, offset, whence) lseek(fd, offset, whence)
|
||||
#define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size)
|
||||
#endif
|
||||
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||
void taosSetRandomFileFailFactor(int factor);
|
||||
void taosSetRandomFileFailOutput(const char *path);
|
||||
ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line);
|
||||
ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line);
|
||||
off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line);
|
||||
#define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_NETWORK
|
||||
#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)
|
||||
|
@ -176,17 +254,6 @@ ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size);
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef TAOS_RANDOM_NETWORK_FAIL
|
||||
ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags);
|
||||
ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count);
|
||||
ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count);
|
||||
#define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len)
|
||||
#define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len)
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_LZ4
|
||||
#define BUILDIN_CLZL(val) __builtin_clzl(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
|
||||
|
@ -194,6 +261,10 @@ ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size);
|
|||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_WCHAR
|
||||
#define twcslen wcslen
|
||||
#endif
|
||||
|
||||
#undef threadlocal
|
||||
#ifdef _ISOC11_SOURCE
|
||||
#define threadlocal _Thread_local
|
||||
|
@ -233,6 +304,81 @@ void taosMsleep(int mseconds);
|
|||
int taosInitTimer(void (*callback)(int), int ms);
|
||||
void taosUninitTimer();
|
||||
|
||||
// TAOS_OS_FUNC_RAND
|
||||
uint32_t taosRand(void);
|
||||
void taosRandStr(char* str, int32_t size);
|
||||
uint32_t trand(void);
|
||||
|
||||
// TAOS_OS_FUNC_FILE
|
||||
void getTmpfilePath(const char *fileNamePrefix, char *dstPath);
|
||||
int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath);
|
||||
|
||||
// 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, size_t *len);
|
||||
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes);
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
char * taosCharsetReplace(char *charsetstr);
|
||||
|
||||
// TAOS_OS_FUNC_MALLOC
|
||||
#define TAOS_ALLOC_MODE_DEFAULT 0
|
||||
#define TAOS_ALLOC_MODE_RANDOM_FAIL 1
|
||||
#define TAOS_ALLOC_MODE_DETECT_LEAK 2
|
||||
void taosSetAllocMode(int mode, const char *path, bool autoDump);
|
||||
void taosDumpMemoryLeak();
|
||||
void * tmalloc(size_t size);
|
||||
void * tcalloc(size_t nmemb, size_t size);
|
||||
size_t tsizeof(void *ptr);
|
||||
void tmemset(void *ptr, int c);
|
||||
void * trealloc(void *ptr, size_t size);
|
||||
void tzfree(void *ptr);
|
||||
|
||||
// TAOS_OS_FUNC_DIR
|
||||
void taosRemoveDir(char *rootDir);
|
||||
int taosMkDir(const char *pathname, mode_t mode);
|
||||
void taosMvDir(char* destDir, char *srcDir);
|
||||
|
||||
|
||||
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||
void taosSetRandomFileFailFactor(int factor);
|
||||
void taosSetRandomFileFailOutput(const char *path);
|
||||
ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line);
|
||||
ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line);
|
||||
off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line);
|
||||
#define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
#ifdef TAOS_RANDOM_NETWORK_FAIL
|
||||
ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags);
|
||||
ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count);
|
||||
ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count);
|
||||
#define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len)
|
||||
#define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len)
|
||||
#endif
|
||||
|
||||
#ifdef TAOS_MEM_CHECK
|
||||
void * taos_malloc(size_t size, const char *file, uint32_t line);
|
||||
void * taos_calloc(size_t num, size_t size, const char *file, uint32_t line);
|
||||
void * taos_realloc(void *ptr, size_t size, const char *file, uint32_t line);
|
||||
void taos_free(void *ptr, const char *file, uint32_t line);
|
||||
char * taos_strdup(const char *str, const char *file, uint32_t line);
|
||||
char * taos_strndup(const char *str, size_t size, const char *file, uint32_t line);
|
||||
ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line);
|
||||
#define malloc(size) taos_malloc(size, __FILE__, __LINE__)
|
||||
#define calloc(num, size) taos_calloc(num, size, __FILE__, __LINE__)
|
||||
#define realloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__)
|
||||
#define free(ptr) taos_free(ptr, __FILE__, __LINE__)
|
||||
#define strdup(str) taos_strdup(str, __FILE__, __LINE__)
|
||||
#define strndup(str, size) taos_strndup(str, size, __FILE__, __LINE__)
|
||||
#define getline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__)
|
||||
#endif // TAOS_MEM_CHECK
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -48,6 +48,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TAOS_OS_FUNC_WCHAR
|
||||
|
||||
// for function open in stat.h
|
||||
#define S_IRWXU _S_IREAD
|
||||
#define S_IRWXG _S_IWRITE
|
||||
|
@ -359,7 +361,6 @@ int taosSetNonblocking(int sock, int on);
|
|||
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen);
|
||||
|
||||
char *taosCharsetReplace(char *charsetstr);
|
||||
|
||||
void taosPrintOsInfo();
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
#include "tsystem.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_CORE
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_DIR
|
||||
|
||||
void taosRemoveDir(char *rootDir) {
|
||||
DIR *dir = opendir(rootDir);
|
||||
if (dir == NULL) return;
|
||||
|
||||
struct dirent *de = NULL;
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
||||
|
||||
char filename[1024];
|
||||
snprintf(filename, 1023, "%s/%s", rootDir, de->d_name);
|
||||
if (de->d_type & DT_DIR) {
|
||||
taosRemoveDir(filename);
|
||||
} else {
|
||||
(void)remove(filename);
|
||||
uInfo("file:%s is removed", filename);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
rmdir(rootDir);
|
||||
|
||||
uInfo("dir:%s is removed", rootDir);
|
||||
}
|
||||
|
||||
int taosMkDir(const char *path, mode_t mode) {
|
||||
int code = mkdir(path, 0755);
|
||||
if (code < 0 && errno == EEXIST) code = 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
void taosMvDir(char* destDir, char *srcDir) {
|
||||
if (0 == tsEnableVnodeBak) {
|
||||
uInfo("vnode backup not enabled");
|
||||
return;
|
||||
}
|
||||
|
||||
char shellCmd[1024+1] = {0};
|
||||
|
||||
//(void)snprintf(shellCmd, 1024, "cp -rf %s %s", srcDir, destDir);
|
||||
(void)snprintf(shellCmd, 1024, "mv %s %s", srcDir, destDir);
|
||||
tSystem(shellCmd);
|
||||
uInfo("shell cmd:%s is executed", shellCmd);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -15,74 +15,54 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "ttime.h"
|
||||
|
||||
ssize_t taosTReadImp(int fd, void *buf, size_t count) {
|
||||
size_t leftbytes = count;
|
||||
ssize_t readbytes;
|
||||
char * tbuf = (char *)buf;
|
||||
#ifndef TAOS_OS_FUNC_FILE
|
||||
|
||||
while (leftbytes > 0) {
|
||||
readbytes = read(fd, (void *)tbuf, leftbytes);
|
||||
if (readbytes < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (readbytes == 0) {
|
||||
return (ssize_t)(count - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= readbytes;
|
||||
tbuf += readbytes;
|
||||
void getTmpfilePath(const char *fileNamePrefix, char *dstPath) {
|
||||
const char* tdengineTmpFileNamePrefix = "tdengine-";
|
||||
|
||||
char tmpPath[PATH_MAX];
|
||||
char *tmpDir = "/tmp/";
|
||||
|
||||
strcpy(tmpPath, tmpDir);
|
||||
strcat(tmpPath, tdengineTmpFileNamePrefix);
|
||||
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
||||
strcat(tmpPath, fileNamePrefix);
|
||||
strcat(tmpPath, "-%d-%s");
|
||||
}
|
||||
|
||||
return (ssize_t)count;
|
||||
|
||||
char rand[8] = {0};
|
||||
taosRandStr(rand, tListLen(rand) - 1);
|
||||
snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
|
||||
}
|
||||
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) {
|
||||
size_t leftbytes = size;
|
||||
ssize_t sentbytes;
|
||||
// rename file name
|
||||
int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath) {
|
||||
int32_t ts = taosGetTimestampSec();
|
||||
|
||||
while (leftbytes > 0) {
|
||||
/*
|
||||
* TODO : Think to check if file is larger than 1GB
|
||||
*/
|
||||
//if (leftbytes > 1000000000) leftbytes = 1000000000;
|
||||
sentbytes = sendfile(dfd, sfd, offset, leftbytes);
|
||||
if (sentbytes == -1) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
} else if (sentbytes == 0) {
|
||||
return (ssize_t)(size - leftbytes);
|
||||
}
|
||||
char fname[PATH_MAX] = {0}; // max file name length must be less than 255
|
||||
|
||||
leftbytes -= sentbytes;
|
||||
char *delimiterPos = strrchr(fullPath, delimiter);
|
||||
if (delimiterPos == NULL) return -1;
|
||||
|
||||
int32_t fileNameLen = 0;
|
||||
if (suffix)
|
||||
fileNameLen = snprintf(fname, PATH_MAX, "%s.%d.%s", delimiterPos + 1, ts, suffix);
|
||||
else
|
||||
fileNameLen = snprintf(fname, PATH_MAX, "%s.%d", delimiterPos + 1, ts);
|
||||
|
||||
size_t len = (size_t)((delimiterPos - fullPath) + fileNameLen + 1);
|
||||
if (*dstPath == NULL) {
|
||||
*dstPath = calloc(1, len + 1);
|
||||
if (*dstPath == NULL) return -1;
|
||||
}
|
||||
|
||||
return size;
|
||||
strncpy(*dstPath, fullPath, (size_t)(delimiterPos - fullPath + 1));
|
||||
strncat(*dstPath, fname, (size_t)fileNameLen);
|
||||
(*dstPath)[len] = 0;
|
||||
|
||||
return rename(fullPath, *dstPath);
|
||||
}
|
||||
|
||||
ssize_t taosTWriteImp(int fd, void *buf, size_t n) {
|
||||
size_t nleft = n;
|
||||
ssize_t nwritten = 0;
|
||||
char *tbuf = (char *)buf;
|
||||
|
||||
while (nleft > 0) {
|
||||
nwritten = write(fd, (void *)tbuf, nleft);
|
||||
if (nwritten < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
nleft -= nwritten;
|
||||
tbuf += nwritten;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
ssize_t taosTReadImp(int fd, void *buf, size_t count) {
|
||||
size_t leftbytes = count;
|
||||
ssize_t readbytes;
|
||||
char * tbuf = (char *)buf;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
readbytes = read(fd, (void *)tbuf, leftbytes);
|
||||
if (readbytes < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (readbytes == 0) {
|
||||
return (ssize_t)(count - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= readbytes;
|
||||
tbuf += readbytes;
|
||||
}
|
||||
|
||||
return (ssize_t)count;
|
||||
}
|
||||
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) {
|
||||
size_t leftbytes = size;
|
||||
ssize_t sentbytes;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
/*
|
||||
* TODO : Think to check if file is larger than 1GB
|
||||
*/
|
||||
//if (leftbytes > 1000000000) leftbytes = 1000000000;
|
||||
sentbytes = sendfile(dfd, sfd, offset, leftbytes);
|
||||
if (sentbytes == -1) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
} else if (sentbytes == 0) {
|
||||
return (ssize_t)(size - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= sentbytes;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
ssize_t taosTWriteImp(int fd, void *buf, size_t n) {
|
||||
size_t nleft = n;
|
||||
ssize_t nwritten = 0;
|
||||
char *tbuf = (char *)buf;
|
||||
|
||||
while (nleft > 0) {
|
||||
nwritten = write(fd, (void *)tbuf, nleft);
|
||||
if (nwritten < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
nleft -= nwritten;
|
||||
tbuf += nwritten;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_MALLOC
|
||||
|
||||
void *tmalloc(size_t size) {
|
||||
if (size <= 0) return NULL;
|
||||
|
||||
void *ret = malloc(size + sizeof(size_t));
|
||||
if (ret == NULL) return NULL;
|
||||
|
||||
*(size_t *)ret = size;
|
||||
|
||||
return (void *)((char *)ret + sizeof(size_t));
|
||||
}
|
||||
|
||||
void *tcalloc(size_t nmemb, size_t size) {
|
||||
size_t tsize = nmemb * size;
|
||||
void * ret = tmalloc(tsize);
|
||||
if (ret == NULL) return NULL;
|
||||
|
||||
tmemset(ret, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t tsizeof(void *ptr) { return (ptr) ? (*(size_t *)((char *)ptr - sizeof(size_t))) : 0; }
|
||||
|
||||
void tmemset(void *ptr, int c) { memset(ptr, c, tsizeof(ptr)); }
|
||||
|
||||
void * trealloc(void *ptr, size_t size) {
|
||||
if (ptr == NULL) return tmalloc(size);
|
||||
|
||||
if (size <= tsizeof(ptr)) return ptr;
|
||||
|
||||
void * tptr = (void *)((char *)ptr - sizeof(size_t));
|
||||
size_t tsize = size + sizeof(size_t);
|
||||
tptr = realloc(tptr, tsize);
|
||||
if (tptr == NULL) return NULL;
|
||||
|
||||
*(size_t *)tptr = size;
|
||||
|
||||
return (void *)((char *)tptr + sizeof(size_t));
|
||||
}
|
||||
|
||||
void tzfree(void *ptr) {
|
||||
if (ptr) {
|
||||
free((void *)((char *)ptr - sizeof(size_t)));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -16,10 +16,6 @@
|
|||
#include "os.h"
|
||||
#include "tulog.h"
|
||||
|
||||
#define TAOS_MEM_CHECK_IMPL
|
||||
#include "tutil.h"
|
||||
|
||||
|
||||
#ifdef TAOS_MEM_CHECK
|
||||
|
||||
static int allocMode = TAOS_ALLOC_MODE_DEFAULT;
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_RAND
|
||||
|
||||
uint32_t taosRand(void) { return rand(); }
|
||||
|
||||
uint32_t trand(void) {
|
||||
int fd;
|
||||
int seed;
|
||||
|
||||
fd = open("/dev/urandom", 0);
|
||||
if (fd < 0) {
|
||||
seed = time(0);
|
||||
} else {
|
||||
int len = read(fd, &seed, sizeof(seed));
|
||||
if (len < 0) {
|
||||
seed = time(0);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return (uint32_t)seed;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void taosRandStr(char* str, int32_t size) {
|
||||
const char* set = "abcdefghijklmnopqrstuvwxyz0123456789-_.";
|
||||
int32_t len = 39;
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
str[i] = set[taosRand() % len];
|
||||
}
|
||||
}
|
|
@ -18,8 +18,8 @@
|
|||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
#include "tsystem.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SYSINFO
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include "tglobal.h"
|
||||
#include "ttimer.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
#include <signal.h>
|
||||
|
||||
#ifndef TAOS_OS_FUNC_TIMER
|
||||
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_WCHAR
|
||||
|
||||
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
|
||||
#include "iconv.h"
|
||||
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
|
||||
iconv_t cd = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||
size_t ucs4_input_len = ucs4_max_len;
|
||||
size_t outLen = ucs4_max_len;
|
||||
if (iconv(cd, (char **)&ucs4, &ucs4_input_len, &mbs, &outLen) == -1) {
|
||||
iconv_close(cd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
iconv_close(cd);
|
||||
return (int32_t)(ucs4_max_len - outLen);
|
||||
}
|
||||
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, size_t *len) {
|
||||
memset(ucs4, 0, ucs4_max_len);
|
||||
iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
size_t ucs4_input_len = mbsLength;
|
||||
size_t outLeft = ucs4_max_len;
|
||||
if (iconv(cd, &mbs, &ucs4_input_len, &ucs4, &outLeft) == -1) {
|
||||
iconv_close(cd);
|
||||
return false;
|
||||
}
|
||||
|
||||
iconv_close(cd);
|
||||
if (len != NULL) {
|
||||
*len = ucs4_max_len - outLeft;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool taosValidateEncodec(const char *encodec) {
|
||||
iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC);
|
||||
if (cd == (iconv_t)(-1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
iconv_close(cd);
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
|
||||
mbstate_t state = {0};
|
||||
int32_t len = (int32_t)wcsnrtombs(NULL, (const wchar_t **)&ucs4, ucs4_max_len / 4, 0, &state);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
len = wcsnrtombs(mbs, (const wchar_t **)&ucs4, ucs4_max_len / 4, (size_t)len, &state);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, size_t *len) {
|
||||
memset(ucs4, 0, ucs4_max_len);
|
||||
mbstate_t state = {0};
|
||||
int32_t retlen = mbsnrtowcs((wchar_t *)ucs4, (const char **)&mbs, mbsLength, ucs4_max_len / 4, &state);
|
||||
*len = retlen;
|
||||
|
||||
return retlen >= 0;
|
||||
}
|
||||
|
||||
bool taosValidateEncodec(const char *encodec) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct CharsetPair {
|
||||
char *oldCharset;
|
||||
char *newCharset;
|
||||
} CharsetPair;
|
||||
|
||||
char *taosCharsetReplace(char *charsetstr) {
|
||||
CharsetPair charsetRep[] = {
|
||||
{ "utf8", "UTF-8" }, { "936", "CP936" },
|
||||
};
|
||||
|
||||
for (int32_t i = 0; i < tListLen(charsetRep); ++i) {
|
||||
if (strcasecmp(charsetRep[i].oldCharset, charsetstr) == 0) {
|
||||
return strdup(charsetRep[i].newCharset);
|
||||
}
|
||||
}
|
||||
|
||||
return strdup(charsetstr);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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 getTmpfilePath(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);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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
|
||||
}
|
|
@ -20,9 +20,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include "tutil.h"
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
//@return timestamp in second
|
||||
int32_t taosGetTimestampSec();
|
||||
|
|
|
@ -25,148 +25,24 @@ extern "C" {
|
|||
#include "tcrc32c.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO (2)
|
||||
#endif
|
||||
|
||||
#define FD_VALID(x) ((x) > STDERR_FILENO)
|
||||
#define FD_INITIALIZER ((int32_t)-1)
|
||||
|
||||
#define WCHAR wchar_t
|
||||
|
||||
#define tfree(x) \
|
||||
do { \
|
||||
if (x) { \
|
||||
free((void *)(x)); \
|
||||
x = 0; \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
#define tstrncpy(dst, src, size) \
|
||||
do { \
|
||||
strncpy((dst), (src), (size)); \
|
||||
(dst)[(size)-1] = 0; \
|
||||
} while (0);
|
||||
|
||||
#define tclose(x) taosCloseSocket(x)
|
||||
|
||||
// Pointer p drift right by b bytes
|
||||
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
|
||||
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define ASSERT(x) assert(x)
|
||||
#else
|
||||
#define ASSERT(x)
|
||||
#endif
|
||||
|
||||
#ifdef UNUSED
|
||||
#undefine UNUSED
|
||||
#endif
|
||||
#define UNUSED(x) ((void)(x))
|
||||
|
||||
#ifdef UNUSED_FUNC
|
||||
#undefine UNUSED_FUNC
|
||||
#endif
|
||||
|
||||
#ifdef UNUSED_PARAM
|
||||
#undef UNUSED_PARAM
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define UNUSED_PARAM(x) _UNUSED##x __attribute__((unused))
|
||||
#define UNUSED_FUNC __attribute__((unused))
|
||||
#else
|
||||
#define UNUSED_PARAM(x) x
|
||||
#define UNUSED_FUNC
|
||||
#endif
|
||||
|
||||
#ifdef tListLen
|
||||
#undefine tListLen
|
||||
#endif
|
||||
#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define FORCE_INLINE inline __attribute__((always_inline))
|
||||
#else
|
||||
#define FORCE_INLINE
|
||||
#endif
|
||||
|
||||
#define DEFAULT_UNICODE_ENCODEC "UCS-4LE"
|
||||
|
||||
#define DEFAULT_COMP(x, y) \
|
||||
do { \
|
||||
if ((x) == (y)) { \
|
||||
return 0; \
|
||||
} else { \
|
||||
return (x) < (y) ? -1 : 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1)))
|
||||
|
||||
// align to 8bytes
|
||||
#define ALIGN8(n) ALIGN_NUM(n, 8)
|
||||
|
||||
#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60)
|
||||
#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60)
|
||||
#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24)
|
||||
#define MILLISECOND_PER_WEEK (MILLISECOND_PER_DAY * 7)
|
||||
#define MILLISECOND_PER_MONTH (MILLISECOND_PER_DAY * 30)
|
||||
#define MILLISECOND_PER_YEAR (MILLISECOND_PER_DAY * 365)
|
||||
|
||||
#define POW2(x) ((x) * (x))
|
||||
|
||||
uint32_t taosRand(void);
|
||||
|
||||
uint32_t trand(void);
|
||||
|
||||
size_t twcslen(const wchar_t *wcs);
|
||||
|
||||
int32_t strdequote(char *src);
|
||||
|
||||
size_t strtrim(char *src);
|
||||
|
||||
char *strnchr(char *haystack, char needle, int32_t len, bool skipquote);
|
||||
|
||||
char **strsplit(char *src, const char *delim, int32_t *num);
|
||||
|
||||
char* strtolower(char *dst, const char *src);
|
||||
|
||||
char* strntolower(char *dst, const char *src, int32_t n);
|
||||
|
||||
size_t strtrim(char *src);
|
||||
char * strnchr(char *haystack, char needle, int32_t len, bool skipquote);
|
||||
char ** strsplit(char *src, const char *delim, int32_t *num);
|
||||
char * strtolower(char *dst, const char *src);
|
||||
char * strntolower(char *dst, const char *src, int32_t n);
|
||||
int64_t strnatoi(char *num, int32_t len);
|
||||
|
||||
//char* strreplace(const char* str, const char* pattern, const char* rep);
|
||||
|
||||
char *strbetween(char *string, char *begin, char *end);
|
||||
|
||||
char *paGetToken(char *src, char **token, int32_t *tokenLen);
|
||||
char * strbetween(char *string, char *begin, char *end);
|
||||
char * paGetToken(char *src, char **token, int32_t *tokenLen);
|
||||
|
||||
int32_t taosByteArrayToHexStr(char bytes[], int32_t len, char hexstr[]);
|
||||
|
||||
int32_t taosHexStrToByteArray(char hexstr[], char bytes[]);
|
||||
|
||||
int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fileNamePattern
|
||||
* @param dstPath
|
||||
*/
|
||||
void getTmpfilePath(const char *fileNamePattern, char *dstPath);
|
||||
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, size_t* len);
|
||||
|
||||
int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes);
|
||||
|
||||
void taosRandStr(char* str, int32_t size);
|
||||
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
|
||||
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
|
||||
bool taosGetVersionNumber(char *versionStr, int *versionNubmer);
|
||||
int taosCheckVersion(char *input_client_version, char *input_server_version, int compared_segments);
|
||||
|
||||
char * taosIpStr(uint32_t ipInt);
|
||||
uint32_t ip2uint(const char *const ip_addr);
|
||||
|
||||
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, char *target) {
|
||||
MD5_CTX context;
|
||||
|
@ -176,56 +52,6 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, cha
|
|||
memcpy(target, context.digest, TSDB_KEY_LEN);
|
||||
}
|
||||
|
||||
int taosCheckVersion(char *input_client_version, char *input_server_version, int compared_segments);
|
||||
|
||||
char *taosIpStr(uint32_t ipInt);
|
||||
|
||||
uint32_t ip2uint(const char *const ip_addr);
|
||||
|
||||
void taosRemoveDir(char *rootDir);
|
||||
int tmkdir(const char *pathname, mode_t mode);
|
||||
void taosMvDir(char* destDir, char *srcDir);
|
||||
|
||||
#define TAOS_ALLOC_MODE_DEFAULT 0
|
||||
#define TAOS_ALLOC_MODE_RANDOM_FAIL 1
|
||||
#define TAOS_ALLOC_MODE_DETECT_LEAK 2
|
||||
void taosSetAllocMode(int mode, const char* path, bool autoDump);
|
||||
void taosDumpMemoryLeak();
|
||||
|
||||
void * tmalloc(size_t size);
|
||||
void * tcalloc(size_t nmemb, size_t size);
|
||||
size_t tsizeof(void *ptr);
|
||||
void tmemset(void *ptr, int c);
|
||||
void * trealloc(void *ptr, size_t size);
|
||||
void tzfree(void *ptr);
|
||||
|
||||
#ifdef TAOS_MEM_CHECK
|
||||
|
||||
void * taos_malloc(size_t size, const char *file, uint32_t line);
|
||||
void * taos_calloc(size_t num, size_t size, const char *file, uint32_t line);
|
||||
void * taos_realloc(void *ptr, size_t size, const char *file, uint32_t line);
|
||||
void taos_free(void *ptr, const char *file, uint32_t line);
|
||||
char * taos_strdup(const char *str, const char *file, uint32_t line);
|
||||
char * taos_strndup(const char *str, size_t size, const char *file, uint32_t line);
|
||||
ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line);
|
||||
|
||||
#ifndef TAOS_MEM_CHECK_IMPL
|
||||
|
||||
#define malloc(size) taos_malloc(size, __FILE__, __LINE__)
|
||||
#define calloc(num, size) taos_calloc(num, size, __FILE__, __LINE__)
|
||||
#define realloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__)
|
||||
#define free(ptr) taos_free(ptr, __FILE__, __LINE__)
|
||||
#define strdup(str) taos_strdup(str, __FILE__, __LINE__)
|
||||
#define strndup(str, size) taos_strndup(str, size, __FILE__, __LINE__)
|
||||
#define getline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__)
|
||||
|
||||
#endif // TAOS_MEM_CHECK_IMPL
|
||||
|
||||
#endif // TAOS_MEM_CHECK
|
||||
|
||||
|
||||
char *taosCharsetReplace(char *charsetstr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -14,10 +14,9 @@
|
|||
*/
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#include "hash.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
static FORCE_INLINE void __wr_lock(void *lock) {
|
||||
if (lock == NULL) {
|
||||
|
|
|
@ -118,7 +118,7 @@ static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
|
|||
|
||||
wordfree(&full_path);
|
||||
|
||||
int code = tmkdir(option, 0755);
|
||||
int code = taosMkDir(option, 0755);
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("config option:%s, input value:%s, directory not exist, create fail:%s",
|
||||
|
|
|
@ -14,11 +14,6 @@
|
|||
*/
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef USE_LIBICONV
|
||||
#include "iconv.h"
|
||||
#endif
|
||||
|
||||
#include "tcrc32c.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttime.h"
|
||||
|
@ -27,76 +22,6 @@
|
|||
#include "tulog.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
|
||||
#ifdef WINDOWS
|
||||
uint32_t taosRand(void)
|
||||
{
|
||||
return rand();
|
||||
}
|
||||
#else
|
||||
uint32_t taosRand(void)
|
||||
{
|
||||
/*
|
||||
int fd;
|
||||
int seed;
|
||||
|
||||
fd = open("/dev/urandom", 0);
|
||||
if (fd < 0) {
|
||||
seed = time(0);
|
||||
} else {
|
||||
int len = read(fd, &seed, sizeof(seed));
|
||||
if (len < 0) {
|
||||
seed = time(0);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return (uint32_t)seed;
|
||||
*/
|
||||
return rand();
|
||||
}
|
||||
|
||||
uint32_t trand(void)
|
||||
{
|
||||
int fd;
|
||||
int seed;
|
||||
|
||||
fd = open("/dev/urandom", 0);
|
||||
if (fd < 0) {
|
||||
seed = time(0);
|
||||
} else {
|
||||
int len = read(fd, &seed, sizeof(seed));
|
||||
if (len < 0) {
|
||||
seed = time(0);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return (uint32_t)seed;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t twcslen(const wchar_t *wcs) {
|
||||
#ifdef WINDOWS
|
||||
int *wstr = (int *)wcs;
|
||||
if (NULL == wstr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t n = 0;
|
||||
while (1) {
|
||||
if (0 == *wstr++) {
|
||||
break;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
|
||||
return n;
|
||||
#else
|
||||
return wcslen(wcs);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t strdequote(char *z) {
|
||||
if (z == NULL) {
|
||||
return 0;
|
||||
|
@ -234,6 +159,7 @@ char* strtolower(char *dst, const char *src) {
|
|||
*p = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
char* strntolower(char *dst, const char *src, int32_t n) {
|
||||
int esc = 0;
|
||||
char quote = 0, *p = dst, c;
|
||||
|
@ -343,96 +269,6 @@ int64_t strnatoi(char *num, int32_t len) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
FORCE_INLINE size_t getLen(size_t old, size_t size) {
|
||||
if (old == 1) {
|
||||
old = 2;
|
||||
}
|
||||
|
||||
while (old < size) {
|
||||
old = (old * 1.5);
|
||||
}
|
||||
|
||||
return old;
|
||||
}
|
||||
|
||||
static char *ensureSpace(char *dest, size_t *curSize, size_t size) {
|
||||
if (*curSize < size) {
|
||||
*curSize = getLen(*curSize, size);
|
||||
|
||||
char *tmp = realloc(dest, *curSize);
|
||||
if (tmp == NULL) {
|
||||
free(dest);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *strreplace(const char *str, const char *pattern, const char *rep) {
|
||||
if (str == NULL || pattern == NULL || rep == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *s = str;
|
||||
|
||||
size_t oldLen = strlen(str);
|
||||
size_t newLen = oldLen;
|
||||
|
||||
size_t repLen = strlen(rep);
|
||||
size_t patternLen = strlen(pattern);
|
||||
|
||||
char *dest = calloc(1, oldLen + 1);
|
||||
if (dest == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (patternLen == 0) {
|
||||
return strcpy(dest, str);
|
||||
}
|
||||
|
||||
int32_t start = 0;
|
||||
|
||||
while (1) {
|
||||
char *p = strstr(str, pattern);
|
||||
if (p == NULL) { // remain does not contain pattern
|
||||
size_t remain = (oldLen - (str - s));
|
||||
size_t size = remain + start + 1;
|
||||
|
||||
dest = ensureSpace(dest, &newLen, size);
|
||||
if (dest == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(dest + start, str);
|
||||
dest[start + remain] = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t len = p - str;
|
||||
size_t size = start + len + repLen + 1;
|
||||
|
||||
dest = ensureSpace(dest, &newLen, size);
|
||||
if (dest == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(dest + start, str, len);
|
||||
|
||||
str += (len + patternLen);
|
||||
start += len;
|
||||
|
||||
memcpy(dest + start, rep, repLen);
|
||||
start += repLen;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
#endif
|
||||
|
||||
char *strbetween(char *string, char *begin, char *end) {
|
||||
char *result = NULL;
|
||||
char *_begin = strstr(string, begin);
|
||||
|
@ -491,170 +327,6 @@ int32_t taosHexStrToByteArray(char hexstr[], char bytes[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// rename file name
|
||||
int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath) {
|
||||
int32_t ts = taosGetTimestampSec();
|
||||
|
||||
char fname[PATH_MAX] = {0}; // max file name length must be less than 255
|
||||
|
||||
char *delimiterPos = strrchr(fullPath, delimiter);
|
||||
if (delimiterPos == NULL) return -1;
|
||||
|
||||
int32_t fileNameLen = 0;
|
||||
if (suffix)
|
||||
fileNameLen = snprintf(fname, PATH_MAX, "%s.%d.%s", delimiterPos + 1, ts, suffix);
|
||||
else
|
||||
fileNameLen = snprintf(fname, PATH_MAX, "%s.%d", delimiterPos + 1, ts);
|
||||
|
||||
size_t len = (size_t)((delimiterPos - fullPath) + fileNameLen + 1);
|
||||
if (*dstPath == NULL) {
|
||||
*dstPath = calloc(1, len + 1);
|
||||
if (*dstPath == NULL) return -1;
|
||||
}
|
||||
|
||||
strncpy(*dstPath, fullPath, (size_t)(delimiterPos - fullPath + 1));
|
||||
strncat(*dstPath, fname, (size_t)fileNameLen);
|
||||
(*dstPath)[len] = 0;
|
||||
|
||||
return rename(fullPath, *dstPath);
|
||||
}
|
||||
|
||||
void getTmpfilePath(const char *fileNamePrefix, char *dstPath) {
|
||||
const char* tdengineTmpFileNamePrefix = "tdengine-";
|
||||
|
||||
char tmpPath[PATH_MAX];
|
||||
|
||||
#ifdef WINDOWS
|
||||
char *tmpDir = getenv("tmp");
|
||||
if (tmpDir == NULL) {
|
||||
tmpDir = "";
|
||||
}
|
||||
#else
|
||||
char *tmpDir = "/tmp/";
|
||||
#endif
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void taosRandStr(char* str, int32_t size) {
|
||||
const char* set = "abcdefghijklmnopqrstuvwxyz0123456789-_.";
|
||||
int32_t len = 39;
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
str[i] = set[taosRand() % len];
|
||||
}
|
||||
}
|
||||
|
||||
int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes) {
|
||||
#if defined WINDOWS
|
||||
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
|
||||
|
||||
#else
|
||||
return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / TSDB_NCHAR_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
|
||||
#ifdef USE_LIBICONV
|
||||
iconv_t cd = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||
size_t ucs4_input_len = ucs4_max_len;
|
||||
size_t outLen = ucs4_max_len;
|
||||
if (iconv(cd, (char **)&ucs4, &ucs4_input_len, &mbs, &outLen) == -1) {
|
||||
iconv_close(cd);
|
||||
return -1;
|
||||
}
|
||||
iconv_close(cd);
|
||||
return (int32_t)(ucs4_max_len - outLen);
|
||||
#else
|
||||
mbstate_t state = {0};
|
||||
int32_t len = (int32_t) wcsnrtombs(NULL, (const wchar_t **) &ucs4, ucs4_max_len / 4, 0, &state);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
memset(&state, 0, sizeof(state));
|
||||
len = wcsnrtombs(mbs, (const wchar_t **) &ucs4, ucs4_max_len / 4, (size_t) len, &state);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
return len;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, size_t* len) {
|
||||
memset(ucs4, 0, ucs4_max_len);
|
||||
#ifdef USE_LIBICONV
|
||||
iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
size_t ucs4_input_len = mbsLength;
|
||||
size_t outLeft = ucs4_max_len;
|
||||
if (iconv(cd, &mbs, &ucs4_input_len, &ucs4, &outLeft) == -1) {
|
||||
iconv_close(cd);
|
||||
return false;
|
||||
}
|
||||
|
||||
iconv_close(cd);
|
||||
if (len != NULL) {
|
||||
*len = ucs4_max_len - outLeft;
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
mbstate_t state = {0};
|
||||
int32_t len = mbsnrtowcs((wchar_t *) ucs4, (const char **) &mbs, mbsLength, ucs4_max_len / 4, &state);
|
||||
return len >= 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool taosValidateEncodec(const char *encodec) {
|
||||
#ifdef USE_LIBICONV
|
||||
iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC);
|
||||
if (cd == (iconv_t)(-1)) {
|
||||
return false;
|
||||
}
|
||||
iconv_close(cd);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool taosGetVersionNumber(char *versionStr, int *versionNubmer) {
|
||||
if (versionStr == NULL || versionNubmer == NULL) {
|
||||
return false;
|
||||
|
@ -734,112 +406,3 @@ FORCE_INLINE double taos_align_get_double(const char* pBuf) {
|
|||
*(int64_t*)(&dv) = *(int64_t*)pBuf;
|
||||
return dv;
|
||||
}
|
||||
|
||||
typedef struct CharsetPair {
|
||||
char *oldCharset;
|
||||
char *newCharset;
|
||||
} CharsetPair;
|
||||
|
||||
char *taosCharsetReplace(char *charsetstr) {
|
||||
CharsetPair charsetRep[] = {
|
||||
{ "utf8", "UTF-8" }, { "936", "CP936" },
|
||||
};
|
||||
|
||||
for (int32_t i = 0; i < tListLen(charsetRep); ++i) {
|
||||
if (strcasecmp(charsetRep[i].oldCharset, charsetstr) == 0) {
|
||||
return strdup(charsetRep[i].newCharset);
|
||||
}
|
||||
}
|
||||
|
||||
return strdup(charsetstr);
|
||||
}
|
||||
|
||||
void *tmalloc(size_t size) {
|
||||
if (size <= 0) return NULL;
|
||||
|
||||
void *ret = malloc(size + sizeof(size_t));
|
||||
if (ret == NULL) return NULL;
|
||||
|
||||
*(size_t *)ret = size;
|
||||
|
||||
return (void *)((char *)ret + sizeof(size_t));
|
||||
}
|
||||
|
||||
void *tcalloc(size_t nmemb, size_t size) {
|
||||
size_t tsize = nmemb * size;
|
||||
void * ret = tmalloc(tsize);
|
||||
if (ret == NULL) return NULL;
|
||||
|
||||
tmemset(ret, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t tsizeof(void *ptr) { return (ptr) ? (*(size_t *)((char *)ptr - sizeof(size_t))) : 0; }
|
||||
|
||||
void tmemset(void *ptr, int c) { memset(ptr, c, tsizeof(ptr)); }
|
||||
|
||||
void * trealloc(void *ptr, size_t size) {
|
||||
if (ptr == NULL) return tmalloc(size);
|
||||
|
||||
if (size <= tsizeof(ptr)) return ptr;
|
||||
|
||||
void * tptr = (void *)((char *)ptr - sizeof(size_t));
|
||||
size_t tsize = size + sizeof(size_t);
|
||||
tptr = realloc(tptr, tsize);
|
||||
if (tptr == NULL) return NULL;
|
||||
|
||||
*(size_t *)tptr = size;
|
||||
|
||||
return (void *)((char *)tptr + sizeof(size_t));
|
||||
}
|
||||
|
||||
void tzfree(void *ptr) {
|
||||
if (ptr) {
|
||||
free((void *)((char *)ptr - sizeof(size_t)));
|
||||
}
|
||||
}
|
||||
|
||||
void taosRemoveDir(char *rootDir) {
|
||||
DIR *dir = opendir(rootDir);
|
||||
if (dir == NULL) return;
|
||||
|
||||
struct dirent *de = NULL;
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
||||
|
||||
char filename[1024];
|
||||
snprintf(filename, 1023, "%s/%s", rootDir, de->d_name);
|
||||
if (de->d_type & DT_DIR) {
|
||||
taosRemoveDir(filename);
|
||||
} else {
|
||||
(void)remove(filename);
|
||||
uInfo("file:%s is removed", filename);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
rmdir(rootDir);
|
||||
|
||||
uInfo("dir:%s is removed", rootDir);
|
||||
}
|
||||
|
||||
int tmkdir(const char *path, mode_t mode) {
|
||||
int code = mkdir(path, 0755);
|
||||
if (code < 0 && errno == EEXIST) code = 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
void taosMvDir(char* destDir, char *srcDir) {
|
||||
if (0 == tsEnableVnodeBak) {
|
||||
uInfo("vnode backup not enabled");
|
||||
return;
|
||||
}
|
||||
|
||||
char shellCmd[1024+1] = {0};
|
||||
|
||||
//(void)snprintf(shellCmd, 1024, "cp -rf %s %s", srcDir, destDir);
|
||||
(void)snprintf(shellCmd, 1024, "mv %s %s", srcDir, destDir);
|
||||
tSystem(shellCmd);
|
||||
uInfo("shell cmd:%s is executed", shellCmd);
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ void *walOpen(const char *path, const SWalCfg *pCfg) {
|
|||
}
|
||||
}
|
||||
|
||||
if (tmkdir(path, 0755) != 0) {
|
||||
if (taosMkDir(path, 0755) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
wError("wal:%s, failed to create directory(%s)", path, strerror(errno));
|
||||
walRelease(pWal);
|
||||
|
@ -420,7 +420,7 @@ int walHandleExistingFiles(const char *path) {
|
|||
if ( strncmp(ent->d_name, walPrefix, plen) == 0) {
|
||||
snprintf(oname, sizeof(oname), "%s/%s", path, ent->d_name);
|
||||
snprintf(nname, sizeof(nname), "%s/old/%s", path, ent->d_name);
|
||||
if (tmkdir(opath, 0755) != 0) {
|
||||
if (taosMkDir(opath, 0755) != 0) {
|
||||
wError("wal:%s, failed to create directory:%s(%s)", oname, opath, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue