This commit is contained in:
twinaphex 2017-09-30 17:34:28 +02:00
parent de6b1bcbf0
commit 9dde5fc33f
1 changed files with 11 additions and 14 deletions

View File

@ -538,8 +538,6 @@ bool command_network_send(const char *cmd_)
#endif #endif
} }
#ifdef HAVE_STDIN_CMD #ifdef HAVE_STDIN_CMD
static bool command_stdin_init(command_t *handle) static bool command_stdin_init(command_t *handle)
{ {
@ -597,22 +595,20 @@ error:
#ifdef HAVE_STDIN_CMD #ifdef HAVE_STDIN_CMD
static void command_stdin_poll(command_t *handle) static void command_stdin_poll(command_t *handle)
{ {
ssize_t ret;
ptrdiff_t msg_len; ptrdiff_t msg_len;
char *last_newline = NULL; char *last_newline = NULL;
ssize_t ret = read_stdin(
if (!handle->stdin_enable) handle->stdin_buf + handle->stdin_buf_ptr,
return;
ret = read_stdin(handle->stdin_buf + handle->stdin_buf_ptr,
STDIN_BUF_SIZE - handle->stdin_buf_ptr - 1); STDIN_BUF_SIZE - handle->stdin_buf_ptr - 1);
if (ret == 0) if (ret == 0)
return; return;
handle->stdin_buf_ptr += ret; handle->stdin_buf_ptr += ret;
handle->stdin_buf[handle->stdin_buf_ptr] = '\0'; handle->stdin_buf[handle->stdin_buf_ptr] = '\0';
last_newline = strrchr(handle->stdin_buf, '\n'); last_newline =
strrchr(handle->stdin_buf, '\n');
if (!last_newline) if (!last_newline)
{ {
@ -621,14 +617,14 @@ static void command_stdin_poll(command_t *handle)
if (handle->stdin_buf_ptr + 1 >= STDIN_BUF_SIZE) if (handle->stdin_buf_ptr + 1 >= STDIN_BUF_SIZE)
{ {
handle->stdin_buf_ptr = 0; handle->stdin_buf_ptr = 0;
handle->stdin_buf[0] = '\0'; handle->stdin_buf[0] = '\0';
} }
return; return;
} }
*last_newline++ = '\0'; *last_newline++ = '\0';
msg_len = last_newline - handle->stdin_buf; msg_len = last_newline - handle->stdin_buf;
command_parse_msg(handle, handle->stdin_buf, CMD_STDIN); command_parse_msg(handle, handle->stdin_buf, CMD_STDIN);
@ -645,7 +641,8 @@ bool command_poll(command_t *handle)
#endif #endif
#ifdef HAVE_STDIN_CMD #ifdef HAVE_STDIN_CMD
command_stdin_poll(handle); if (handle->stdin_enable)
command_stdin_poll(handle);
#endif #endif
return true; return true;