The following code:
#include <stdio.h>
main()
{
int fd;
fpos_t pos;
printf("stdout, ");
fflush(stdout);
fgetpos(stdout, &pos);
fd = dup(fileno(stdout));
freopen("stdout.out", "w", stdout);
f();
fflush(stdout);
dup2(fd, fileno(stdout));
close(fd);
clearerr(stdout);
fsetpos(stdout, &pos); /* for C9X */
printf("stdout again\n");
}
f()
{
printf("stdout in f()");
}
Works fine to redirect stdout
and then put it back. However, changing f()
to:
f()
{
wprintf(L"stdout in f()");
}
Will not allow the stdout to be restored. Anyone know why this may be the case?
[matt test] uname -r
3.4.6-2.fc17.x86_64