Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/article_favor_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static enum select_cmd_t article_favor_select(int total_page, int item_count, in
case KEY_TIMEOUT:
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
{
log_error("User input timeout\n");
log_debug("User input timeout\n");
return EXIT_LIST; // exit list
}
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/bbs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ int bbs_center()
case KEY_TIMEOUT:
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
{
log_error("User input timeout\n");
log_debug("User input timeout\n");
loop = 0;
break;
}
Expand Down
5 changes: 3 additions & 2 deletions src/bbs_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ static int bbsnet_connect(int n)
{
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
{
log_debug("User input timeout\n");
break;
}
}
Expand Down Expand Up @@ -1372,7 +1373,7 @@ static int bbsnet_connect(int n)

if (sock != -1 && close(sock) == -1)
{
log_error("Close socket failed\n");
log_error("close(socket) error (%d)\n", errno);
}

if (res)
Expand Down Expand Up @@ -1465,7 +1466,7 @@ int bbs_net()
case KEY_TIMEOUT:
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
{
log_error("User input timeout\n");
log_debug("User input timeout\n");
goto cleanup;
}
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ int editor_display(EDITOR_DATA *p_editor_data)
log_debug("KEY_NULL\n");
goto cleanup;
case KEY_TIMEOUT:
log_error("User input timeout\n");
log_debug("User input timeout\n");
goto cleanup;
case Ctrl('W'):
case Ctrl('X'):
Expand Down
21 changes: 7 additions & 14 deletions src/hash_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ static const unsigned int hash_dict_prime_list[] = {
50331653,
};

static const int hash_dict_prime_list_count = sizeof(hash_dict_prime_list) / sizeof(hash_dict_prime_list[0]);
static const unsigned int hash_dict_prime_list_count = sizeof(hash_dict_prime_list) / sizeof(hash_dict_prime_list[0]);

HASH_DICT *hash_dict_create(int item_count_limit)
{
HASH_DICT *p_dict = NULL;
unsigned int i;
unsigned int j;

if (item_count_limit <= 0)
{
Expand All @@ -56,7 +54,7 @@ HASH_DICT *hash_dict_create(int item_count_limit)
}

p_dict->prime_index = hash_dict_prime_list_count - 1;
for (i = 0; i < hash_dict_prime_list_count; i++)
for (unsigned int i = 0; i < hash_dict_prime_list_count; i++)
{
if (item_count_limit < hash_dict_prime_list[i])
{
Expand All @@ -75,17 +73,14 @@ HASH_DICT *hash_dict_create(int item_count_limit)
return NULL;
}

for (i = 0; i < p_dict->bucket_count; i++)
for (unsigned int i = 0; i < p_dict->bucket_count; i++)
{
p_dict->buckets[i] = calloc(HASH_DICT_BUCKET_SIZE, sizeof(HASH_ITEM *));
if (p_dict->buckets[i] == NULL)
{
log_error("calloc(HASH_DICT_BUCKET_SIZE, HASH_ITEM) error at bucket %d\n", i);
for (j = i - 1; j >= 0; j--)
{
free(p_dict->buckets[j]);
}
free(p_dict);
p_dict->bucket_count = i;
hash_dict_destroy(p_dict);
return NULL;
}
}
Expand All @@ -99,17 +94,15 @@ void hash_dict_destroy(HASH_DICT *p_dict)
{
HASH_ITEM *p_item;
HASH_ITEM *p_next;
unsigned int i;
unsigned int j;

if (p_dict == NULL)
{
return;
}

for (i = 0; i < p_dict->bucket_count; i++)
for (unsigned int i = 0; i < p_dict->bucket_count; i++)
{
for (j = 0; j < HASH_DICT_BUCKET_SIZE; j++)
for (unsigned int j = 0; j < HASH_DICT_BUCKET_SIZE; j++)
{
p_item = p_dict->buckets[i][j];
while (p_item != NULL)
Expand Down
115 changes: 86 additions & 29 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,32 @@ int io_init(void)
log_error("epoll_ctl(STDIN_FILENO) error (%d)\n", errno);
if (close(stdin_epollfd) < 0)
{
log_error("close(stdin_epollfd) error (%d)\n");
log_error("close(stdin_epollfd) error (%d)\n", errno);
}
stdin_epollfd = -1;
return -1;
}

stdin_flags = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK);
if ((stdin_flags = fcntl(STDIN_FILENO, F_GETFL, 0)) == -1)
{
log_error("fcntl(F_GETFL) error (%d)\n", errno);
if (close(stdin_epollfd) < 0)
{
log_error("close(stdin_epollfd) error (%d)\n", errno);
}
stdin_epollfd = -1;
return -1;
}
if ((fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK)) == -1)
{
log_error("fcntl(F_SETFL) error (%d)\n", errno);
if (close(stdin_epollfd) < 0)
{
log_error("close(stdin_epollfd) error (%d)\n", errno);
}
stdin_epollfd = -1;
return -1;
}
}

if (stdout_epollfd == -1)
Expand All @@ -114,26 +132,60 @@ int io_init(void)
log_error("epoll_ctl(STDOUT_FILENO) error (%d)\n", errno);
if (close(stdout_epollfd) < 0)
{
log_error("close(stdout_epollfd) error (%d)\n");
log_error("close(stdout_epollfd) error (%d)\n", errno);
}
stdout_epollfd = -1;
return -1;
}

stdout_flags = fcntl(STDOUT_FILENO, F_GETFL, 0);
fcntl(STDOUT_FILENO, F_SETFL, stdout_flags | O_NONBLOCK);
if ((stdout_flags = fcntl(STDOUT_FILENO, F_GETFL, 0)) == -1)
{
log_error("fcntl(F_GETFL) error (%d)\n", errno);
if (close(stdout_epollfd) < 0)
{
log_error("close(stdout_epollfd) error (%d)\n", errno);
}
stdout_epollfd = -1;
return -1;
}
if ((fcntl(STDOUT_FILENO, F_SETFL, stdout_flags | O_NONBLOCK)) == -1)
{
log_error("fcntl(F_SETFL) error (%d)\n", errno);
if (close(stdout_epollfd) < 0)
{
log_error("close(stdout_epollfd) error (%d)\n", errno);
}
stdout_epollfd = -1;
return -1;
}
}
#else
if (stdin_flags == 0)
{
stdin_flags = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK);
if ((stdin_flags = fcntl(STDIN_FILENO, F_GETFL, 0)) == -1)
{
log_error("fcntl(F_GETFL) error (%d)\n", errno);
return -1;
}
if ((fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK)) == -1)
{
log_error("fcntl(F_SETFL) error (%d)\n", errno);
return -1;
}
}

