more detailed io state; new_handler and thread safety

Jonathan Wakely cow@compsoc.man.ac.uk
Fri Apr 5 09:11:00 GMT 2002


On Fri, Apr 05, 2002 at 07:31:29PM +0200, Matthias Weiss wrote:

> On Thu, Apr 04, 2002 at 11:36:22AM -0800, Benjamin Kosnik wrote:
> > 
> > > 1.) How can I determine what caused a stream to get
> > > the ios_base::failbit or ios_base::badbit?
> > > E.g. how can I find out if opening a file failed due
> > > to permission problems?
> > 
> > You could check for state after open.
> > 
> >   std::ifstream ifs1;
> >   ifs1.open(name_01);
> >   if (ifs1.rdstate() == std::ios_base::failbit)
> >   
> 
> Well, if I read this right, this tells me that *SOMETHING* went
> wrong while opening the file. But I'd like to know whether the
> error arose due to a wrong file permissions, or maybe the file
> doesn't exist or whatever. How do I get this out of the "failbit"?

AFAIK file permissions aren't covered in standard C or C++, as they're an
OS-specific feature. Personally I'd use stat() in the event of a failure
and check the mode, uid and gid, but there are probably better ways.

jon


-- 
Please do not use this document as toilet tissue



More information about the Libstdc++ mailing list