Created
April 18, 2019 17:12
-
-
Save mhashim6/7c21f8338f43a7e1ca36da4459661605 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fcntl.h> | |
#include <signal.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <sys/mman.h> | |
#include <sys/termios.h> | |
#include <sys/time.h> | |
#include <sys/types.h> | |
struct termios original_tio; | |
void disable_input_buffering() { | |
tcgetattr(STDIN_FILENO, &original_tio); | |
struct termios new_tio = original_tio; | |
new_tio.c_lflag &= ~ICANON & ~ECHO; | |
tcsetattr(STDIN_FILENO, TCSANOW, &new_tio); | |
} | |
void restore_input_buffering() { | |
tcsetattr(STDIN_FILENO, TCSANOW, &original_tio); | |
} | |
int main() { | |
disable_input_buffering(); | |
char c = getc(stdin); | |
printf("%c\n", c); | |
restore_input_buffering(); | |
c = getc(stdin); | |
printf("%c\n", c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment