cmdline: add internal wrappers for terminal handling
[dpdk.git] / lib / librte_cmdline / cmdline_os_unix.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2020 Dmitry Kozlyuk
3  */
4
5 #include <string.h>
6
7 #include "cmdline_private.h"
8
9 void
10 terminal_adjust(struct cmdline *cl)
11 {
12         struct termios term;
13
14         tcgetattr(0, &cl->oldterm);
15
16         memcpy(&term, &cl->oldterm, sizeof(term));
17         term.c_lflag &= ~(ICANON | ECHO | ISIG);
18         tcsetattr(0, TCSANOW, &term);
19
20         setbuf(stdin, NULL);
21 }
22
23 void
24 terminal_restore(const struct cmdline *cl)
25 {
26         tcsetattr(fileno(stdin), TCSANOW, &cl->oldterm);
27 }