未验证 提交 d131e525 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #9502 from taosdata/fix/ZhiqiangWang/TD-345-win-read-file-binary-error

[TD-345]<fix>(other): win read file binary error.
...@@ -433,7 +433,7 @@ int32_t readFromFile(char *name, uint32_t *len, void **buf) { ...@@ -433,7 +433,7 @@ int32_t readFromFile(char *name, uint32_t *len, void **buf) {
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
int fd = open(name, O_RDONLY); int fd = open(name, O_RDONLY | O_BINARY);
if (fd < 0) { if (fd < 0) {
tscError("open file %s failed, error:%s", name, strerror(errno)); tscError("open file %s failed, error:%s", name, strerror(errno));
tfree(*buf); tfree(*buf);
......
...@@ -240,7 +240,7 @@ static void dnodeCheckDataDirOpenned(char *dir) { ...@@ -240,7 +240,7 @@ static void dnodeCheckDataDirOpenned(char *dir) {
char filepath[256] = {0}; char filepath[256] = {0};
sprintf(filepath, "%s/.running", dir); sprintf(filepath, "%s/.running", dir);
int fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); int fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd < 0) { if (fd < 0) {
dError("failed to open lock file:%s, reason: %s, quit", filepath, strerror(errno)); dError("failed to open lock file:%s, reason: %s, quit", filepath, strerror(errno));
exit(0); exit(0);
......
...@@ -266,7 +266,7 @@ static void* telemetryThread(void* param) { ...@@ -266,7 +266,7 @@ static void* telemetryThread(void* param) {
} }
static void dnodeGetEmail(char* filepath) { static void dnodeGetEmail(char* filepath) {
int32_t fd = open(filepath, O_RDONLY); int32_t fd = open(filepath, O_RDONLY | O_BINARY);
if (fd < 0) { if (fd < 0) {
return; return;
} }
......
...@@ -70,7 +70,7 @@ typedef struct { ...@@ -70,7 +70,7 @@ typedef struct {
#define TFILE_NAME(pf) ((pf)->aname) #define TFILE_NAME(pf) ((pf)->aname)
#define TFILE_REL_NAME(pf) ((pf)->rname) #define TFILE_REL_NAME(pf) ((pf)->rname)
#define tfsopen(pf, flags) open(TFILE_NAME(pf), flags) #define tfsopen(pf, flags) open(TFILE_NAME(pf), flags | O_BINARY)
#define tfsclose(fd) close(fd) #define tfsclose(fd) close(fd)
#define tfsremove(pf) remove(TFILE_NAME(pf)) #define tfsremove(pf) remove(TFILE_NAME(pf))
#define tfscopy(sf, df) taosCopy(TFILE_NAME(sf), TFILE_NAME(df)) #define tfscopy(sf, df) taosCopy(TFILE_NAME(sf), TFILE_NAME(df))
......
...@@ -22,7 +22,7 @@ uint32_t taosSafeRand(void) { ...@@ -22,7 +22,7 @@ uint32_t taosSafeRand(void) {
int fd; int fd;
int seed; int seed;
fd = open("/dev/urandom", 0); fd = open("/dev/urandom", 0 | O_BINARY);
if (fd < 0) { if (fd < 0) {
seed = (int)time(0); seed = (int)time(0);
} else { } else {
......
...@@ -713,7 +713,7 @@ bool taosGetSystemUid(char *uid) { ...@@ -713,7 +713,7 @@ bool taosGetSystemUid(char *uid) {
int fd; int fd;
int len = 0; int len = 0;
fd = open("/proc/sys/kernel/random/uuid", 0); fd = open("/proc/sys/kernel/random/uuid", 0 | O_BINARY);
if (fd < 0) { if (fd < 0) {
return false; return false;
} else { } else {
......
...@@ -72,7 +72,7 @@ char* taosGetCmdlineByPID(int pid) { ...@@ -72,7 +72,7 @@ char* taosGetCmdlineByPID(int pid) {
static char cmdline[1024]; static char cmdline[1024];
sprintf(cmdline, "/proc/%d/cmdline", pid); sprintf(cmdline, "/proc/%d/cmdline", pid);
int fd = open(cmdline, O_RDONLY); int fd = open(cmdline, O_RDONLY | O_BINARY);
if (fd >= 0) { if (fd >= 0) {
int n = read(fd, cmdline, sizeof(cmdline) - 1); int n = read(fd, cmdline, sizeof(cmdline) - 1);
if (n < 0) n = 0; if (n < 0) n = 0;
......
...@@ -172,7 +172,7 @@ int main(int argc, char *argv[]) { ...@@ -172,7 +172,7 @@ int main(int argc, char *argv[]) {
tInfo("RPC server is running, ctrl-c to exit"); tInfo("RPC server is running, ctrl-c to exit");
if (commit) { if (commit) {
dataFd = open(dataName, O_APPEND | O_CREAT | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); dataFd = open(dataName, O_APPEND | O_CREAT | O_WRONLY | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
if (dataFd<0) if (dataFd<0)
tInfo("failed to open data file, reason:%s", strerror(errno)); tInfo("failed to open data file, reason:%s", strerror(errno));
} }
......
...@@ -43,7 +43,7 @@ int writeIntoWal(SWalHead *pHead) { ...@@ -43,7 +43,7 @@ int writeIntoWal(SWalHead *pHead) {
char walName[280]; char walName[280];
snprintf(walName, sizeof(walName), "%s/wal/wal.%d", path, walNum); snprintf(walName, sizeof(walName), "%s/wal/wal.%d", path, walNum);
(void)remove(walName); (void)remove(walName);
dataFd = open(walName, O_CREAT | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); dataFd = open(walName, O_CREAT | O_WRONLY | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
if (dataFd < 0) { if (dataFd < 0) {
uInfo("failed to open wal file:%s(%s)", walName, strerror(errno)); uInfo("failed to open wal file:%s(%s)", walName, strerror(errno));
return -1; return -1;
......
...@@ -89,7 +89,7 @@ static FORCE_INLINE void tsdbSetMFileInfo(SMFile* pMFile, SMFInfo* pInfo) { pMFi ...@@ -89,7 +89,7 @@ static FORCE_INLINE void tsdbSetMFileInfo(SMFile* pMFile, SMFInfo* pInfo) { pMFi
static FORCE_INLINE int tsdbOpenMFile(SMFile* pMFile, int flags) { static FORCE_INLINE int tsdbOpenMFile(SMFile* pMFile, int flags) {
ASSERT(TSDB_FILE_CLOSED(pMFile)); ASSERT(TSDB_FILE_CLOSED(pMFile));
pMFile->fd = open(TSDB_FILE_FULL_NAME(pMFile), flags); pMFile->fd = open(TSDB_FILE_FULL_NAME(pMFile), flags | O_BINARY);
if (pMFile->fd < 0) { if (pMFile->fd < 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
...@@ -204,7 +204,7 @@ static FORCE_INLINE void tsdbSetDFileInfo(SDFile* pDFile, SDFInfo* pInfo) { pDFi ...@@ -204,7 +204,7 @@ static FORCE_INLINE void tsdbSetDFileInfo(SDFile* pDFile, SDFInfo* pInfo) { pDFi
static FORCE_INLINE int tsdbOpenDFile(SDFile* pDFile, int flags) { static FORCE_INLINE int tsdbOpenDFile(SDFile* pDFile, int flags) {
ASSERT(!TSDB_FILE_OPENED(pDFile)); ASSERT(!TSDB_FILE_OPENED(pDFile));
pDFile->fd = open(TSDB_FILE_FULL_NAME(pDFile), flags); pDFile->fd = open(TSDB_FILE_FULL_NAME(pDFile), flags | O_BINARY);
if (pDFile->fd < 0) { if (pDFile->fd < 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
......
...@@ -191,7 +191,7 @@ static void *taosThreadToOpenNewFile(void *param) { ...@@ -191,7 +191,7 @@ static void *taosThreadToOpenNewFile(void *param) {
umask(0); umask(0);
int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd < 0) { if (fd < 0) {
tsLogObj.openInProgress = 0; tsLogObj.openInProgress = 0;
tsLogObj.lines = tsLogObj.maxLines - 1000; tsLogObj.lines = tsLogObj.maxLines - 1000;
...@@ -252,7 +252,7 @@ void taosResetLog() { ...@@ -252,7 +252,7 @@ void taosResetLog() {
} }
static bool taosCheckFileIsOpen(char *logFileName) { static bool taosCheckFileIsOpen(char *logFileName) {
int32_t fd = open(logFileName, O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); int32_t fd = open(logFileName, O_WRONLY | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd < 0) { if (fd < 0) {
if (errno == ENOENT) { if (errno == ENOENT) {
return false; return false;
...@@ -340,7 +340,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { ...@@ -340,7 +340,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
pthread_mutex_init(&tsLogObj.logMutex, NULL); pthread_mutex_init(&tsLogObj.logMutex, NULL);
umask(0); umask(0);
tsLogObj.logHandle->fd = open(fileName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); tsLogObj.logHandle->fd = open(fileName, O_WRONLY | O_CREAT | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
if (tsLogObj.logHandle->fd < 0) { if (tsLogObj.logHandle->fd < 0) {
printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno)); printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno));
......
...@@ -92,7 +92,7 @@ static void *taosThreadToOpenNewNote(void *param) { ...@@ -92,7 +92,7 @@ static void *taosThreadToOpenNewNote(void *param) {
umask(0); umask(0);
int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd < 0) { if (fd < 0) {
return NULL; return NULL;
} }
...@@ -132,7 +132,7 @@ static int32_t taosOpenNewNote(SNoteObj *pNote) { ...@@ -132,7 +132,7 @@ static int32_t taosOpenNewNote(SNoteObj *pNote) {
} }
static bool taosCheckNoteIsOpen(char *noteName, SNoteObj *pNote) { static bool taosCheckNoteIsOpen(char *noteName, SNoteObj *pNote) {
int32_t fd = open(noteName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); int32_t fd = open(noteName, O_WRONLY | O_CREAT | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "failed to open note:%s reason:%s\n", noteName, strerror(errno)); fprintf(stderr, "failed to open note:%s reason:%s\n", noteName, strerror(errno));
return true; return true;
...@@ -207,7 +207,7 @@ static int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxN ...@@ -207,7 +207,7 @@ static int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxN
pthread_mutex_init(&pNote->mutex, NULL); pthread_mutex_init(&pNote->mutex, NULL);
umask(0); umask(0);
pNote->fd = open(noteName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); pNote->fd = open(noteName, O_WRONLY | O_CREAT | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
if (pNote->fd < 0) { if (pNote->fd < 0) {
fprintf(stderr, "failed to open note file:%s reason:%s\n", noteName, strerror(errno)); fprintf(stderr, "failed to open note file:%s reason:%s\n", noteName, strerror(errno));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册