[PATCH] printf: fix exit code on conversion failure

Denys Vlasenko vda.linux at googlemail.com
Fri Jun 19 08:10:00 UTC 2009


On Friday 19 June 2009 00:03, Cathey, Jim wrote:
> >Well, it may change, but it never goes to 0:
> >"No function in this volume of IEEE Std 1003.1-2001 shall set errno to
> 0."
> >And that's the only thing we care about: errno != 0 -> bad.
> 
> Except that it's a generally bad idea, because not all errors
> are errors!  Some are expected, such as a stat failure, or a
> pre-emptive unlink.  So unless you know how any given service
> routine is coded, you can't make general assumptions about the
> state of errno, or even how 'bad' the consequences should be.
> Fragile coding techniques should be avoided.
> 
> 	errno = 0;
> 	close(fd);
> 	saved = errno;
> 	wipe_my_temp_files();
> 
> 	if (saved) bad_juju(); // Is appropriate.  Whereas
> 	if (errno) bad_juju(); // is not, what if temps were already
> gone?

Do we still talk about printf applet?

IIRC, printf applet may have only two kinds of failures:
numeric conversion errors and write errors.
In both cases, exitcode should be nonzero.
--
vda


More information about the busybox mailing list