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. 4 7617
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.
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
"Klaus Füller" <kl****@schule. de> wrote in message
news:3F******** ******@schule.d e...
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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>
|
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 overlooking something trivial
here)?
Thanks,
Martijn
|
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 same
file) with the same object, and wonder why operations are failing.
If standard C's open/fopen functions will open a file without caring
about previous error states of the filehandle, then C++ should do the
same with fstream::open, or at...
|
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 library to Jython and some parts are missing. My
question basically is where do I find information on what to use
instead. E.g. I could not find information on the os module. I do not
find the sys module docu either.
The concrete problem is I have...
|
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>
using namespace std;
| |
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);
|
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
****************************************************************
pair_status/myPair
|
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 a software buffer of size 3MB. This is needed so as to see which function to use to read from the file. As the files used range from very large (>30GB) to very small (<3MB), I have enabled large file support and I obtain the file size by using the...
|
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 ?
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |