socket
stat-time
strchrnul
-strerror
-strerror_r-posix
strptime
strsep
strtok_r
<dd>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.</dd>
+
+ <dt>virStrerror</dt>
+ <dd>The GLib g_strerror() function should be used instead,
+ which has a simpler calling convention as an added benefit.</dd>
</dl>
<h2><a id="file_handling">File handling</a></h2>
{
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;
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;
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);
}
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;
}
}
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;
}
}
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;
}
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);
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;
}
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;
}
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;
cpuinfo = fopen(cpuinfofile, "r");
if (!cpuinfo) {
fprintf(stderr, "unable to open: %s : %s\n",
- cpuinfofile, strerror(errno));
+ cpuinfofile, g_strerror(errno));
goto fail;
}
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;
}
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();
}