#include <stdarg.h>
#include <inttypes.h>
#include <fcntl.h>
-#include <poll.h>
#include <errno.h>
#include <netinet/in.h>
#include <rte_string_fns.h>
-#include "cmdline.h"
+#include "cmdline_private.h"
static void
cmdline_valid_buffer(struct rdline *rdl, const char *buf,
int
cmdline_poll(struct cmdline *cl)
{
- struct pollfd pfd;
int status;
ssize_t read_status;
char c;
else if (cl->rdl.status == RDLINE_EXITED)
return RDLINE_EXITED;
- pfd.fd = cl->s_in;
- pfd.events = POLLIN;
- pfd.revents = 0;
-
- status = poll(&pfd, 1, 0);
+ status = cmdline_poll_char(cl);
if (status < 0)
return status;
else if (status > 0) {
c = -1;
- read_status = read(cl->s_in, &c, 1);
+ read_status = cmdline_read_char(cl, &c);
if (read_status < 0)
return read_status;
c = -1;
while (1) {
- if (read(cl->s_in, &c, 1) <= 0)
+ if (cmdline_read_char(cl, &c) <= 0)
break;
if (cmdline_in(cl, &c, 1) < 0)
break;
* Copyright (c) 2020 Dmitry Kozlyuk
*/
+#include <poll.h>
#include <string.h>
+#include <unistd.h>
#include "cmdline_private.h"
{
tcsetattr(fileno(stdin), TCSANOW, &cl->oldterm);
}
+
+int
+cmdline_poll_char(struct cmdline *cl)
+{
+ struct pollfd pfd;
+
+ pfd.fd = cl->s_in;
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+
+ return poll(&pfd, 1, 0);
+}
+
+ssize_t
+cmdline_read_char(struct cmdline *cl, char *c)
+{
+ return read(cl->s_in, c, 1);
+}
/* Restore terminal settings form oldterm. */
void terminal_restore(const struct cmdline *cl);
+/* Check if a single character can be read from input. */
+int cmdline_poll_char(struct cmdline *cl);
+
+/* Read one character from input. */
+ssize_t cmdline_read_char(struct cmdline *cl, char *c);
+
#endif