help with standard streams and the file descriptor
Robert Schweikert
rjschwei@hks.com
Fri Jan 2 16:53:00 GMT 2004
I am working on getting our uses of iostream up to par with the new
iostream model, i.e. standard C++ I/O streams. I have run into some
problems and was able to work around most of them. However, for this one
particular problem I am at a loss and am hoping someone on the list can
provide me with a suggestion on how to address the issue.
The basic issue is the manipulation of flags on the file descriptor.
Currently this is implemented like so.
bool utl_noInheritFile(int fildes)
{
#if !defined (WIN32)
int flags = fcntl(fildes, F_GETFD);
flags |= FD_CLOEXEC;
return (fcntl(fildes, F_SETFD, flags) != -1);
#else
long int h = _get_osfhandle(fildes);
if (h != -1) {
HANDLE handle = reinterpret_cast<HANDLE>(h);
if (SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0))
return true;
}
return false;
#endif
}
and is called as follows:
utl_noInheritFile(journalStream->rdbuf()->fd());
The C++ standard does not support this as fd() is gone. Is there a way
to do this in a portable fashion or will I be able to make this work
only if I use the gcc extension as described in
http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#11
Help is appreciated.
Thanks,
Robert
--
Robert Schweikert MAY THE SOURCE BE WITH YOU
LINUX
More information about the Libstdc++
mailing list