if (stdout_flags == 0)
{
stdout_flags = fcntl(STDOUT_FILENO, F_GETFL, 0);
fcntl(STDOUT_FILENO, F_SETFL, stdout_flags | O_NONBLOCK);
if ((stdout_flags = fcntl(STDOUT_FILENO, F_GETFL, 0)) == -1)
{
log_error("fcntl(F_GETFL) error (%d)\n", errno);
return -1;
}
if ((fcntl(STDOUT_FILENO, F_SETFL, stdout_flags | O_NONBLOCK)) == -1)
{
log_error("fcntl(F_SETFL) error (%d)\n", errno);
return -1;
}
}
#endif

Expand All @@ -150,7 +202,7 @@ void io_cleanup(void)

if (close(stdin_epollfd) < 0)
{
log_error("close(stdin_epollfd) error (%d)\n");
log_error("close(stdin_epollfd) error (%d)\n", errno);
}
stdin_epollfd = -1;
}
Expand All @@ -162,7 +214,7 @@ void io_cleanup(void)

if (close(stdout_epollfd) < 0)
{
log_error("close(stdout_epollfd) error (%d)\n");
log_error("close(stdout_epollfd) error (%d)\n", errno);
}
stdout_epollfd = -1;
}
Expand Down Expand Up @@ -191,23 +243,27 @@ int prints(const char *format, ...)
ret = vsnprintf(buf, sizeof(buf), format, args);
va_end(args);

