[libvirt] [PATCH] Fix domain events C example on Win32

printf on Win32 does not neccessarily support %lld and we don't have GNULIBs wrapper for printf(). Switch to use asprintf() for which we do have a gnulib wrapper with %lld support * examples/domain-events/events-c/event-test.c: Fix formatting of %lld on Win32 * cfg.mk: Don't require use of virAsprintf since this is an example app for out of tree users to follow --- cfg.mk | 2 +- examples/domain-events/events-c/event-test.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cfg.mk b/cfg.mk index ac419f7..0440425 100644 --- a/cfg.mk +++ b/cfg.mk @@ -564,7 +564,7 @@ exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \ (^docs|^python/(libvirt-override|typewrappers)\.c$$) exclude_file_name_regexp--sc_prohibit_asprintf = \ - ^(bootstrap.conf$$|po/|src/util/util\.c$$) + ^(bootstrap.conf$$|po/|src/util/util\.c$$|examples/domain-events/events-c/event-test\.c$$) exclude_file_name_regexp--sc_prohibit_close = \ (\.py$$|^docs/|(src/util/files\.c|src/libvirt\.c)$$) diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c index 7d05dd8..44e94ec 100644 --- a/examples/domain-events/events-c/event-test.c +++ b/examples/domain-events/events-c/event-test.c @@ -169,8 +169,14 @@ static int myDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED, long long offset, void *opaque ATTRIBUTE_UNUSED) { - printf("%s EVENT: Domain %s(%d) rtc change %lld\n", __func__, virDomainGetName(dom), - virDomainGetID(dom), offset); + char *str = NULL; + /* HACK: use asprintf since we have gnulib's wrapper for %lld on Win32 + * but don't have a printf() replacement with %lld */ + if (asprintf(&str, "%s EVENT: Domain %s(%d) rtc change %lld\n", __func__, virDomainGetName(dom), + virDomainGetID(dom), offset) < 0) + return 0; + + printf("%s", str); return 0; } -- 1.7.4

On 03/31/2011 07:43 AM, Daniel P. Berrange wrote:
printf on Win32 does not neccessarily support %lld and we don't
s/neccessarily/necessarily/
have GNULIBs wrapper for printf(). Switch to use asprintf() for which we do have a gnulib wrapper with %lld support
* examples/domain-events/events-c/event-test.c: Fix formatting of %lld on Win32 * cfg.mk: Don't require use of virAsprintf since this is an example app for out of tree users to follow --- cfg.mk | 2 +- examples/domain-events/events-c/event-test.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/cfg.mk b/cfg.mk index ac419f7..0440425 100644 --- a/cfg.mk +++ b/cfg.mk @@ -564,7 +564,7 @@ exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \ (^docs|^python/(libvirt-override|typewrappers)\.c$$)
exclude_file_name_regexp--sc_prohibit_asprintf = \ - ^(bootstrap.conf$$|po/|src/util/util\.c$$) + ^(bootstrap.conf$$|po/|src/util/util\.c$$|examples/domain-events/events-c/event-test\.c$$)
Hmm, we could factor the $$ outside of the () to reduce the line by 4 bytes.
+++ b/examples/domain-events/events-c/event-test.c @@ -169,8 +169,14 @@ static int myDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED, long long offset, void *opaque ATTRIBUTE_UNUSED) { - printf("%s EVENT: Domain %s(%d) rtc change %lld\n", __func__, virDomainGetName(dom), - virDomainGetID(dom), offset); + char *str = NULL; + /* HACK: use asprintf since we have gnulib's wrapper for %lld on Win32 + * but don't have a printf() replacement with %lld */ + if (asprintf(&str, "%s EVENT: Domain %s(%d) rtc change %lld\n", __func__, virDomainGetName(dom),
Is it worth wrapping this to keep it in 80 columns? ACK with nits addressed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On Thu, Mar 31, 2011 at 08:11:05AM -0600, Eric Blake wrote:
On 03/31/2011 07:43 AM, Daniel P. Berrange wrote:
printf on Win32 does not neccessarily support %lld and we don't
s/neccessarily/necessarily/
have GNULIBs wrapper for printf(). Switch to use asprintf() for which we do have a gnulib wrapper with %lld support
* examples/domain-events/events-c/event-test.c: Fix formatting of %lld on Win32 * cfg.mk: Don't require use of virAsprintf since this is an example app for out of tree users to follow --- cfg.mk | 2 +- examples/domain-events/events-c/event-test.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/cfg.mk b/cfg.mk index ac419f7..0440425 100644 --- a/cfg.mk +++ b/cfg.mk @@ -564,7 +564,7 @@ exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \ (^docs|^python/(libvirt-override|typewrappers)\.c$$)
exclude_file_name_regexp--sc_prohibit_asprintf = \ - ^(bootstrap.conf$$|po/|src/util/util\.c$$) + ^(bootstrap.conf$$|po/|src/util/util\.c$$|examples/domain-events/events-c/event-test\.c$$)
Hmm, we could factor the $$ outside of the () to reduce the line by 4 bytes.
We can't actually, because po/ doesn't want the $$ token. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Daniel P. Berrange
-
Eric Blake