aboutsummaryrefslogtreecommitdiff
path: root/spike_main/termios-xspike.cc
blob: e533933bf567a2309e6de9a0ed5cf64195c04c76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// See LICENSE for license details.

// termios-xspike sets up a canonical terminal and blocks forever.
// It allows us to send Ctrl-C etc. to the target machine.

#include <unistd.h>
#include <termios.h>
#include <signal.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
  struct termios old_tios;
  if (tcgetattr(0, &old_tios) < 0)
    return -1;

  signal(SIGTERM, [](int) { });

  struct termios new_tios = old_tios;
  new_tios.c_lflag &= ~(ICANON | ECHO | ISIG);
  if (tcsetattr(0, TCSANOW, &new_tios) < 0)
    return -1;

  pause();

  return tcsetattr(0, TCSANOW, &old_tios);
}