From d18ad54c2b2cf3a0cf090b5ef098022c8ea39c6e Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Thu, 15 Feb 2024 16:44:00 +0800 Subject: [PATCH] add macro FC_SET_STRING_EMPTY --- HISTORY | 3 +++ src/common_define.h | 2 ++ src/fast_task_queue.c | 3 +++ src/shared_func.c | 37 ++++++++++++++++++------------------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/HISTORY b/HISTORY index 748845d..d3fe99f 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 1.73 2024-02-15 + * add macro FC_SET_STRING_EMPTY + Version 1.72 2024-01-21 * call fast_mblock_ref_counter_dec for delay free node correctly * fc_queue.[hc]: add function fc_queue_remove diff --git a/src/common_define.h b/src/common_define.h index c862383..6b6e900 100644 --- a/src/common_define.h +++ b/src/common_define.h @@ -406,6 +406,8 @@ typedef void* (*MallocFunc)(size_t size); (dest).len = l; \ } while (0) +#define FC_SET_STRING_EMPTY(dest, s) FC_SET_STRING_EX(dest, s, 0) + #define FC_SET_STRING_NULL(dest) \ do { \ (dest).str = NULL; \ diff --git a/src/fast_task_queue.c b/src/fast_task_queue.c index 86d9326..cf6b785 100644 --- a/src/fast_task_queue.c +++ b/src/fast_task_queue.c @@ -212,6 +212,9 @@ int free_queue_get_new_buffer_size(const int min_buff_size, "exceeds max buffer size: %d", __LINE__, expect_size, max_buff_size); return EOVERFLOW; + } else if (expect_size == max_buff_size) { + *new_size = max_buff_size; + return 0; } *new_size = min_buff_size; diff --git a/src/shared_func.c b/src/shared_func.c index fbd8cd0..678d1ef 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -3803,11 +3803,11 @@ int fc_get_first_line(const char *filename, char *buff, read_bytes = buff_size - 1; if ((result=getFileContentEx(filename, buff, 0, &read_bytes)) != 0) { - line->len = 0; + FC_SET_STRING_EMPTY(*line, buff); return result; } if (read_bytes == 0) { - line->len = 0; + FC_SET_STRING_EMPTY(*line, buff); return ENOENT; } @@ -3817,11 +3817,11 @@ int fc_get_first_line(const char *filename, char *buff, "file: %s, line no: 1, " "expect new line char \"\\n\"", __LINE__, filename); - line->len = 0; + FC_SET_STRING_EMPTY(*line, buff); return EINVAL; } - line->str = buff; - line->len = line_end - buff + 1; + + FC_SET_STRING_EX(*line, buff, line_end - buff + 1); return 0; } @@ -3836,19 +3836,19 @@ int fc_get_first_lines(const char *filename, char *buff, char *line_end; if (*count <= 0) { - lines->len = 0; + FC_SET_STRING_EMPTY(*lines, buff); return EINVAL; } read_bytes = buff_size - 1; if ((result=getFileContentEx(filename, buff, 0, &read_bytes)) != 0) { *count = 0; - lines->len = 0; + FC_SET_STRING_EMPTY(*lines, buff); return result; } if (read_bytes == 0) { *count = 0; - lines->len = 0; + FC_SET_STRING_EMPTY(*lines, buff); return ENOENT; } @@ -3868,8 +3868,7 @@ int fc_get_first_lines(const char *filename, char *buff, } } - lines->str = buff; - lines->len = p - buff; + FC_SET_STRING_EX(*lines, buff, p - buff); return (*count > 0 ? 0 : ENOENT); } @@ -3881,12 +3880,12 @@ int fc_get_last_line(const char *filename, char *buff, int result; if ((result=getFileSize(filename, file_size)) != 0) { - line->len = 0; + FC_SET_STRING_EMPTY(*line, buff); return result; } if (*file_size == 0) { - line->len = 0; + FC_SET_STRING_EMPTY(*line, buff); return ENOENT; } @@ -3899,11 +3898,11 @@ int fc_get_last_line(const char *filename, char *buff, if ((result=getFileContentEx(filename, buff, offset, &read_bytes)) != 0) { - line->len = 0; + FC_SET_STRING_EMPTY(*line, buff); return result; } if (read_bytes == 0) { - line->len = 0; + FC_SET_STRING_EMPTY(*line, buff); return ENOENT; } @@ -3928,19 +3927,19 @@ int fc_get_last_lines(const char *filename, char *buff, int result; if (*count <= 0) { - lines->len = 0; + FC_SET_STRING_EMPTY(*lines, buff); return EINVAL; } if ((result=getFileSize(filename, &file_size)) != 0) { *count = 0; - lines->len = 0; + FC_SET_STRING_EMPTY(*lines, buff); return result; } if (file_size == 0) { *count = 0; - lines->len = 0; + FC_SET_STRING_EMPTY(*lines, buff); return ENOENT; } @@ -3954,12 +3953,12 @@ int fc_get_last_lines(const char *filename, char *buff, offset, &read_bytes)) != 0) { *count = 0; - lines->len = 0; + FC_SET_STRING_EMPTY(*lines, buff); return result; } if (read_bytes == 0) { *count = 0; - lines->len = 0; + FC_SET_STRING_EMPTY(*lines, buff); return ENOENT; }