This commit is contained in:
facetosea 2024-11-11 13:41:56 +08:00
parent 82cf87369a
commit 6de6e53482
2 changed files with 27 additions and 5 deletions

View File

@ -137,6 +137,13 @@ extern threadlocal bool tsEnableRandErr;
terrno = _code; \ terrno = _code; \
} }
#define OS_PARAM_CHECK(_o) \
do { \
if ((_o) == NULL) { \
return TSDB_CODE_INVALID_PARA; \
} \
} while(0)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -116,7 +116,10 @@ void taosRemoveDir(const char *dirname) {
return; return;
} }
bool taosDirExist(const char *dirname) { return taosCheckExistFile(dirname); } bool taosDirExist(const char *dirname) {
if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return false;
return taosCheckExistFile(dirname);
}
int32_t taosMkDir(const char *dirname) { int32_t taosMkDir(const char *dirname) {
if (taosDirExist(dirname)) return 0; if (taosDirExist(dirname)) return 0;
@ -333,6 +336,8 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
} }
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
OS_PARAM_CHECK(dirname);
OS_PARAM_CHECK(outname);
wordexp_t full_path; wordexp_t full_path;
int32_t code = wordexp(dirname, &full_path, 0); int32_t code = wordexp(dirname, &full_path, 0);
switch (code) { switch (code) {
@ -355,6 +360,8 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
} }
int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) { int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
OS_PARAM_CHECK(dirname);
OS_PARAM_CHECK(realPath);
char tmp[PATH_MAX] = {0}; char tmp[PATH_MAX] = {0};
#ifdef WINDOWS #ifdef WINDOWS
if (_fullpath(tmp, dirname, maxlen) != NULL) { if (_fullpath(tmp, dirname, maxlen) != NULL) {
@ -386,6 +393,10 @@ bool taosIsDir(const char *dirname) {
} }
char *taosDirName(char *name) { char *taosDirName(char *name) {
if(name == NULL) {
terrno = TSDB_CODE_INVALID_PARA;
return NULL;
}
#ifdef WINDOWS #ifdef WINDOWS
char Drive1[MAX_PATH], Dir1[MAX_PATH]; char Drive1[MAX_PATH], Dir1[MAX_PATH];
_splitpath(name, Drive1, Dir1, NULL, NULL); _splitpath(name, Drive1, Dir1, NULL, NULL);
@ -412,12 +423,16 @@ char *taosDirName(char *name) {
} }
char *taosDirEntryBaseName(char *name) { char *taosDirEntryBaseName(char *name) {
if(name == NULL) {
terrno = TSDB_CODE_INVALID_PARA;
return NULL;
}
#ifdef WINDOWS #ifdef WINDOWS
char Filename1[MAX_PATH], Ext1[MAX_PATH]; char Filename1[MAX_PATH], Ext1[MAX_PATH];
_splitpath(name, NULL, NULL, Filename1, Ext1); _splitpath(name, NULL, NULL, Filename1, Ext1);
return name + (strlen(name) - strlen(Filename1) - strlen(Ext1)); return name + (strlen(name) - strlen(Filename1) - strlen(Ext1));
#else #else
if (name == NULL || (name[0] == '/' && name[1] == '\0')) return name; if ((name[0] == '/' && name[1] == '\0')) return name;
char *pPoint = strrchr(name, '/'); char *pPoint = strrchr(name, '/');
if (pPoint != NULL) { if (pPoint != NULL) {
if (*(pPoint + 1) == '\0') { if (*(pPoint + 1) == '\0') {
@ -515,9 +530,9 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) {
} }
char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) { char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) {
/*if (pDirEntry == NULL) {*/ if (pDirEntry == NULL) {
/*return NULL;*/ return NULL;
/*}*/ }
#ifdef WINDOWS #ifdef WINDOWS
return pDirEntry->findFileData.cFileName; return pDirEntry->findFileData.cFileName;
#else #else