[lug] C++, fstream, finding name of open stream

Tkil tkil at scrye.com
Fri Dec 7 13:22:45 MST 2001


>>>>> "DS" == D Stimits <stimits at idcomm.com> writes:

DS> Somehow it seems a bit silly though that a file stream doesn't
DS> have a means of uniquely identifying itself the way a file
DS> descriptor would (I can do an fstat on a descriptor...I'd love an
DS> overloaded fstat() that accepted an fstream in place of a
DS> descriptor). I can live without it, but life would be simpler with
DS> it.

look at fstream::rdbuf, which returns a filebuf (derived from
streambuf), which has a "fd()" method.  so, something like this should
work:

   ifstream is;
   int file_descriptor = is.rdbuf->fd();

as for portability ... no idea.  probably not very -- but then again,
if you're thinking in terms of inodes, how portable are you being?

t.



More information about the LUG mailing list