From nobody Sat Feb 7 08:23:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1580217493359341.08083353437553; Tue, 28 Jan 2020 05:18:13 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-Hg3NfuWWPviOk3ftgSOD0w-1; Tue, 28 Jan 2020 08:14:47 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72C46100551B; Tue, 28 Jan 2020 13:14:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 460DA60BFB; Tue, 28 Jan 2020 13:14:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 07879180203E; Tue, 28 Jan 2020 13:14:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00SDEZKc019804 for ; Tue, 28 Jan 2020 08:14:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id B15DA1036D1A; Tue, 28 Jan 2020 13:14:35 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (unknown [10.33.8.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 125FC1001DE1; Tue, 28 Jan 2020 13:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580217492; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7RHQBqUvxb0WTuML++dk+2JboS5wsTw/OqS9pgyXKSE=; b=dz0Z7v5KZcKCXj/sjjvYZQsWPFXj1uTO6N85LA6QfDIsTQFO0GDsft/r9vXJuKcVjSl2NH EnvsCDBD47V4VJ9BD7y2FvhS4gWrg91tkuhEM/p4SCUUilPM4HotcAnZ/ZV5GVOTmmfZV3 VV1lCG6/vMiiZYK0rCBkHX19A57sRNA= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 55/56] src: remove virFilePrintf in favour of g_fprintf Date: Tue, 28 Jan 2020 13:11:36 +0000 Message-Id: <20200128131137.1762449-56-berrange@redhat.com> In-Reply-To: <20200128131137.1762449-1-berrange@redhat.com> References: <20200128131137.1762449-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: Hg3NfuWWPviOk3ftgSOD0w-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- src/libvirt_private.syms | 1 - src/util/virfile.c | 31 ----------------------------- src/util/virfile.h | 3 --- tests/commandhelper.c | 3 +-- tests/fdstreamtest.c | 42 ++++++++++++++++++++-------------------- tests/qemusecuritytest.c | 2 +- tests/shunloadtest.c | 2 +- tests/ssh.c | 3 +-- tests/testutils.h | 6 ------ tests/testutilsqemu.c | 4 ++-- tests/virstringtest.c | 34 ++++++++++++++++---------------- 11 files changed, 44 insertions(+), 87 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 56981541c5..59e1399c79 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2007,7 +2007,6 @@ virFileMoveMount; virFileNBDDeviceAssociate; virFileOpenAs; virFileOpenTty; -virFilePrintf; virFileReadAll; virFileReadAllQuiet; virFileReadBufQuiet; diff --git a/src/util/virfile.c b/src/util/virfile.c index 2ab4ccb1d5..0633a1fa8d 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3331,37 +3331,6 @@ virFileRemoveLastComponent(char *path) path[0] =3D '\0'; } =20 -/** - * 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 =3D NULL; - int ret =3D -1; - - va_start(vargs, msg); - - str =3D g_strdup_vprintf(msg, vargs); - ret =3D strlen(str); - - if (fwrite(str, 1, ret, fp) !=3D ret) { - virReportSystemError(errno, "%s", - _("Could not write to stream")); - ret =3D -1; - } - - va_end(vargs); - - return ret; -} - - #ifdef __linux__ =20 # ifndef NFS_SUPER_MAGIC diff --git a/src/util/virfile.h b/src/util/virfile.h index c805d87b3f..0a520a7522 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -293,9 +293,6 @@ char *virFileFindMountPoint(const char *type); virBuildPathInternal(path, __VA_ARGS__, NULL) int virBuildPathInternal(char **path, ...) G_GNUC_NULL_TERMINATED; =20 -int virFilePrintf(FILE *fp, const char *msg, ...) - G_GNUC_PRINTF(2, 3); - typedef struct _virHugeTLBFS virHugeTLBFS; typedef virHugeTLBFS *virHugeTLBFSPtr; struct _virHugeTLBFS { diff --git a/tests/commandhelper.c b/tests/commandhelper.c index b9677f2caa..3f040be8f2 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -24,8 +24,7 @@ #include #include =20 -#include "internal.h" -#define NO_LIBVIRT +#define VIR_NO_GLIB_STDIO /* This file intentionally does not link to libv= irt/glib */ #include "testutils.h" =20 #ifndef WIN32 diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c index 03f5520fa6..7c784a49f1 100644 --- a/tests/fdstreamtest.c +++ b/tests/fdstreamtest.c @@ -103,16 +103,16 @@ static int testFDStreamReadCommon(const char *scratch= dir, bool blocking) g_usleep(20 * 1000); goto reread; } - virFilePrintf(stderr, "Failed to read stream: %s\n", - virGetLastErrorMessage()); + fprintf(stderr, "Failed to read stream: %s\n", + virGetLastErrorMessage()); goto cleanup; } if (got =3D=3D 0) { /* Expect EOF 1/2 through last pattern */ if (i =3D=3D 9 && want =3D=3D (PATTERN_LEN / 2)) break; - virFilePrintf(stderr, "Unexpected EOF block %zu want %zu\n= ", - i, want); + fprintf(stderr, "Unexpected EOF block %zu want %zu\n", + i, want); goto cleanup; } offset +=3D got; @@ -120,25 +120,25 @@ static int testFDStreamReadCommon(const char *scratch= dir, bool blocking) } if (i =3D=3D 0) { if (memcmp(buf, pattern + (PATTERN_LEN / 2), PATTERN_LEN / 2) = !=3D 0) { - virFilePrintf(stderr, "Mismatched pattern data iteration %= zu\n", i); + fprintf(stderr, "Mismatched pattern data iteration %zu\n",= i); goto cleanup; } } else if (i =3D=3D 9) { if (memcmp(buf, pattern, PATTERN_LEN / 2) !=3D 0) { - virFilePrintf(stderr, "Mismatched pattern data iteration %= zu\n", i); + fprintf(stderr, "Mismatched pattern data iteration %zu\n",= i); goto cleanup; } } else { if (memcmp(buf, pattern, PATTERN_LEN) !=3D 0) { - virFilePrintf(stderr, "Mismatched pattern data iteration %= zu\n", i); + fprintf(stderr, "Mismatched pattern data iteration %zu\n",= i); goto cleanup; } } } =20 if (st->driver->streamFinish(st) !=3D 0) { - virFilePrintf(stderr, "Failed to finish stream: %s\n", - virGetLastErrorMessage()); + fprintf(stderr, "Failed to finish stream: %s\n", + virGetLastErrorMessage()); goto cleanup; } =20 @@ -226,8 +226,8 @@ static int testFDStreamWriteCommon(const char *scratchd= ir, bool blocking) if (i =3D=3D 9 && want =3D=3D (PATTERN_LEN / 2)) break; - virFilePrintf(stderr, "Failed to write stream: %s\n", - virGetLastErrorMessage()); + fprintf(stderr, "Failed to write stream: %s\n", + virGetLastErrorMessage()); goto cleanup; } offset +=3D got; @@ -236,8 +236,8 @@ static int testFDStreamWriteCommon(const char *scratchd= ir, bool blocking) } =20 if (st->driver->streamFinish(st) !=3D 0) { - virFilePrintf(stderr, "Failed to finish stream: %s\n", - virGetLastErrorMessage()); + fprintf(stderr, "Failed to finish stream: %s\n", + virGetLastErrorMessage()); goto cleanup; } =20 @@ -252,9 +252,9 @@ static int testFDStreamWriteCommon(const char *scratchd= ir, bool blocking) want =3D PATTERN_LEN; =20 if ((got =3D saferead(fd, buf, want)) !=3D want) { - virFilePrintf(stderr, - "Short read from data, i=3D%zu got=3D%zu want=3D= %zu\n", - i, got, want); + fprintf(stderr, + "Short read from data, i=3D%zu got=3D%zu want=3D%zu\n", + i, got, want); goto cleanup; } =20 @@ -262,22 +262,22 @@ static int testFDStreamWriteCommon(const char *scratc= hdir, bool blocking) size_t j; for (j =3D 0; j < (PATTERN_LEN / 2); j++) { if (buf[j] !=3D 0) { - virFilePrintf(stderr, "Mismatched pattern data iterati= on %zu\n", i); + fprintf(stderr, "Mismatched pattern data iteration %zu= \n", i); goto cleanup; } } if (memcmp(buf + (PATTERN_LEN / 2), pattern, PATTERN_LEN / 2) = !=3D 0) { - virFilePrintf(stderr, "Mismatched pattern data iteration %= zu\n", i); + fprintf(stderr, "Mismatched pattern data iteration %zu\n",= i); goto cleanup; } } else if (i =3D=3D 9) { if (memcmp(buf, pattern, PATTERN_LEN / 2) !=3D 0) { - virFilePrintf(stderr, "Mismatched pattern data iteration %= zu\n", i); + fprintf(stderr, "Mismatched pattern data iteration %zu\n",= i); goto cleanup; } } else { if (memcmp(buf, pattern, PATTERN_LEN) !=3D 0) { - virFilePrintf(stderr, "Mismatched pattern data iteration %= zu\n", i); + fprintf(stderr, "Mismatched pattern data iteration %zu\n",= i); goto cleanup; } } @@ -320,7 +320,7 @@ mymain(void) int ret =3D 0; =20 if (!g_mkdtemp(scratchdir)) { - virFilePrintf(stderr, "Cannot create fdstreamdir"); + fprintf(stderr, "Cannot create fdstreamdir"); abort(); } =20 diff --git a/tests/qemusecuritytest.c b/tests/qemusecuritytest.c index 4b5bfabeba..a1ef9d8802 100644 --- a/tests/qemusecuritytest.c +++ b/tests/qemusecuritytest.c @@ -146,7 +146,7 @@ mymain(void) VIR_SECURITY_M= ANAGER_PRIVILEGED | VIR_SECURITY_M= ANAGER_DYNAMIC_OWNERSHIP, NULL))) { - virFilePrintf(stderr, "Cannot initialize DAC security driver"); + fprintf(stderr, "Cannot initialize DAC security driver"); ret =3D -1; goto cleanup; } diff --git a/tests/shunloadtest.c b/tests/shunloadtest.c index 65c627ed17..b377c07294 100644 --- a/tests/shunloadtest.c +++ b/tests/shunloadtest.c @@ -40,7 +40,7 @@ =20 #include =20 -#define NO_LIBVIRT /* This file intentionally does not link to libvirt */ +#define VIR_NO_GLIB_STDIO /* This file intentionally does not link to libv= irt/glib */ #include "testutils.h" =20 #ifdef linux diff --git a/tests/ssh.c b/tests/ssh.c index 58148fef77..415dfbdb25 100644 --- a/tests/ssh.c +++ b/tests/ssh.c @@ -18,8 +18,7 @@ =20 #include =20 -#include "internal.h" -#define NO_LIBVIRT /* This file intentionally does not link to libvirt */ +#define VIR_NO_GLIB_STDIO /* This file intentionally does not link to libv= irt/glib */ #include "testutils.h" =20 #ifndef WIN32 diff --git a/tests/testutils.h b/tests/testutils.h index ad62dfb647..c1b365ab0d 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -30,12 +30,6 @@ #define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */ #define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken = */ =20 -/* Work around lack of gnulib support for fprintf %z */ -#ifndef NO_LIBVIRT -# undef fprintf -# define fprintf virFilePrintf -#endif - /* Makefile.am provides these two definitions */ #if !defined(abs_srcdir) || !defined(abs_builddir) # error Fix Makefile.am diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index c25aa1f705..c17e284930 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -405,14 +405,14 @@ int qemuTestDriverInit(virQEMUDriver *driver) driver->config->channelTargetDir =3D g_strdup("/tmp/channel"); =20 if (!g_mkdtemp(statedir)) { - virFilePrintf(stderr, "Cannot create fake stateDir"); + fprintf(stderr, "Cannot create fake stateDir"); goto error; } =20 driver->config->stateDir =3D g_strdup(statedir); =20 if (!g_mkdtemp(configdir)) { - virFilePrintf(stderr, "Cannot create fake configDir"); + fprintf(stderr, "Cannot create fake configDir"); goto error; } =20 diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 88f50185e5..c87e1b9bec 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -58,16 +58,16 @@ static int testStreq(const void *args) strneq_rv =3D STRNEQ_NULLABLE(data->a, data->b); =20 if (streq_rv !=3D equal) { - virFilePrintf(stderr, - "STREQ not working correctly. Expected %d got %d", - (int) equal, (int) streq_rv); + fprintf(stderr, + "STREQ not working correctly. Expected %d got %d", + (int) equal, (int) streq_rv); return -1; } =20 if (strneq_rv =3D=3D equal) { - virFilePrintf(stderr, - "STRNEQ not working correctly. Expected %d got %d", - (int) equal, (int) strneq_rv); + fprintf(stderr, + "STRNEQ not working correctly. Expected %d got %d", + (int) equal, (int) strneq_rv); return -1; } =20 @@ -108,7 +108,7 @@ static int testSplit(const void *args) tmp2 =3D data->tokens; while (*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; } tmp1++; @@ -116,19 +116,19 @@ static int testSplit(const void *args) exptokens++; } if (*tmp1) { - virFilePrintf(stderr, "Too many pieces returned\n"); + fprintf(stderr, "Too many pieces returned\n"); goto cleanup; } if (*tmp2) { - virFilePrintf(stderr, "Too few pieces returned\n"); + fprintf(stderr, "Too few pieces returned\n"); goto cleanup; } =20 if (ntokens !=3D exptokens) { - virFilePrintf(stderr, - "Returned token count (%zu) doesn't match " - "expected count (%zu)", - ntokens, exptokens); + fprintf(stderr, + "Returned token count (%zu) doesn't match " + "expected count (%zu)", + ntokens, exptokens); goto cleanup; } =20 @@ -151,7 +151,7 @@ static int testJoin(const void *args) return -1; } 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; } =20 @@ -186,7 +186,7 @@ static int testAdd(const void *args) } =20 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; } =20 @@ -215,13 +215,13 @@ static int testRemove(const void *args) for (i =3D 0; data->tokens[i]; i++) { virStringListRemove(&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; } } =20 if (list && list[0]) { - virFilePrintf(stderr, "Not removed all tokens: %s", list[0]); + fprintf(stderr, "Not removed all tokens: %s", list[0]); goto cleanup; } =20 --=20 2.24.1