Re: perror sets errno to "Illegal Seek"
From: William Ahern (william_at_wilbur.25thandClement.com)
Date: 12/16/04
- Next message: Chen Bin: "About writing an input method."
- Previous message: Kasper Dupont: "Re: perror sets errno to "Illegal Seek""
- In reply to: Martin Blume: "Re: perror sets errno to "Illegal Seek""
- Next in thread: Kasper Dupont: "Re: perror sets errno to "Illegal Seek""
- Reply: Kasper Dupont: "Re: perror sets errno to "Illegal Seek""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 16 Dec 2004 13:34:40 -0800
Martin Blume <mblume@socha.net> wrote:
> "gipsy boy" schrieb
> > I have an odd problem..whenever I call perror(), even
> > if it prints out "Success", when I call perror() again,
> > it always says "Illegal Seek".
> > What is going on?
> >
> According to my reading of the man page, a call to
> perror() only makes sense if a previous system call
> ***failed*** and thus errno is set to a meaningful
> value. Calling perror() again may print out anything,
> as errno may have been set to any value.
>
> Or am I wrong?
This is the standard answer in comp.lang.c and comp.unix.programmer. Once
you call a library function you can't depend on errno not being touched.
The only thing you can depend on is that it will be a meaningful value
*if* the function reports failure *and* the specification says the function
will set errno. Portably, that is the only circumstance you should bother
looking at errno to make sense of it.
Now, whether any particular glibc function makes stronger promises about not
setting errno, I dunno. But in general you should not be surprised.
Actually, since perror() has no way to report failure you have no way
knowing whether a changed errno is meaningful and whether a real error
occured (stderr was closed suddenly). The only possible way is if the spec
for perror explicitly said "errno shall be set to ESUCCESS on success, and
not ESUCCESS otherwise". I don't believe it says that.
- Next message: Chen Bin: "About writing an input method."
- Previous message: Kasper Dupont: "Re: perror sets errno to "Illegal Seek""
- In reply to: Martin Blume: "Re: perror sets errno to "Illegal Seek""
- Next in thread: Kasper Dupont: "Re: perror sets errno to "Illegal Seek""
- Reply: Kasper Dupont: "Re: perror sets errno to "Illegal Seek""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|