Re: [PATCH v2 1/3] Introduce die_errno() that appends strerror(errno) to die()
- From
Jeff King <peff@peff.net>
- Date
- Jun 6, 2009, 22:13 UTC
- Message-ID
- <20090606221320.GB30064@coredump.intra.peff.net>
- In-Reply-To
- <3672f22723a4c14c4a6d67278e9865424c0c68dc.1244299302.git.trast@student.ethz.ch>
On Sat, Jun 06, 2009 at 04:44:51PM +0200, Thomas Rast wrote:
Show 15 quoted lines
> Code by Jeff King and Alexander Potashev, name by Johannes Sixt.
> [...]
> +void die_errno(const char *err, ...)
> +{
> + va_list params;
> + char msg[1024];
> +
> + va_start(params, err);
> +
> + vsnprintf(msg, sizeof(msg), err, params);
> + die("%s: %s", msg, strerror(errno));
> +
> + va_end(params);
> +}
> +No, this approach is much more elegant than what I posted, so no need to credit me, at least. ;)
I do agree with Johannes, though. Style-wise, it reads much better as:
va_start(params, err); vsnprintf(msg, sizeof(msg), err, params); va_end(params);
die("%s: %s", msg, strerror(errno));since you can more easily see that params isn't leaked (and that die, which doesn't return, is the _last_ thing called).
-Peff