File descriptors and streams and co

carroll at s.cs.uiuc.edu carroll at s.cs.uiuc.edu
Mon Apr 17 09:32:00 AEST 1989


I must be missing something - given that
FILE *my_file;
has been properly set up (with fopen(), no errors, etc.), why can't you
switch stdin by having another variable
FILE *tmp;
and doing
tmp = stdin; stdin = my_file;

'stdin' is declared as a pointer, and so setting the pointer to point at
a different FILE I/O block should cause routines that use it to read from
that file instead. You can then restore by
stdin = tmp;

Mr. Salz indicated that things are more complex than this. Is this because
of library routines with file descriptor 0 wired in, or because file info
is kept in places other than the FILE I/O block stdin points to? While
this might not work in all cases, it seems to me it should in the original
case, if twiddling the file descriptor in the block works. (i.e., it must
not be hard-wired and must look in the FILE I/O block for things).

Alan M. Carroll                "And then you say,
carroll at s.cs.uiuc.edu           We have the Moon, so now the Stars..."  - YES
CS Grad / U of Ill @ Urbana    ...{ucbvax,pur-ee,convex}!s.cs.uiuc.edu!carroll



More information about the Comp.lang.c mailing list