Fix domain events C example on Win32

printf on Win32 does not necessarily 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
This commit is contained in:
Daniel P. Berrange 2011-03-29 11:26:55 +01:00
parent 6c9e89bbd2
commit 242195425c
2 changed files with 11 additions and 3 deletions

2
cfg.mk
View File

@ -571,7 +571,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)$$)

View File

@ -169,8 +169,16 @@ 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);
free(str);
return 0;
}