| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <stdio.h> |
| 17 |
#include <string.h> |
| 18 |
|
| 19 |
extern int init_autotee(char *filename); |
| 20 |
extern int close_autotee(); |
| 21 |
|
| 22 |
#define OUTPUT_FILE "tee.out" |
| 23 |
|
| 24 |
int main() { |
| 25 |
int result; |
| 26 |
|
| 27 |
printf("Every stdout print after this line should also appear in %s:\n", |
| 28 |
OUTPUT_FILE); |
| 29 |
|
| 30 |
result = init_autotee(OUTPUT_FILE); |
| 31 |
if (result != 0) return -1; |
| 32 |
|
| 33 |
printf("First line\n"); |
| 34 |
printf("Second %s\n", "line"); |
| 35 |
fprintf(stdout, "Third line\n"); |
| 36 |
fprintf(stdout, "%s line\n", "Forth"); |
| 37 |
puts("Fifth line"); |
| 38 |
fputs("Sixth ", stdout); |
| 39 |
fputs("line\n", stdout); |
| 40 |
fwrite("Seventh line\n", 1, strlen("Seventh line\n"), stdout); |
| 41 |
fprintf(stderr, "Eighth line is stderr and should not appear in in %s\n", |
| 42 |
OUTPUT_FILE); |
| 43 |
close_autotee(); |
| 44 |
printf("Ninth line is after close and should not appear in %s\n", |
| 45 |
OUTPUT_FILE); |
| 46 |
|
| 47 |
return 0; |
| 48 |
} |