add macro FC_SET_STRING_EMPTY

use_iouring
YuQing 2024-02-15 16:44:00 +08:00
parent 2205cae6f3
commit d18ad54c2b
4 changed files with 26 additions and 19 deletions

View File

@ -1,4 +1,7 @@
Version 1.73 2024-02-15
* add macro FC_SET_STRING_EMPTY
Version 1.72 2024-01-21 Version 1.72 2024-01-21
* call fast_mblock_ref_counter_dec for delay free node correctly * call fast_mblock_ref_counter_dec for delay free node correctly
* fc_queue.[hc]: add function fc_queue_remove * fc_queue.[hc]: add function fc_queue_remove

View File

@ -406,6 +406,8 @@ typedef void* (*MallocFunc)(size_t size);
(dest).len = l; \ (dest).len = l; \
} while (0) } while (0)
#define FC_SET_STRING_EMPTY(dest, s) FC_SET_STRING_EX(dest, s, 0)
#define FC_SET_STRING_NULL(dest) \ #define FC_SET_STRING_NULL(dest) \
do { \ do { \
(dest).str = NULL; \ (dest).str = NULL; \

View File

@ -212,6 +212,9 @@ int free_queue_get_new_buffer_size(const int min_buff_size,
"exceeds max buffer size: %d", __LINE__, expect_size, "exceeds max buffer size: %d", __LINE__, expect_size,
max_buff_size); max_buff_size);
return EOVERFLOW; return EOVERFLOW;
} else if (expect_size == max_buff_size) {
*new_size = max_buff_size;
return 0;
} }
*new_size = min_buff_size; *new_size = min_buff_size;

View File

@ -3803,11 +3803,11 @@ int fc_get_first_line(const char *filename, char *buff,
read_bytes = buff_size - 1; read_bytes = buff_size - 1;
if ((result=getFileContentEx(filename, buff, 0, &read_bytes)) != 0) { if ((result=getFileContentEx(filename, buff, 0, &read_bytes)) != 0) {
line->len = 0; FC_SET_STRING_EMPTY(*line, buff);
return result; return result;
} }
if (read_bytes == 0) { if (read_bytes == 0) {
line->len = 0; FC_SET_STRING_EMPTY(*line, buff);
return ENOENT; return ENOENT;
} }
@ -3817,11 +3817,11 @@ int fc_get_first_line(const char *filename, char *buff,
"file: %s, line no: 1, " "file: %s, line no: 1, "
"expect new line char \"\\n\"", "expect new line char \"\\n\"",
__LINE__, filename); __LINE__, filename);
line->len = 0; FC_SET_STRING_EMPTY(*line, buff);
return EINVAL; return EINVAL;
} }
line->str = buff;
line->len = line_end - buff + 1; FC_SET_STRING_EX(*line, buff, line_end - buff + 1);
return 0; return 0;
} }
@ -3836,19 +3836,19 @@ int fc_get_first_lines(const char *filename, char *buff,
char *line_end; char *line_end;
if (*count <= 0) { if (*count <= 0) {
lines->len = 0; FC_SET_STRING_EMPTY(*lines, buff);
return EINVAL; return EINVAL;
} }
read_bytes = buff_size - 1; read_bytes = buff_size - 1;
if ((result=getFileContentEx(filename, buff, 0, &read_bytes)) != 0) { if ((result=getFileContentEx(filename, buff, 0, &read_bytes)) != 0) {
*count = 0; *count = 0;
lines->len = 0; FC_SET_STRING_EMPTY(*lines, buff);
return result; return result;
} }
if (read_bytes == 0) { if (read_bytes == 0) {
*count = 0; *count = 0;
lines->len = 0; FC_SET_STRING_EMPTY(*lines, buff);
return ENOENT; return ENOENT;
} }
@ -3868,8 +3868,7 @@ int fc_get_first_lines(const char *filename, char *buff,
} }
} }
lines->str = buff; FC_SET_STRING_EX(*lines, buff, p - buff);
lines->len = p - buff;
return (*count > 0 ? 0 : ENOENT); return (*count > 0 ? 0 : ENOENT);
} }
@ -3881,12 +3880,12 @@ int fc_get_last_line(const char *filename, char *buff,
int result; int result;
if ((result=getFileSize(filename, file_size)) != 0) { if ((result=getFileSize(filename, file_size)) != 0) {
line->len = 0; FC_SET_STRING_EMPTY(*line, buff);
return result; return result;
} }
if (*file_size == 0) { if (*file_size == 0) {
line->len = 0; FC_SET_STRING_EMPTY(*line, buff);
return ENOENT; return ENOENT;
} }
@ -3899,11 +3898,11 @@ int fc_get_last_line(const char *filename, char *buff,
if ((result=getFileContentEx(filename, buff, if ((result=getFileContentEx(filename, buff,
offset, &read_bytes)) != 0) offset, &read_bytes)) != 0)
{ {
line->len = 0; FC_SET_STRING_EMPTY(*line, buff);
return result; return result;
} }
if (read_bytes == 0) { if (read_bytes == 0) {
line->len = 0; FC_SET_STRING_EMPTY(*line, buff);
return ENOENT; return ENOENT;
} }
@ -3928,19 +3927,19 @@ int fc_get_last_lines(const char *filename, char *buff,
int result; int result;
if (*count <= 0) { if (*count <= 0) {
lines->len = 0; FC_SET_STRING_EMPTY(*lines, buff);
return EINVAL; return EINVAL;
} }
if ((result=getFileSize(filename, &file_size)) != 0) { if ((result=getFileSize(filename, &file_size)) != 0) {
*count = 0; *count = 0;
lines->len = 0; FC_SET_STRING_EMPTY(*lines, buff);
return result; return result;
} }
if (file_size == 0) { if (file_size == 0) {
*count = 0; *count = 0;
lines->len = 0; FC_SET_STRING_EMPTY(*lines, buff);
return ENOENT; return ENOENT;
} }
@ -3954,12 +3953,12 @@ int fc_get_last_lines(const char *filename, char *buff,
offset, &read_bytes)) != 0) offset, &read_bytes)) != 0)
{ {
*count = 0; *count = 0;
lines->len = 0; FC_SET_STRING_EMPTY(*lines, buff);
return result; return result;
} }
if (read_bytes == 0) { if (read_bytes == 0) {
*count = 0; *count = 0;
lines->len = 0; FC_SET_STRING_EMPTY(*lines, buff);
return ENOENT; return ENOENT;
} }