|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [XTF 3/6] time: add gettimeofday() function to time managment
From: Paul Semel <phentex@xxxxxxxxx>
Signed-off-by: Paul Semel <phentex@xxxxxxxxx>
---
common/time.c | 14 ++++++++++++++
include/xtf/time.h | 12 ++++++++++++
2 files changed, 26 insertions(+)
diff --git a/common/time.c b/common/time.c
index 7decd07..fffae1c 100644
--- a/common/time.c
+++ b/common/time.c
@@ -90,6 +90,20 @@ uint64_t current_time(void)
return seconds + (since_boot_time() / 1000000000);
}
+/* The POSIX gettimeofday syscall normally takes a second argument, which is
+ * the timezone (struct timezone). However, it sould be NULL because linux
+ * doesn't use it anymore. So we need for us to add it in this function
+ */
+int gettimeofday(struct timeval *tp)
+{
+ if (!tp)
+ return -1;
+
+ tp->sec = current_time();
+ tp->nsec = shared_info.wc_nsec + (since_boot_time() % 1000000000);
+ return 0;
+}
+
/*
* Local variables:
* mode: C
diff --git a/include/xtf/time.h b/include/xtf/time.h
index 52da27a..e312465 100644
--- a/include/xtf/time.h
+++ b/include/xtf/time.h
@@ -8,6 +8,16 @@
#include <xtf/types.h>
+struct timeval {
+#if !defined(__i386__)
+ uint64_t sec;
+ uint64_t nsec;
+#else
+ uint32_t sec;
+ uint32_t nsec;
+#endif
+};
+
#if defined(__i386__)
/* Time from boot in nanoseconds */
uint32_t since_boot_time(void);
@@ -19,6 +29,8 @@ uint64_t since_boot_time(void);
uint64_t current_time(void);
#endif
+int gettimeofday(struct timeval *tp);
+
#endif /* XTF_TIME_H */
/*
--
2.16.6
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |