[PATCH evemu 1/5] Use the time_to_long helpers in evemu_read_event_realtime

Peter Hutterer peter.hutterer at who-t.net
Thu Aug 6 17:58:22 PDT 2015


And make sure the time we return is a long there.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evemu.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/evemu.c b/src/evemu.c
index 19a372b..c3079dd 100644
--- a/src/evemu.c
+++ b/src/evemu.c
@@ -743,13 +743,13 @@ int evemu_write_event(FILE *fp, const struct input_event *ev)
 }
 
 static inline long time_to_long(const struct timeval *tv) {
-	return tv->tv_sec * 1000000 + tv->tv_usec;
+	return tv->tv_sec * 1000000L + tv->tv_usec;
 }
 
 static inline struct timeval long_to_time(long time) {
 	struct timeval tv;
-	tv.tv_sec = time/1000000;
-	tv.tv_usec = time % 1000000;
+	tv.tv_sec = time/1000000L;
+	tv.tv_usec = time % 1000000L;
 	return tv;
 }
 
@@ -838,8 +838,7 @@ int evemu_read_event_realtime(FILE *fp, struct input_event *ev,
 	if (evtime) {
 		if (!evtime->tv_sec)
 			*evtime = ev->time;
-		usec = 1000000L * (ev->time.tv_sec - evtime->tv_sec);
-		usec += ev->time.tv_usec - evtime->tv_usec;
+		usec = time_to_long(&ev->time) - time_to_long(evtime);
 		if (usec > 500) {
 			usleep(usec);
 			*evtime = ev->time;
-- 
2.4.3



More information about the Input-tools mailing list