summaryrefslogtreecommitdiff
path: root/vcl/inc/unx/salunxtime.h
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2011-10-26 19:45:35 +0100
committerMichael Meeks <michael.meeks@suse.com>2011-10-26 19:46:15 +0100
commit90067e8007227b7f1e555a878088d81c117fee56 (patch)
treef980909fe1c008db0aa57b277c44a7022f40fd10 /vcl/inc/unx/salunxtime.h
parent306c79e24f29bfb01b64aad1b6054a454e2927e4 (diff)
gtk3: cleanup some code inclusion, and share timeval operators
Diffstat (limited to 'vcl/inc/unx/salunxtime.h')
-rw-r--r--vcl/inc/unx/salunxtime.h120
1 files changed, 120 insertions, 0 deletions
diff --git a/vcl/inc/unx/salunxtime.h b/vcl/inc/unx/salunxtime.h
new file mode 100644
index 000000000000..6825581cacb1
--- /dev/null
+++ b/vcl/inc/unx/salunxtime.h
@@ -0,0 +1,120 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SALUNX_TIME_H
+#define _SALUNX_TIME_H
+
+#if defined LINUX || defined FREEBSD || \
+ defined NETBSD || defined OPENBSD || defined DRAGONFLY
+#include <sys/time.h>
+#elif defined AIX
+#include <time.h>
+#include <sys/time.h>
+#include <strings.h>
+#endif
+#include <sal/types.h>
+
+// -=-= timeval =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+inline int operator >= ( const timeval &t1, const timeval &t2 )
+{
+ if( t1.tv_sec == t2.tv_sec )
+ return t1.tv_usec >= t2.tv_usec;
+ return t1.tv_sec > t2.tv_sec;
+}
+
+inline int operator > ( const timeval &t1, const timeval &t2 )
+{
+ if( t1.tv_sec == t2.tv_sec )
+ return t1.tv_usec > t2.tv_usec;
+ return t1.tv_sec > t2.tv_sec;
+}
+
+inline int operator == ( const timeval &t1, const timeval &t2 )
+{
+ if( t1.tv_sec == t2.tv_sec )
+ return t1.tv_usec == t2.tv_usec;
+ return sal_False;
+}
+
+inline timeval &operator -= ( timeval &t1, const timeval &t2 )
+{
+ if( t1.tv_usec < t2.tv_usec )
+ {
+ t1.tv_sec--;
+ t1.tv_usec += 1000000;
+ }
+ t1.tv_sec -= t2.tv_sec;
+ t1.tv_usec -= t2.tv_usec;
+ return t1;
+}
+
+inline timeval &operator += ( timeval &t1, const timeval &t2 )
+{
+ t1.tv_sec += t2.tv_sec;
+ t1.tv_usec += t2.tv_usec;
+ if( t1.tv_usec > 1000000 )
+ {
+ t1.tv_sec++;
+ t1.tv_usec -= 1000000;
+ }
+ return t1;
+}
+
+inline timeval &operator += ( timeval &t1, sal_uIntPtr t2 )
+{
+ t1.tv_sec += t2 / 1000;
+ t1.tv_usec += t2 ? (t2 % 1000) * 1000 : 500;
+ if( t1.tv_usec > 1000000 )
+ {
+ t1.tv_sec++;
+ t1.tv_usec -= 1000000;
+ }
+ return t1;
+}
+
+inline timeval operator + ( const timeval &t1, const timeval &t2 )
+{
+ timeval t0 = t1;
+ return t0 += t2;
+}
+
+inline timeval operator + ( const timeval &t1, sal_uIntPtr t2 )
+{
+ timeval t0 = t1;
+ return t0 += t2;
+}
+
+inline timeval operator - ( const timeval &t1, const timeval &t2 )
+{
+ timeval t0 = t1;
+ return t0 -= t2;
+}
+
+#endif // _SALUNX_TIME_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */