Re: using long long and printf("%m") in debian
On Sun, Aug 20, 2006 at 07:48:29PM +0300, Lars Wirzenius wrote:
> 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.
Still; my point was that it is incorrect to say that "perror is, on the
whole, useful only in throwaway programs, or programs whose users like
guessing." I gave an example to the contrary, and I think it still
holds.
As with anything, an API function is not useless merely because most
people use it badly. This bad usage should be abolished, not the
function as a whole.
This is, of course, not the same issue as with things like gets(), which
should just not ever be used. But that has a different reason.
--
Fun will now commence
-- Seven Of Nine, "Ashes to Ashes", stardate 53679.4
Reply to: