Project
Loading...
Searching...
No Matches
linux_helpers.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef LINUX_HELPERS_H
16#define LINUX_HELPERS_H
17
18#include <termios.h>
19#include <unistd.h>
20#include <sys/ioctl.h>
21
22static inline int32_t getch()
23{
24 static struct termios oldt, newt;
25 tcgetattr(STDIN_FILENO, &oldt);
26 newt = oldt;
27 newt.c_lflag &= ~(ICANON | ECHO);
28 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
29 int32_t retVal = getchar();
30 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
31 return (retVal);
32}
33
34static inline int32_t kbhit()
35{
36 termios term;
37 tcgetattr(0, &term);
38 termios term2 = term;
39 term2.c_lflag &= ~ICANON;
40 tcsetattr(0, TCSANOW, &term2);
41 int32_t byteswaiting;
42 ioctl(0, FIONREAD, &byteswaiting);
43 tcsetattr(0, TCSANOW, &term);
44 return byteswaiting > 0;
45}
46
47static void inline Sleep(int32_t msecs) { usleep(msecs * 1000); }
48
49#endif
int32_t retVal