Created
June 9, 2020 20:45
-
-
Save clausecker/54bf8533d23590cd995b7c4592f970d1 to your computer and use it in GitHub Desktop.
Revisions
-
clausecker created this gist
Jun 9, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #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); }