#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include < sys/stat.h> #include <fcntl.h> #include <unistd.h> #define ERR_EXIT (m) do {perror (M); Exit (Exit_failure); }while (0) void activate_nonblock (int fd), void deactivate_nonblock (int fd), int main (int argc, const char *argv[]) {Activa Te_nonblock (Stdin_fileno); Char buffer[1024] = {0}; int ret = read (Stdin_fileno, buffer, 1024); if (ret = =-1) printf ("read"); return 0;} void Activate_nonblock (int fd) {int ret; int flags = FCNTL (FD, F_GETFL); if (flags = =-1) err_exit ("Fcntl"); Flags |= O_nonblock; ret = Fcntl (FD, F_SETFL, flags); if (ret = =-1) err_exit ("Fcntl");} void Deactivate_nonblock (int fd) {int ret; int flags = FCNTL (FD, F_GETFL); if (flags = =-1) err_exit ("Fcntl"); Flags &=~O_NONBLOCK; ret = Fcntl (FD, F_SETFL, flags); if (ret = =-1) err_exit ("Fcntl");}
Plugging properties of clogging function with Fcntl ()