199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson * Copyright (c) 2020 Dmitry Kozlyuk
399a2dd95SBruce Richardson */
499a2dd95SBruce Richardson
599a2dd95SBruce Richardson #include <poll.h>
699a2dd95SBruce Richardson #include <string.h>
799a2dd95SBruce Richardson #include <unistd.h>
899a2dd95SBruce Richardson
999a2dd95SBruce Richardson #include "cmdline_private.h"
1099a2dd95SBruce Richardson
1199a2dd95SBruce Richardson void
terminal_adjust(struct cmdline * cl)1299a2dd95SBruce Richardson terminal_adjust(struct cmdline *cl)
1399a2dd95SBruce Richardson {
1499a2dd95SBruce Richardson struct termios term;
1599a2dd95SBruce Richardson
1699a2dd95SBruce Richardson tcgetattr(0, &cl->oldterm);
1799a2dd95SBruce Richardson
1899a2dd95SBruce Richardson memcpy(&term, &cl->oldterm, sizeof(term));
1999a2dd95SBruce Richardson term.c_lflag &= ~(ICANON | ECHO | ISIG);
2099a2dd95SBruce Richardson tcsetattr(0, TCSANOW, &term);
2199a2dd95SBruce Richardson
2299a2dd95SBruce Richardson setbuf(stdin, NULL);
2399a2dd95SBruce Richardson }
2499a2dd95SBruce Richardson
2599a2dd95SBruce Richardson void
terminal_restore(const struct cmdline * cl)2699a2dd95SBruce Richardson terminal_restore(const struct cmdline *cl)
2799a2dd95SBruce Richardson {
2899a2dd95SBruce Richardson tcsetattr(fileno(stdin), TCSANOW, &cl->oldterm);
2999a2dd95SBruce Richardson }
3099a2dd95SBruce Richardson
3199a2dd95SBruce Richardson ssize_t
cmdline_read_char(struct cmdline * cl,char * c)3299a2dd95SBruce Richardson cmdline_read_char(struct cmdline *cl, char *c)
3399a2dd95SBruce Richardson {
3499a2dd95SBruce Richardson return read(cl->s_in, c, 1);
3599a2dd95SBruce Richardson }
3699a2dd95SBruce Richardson
3799a2dd95SBruce Richardson int
cmdline_vdprintf(int fd,const char * format,va_list op)3899a2dd95SBruce Richardson cmdline_vdprintf(int fd, const char *format, va_list op)
3999a2dd95SBruce Richardson {
4099a2dd95SBruce Richardson return vdprintf(fd, format, op);
4199a2dd95SBruce Richardson }
42*f1d0993eSStephen Hemminger
43*f1d0993eSStephen Hemminger /* This function is not needed on Linux, instead use sigaction() */
44*f1d0993eSStephen Hemminger void
cmdline_cancel(__rte_unused struct cmdline * cl)45*f1d0993eSStephen Hemminger cmdline_cancel(__rte_unused struct cmdline *cl)
46*f1d0993eSStephen Hemminger {
47*f1d0993eSStephen Hemminger }
48