if (ret > 0)
if (ret >= 0)
{
if (stdout_buf_len + ret > OUTPUT_BUF_SIZE)
int written = (ret >= sizeof(buf) ? (int)sizeof(buf) - 1 : ret);

if (stdout_buf_len + written > OUTPUT_BUF_SIZE)
{
iflush();
}

if (stdout_buf_len + ret <= OUTPUT_BUF_SIZE)
if (stdout_buf_len + written <= OUTPUT_BUF_SIZE)
{
memcpy(stdout_buf + stdout_buf_len, buf, (size_t)ret);
stdout_buf_len += ret;
memcpy(stdout_buf + stdout_buf_len, buf, (size_t)written);
stdout_buf_len += written;
ret = written;
}
else
{
errno = EAGAIN;
ret = (OUTPUT_BUF_SIZE - stdout_buf_len - ret);
log_error("Output buffer is full, additional %d is required\n", ret);
int need = stdout_buf_len + written - OUTPUT_BUF_SIZE;
log_error("Output buffer is full, additional %d bytes are required\n", need);
ret = -need;
}
}

Expand All @@ -216,7 +272,7 @@ int prints(const char *format, ...)

int outc(char c)
{
int ret;
int ret = 0;

if (stdout_buf_len + 1 > OUTPUT_BUF_SIZE)
{
Expand Down Expand Up @@ -1058,7 +1114,7 @@ int io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char
size_t i = 0;
int skip_current = 0;

if (cd == NULL || p_buf == NULL || p_buf_len == NULL || p_buf_offset == NULL || p_conv == NULL || p_conv_len == NULL)
if (cd == (iconv_t)(-1) || p_buf == NULL || p_buf_len == NULL || p_buf_offset == NULL || p_conv == NULL || p_conv_len == NULL)
{
log_error("NULL pointer error\n");
return -1;
Expand Down Expand Up @@ -1112,7 +1168,8 @@ int io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char
{
if (errno == EINVAL) // Incomplete
{
log_debug("iconv(inbytes=%d, outbytes=%d) error: EINVAL, in_buf[0]=%d\n", in_bytes, out_bytes, in_buf[0]);
log_debug("iconv(inbytes=%zu, outbytes=%zu) error: EINVAL, in_buf[0]=%d\n",
in_bytes, out_bytes, (unsigned char)in_buf[0]);
if (p_buf != in_buf)
{
*p_buf_len -= (int)(in_buf - p_buf);
Expand All @@ -1125,32 +1182,32 @@ int io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char
}
else if (errno == E2BIG)
{
log_error("iconv(inbytes=%d, outbytes=%d) error: E2BIG\n", in_bytes, out_bytes);
log_error("iconv(inbytes=%zu, outbytes=%zu) error: E2BIG\n", in_bytes, out_bytes);
return -1;
}
else if (errno == EILSEQ)
{
if (in_bytes > out_bytes || out_bytes <= 0)
{
log_error("iconv(inbytes=%d, outbytes=%d) error: EILSEQ and E2BIG\n", in_bytes, out_bytes);
log_error("iconv(inbytes=%zu, outbytes=%zu) error: EILSEQ\n", in_bytes, out_bytes);
return -2;
}

// reset in_bytes when "//IGNORE" is applied
if (in_bytes == 0)
{
in_bytes = (size_t)(*p_buf_len - *p_buf_offset);
log_debug("Reset in_bytes from 0 to %d\n", in_bytes);
log_debug("Reset in_bytes from 0 to %zu\n", in_bytes);
}

log_debug("iconv(in_bytes=%d, out_bytes=%d) error: EILSEQ, in_buf[0]=%d\n",
in_bytes, out_bytes, in_buf[0]);
log_debug("iconv(in_bytes=%zu, out_bytes=%zu) error: EILSEQ, in_buf[0]=%d\n",
in_bytes, out_bytes, (unsigned char)in_buf[0]);
skip_current = 1;
}
else // something strange
{
log_debug("iconv(in_bytes=%d, out_bytes=%d) error: %d, in_buf[0]=%d\n",
in_bytes, out_bytes, errno, in_buf[0]);
log_debug("iconv(in_bytes=%zu, out_bytes=%zu) error: %d, in_buf[0]=%d\n",
in_bytes, out_bytes, errno, (unsigned char)in_buf[0]);
*p_buf_offset = (int)(in_buf - p_buf);
*p_conv_len = (int)(conv_size - out_bytes);
skip_current = 1;
Expand Down
Loading