Created
June 9, 2020 20:45
-
-
Save clausecker/54bf8533d23590cd995b7c4592f970d1 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 <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
extern int | |
main(int argc, char *argv[]) | |
{ | |
ssize_t count; | |
int flags; | |
char buf; | |
flags = fcntl(STDIN_FILENO, F_GETFL); | |
if (flags == -1) { | |
perror("fcntl(stdin, F_GETFL)"); | |
exit(EXIT_FAILURE); | |
} | |
flags = fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK); | |
if (flags == -1) { | |
perror("fcntl(stdin, F_SETFL)"); | |
exit(EXIT_FAILURE); | |
} | |
count = read(STDIN_FILENO, &buf, 1); | |
if (count == -1) | |
perror("read"); | |
else | |
printf("read: %zd bytes\n", count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment