Advertisement
Guest User

Untitled

a guest
Apr 8th, 2012
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <signal.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <errno.h>
  5.  
  6. static sig_atomic_t exitflag = 0;
  7.  
  8. static void interrupt(int sig)
  9. {
  10.     exitflag = 1;
  11. }
  12.  
  13. int main()
  14. {
  15.     struct sigaction sa;
  16.     sigaction(SIGHUP, NULL, &sa);
  17.     sa.sa_handler = interrupt;
  18.     sa.sa_flags &= ~SA_RESTART;
  19.     sigaction(SIGHUP, &sa, NULL);
  20.  
  21.     while (!exitflag) {
  22.         char buf[1024];
  23.         int l = read(0, buf, sizeof(buf));
  24.         if (l == -1) {
  25.             if (errno == EINTR || errno == EAGAIN) {
  26.                 perror("read");
  27.                 continue;
  28.             }
  29.             break;
  30.         } else if (l == 0) {
  31.             break;
  32.         }
  33.         write(1, buf, l);
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement