[libvirt] [PATCHv2] Macro for testing the version you are compiling with

Doug Goldstein cardoe at cardoe.com
Wed Nov 13 18:02:59 UTC 2013


Added a macro similar to the GLib's GLIB_CHECK_VERSION so that one can
simplydo something like:

 #if LIBVIRT_CHECK_VERSION(1,1,3)
   /* Call function here that appeared in 1.1.3 and newer */
   virSomeNewFunction();
 #endif
---
 include/libvirt/libvirt.h.in | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 80b2d78..65f98c6 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1466,6 +1466,20 @@ VIR_EXPORT_VAR virConnectAuthPtr virConnectAuthPtrDefault;
 
 #define LIBVIR_VERSION_NUMBER @LIBVIRT_VERSION_NUMBER@
 
+/**
+ * LIBVIRT_CHECK_VERSION:
+ *
+ * Macro for developers to easily check what version of the library
+ * their code is compiling against.
+ * e.g.
+ * #if LIBVIR_CHECK_VERSION(1,1,3)
+ *   // some code that only works in 1.1.3 and newer
+ * #endif
+ */
+#define LIBVIRT_CHECK_VERSION(major,minor,micro) \
+    ((((major) * 1000000) + ((minor) * 1000) + (micro)) <= \
+     LIBVIR_VERSION_NUMBER)
+
 int                     virGetVersion           (unsigned long *libVer,
                                                  const char *type,
                                                  unsigned long *typeVer);
-- 
1.8.1.5




More information about the libvir-list mailing list