Advertisement
andruhovski

unix-0103b

Apr 1st, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2. int main(void)
  3. {
  4.     int    fd;
  5.     fpos_t pos;
  6.  
  7.     printf("stdout, ");
  8.  
  9.     fflush(stdout);
  10.     fgetpos(stdout, &pos);
  11.     fd = dup(fileno(stdout));
  12.     freopen("stdout.out", "w", stdout);
  13.  
  14.     f();
  15.  
  16.     fflush(stdout);
  17.     dup2(fd, fileno(stdout));
  18.     close(fd);
  19.     clearerr(stdout);
  20.     fsetpos(stdout, &pos);        /* for C9X */
  21.  
  22.     printf("stdout again\n");
  23. }
  24.  
  25. void f()
  26. {
  27.     printf("stdout in f()");
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement