feat: zlib compression is supported only on linux and mac platforms
This commit is contained in:
parent
53b9743ac4
commit
4e79e8f489
|
@ -16,7 +16,10 @@
|
||||||
#ifndef INC_BENCHCSV_H_
|
#ifndef INC_BENCHCSV_H_
|
||||||
#define INC_BENCHCSV_H_
|
#define INC_BENCHCSV_H_
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "bench.h"
|
#include "bench.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,7 +41,9 @@ typedef struct {
|
||||||
CsvCompressionLevel compress_level;
|
CsvCompressionLevel compress_level;
|
||||||
CsvIoError result;
|
CsvIoError result;
|
||||||
union {
|
union {
|
||||||
|
#ifndef _WIN32
|
||||||
gzFile gf;
|
gzFile gf;
|
||||||
|
#endif
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
} handle;
|
} handle;
|
||||||
} CsvFileHandle;
|
} CsvFileHandle;
|
||||||
|
|
|
@ -316,6 +316,9 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
|
target_link_libraries(taosBenchmark z)
|
||||||
|
|
||||||
ELSE ()
|
ELSE ()
|
||||||
ADD_DEFINITIONS(-DWINDOWS)
|
ADD_DEFINITIONS(-DWINDOWS)
|
||||||
SET(CMAKE_C_STANDARD 11)
|
SET(CMAKE_C_STANDARD 11)
|
||||||
|
@ -364,4 +367,3 @@ ELSE ()
|
||||||
TARGET_LINK_LIBRARIES(taosBenchmark taos msvcregex pthread toolscJson ${WEBSOCKET_LINK_FLAGS})
|
TARGET_LINK_LIBRARIES(taosBenchmark taos msvcregex pthread toolscJson ${WEBSOCKET_LINK_FLAGS})
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
target_link_libraries(taosBenchmark z)
|
|
||||||
|
|
|
@ -953,12 +953,15 @@ static CsvFileHandle* csvOpen(const char* filename, CsvCompressionLevel compress
|
||||||
if (compress_level == CSV_COMPRESS_NONE) {
|
if (compress_level == CSV_COMPRESS_NONE) {
|
||||||
fhdl->handle.fp = fopen(filename, "w");
|
fhdl->handle.fp = fopen(filename, "w");
|
||||||
failed = (!fhdl->handle.fp);
|
failed = (!fhdl->handle.fp);
|
||||||
} else {
|
}
|
||||||
|
#ifndef _WIN32
|
||||||
|
else {
|
||||||
char mode[TINY_BUFF_LEN];
|
char mode[TINY_BUFF_LEN];
|
||||||
(void)snprintf(mode, sizeof(mode), "wb%d", compress_level);
|
(void)snprintf(mode, sizeof(mode), "wb%d", compress_level);
|
||||||
fhdl->handle.gf = gzopen(filename, mode);
|
fhdl->handle.gf = gzopen(filename, mode);
|
||||||
failed = (!fhdl->handle.gf);
|
failed = (!fhdl->handle.gf);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (failed) {
|
if (failed) {
|
||||||
tmfree(fhdl);
|
tmfree(fhdl);
|
||||||
|
@ -986,7 +989,9 @@ static CsvIoError csvWrite(CsvFileHandle* fhdl, const char* buf, size_t size) {
|
||||||
fhdl->result = CSV_ERR_WRITE_FAILED;
|
fhdl->result = CSV_ERR_WRITE_FAILED;
|
||||||
return CSV_ERR_WRITE_FAILED;
|
return CSV_ERR_WRITE_FAILED;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
#ifndef _WIN32
|
||||||
|
else {
|
||||||
int ret = gzwrite(fhdl->handle.gf, buf, size);
|
int ret = gzwrite(fhdl->handle.gf, buf, size);
|
||||||
if (ret != size) {
|
if (ret != size) {
|
||||||
errorPrint("Failed to write csv file: %s. expected written %zu but %d.\n",
|
errorPrint("Failed to write csv file: %s. expected written %zu but %d.\n",
|
||||||
|
@ -998,6 +1003,8 @@ static CsvIoError csvWrite(CsvFileHandle* fhdl, const char* buf, size_t size) {
|
||||||
return CSV_ERR_WRITE_FAILED;
|
return CSV_ERR_WRITE_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return CSV_ERR_OK;
|
return CSV_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1012,12 +1019,16 @@ static void csvClose(CsvFileHandle* fhdl) {
|
||||||
fclose(fhdl->handle.fp);
|
fclose(fhdl->handle.fp);
|
||||||
fhdl->handle.fp = NULL;
|
fhdl->handle.fp = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
#ifndef _WIN32
|
||||||
|
else {
|
||||||
if (fhdl->handle.gf) {
|
if (fhdl->handle.gf) {
|
||||||
gzclose(fhdl->handle.gf);
|
gzclose(fhdl->handle.gf);
|
||||||
fhdl->handle.gf = NULL;
|
fhdl->handle.gf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
tmfree(fhdl);
|
tmfree(fhdl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue