diff --git a/bootstrap.conf b/bootstrap.conf
index bb40e978aaedd4adca76156942b0067a3c79cf30..241dce50c29c7187a514ae52384f917f7b10a708 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -79,8 +79,6 @@ snprintf
socket
stat-time
strchrnul
-strerror
-strerror_r-posix
strptime
strsep
strtok_r
diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index a7a0c7c3cc84f6bd9c1b6a07925f3c40854754c8..de450b7cde10c0024d2e23bee38a5ddf16775c6b 100644
--- a/docs/hacking.html.in
+++ b/docs/hacking.html.in
@@ -1051,6 +1051,10 @@ BAD:
The GLib macros g_autoptr and G_DEFINE_AUTOPTR_CLEANUP_FUNC
should be used to manage autoclean of virObject classes.
This matches usage with GObject classes.
+
+ virStrerror
+ The GLib g_strerror() function should be used instead,
+ which has a simpler calling convention as an added benefit.
diff --git a/src/util/virerror.c b/src/util/virerror.c
index 3bb9d1d32c833e6d5eccc277e683392cb3b5087f..5d69e4e972f162ef7a3d2348ba9f296b2bcdc0e7 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -1322,8 +1322,11 @@ const char *virStrerror(int theerrno, char *errBuf, size_t errBufLen)
{
int save_errno = errno;
const char *ret;
+ const char *str = g_strerror(theerrno);
+ size_t len = strlen(str);
- strerror_r(theerrno, errBuf, errBufLen);
+ memcpy(errBuf, str, MIN(len, errBufLen));
+ errBuf[errBufLen-1] = '\0';
ret = errBuf;
errno = save_errno;
return ret;
@@ -1349,11 +1352,9 @@ void virReportSystemErrorFull(int domcode,
const char *fmt, ...)
{
int save_errno = errno;
- char strerror_buf[VIR_ERROR_MAX_LENGTH];
char msgDetailBuf[VIR_ERROR_MAX_LENGTH];
- const char *errnoDetail = virStrerror(theerrno, strerror_buf,
- sizeof(strerror_buf));
+ const char *errnoDetail = g_strerror(theerrno);
const char *msg = virErrorMsg(VIR_ERR_SYSTEM_ERROR, fmt);
const char *msgDetail = NULL;
diff --git a/src/util/virerror.h b/src/util/virerror.h
index fa88217b274b4ee75de28ef20a5854d27f11f0f4..201195d660dc17abd3adce7d9ba5dada04ac1031 100644
--- a/src/util/virerror.h
+++ b/src/util/virerror.h
@@ -193,6 +193,7 @@ void virReportOOMErrorFull(int domcode,
int virSetError(virErrorPtr newerr);
virErrorPtr virErrorCopyNew(virErrorPtr err);
void virDispatchError(virConnectPtr conn);
+/* DEPRECATED: use g_strerror() directly */
const char *virStrerror(int theerrno, char *errBuf, size_t errBufLen);
typedef int (*virErrorLogPriorityFunc)(virErrorPtr, int);
diff --git a/tests/commandtest.c b/tests/commandtest.c
index c6fd826003868c18708ce4fe91164fb82429cde4..2aaddef3d1bea705244a2d9ca7bcb7aa13fe0103 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -636,12 +636,12 @@ static int test16(const void *unused ATTRIBUTE_UNUSED)
}
if ((fd = open(abs_builddir "/commandhelper.log",
O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0) {
- printf("Cannot open log file: %s\n", strerror(errno));
+ printf("Cannot open log file: %s\n", g_strerror(errno));
goto cleanup;
}
virCommandWriteArgLog(cmd, fd);
if (VIR_CLOSE(fd) < 0) {
- printf("Cannot close log file: %s\n", strerror(errno));
+ printf("Cannot close log file: %s\n", g_strerror(errno));
goto cleanup;
}
@@ -1116,12 +1116,12 @@ static int test26(const void *unused ATTRIBUTE_UNUSED)
}
if ((fd = open(abs_builddir "/commandhelper.log",
O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0) {
- printf("Cannot open log file: %s\n", strerror(errno));
+ printf("Cannot open log file: %s\n", g_strerror(errno));
goto cleanup;
}
virCommandWriteArgLog(cmd, fd);
if (VIR_CLOSE(fd) < 0) {
- printf("Cannot close log file: %s\n", strerror(errno));
+ printf("Cannot close log file: %s\n", g_strerror(errno));
goto cleanup;
}
@@ -1186,7 +1186,7 @@ static int test27(const void *unused ATTRIBUTE_UNUSED)
}
if (pipe(pipe1) < 0 || pipe(pipe2) < 0) {
- printf("Could not create pipe: %s\n", strerror(errno));
+ printf("Could not create pipe: %s\n", g_strerror(errno));
goto cleanup;
}
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index c7580c5f28fa8fa50c77ea591126523d78c9ab80..9f2594b09a7990cddd626cf52df882189ede5112 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -417,7 +417,7 @@ qemuMonitorTestFree(qemuMonitorTestPtr test)
VIR_FREE(test->items);
if (test->tmpdir && rmdir(test->tmpdir) < 0)
- VIR_WARN("Failed to remove tempdir: %s", strerror(errno));
+ VIR_WARN("Failed to remove tempdir: %s", g_strerror(errno));
VIR_FREE(test->tmpdir);
diff --git a/tests/seclabeltest.c b/tests/seclabeltest.c
index 42dcb8c97ff2f7be2205ec470c760e3ee9f06beb..105c25ea2dfdaf5d5c54bd867e08a509c5623030 100644
--- a/tests/seclabeltest.c
+++ b/tests/seclabeltest.c
@@ -20,14 +20,14 @@ mymain(void)
model = virSecurityManagerGetModel(mgr);
if (!model) {
fprintf(stderr, "Failed to copy secModel model: %s",
- strerror(errno));
+ g_strerror(errno));
return EXIT_FAILURE;
}
doi = virSecurityManagerGetDOI(mgr);
if (!doi) {
fprintf(stderr, "Failed to copy secModel DOI: %s",
- strerror(errno));
+ g_strerror(errno));
return EXIT_FAILURE;
}
diff --git a/tests/testutils.c b/tests/testutils.c
index 1b663f9d5d334e34949c5ec33492a9049fba03c6..1f3718b5cda56847054815b94c91ca2c576afa95 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -172,12 +172,12 @@ virTestLoadFile(const char *file, char **buf)
int len, tmplen, buflen;
if (!fp) {
- fprintf(stderr, "%s: failed to open: %s\n", file, strerror(errno));
+ fprintf(stderr, "%s: failed to open: %s\n", file, g_strerror(errno));
return -1;
}
if (fstat(fileno(fp), &st) < 0) {
- fprintf(stderr, "%s: failed to fstat: %s\n", file, strerror(errno));
+ fprintf(stderr, "%s: failed to fstat: %s\n", file, g_strerror(errno));
VIR_FORCE_FCLOSE(fp);
return -1;
}
@@ -208,7 +208,7 @@ virTestLoadFile(const char *file, char **buf)
tmplen -= len;
}
if (ferror(fp)) {
- fprintf(stderr, "%s: read failed: %s\n", file, strerror(errno));
+ fprintf(stderr, "%s: read failed: %s\n", file, g_strerror(errno));
VIR_FORCE_FCLOSE(fp);
VIR_FREE(*buf);
return -1;
diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c
index 03ed3b16092e59043ea4224b6d416d0222b40267..d9bdef701d41d82ab2a4fae3a1f8d5dbaca79aa2 100644
--- a/tests/virhostcputest.c
+++ b/tests/virhostcputest.c
@@ -37,7 +37,7 @@ linuxTestCompareFiles(const char *cpuinfofile,
cpuinfo = fopen(cpuinfofile, "r");
if (!cpuinfo) {
fprintf(stderr, "unable to open: %s : %s\n",
- cpuinfofile, strerror(errno));
+ cpuinfofile, g_strerror(errno));
goto fail;
}
@@ -86,7 +86,7 @@ linuxCPUStatsToBuf(virBufferPtr buf,
if ((sc_clk_tck = sysconf(_SC_CLK_TCK)) < 0) {
fprintf(stderr, "sysconf(_SC_CLK_TCK) fails : %s\n",
- strerror(errno));
+ g_strerror(errno));
return -1;
}
tick_to_nsec = (1000ull * 1000ull * 1000ull) / sc_clk_tck;
diff --git a/tests/virtestmock.c b/tests/virtestmock.c
index df8cac64411a1910b60a727b295db631b641d8ae..fa52667a2b299cf5f3eb72522421ebb8d0bfc900 100644
--- a/tests/virtestmock.c
+++ b/tests/virtestmock.c
@@ -76,12 +76,12 @@ printFile(const char *file,
}
if (!(fp = real_fopen(output, "a"))) {
- fprintf(stderr, "Unable to open %s: %s\n", output, strerror(errno));
+ fprintf(stderr, "Unable to open %s: %s\n", output, g_strerror(errno));
abort();
}
if (flock(fileno(fp), LOCK_EX) < 0) {
- fprintf(stderr, "Unable to lock %s: %s\n", output, strerror(errno));
+ fprintf(stderr, "Unable to lock %s: %s\n", output, g_strerror(errno));
fclose(fp);
abort();
}