473,503 Members | 12,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fstat for an open fstream

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.

Jul 19 '05 #1
4 7602
WW
Klaus Füller wrote:
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 :-)

http://www.slack.net/~shiva/welcome.txt

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

--
WW aka Attila
Jul 19 '05 #2
WW schrieb:
Klaus Füller wrote:
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.

Jul 19 '05 #3
WW
Klaus Füller wrote:
WW schrieb:
Klaus Füller wrote:
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.

--
WW aka Attila
Jul 19 '05 #4
"Klaus Füller" <kl****@schule.de> wrote in message
news:3F**************@schule.de...
WW schrieb:
Klaus Füller wrote:
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


Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2414
by: Mike Austin | last post by:
It's the most annoying thing, and causes hours of frustration. Why can't it be resolved? Regards, Mike Austin Example: #include <iostream> #include <string>
2
4870
by: Martijn | last post by:
Hi, I have an open file handle from which I would like to retrieve the file descriptor for use with fstat. Is this possible or should I redesign my algorithm a bit (I have the feeling I am...
5
3127
by: derek | last post by:
I see this has come up over and over again in the past... that programmers waste hours of confusion when using a fstream object to open, read/write, close then attempt to open another file (or the...
1
2355
by: Mark Fink | last post by:
Hi there, unfortunately I am new to Jython and my "Jython Essentials" book is still in the mail. I looked into the Jython API Doc but could not find the information. I am porting a Python...
5
3931
by: ehui928 | last post by:
The following program is used to open a file in mode both read and append, but it has a problem that the file can't be opened. #include <iostream> #include <fstream> #include <cstdlib> ...
9
4973
by: Robin | last post by:
// Pls note that test.txt exists. #include <iostream> #include <fstream> #include <string> using namespace std; int main() { fstream fs("test.txt", ios_base::in | ios_base::app);
16
2204
by: Gary Wessle | last post by:
Hi please help with this. std::fstream iofs( f.c_str(), std::ios::in|std::ios::out ); std::cout << f << '\n' << iofs.is_open() << std::endl; puts out...
1
6301
by: Lars B | last post by:
Hey guys, I have written a C++ program that passes data from a file to an FPGA board and back again using software and DMA buffers. In my program I need to compare the size of a given file against...
11
5116
by: solarisss | last post by:
I have thousands of files whose exitence needs to be checked. I think fstat is too costly for this. Is there any better way for the same ?
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.