[PATCH 1/6] Introduce virTimeMs for getting current time in ms

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/libvirt_private.syms |    1 +
 src/util/util.c          |   24 ++++++++++++++++++++++++
 src/util/util.h          |    2 ++
 3 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e6ab870..2415a89 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1027,6 +1027,7 @@ virStrToLong_ul;
 virStrToLong_ull;
 virStrcpy;
 virStrncpy;
+virTimeMs;
 virTimestamp;
 virVasprintf;
 
diff --git a/src/util/util.c b/src/util/util.c
index e221abe..d758cf9 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -3117,6 +3117,30 @@ virTimestamp(void)
     return timestamp;
 }
 
+#define timeval_to_ms(tv)   (((tv).tv_sec * 1000ull) + ((tv).tv_usec / 1000))
+
+/**
+ * virTimeMs:
+ *
+ * Get current time in milliseconds.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int
+virTimeMs(unsigned long long *ms)
+{
+    struct timeval now;
+
+    if (gettimeofday(&now, NULL) < 0) {
+        virReportSystemError(errno, "%s",
+                             _("cannot get time of day"));
+        return -1;
+    }
+
+    *ms = timeval_to_ms(now);
+    return 0;
+}
+
 #if HAVE_LIBDEVMAPPER_H
 bool
 virIsDevMapperDevice(const char *devname)
diff --git a/src/util/util.h b/src/util/util.h
index a1bcca0..273248a 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -286,6 +286,8 @@ int virBuildPathInternal(char **path, ...) ATTRIBUTE_SENTINEL;
 
 char *virTimestamp(void);
 
+int virTimeMs(unsigned long long *ms);
+
 bool virIsDevMapperDevice(const char *devname) ATTRIBUTE_NONNULL(1);
 
 int virEmitXMLWarning(int fd,
-- 
1.7.5.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]