Merge remote-tracking branch 'origin/3.0' into feature/config

This commit is contained in:
Shengliang Guan 2022-02-25 16:08:57 +08:00
commit 71b562e5cb
2 changed files with 62 additions and 74 deletions

View File

@ -62,7 +62,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count);
int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset); int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset);
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count); int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count);
void taosFprintfFile(TdFilePtr pFile, const char *format, ...); void taosFprintfFile(TdFilePtr pFile, const char *format, ...);
size_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf); int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf);
int32_t taosEOFFile(TdFilePtr pFile); int32_t taosEOFFile(TdFilePtr pFile);
int64_t taosCloseFile(TdFilePtr *ppFile); int64_t taosCloseFile(TdFilePtr *ppFile);

View File

@ -15,6 +15,8 @@
#define ALLOW_FORBID_FUNC #define ALLOW_FORBID_FUNC
#include "os.h" #include "os.h"
#define MAX_FPRINTFLINE_BUFFER_SIZE (1000)
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#include <io.h> #include <io.h>
@ -50,8 +52,6 @@ typedef struct TdFile {
FILE *fp; FILE *fp;
} * TdFilePtr, TdFile; } * TdFilePtr, TdFile;
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) { void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
const char *tdengineTmpFileNamePrefix = "tdengine-"; const char *tdengineTmpFileNamePrefix = "tdengine-";
@ -184,9 +184,7 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
#endif #endif
} }
void autoDelFileListAdd(const char *path) { void autoDelFileListAdd(const char *path) { return; }
return;
}
TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
@ -195,8 +193,7 @@ TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions) {
int access = O_BINARY; int access = O_BINARY;
char *mode = NULL; char *mode = NULL;
access |= (tdFileOptions & TD_FILE_CTEATE) ? O_CREAT : 0; access |= (tdFileOptions & TD_FILE_CTEATE) ? O_CREAT : 0;
if ((tdFileOptions & TD_FILE_WRITE) && (tdFileOptions & TD_FILE_READ)) if ((tdFileOptions & TD_FILE_WRITE) && (tdFileOptions & TD_FILE_READ)) {
{
access |= O_RDWR; access |= O_RDWR;
mode = (tdFileOptions & TD_FILE_TEXT) ? "rt+" : "rb+"; mode = (tdFileOptions & TD_FILE_TEXT) ? "rt+" : "rb+";
} else if (tdFileOptions & TD_FILE_WRITE) { } else if (tdFileOptions & TD_FILE_WRITE) {
@ -242,7 +239,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
if (ppFile == NULL || *ppFile == NULL || (*ppFile)->fd == -1) { if (ppFile == NULL || *ppFile == NULL || (*ppFile)->fd == -1) {
return 0; return 0;
} }
fsync((*ppFile)->fd); fflush((*ppFile)->fp);
close((*ppFile)->fd); close((*ppFile)->fd);
(*ppFile)->fd = -1; (*ppFile)->fd = -1;
(*ppFile)->fp = NULL; (*ppFile)->fp = NULL;
@ -417,7 +414,7 @@ int32_t taosFsyncFile(TdFilePtr pFile) {
return FlushFileBuffers(h); return FlushFileBuffers(h);
#else #else
return fsync(pFile->fd); return fflush(pFile->fp);
#endif #endif
} }
@ -568,14 +565,11 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
#endif #endif
#ifdef __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
void taosFprintfFile(TdFilePtr pFile, const char *format, ...) { void taosFprintfFile(TdFilePtr pFile, const char *format, ...) {
char buffer[MAX_FPRINTFLINE_BUFFER_SIZE] = {0};
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
fprintf(pFile->fp, format, ap); vfprintf(pFile->fp, format, ap);
va_end(ap); va_end(ap);
fflush(pFile->fp); fflush(pFile->fp);
} }
@ -587,9 +581,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) {
return ptr; return ptr;
} }
bool taosValidFile(TdFilePtr pFile) { bool taosValidFile(TdFilePtr pFile) { return pFile != NULL; }
return pFile != NULL;
}
int32_t taosUmaskFile(int32_t maskVal) { int32_t taosUmaskFile(int32_t maskVal) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
@ -599,13 +591,9 @@ int32_t taosUmaskFile(int32_t maskVal) {
#endif #endif
} }
int taosGetErrorFile(TdFilePtr pFile) { int32_t taosGetErrorFile(TdFilePtr pFile) { return errno; }
return errno; int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict__ ptrBuf) {
}
size_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf) {
size_t len = 0; size_t len = 0;
return getline(ptrBuf, &len, pFile->fp); return getline(ptrBuf, &len, pFile->fp);
} }
int32_t taosEOFFile(TdFilePtr pFile) { int32_t taosEOFFile(TdFilePtr pFile) { return feof(pFile->fp); }
return feof(pFile->fp);
}