Add timersub macro for platforms where it isn't defined
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 11 Jul 2013 18:30:38 +0000 (14:30 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 11 Jul 2013 18:30:38 +0000 (14:30 -0400)
libs/pbd/pbd/timersub.h [new file with mode: 0644]

diff --git a/libs/pbd/pbd/timersub.h b/libs/pbd/pbd/timersub.h
new file mode 100644 (file)
index 0000000..6cb1524
--- /dev/null
@@ -0,0 +1,32 @@
+/* Copyright (C) 1991-1994,1996-2003,2005,2006,2009
+       Free Software Foundation, Inc.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sys/time.h>
+
+#ifndef timersub
+# define timersub(a, b, result)                                                      \
+  do {                                                                       \
+    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                            \
+    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                         \
+    if ((result)->tv_usec < 0) {                                             \
+      --(result)->tv_sec;                                                    \
+      (result)->tv_usec += 1000000;                                          \
+    }                                                                        \
+  } while (0)
+#endif
+