dpdk/lib/cmdline/cmdline_os_unix.c
<<
>>
Prefs
   1/* SPDX-License-Identifier: BSD-3-Clause
   2 * Copyright (c) 2020 Dmitry Kozlyuk
   3 */
   4
   5#include <poll.h>
   6#include <string.h>
   7#include <unistd.h>
   8
   9#include "cmdline_private.h"
  10
  11void
  12terminal_adjust(struct cmdline *cl)
  13{
  14        struct termios term;
  15
  16        tcgetattr(0, &cl->oldterm);
  17
  18        memcpy(&term, &cl->oldterm, sizeof(term));
  19        term.c_lflag &= ~(ICANON | ECHO | ISIG);
  20        tcsetattr(0, TCSANOW, &term);
  21
  22        setbuf(stdin, NULL);
  23}
  24
  25void
  26terminal_restore(const struct cmdline *cl)
  27{
  28        tcsetattr(fileno(stdin), TCSANOW, &cl->oldterm);
  29}
  30
  31int
  32cmdline_poll_char(struct cmdline *cl)
  33{
  34        struct pollfd pfd;
  35
  36        pfd.fd = cl->s_in;
  37        pfd.events = POLLIN;
  38        pfd.revents = 0;
  39
  40        return poll(&pfd, 1, 0);
  41}
  42
  43ssize_t
  44cmdline_read_char(struct cmdline *cl, char *c)
  45{
  46        return read(cl->s_in, c, 1);
  47}
  48
  49int
  50cmdline_vdprintf(int fd, const char *format, va_list op)
  51{
  52        return vdprintf(fd, format, op);
  53}
  54