Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _SALUNX_TIME_H
21 : #define _SALUNX_TIME_H
22 :
23 : #if defined LINUX || defined FREEBSD || \
24 : defined NETBSD || defined OPENBSD || defined DRAGONFLY
25 : #include <sys/time.h>
26 : #elif defined AIX
27 : #include <time.h>
28 : #include <sys/time.h>
29 : #include <strings.h>
30 : #endif
31 : #include <sal/types.h>
32 :
33 : // -=-= timeval =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
34 1326 : inline int operator >= ( const timeval &t1, const timeval &t2 )
35 : {
36 1326 : if( t1.tv_sec == t2.tv_sec )
37 1114 : return t1.tv_usec >= t2.tv_usec;
38 212 : return t1.tv_sec > t2.tv_sec;
39 : }
40 :
41 593 : inline int operator > ( const timeval &t1, const timeval &t2 )
42 : {
43 593 : if( t1.tv_sec == t2.tv_sec )
44 445 : return t1.tv_usec > t2.tv_usec;
45 148 : return t1.tv_sec > t2.tv_sec;
46 : }
47 :
48 : inline int operator == ( const timeval &t1, const timeval &t2 )
49 : {
50 : if( t1.tv_sec == t2.tv_sec )
51 : return t1.tv_usec == t2.tv_usec;
52 : return sal_False;
53 : }
54 :
55 0 : inline timeval &operator -= ( timeval &t1, const timeval &t2 )
56 : {
57 0 : if( t1.tv_usec < t2.tv_usec )
58 : {
59 0 : t1.tv_sec--;
60 0 : t1.tv_usec += 1000000;
61 : }
62 0 : t1.tv_sec -= t2.tv_sec;
63 0 : t1.tv_usec -= t2.tv_usec;
64 0 : return t1;
65 : }
66 :
67 : inline timeval &operator += ( timeval &t1, const timeval &t2 )
68 : {
69 : t1.tv_sec += t2.tv_sec;
70 : t1.tv_usec += t2.tv_usec;
71 : if( t1.tv_usec > 1000000 )
72 : {
73 : t1.tv_sec++;
74 : t1.tv_usec -= 1000000;
75 : }
76 : return t1;
77 : }
78 :
79 1066 : inline timeval &operator += ( timeval &t1, sal_uIntPtr t2 )
80 : {
81 1066 : t1.tv_sec += t2 / 1000;
82 1066 : t1.tv_usec += t2 ? (t2 % 1000) * 1000 : 500;
83 1066 : if( t1.tv_usec > 1000000 )
84 : {
85 53 : t1.tv_sec++;
86 53 : t1.tv_usec -= 1000000;
87 : }
88 1066 : return t1;
89 : }
90 :
91 : inline timeval operator + ( const timeval &t1, const timeval &t2 )
92 : {
93 : timeval t0 = t1;
94 : return t0 += t2;
95 : }
96 :
97 : inline timeval operator + ( const timeval &t1, sal_uIntPtr t2 )
98 : {
99 : timeval t0 = t1;
100 : return t0 += t2;
101 : }
102 :
103 0 : inline timeval operator - ( const timeval &t1, const timeval &t2 )
104 : {
105 0 : timeval t0 = t1;
106 0 : return t0 -= t2;
107 : }
108 :
109 : #endif // _SALUNX_TIME_H
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|