Howdie all,
Time for an actual Linux (or at least programming) question :-)
Now, the question is so simple, I suspect I'm being very dumb about something, but since I can't figure it out I'll have to take my chances and ask anyways....
I have this test program (the vsw5 test suite for the X Window System). Some tests have been failing for a while with the message:
ERROR: pop_stdout: couldn't fdopen stdout
Looking at the test suite code I see the following relevant functions:
/* ** push_stdout ** This redirects stdout to a file, but saves a copy ** of the file descriptor attached to stdout so we can ** restore it later. ** ** Arguments ** file Filename to open stdout to ** mode What mode to open the file to */
int push_stdout(file,mode)
char *file;
char *mode;
{
char pathname[4096];if ((Dup_stdout = dup(fileno(stdout))) == -1){
sprintf(ebuf, "ERROR: push_stdout: dup of fileno(stdout) failed");
tet_infoline(ebuf);
tet_result(TET_FAIL);
return -1;
}
strcpy(pathname, "/tmp/");
strcat(pathname,file);if (freopen(pathname,mode,stdout) == NULL) {
fclose(stdout);
fdopen(Dup_stdout,"w");
sprintf(ebuf, "ERROR: push_stdout: could not freopen(stdout)");
tet_infoline(ebuf);
tet_result(TET_FAIL);
return -1;
}
return 0;
}
/* ** pop_stdout ** Reset stdout back to what it used to point to. ** ** Assumes ** You want stdout opened for writing... */
void pop_stdout()
{
if (Dup_stdout == -1) {
sprintf(ebuf, "ERROR: pop_stdout: push_stdout never called");
tet_infoline(ebuf);
tet_result(TET_FAIL);
return;
}
fclose(stdout);
if (dup2(Dup_stdout,1) != 1) {
sprintf(ebuf, "ERROR: pop_stdout: dup of stdout back to 1 failed");
tet_infoline(ebuf);
tet_result(TET_FAIL);
return;
}
if ((FILE *)fdopen(1,"w") != stdout) {
sprintf(ebuf, "ERROR: pop_stdout: couldn't fdopen stdout");
tet_infoline(ebuf);
tet_result(TET_FAIL);
return;
}close(Dup_stdout);
Dup_stdout = -1; }
The error message is from the third if in pop_stdout.
My dumb question is: why has the authers *expected* that third if ever to work? Is there some law of the universe (POSIX or otherwise) that is supposed to gurantee that when you fdopen file descriptor 1, you'll get the stream that equels to the macro (C99/98 says it's a macro) stdout?
What am I missing?
Thanks,
Gilad.
================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
