On 12/23/2010 11:39 AM, Laine Stump wrote:
There are cases when we want log an error message while still
preserving errno for a caller, but the functions that log errors make
system calls that will clear errno. This patch preserves errno during
those most basic error logging functions (corresponding to
virReportSystemError(), virReportOOMError(), networkReportError(),
etc, as well as virStrError()). It does *not preserve errno across
calls to higher level items such as virDispatchError(), as it's
assumed the caller is all finished with any need for errno by the time
it dispatches the error.
const char *virStrerror(int theerrno, char *errBuf, size_t
errBufLen)
{
+ int save_errno = errno;
+ const char *ret;
+
#ifdef HAVE_STRERROR_R
# ifdef __USE_GNU
/* Annoying linux specific API contract */
- return strerror_r(theerrno, errBuf, errBufLen);
+ ret = strerror_r(theerrno, errBuf, errBufLen);
# else
strerror_r(theerrno, errBuf, errBufLen);
- return errBuf;
+ ret = errBuf;
# endif
#else
/* Mingw lacks strerror_r and its strerror is definitely not
Ah, but gnulib now provides the LGPLv2+ strerror_r-posix module, which
not only provides strerror_r on mingw, but also sanitizes the Linux
interface into the POSIX compatible interface, so that we could use it
to simplify the code. But that's a patch for another day.
ACK as-is.
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org