mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
src: remove virFilePrintf in favour of g_fprintf
The virFilePrintf function was a wrapper for fprintf() to provide Windows portability, since gnulib's fprintf() replacement was license restricted. This is no longer needed now we have the g_fprintf function available. Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
11a79283b8
commit
4ab2120f3b
@ -2022,7 +2022,6 @@ virFileMoveMount;
|
|||||||
virFileNBDDeviceAssociate;
|
virFileNBDDeviceAssociate;
|
||||||
virFileOpenAs;
|
virFileOpenAs;
|
||||||
virFileOpenTty;
|
virFileOpenTty;
|
||||||
virFilePrintf;
|
|
||||||
virFileReadAll;
|
virFileReadAll;
|
||||||
virFileReadAllQuiet;
|
virFileReadAllQuiet;
|
||||||
virFileReadBufQuiet;
|
virFileReadBufQuiet;
|
||||||
|
@ -3331,37 +3331,6 @@ virFileRemoveLastComponent(char *path)
|
|||||||
path[0] = '\0';
|
path[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* virFilePrintf:
|
|
||||||
*
|
|
||||||
* A replacement for fprintf() which uses g_strdup_vprintf
|
|
||||||
* to ensure that portable string format placeholders can
|
|
||||||
* be used, since gnulib's fprintf() replacement is not
|
|
||||||
* LGPLV2+ compatible
|
|
||||||
*/
|
|
||||||
int virFilePrintf(FILE *fp, const char *msg, ...)
|
|
||||||
{
|
|
||||||
va_list vargs;
|
|
||||||
g_autofree char *str = NULL;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
va_start(vargs, msg);
|
|
||||||
|
|
||||||
str = g_strdup_vprintf(msg, vargs);
|
|
||||||
ret = strlen(str);
|
|
||||||
|
|
||||||
if (fwrite(str, 1, ret, fp) != ret) {
|
|
||||||
virReportSystemError(errno, "%s",
|
|
||||||
_("Could not write to stream"));
|
|
||||||
ret = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(vargs);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
# ifndef NFS_SUPER_MAGIC
|
# ifndef NFS_SUPER_MAGIC
|
||||||
|
@ -293,9 +293,6 @@ char *virFileFindMountPoint(const char *type);
|
|||||||
virBuildPathInternal(path, __VA_ARGS__, NULL)
|
virBuildPathInternal(path, __VA_ARGS__, NULL)
|
||||||
int virBuildPathInternal(char **path, ...) G_GNUC_NULL_TERMINATED;
|
int virBuildPathInternal(char **path, ...) G_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
int virFilePrintf(FILE *fp, const char *msg, ...)
|
|
||||||
G_GNUC_PRINTF(2, 3);
|
|
||||||
|
|
||||||
typedef struct _virHugeTLBFS virHugeTLBFS;
|
typedef struct _virHugeTLBFS virHugeTLBFS;
|
||||||
typedef virHugeTLBFS *virHugeTLBFSPtr;
|
typedef virHugeTLBFS *virHugeTLBFSPtr;
|
||||||
struct _virHugeTLBFS {
|
struct _virHugeTLBFS {
|
||||||
|
@ -24,8 +24,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "internal.h"
|
#define VIR_NO_GLIB_STDIO /* This file intentionally does not link to libvirt/glib */
|
||||||
#define NO_LIBVIRT
|
|
||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
@ -103,16 +103,16 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
|
|||||||
g_usleep(20 * 1000);
|
g_usleep(20 * 1000);
|
||||||
goto reread;
|
goto reread;
|
||||||
}
|
}
|
||||||
virFilePrintf(stderr, "Failed to read stream: %s\n",
|
fprintf(stderr, "Failed to read stream: %s\n",
|
||||||
virGetLastErrorMessage());
|
virGetLastErrorMessage());
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (got == 0) {
|
if (got == 0) {
|
||||||
/* Expect EOF 1/2 through last pattern */
|
/* Expect EOF 1/2 through last pattern */
|
||||||
if (i == 9 && want == (PATTERN_LEN / 2))
|
if (i == 9 && want == (PATTERN_LEN / 2))
|
||||||
break;
|
break;
|
||||||
virFilePrintf(stderr, "Unexpected EOF block %zu want %zu\n",
|
fprintf(stderr, "Unexpected EOF block %zu want %zu\n",
|
||||||
i, want);
|
i, want);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
offset += got;
|
offset += got;
|
||||||
@ -120,25 +120,25 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
|
|||||||
}
|
}
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
if (memcmp(buf, pattern + (PATTERN_LEN / 2), PATTERN_LEN / 2) != 0) {
|
if (memcmp(buf, pattern + (PATTERN_LEN / 2), PATTERN_LEN / 2) != 0) {
|
||||||
virFilePrintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
fprintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else if (i == 9) {
|
} else if (i == 9) {
|
||||||
if (memcmp(buf, pattern, PATTERN_LEN / 2) != 0) {
|
if (memcmp(buf, pattern, PATTERN_LEN / 2) != 0) {
|
||||||
virFilePrintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
fprintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (memcmp(buf, pattern, PATTERN_LEN) != 0) {
|
if (memcmp(buf, pattern, PATTERN_LEN) != 0) {
|
||||||
virFilePrintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
fprintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st->driver->streamFinish(st) != 0) {
|
if (st->driver->streamFinish(st) != 0) {
|
||||||
virFilePrintf(stderr, "Failed to finish stream: %s\n",
|
fprintf(stderr, "Failed to finish stream: %s\n",
|
||||||
virGetLastErrorMessage());
|
virGetLastErrorMessage());
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,8 +226,8 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
|
|||||||
if (i == 9 &&
|
if (i == 9 &&
|
||||||
want == (PATTERN_LEN / 2))
|
want == (PATTERN_LEN / 2))
|
||||||
break;
|
break;
|
||||||
virFilePrintf(stderr, "Failed to write stream: %s\n",
|
fprintf(stderr, "Failed to write stream: %s\n",
|
||||||
virGetLastErrorMessage());
|
virGetLastErrorMessage());
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
offset += got;
|
offset += got;
|
||||||
@ -236,8 +236,8 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (st->driver->streamFinish(st) != 0) {
|
if (st->driver->streamFinish(st) != 0) {
|
||||||
virFilePrintf(stderr, "Failed to finish stream: %s\n",
|
fprintf(stderr, "Failed to finish stream: %s\n",
|
||||||
virGetLastErrorMessage());
|
virGetLastErrorMessage());
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,9 +252,9 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
|
|||||||
want = PATTERN_LEN;
|
want = PATTERN_LEN;
|
||||||
|
|
||||||
if ((got = saferead(fd, buf, want)) != want) {
|
if ((got = saferead(fd, buf, want)) != want) {
|
||||||
virFilePrintf(stderr,
|
fprintf(stderr,
|
||||||
"Short read from data, i=%zu got=%zu want=%zu\n",
|
"Short read from data, i=%zu got=%zu want=%zu\n",
|
||||||
i, got, want);
|
i, got, want);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,22 +262,22 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
|
|||||||
size_t j;
|
size_t j;
|
||||||
for (j = 0; j < (PATTERN_LEN / 2); j++) {
|
for (j = 0; j < (PATTERN_LEN / 2); j++) {
|
||||||
if (buf[j] != 0) {
|
if (buf[j] != 0) {
|
||||||
virFilePrintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
fprintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (memcmp(buf + (PATTERN_LEN / 2), pattern, PATTERN_LEN / 2) != 0) {
|
if (memcmp(buf + (PATTERN_LEN / 2), pattern, PATTERN_LEN / 2) != 0) {
|
||||||
virFilePrintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
fprintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else if (i == 9) {
|
} else if (i == 9) {
|
||||||
if (memcmp(buf, pattern, PATTERN_LEN / 2) != 0) {
|
if (memcmp(buf, pattern, PATTERN_LEN / 2) != 0) {
|
||||||
virFilePrintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
fprintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (memcmp(buf, pattern, PATTERN_LEN) != 0) {
|
if (memcmp(buf, pattern, PATTERN_LEN) != 0) {
|
||||||
virFilePrintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
fprintf(stderr, "Mismatched pattern data iteration %zu\n", i);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,7 +320,7 @@ mymain(void)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (!g_mkdtemp(scratchdir)) {
|
if (!g_mkdtemp(scratchdir)) {
|
||||||
virFilePrintf(stderr, "Cannot create fdstreamdir");
|
fprintf(stderr, "Cannot create fdstreamdir");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ mymain(void)
|
|||||||
VIR_SECURITY_MANAGER_PRIVILEGED |
|
VIR_SECURITY_MANAGER_PRIVILEGED |
|
||||||
VIR_SECURITY_MANAGER_DYNAMIC_OWNERSHIP,
|
VIR_SECURITY_MANAGER_DYNAMIC_OWNERSHIP,
|
||||||
NULL))) {
|
NULL))) {
|
||||||
virFilePrintf(stderr, "Cannot initialize DAC security driver");
|
fprintf(stderr, "Cannot initialize DAC security driver");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#define NO_LIBVIRT /* This file intentionally does not link to libvirt */
|
#define VIR_NO_GLIB_STDIO /* This file intentionally does not link to libvirt/glib */
|
||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
|
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
|
@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "internal.h"
|
#define VIR_NO_GLIB_STDIO /* This file intentionally does not link to libvirt/glib */
|
||||||
#define NO_LIBVIRT /* This file intentionally does not link to libvirt */
|
|
||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
@ -30,12 +30,6 @@
|
|||||||
#define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
|
#define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
|
||||||
#define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
|
#define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
|
||||||
|
|
||||||
/* Work around lack of gnulib support for fprintf %z */
|
|
||||||
#ifndef NO_LIBVIRT
|
|
||||||
# undef fprintf
|
|
||||||
# define fprintf virFilePrintf
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Makefile.am provides these two definitions */
|
/* Makefile.am provides these two definitions */
|
||||||
#if !defined(abs_srcdir) || !defined(abs_builddir)
|
#if !defined(abs_srcdir) || !defined(abs_builddir)
|
||||||
# error Fix Makefile.am
|
# error Fix Makefile.am
|
||||||
|
@ -405,14 +405,14 @@ int qemuTestDriverInit(virQEMUDriver *driver)
|
|||||||
driver->config->channelTargetDir = g_strdup("/tmp/channel");
|
driver->config->channelTargetDir = g_strdup("/tmp/channel");
|
||||||
|
|
||||||
if (!g_mkdtemp(statedir)) {
|
if (!g_mkdtemp(statedir)) {
|
||||||
virFilePrintf(stderr, "Cannot create fake stateDir");
|
fprintf(stderr, "Cannot create fake stateDir");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
driver->config->stateDir = g_strdup(statedir);
|
driver->config->stateDir = g_strdup(statedir);
|
||||||
|
|
||||||
if (!g_mkdtemp(configdir)) {
|
if (!g_mkdtemp(configdir)) {
|
||||||
virFilePrintf(stderr, "Cannot create fake configDir");
|
fprintf(stderr, "Cannot create fake configDir");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,16 +58,16 @@ static int testStreq(const void *args)
|
|||||||
strneq_rv = STRNEQ_NULLABLE(data->a, data->b);
|
strneq_rv = STRNEQ_NULLABLE(data->a, data->b);
|
||||||
|
|
||||||
if (streq_rv != equal) {
|
if (streq_rv != equal) {
|
||||||
virFilePrintf(stderr,
|
fprintf(stderr,
|
||||||
"STREQ not working correctly. Expected %d got %d",
|
"STREQ not working correctly. Expected %d got %d",
|
||||||
(int) equal, (int) streq_rv);
|
(int) equal, (int) streq_rv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strneq_rv == equal) {
|
if (strneq_rv == equal) {
|
||||||
virFilePrintf(stderr,
|
fprintf(stderr,
|
||||||
"STRNEQ not working correctly. Expected %d got %d",
|
"STRNEQ not working correctly. Expected %d got %d",
|
||||||
(int) equal, (int) strneq_rv);
|
(int) equal, (int) strneq_rv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ static int testSplit(const void *args)
|
|||||||
tmp2 = data->tokens;
|
tmp2 = data->tokens;
|
||||||
while (*tmp1 && *tmp2) {
|
while (*tmp1 && *tmp2) {
|
||||||
if (STRNEQ(*tmp1, *tmp2)) {
|
if (STRNEQ(*tmp1, *tmp2)) {
|
||||||
virFilePrintf(stderr, "Mismatch '%s' vs '%s'\n", *tmp1, *tmp2);
|
fprintf(stderr, "Mismatch '%s' vs '%s'\n", *tmp1, *tmp2);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
tmp1++;
|
tmp1++;
|
||||||
@ -116,19 +116,19 @@ static int testSplit(const void *args)
|
|||||||
exptokens++;
|
exptokens++;
|
||||||
}
|
}
|
||||||
if (*tmp1) {
|
if (*tmp1) {
|
||||||
virFilePrintf(stderr, "Too many pieces returned\n");
|
fprintf(stderr, "Too many pieces returned\n");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (*tmp2) {
|
if (*tmp2) {
|
||||||
virFilePrintf(stderr, "Too few pieces returned\n");
|
fprintf(stderr, "Too few pieces returned\n");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ntokens != exptokens) {
|
if (ntokens != exptokens) {
|
||||||
virFilePrintf(stderr,
|
fprintf(stderr,
|
||||||
"Returned token count (%zu) doesn't match "
|
"Returned token count (%zu) doesn't match "
|
||||||
"expected count (%zu)",
|
"expected count (%zu)",
|
||||||
ntokens, exptokens);
|
ntokens, exptokens);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ static int testJoin(const void *args)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (STRNEQ(got, data->string)) {
|
if (STRNEQ(got, data->string)) {
|
||||||
virFilePrintf(stderr, "Mismatch '%s' vs '%s'\n", got, data->string);
|
fprintf(stderr, "Mismatch '%s' vs '%s'\n", got, data->string);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ static int testAdd(const void *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (STRNEQ(got, data->string)) {
|
if (STRNEQ(got, data->string)) {
|
||||||
virFilePrintf(stderr, "Mismatch '%s' vs '%s'\n", got, data->string);
|
fprintf(stderr, "Mismatch '%s' vs '%s'\n", got, data->string);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,13 +215,13 @@ static int testRemove(const void *args)
|
|||||||
for (i = 0; data->tokens[i]; i++) {
|
for (i = 0; data->tokens[i]; i++) {
|
||||||
virStringListRemove(&list, data->tokens[i]);
|
virStringListRemove(&list, data->tokens[i]);
|
||||||
if (virStringListHasString((const char **) list, data->tokens[i])) {
|
if (virStringListHasString((const char **) list, data->tokens[i])) {
|
||||||
virFilePrintf(stderr, "Not removed %s", data->tokens[i]);
|
fprintf(stderr, "Not removed %s", data->tokens[i]);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list && list[0]) {
|
if (list && list[0]) {
|
||||||
virFilePrintf(stderr, "Not removed all tokens: %s", list[0]);
|
fprintf(stderr, "Not removed all tokens: %s", list[0]);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user