William Pursell wrote:
> [...]
> Or, if you really feel it necessary to be
> excessively verbose:
>
> fprintf( stderr, "%s can't be opened:", filename );
> perror( NULL );
Don't do it that way, because perror() reports the
error that errno indicates, and fprintf() might change
errno. You could wind up with
flatcat.dat can't be opened: not a typewriter
(See Question 12.24 in the FAQ.)
One way to deal with this is to save and restore errno's
value around the fprintf() call:
#include <errno.h>
...
{
int errno_save = errno;
fprintf(stderr, "%s can't be opened: ", filename);
errno = errno_save;
perror(NULL);
...
.... but in a case like this the advice to use
> (or "%s can't be opened: %s", filename, strerror( errno )
.... seems better.
--
Eric.Sosman@sun.com