From 4735b224ef6a52267a8ca5e9a7a9924c188adb05 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 6 Nov 2020 06:25:06 +0000 Subject: [PATCH] change read/write to taosRead/Write --- src/util/inc/tfile.h | 9 ++++----- src/util/src/tfile.c | 25 +++++++++++-------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/util/inc/tfile.h b/src/util/inc/tfile.h index 981ee7cecb..10b7c1df35 100644 --- a/src/util/inc/tfile.h +++ b/src/util/inc/tfile.h @@ -23,18 +23,17 @@ extern "C" { #include // init taos file module -int tfinit(); +int32_t tfinit(); // clean up taos file module void tfcleanup(); // the same syntax as UNIX standard open/close/read/write // but FD is int64_t and will never be reused -int64_t tfopen(const char *pathname, int flags); +int64_t tfopen(const char *pathname, int32_t flags); int64_t tfclose(int64_t tfd); -ssize_t tfwrite(int64_t tfd, const void *buf, size_t count); -ssize_t tfread(int64_t tfd, void *buf, size_t count); - +int64_t tfwrite(int64_t tfd, void *buf, int64_t count); +int64_t tfread(int64_t tfd, void *buf, int64_t count); #ifdef __cplusplus } diff --git a/src/util/src/tfile.c b/src/util/src/tfile.c index 4807fea0d0..27ba30fe81 100644 --- a/src/util/src/tfile.c +++ b/src/util/src/tfile.c @@ -19,13 +19,13 @@ #include "tutil.h" #include "tref.h" -static int tsFileRsetId = -1; +static int32_t tsFileRsetId = -1; static void taosCloseFile(void *p) { - close((int)(uintptr_t)p); + close((int32_t)(uintptr_t)p); } -int tfinit() { +int32_t tfinit() { tsFileRsetId = taosOpenRef(2000, taosCloseFile); return tsFileRsetId; } @@ -35,8 +35,8 @@ void tfcleanup() { tsFileRsetId = -1; } -int64_t tfopen(const char *pathname, int flags) { - int fd = open(pathname, flags); +int64_t tfopen(const char *pathname, int32_t flags) { + int32_t fd = open(pathname, flags); if (fd < 0) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -54,31 +54,28 @@ int64_t tfclose(int64_t tfd) { return taosRemoveRef(tsFileRsetId, tfd); } -ssize_t tfwrite(int64_t tfd, const void *buf, size_t count) { - +int64_t tfwrite(int64_t tfd, void *buf, int64_t count) { void *p = taosAcquireRef(tsFileRsetId, tfd); if (p == NULL) return -1; - int fd = (int)(uintptr_t)p; + int32_t fd = (int32_t)(uintptr_t)p; - ssize_t ret = write(fd, buf, (uint32_t)count); + int64_t ret = taosWrite(fd, buf, count); if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno); taosReleaseRef(tsFileRsetId, tfd); return ret; } -ssize_t tfread(int64_t tfd, void *buf, size_t count) { - +int64_t tfread(int64_t tfd, void *buf, int64_t count) { void *p = taosAcquireRef(tsFileRsetId, tfd); if (p == NULL) return -1; - int fd = (int)(uintptr_t)p; + int32_t fd = (int32_t)(uintptr_t)p; - ssize_t ret = read(fd, buf, (uint32_t)count); + int64_t ret = taosRead(fd, buf, count); if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno); taosReleaseRef(tsFileRsetId, tfd); return ret; } - -- GitLab