What Jim means is that
errno is undefined after a successful library call. You should only call
perror() immediately after a failing call.
As a matter of fact, the glibc implementation of
perror() calls some other functions such as
dup(),
fdopen() that modify
errno, even if
perror() itself always succeed.
I would personally expect that clean library code doesn't expose their mess to outside. But we cannot complain, as POSIX/SUS allows such behavior.
Cheers,
Loïc
--
My Blog:
Loïc OnStage
“UNIX is simple. It just takes a genius to understand its simplicity.” - Dennis Ritchie