fstat for an open fstream

  • Thread starter =?ISO-8859-1?Q?Klaus_F=FCller?=
  • Start date
?

=?ISO-8859-1?Q?Klaus_F=FCller?=

I would like to use the unix,et.al-fstat() system-call on some sort of
stream which is already open and connected to a disk file.

An example: I have an open stream and want to know the numerical
owner-id of the file associated with the stream.

I can write the code myself if someone tells me how to get the
filedescriptor that must be buried as a member attribute somewhere in
the stream-classes. Eventually all io must pass through such a
descriptor - so it _must_ exist somewhere.

I know how to retrieve the information if I have the filename (call
stat()) --- but I want to use fstat() on an already open stream.

Any glue?

Klaus.
 
?

=?ISO-8859-1?Q?Klaus_F=FCller?=

WW said:
Klaus said:
I would like to use the unix,et.al-fstat() system-call on some sort of
stream which is already open and connected to a disk file.
[SNIP]

Any glue?


Yep. Stick with a UNIX/Posix newsgroup :)
Thank you.

I know how to do it in Unix and Posix but I don't know how to do it in
C++. Although I'm aware about the fact that the information I want to
get is not fully portable there must - or at least should - be a
portable way to get some of this.

So - sorry - I insist that this is the right place to ask for it.

The general question is - how do I get the underlying filedescriptor of
a stream - no matter what OS the program runs on and no matter how
opaque the returnde information might be.
 
W

WW

Klaus said:
WW said:
Klaus said:
I would like to use the unix,et.al-fstat() system-call on some sort
of stream which is already open and connected to a disk file.
[SNIP]

Any glue?


Yep. Stick with a UNIX/Posix newsgroup :)
Thank you.

I know how to do it in Unix and Posix but I don't know how to do it in
C++. Although I'm aware about the fact that the information I want to
get is not fully portable there must - or at least should - be a
portable way to get some of this.

So - sorry - I insist that this is the right place to ask for it.

The general question is - how do I get the underlying filedescriptor
of a stream - no matter what OS the program runs on and no matter how
opaque the returnde information might be.

This newsgroup discusses *only* the standard C++ language. So please don't
insist(*), but go to the group/discussion forum/technical support of your
compiler/standard library implementation and ask it there.

(*) Here the answer is: you cannot do it. Only the pre-standard iostreams
had support to retrieve their file descriptor. The standard iostreams do
not support it. And any non-standard feature discussion should go to the
implementation specific discussion forums.
 
M

Mike Wahler

WW said:
Klaus said:
I would like to use the unix,et.al-fstat() system-call on some sort of
stream which is already open and connected to a disk file.
[SNIP]

Any glue?


Yep. Stick with a UNIX/Posix newsgroup :)
Thank you.
I know how to do it in Unix and Posix but I don't know how to do it in
C++.

It cannot be done with C++ alone. Many C++ implementations
do provide POSIX support as an 'extension', so that's a possible route.
Although I'm aware about the fact that the information I want to
get is not fully portable

It's not portable at all from a C++ perspective.
there must - or at least should - be a
portable way to get some of this.

Say 'should' if you like, but there is no portable way.
It "shouldn't" rain anytime I go outside, but
soemtimes it does. :)
So - sorry - I insist that this is the right place to ask for it.

Insist all you like, but it's not. Only ISO standard C++
is the topic here, which cannot do what you ask. Haven't
you read the welcome message at the link that "WW" provided?
It states very clearly what is and is not topical here.
The general question is - how do I get the underlying filedescriptor of
a stream - no matter what OS the program runs on

You cannot. The form and usage of 'file descriptors'
(if even used) are necessarily dependent upon the
implementation, and by implication, the host OS.
C++ has no concept at all of 'file descriptor'.

E.g. UNIX and VMS don't handle files the same way.
But at the 'higher level' of C++ code, they can
be accessed in a uniform way by using the iostream
abstraction.

I suppose you could dig around in your implementation's
internals and figure it out, but the method you come up
with will only be valid for that implementation (might
also be for other implementations on the same platform,
but not necessarily.)
and no matter how >
opaque the returnde information might be.

'Opaqueness' is already provided by the iostreams
abstraction.

You're talking about a necessarily platform-dependent
issue. So if you want portability, you'll need to
write a module for each platform, and adjust compilation
accordingly for each.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top