This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: more detailed io state; new_handler and thread safety
- From: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>
- To: Matthias Weiss <matthias dot weiss at inode dot at>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Fri, 5 Apr 2002 18:11:10 +0100
- Subject: Re: more detailed io state; new_handler and thread safety
- References: <20020404001715.A512@matthias.weiss@inode.at> <Pine.SOL.3.91.1020404113250.25512A-100000@taarna.cygnus.com> <20020405193129.A2702@matthias.weiss@inode.at>
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