[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: using long long and printf("%m") in debian



su, 2006-08-20 kello 18:08 +0200, Wouter Verhelst kirjoitti:
> On Sun, Aug 20, 2006 at 03:59:17PM +0300, Lars Wirzenius wrote:
> [...]
> >         fprintf(stderr, "Could not read file: %s: %s\n", filename,
> >         strerror(errno));
> > 
> > Please consider the above a minimal requirement for an error message: it
> > reports the operation that was attempted (reading a file), the target of
> > the operation (the filename), and the error message.
> > 
> > perror is, on the whole, useful only in throwaway programs, or programs
> > whose users like guessing.
> 
> Bullshit.

Your version is a common mistake. Calling sprintf may change errno.
perror uses errno, so at the very least you need to save and then
restore errno just before calling perror. Using strerror is just easier.

-- 
It's 1978! Things should be round by now -- Michael Kelso (That 70's
show)



Reply to: