[comp.unix.questions] freopen - no file name available

nall@loligo.cc.fsu.edu (John Nall) (09/24/89)

If one uses freopen to temporarily use a file for which only the
stream pointer is available  (freopen(filename,access,FILE *)
is there any way to subsequently use freopen to go BACK to using
the original stream?  (This can probably be rephrased as "is there
a way to go from a stream pointer to the original file name").  

I have humbly did the required rituals - RTFM'd, asked local guru's,
and checked Unix Most Frequent Questions, but to save my ego in case
this is a stupid question "I Am Only Asking For A Friend".

======================================================================
John Nall                              Internet:  nall@nu.cs.fsu.edu
Computer Science Department            Florida State University
    "Today, a Moon Moth -- tomorrow, a Sea Dragon Conquerer!!"

gwyn@smoke.BRL.MIL (Doug Gwyn) (09/25/89)

In article <206@vsserv.scri.fsu.edu> nall@loligo.cc.fsu.edu (John Nall) writes:
>If one uses freopen to temporarily use a file for which only the
>stream pointer is available  (freopen(filename,access,FILE *)
>is there any way to subsequently use freopen to go BACK to using
>the original stream?  (This can probably be rephrased as "is there
>a way to go from a stream pointer to the original file name").  

I don't understand your first clause -- freopen() CLOSES the open
stream, then reuses its data area for the new stream that it opens
by name.

On UNIX, you could first dup(fileno(fp)) and later use fdopen() to
reassociate another stdio stream with the file handle, without
having to know how to open it by name (assuming it even had a name).