xref: /AOO41X/main/vcl/inc/unx/salunx.h (revision 24f6443dc28f6479acd9115159f263e09548a0af)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SALUNX_H
25 #define _SALUNX_H
26 
27 // -=-= #includes =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
28 #if defined SCO || defined LINUX || defined HPUX || defined FREEBSD || defined NETBSD
29 #include <sys/time.h>
30 #elif defined AIX
31 #include <time.h>
32 #include <sys/time.h>
33 #include <strings.h>
34 #endif
35 #include <unx/svunx.h>
36 #include <unx/salstd.hxx>
37 
38 // -=-= #defines -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
39 #define capacityof(a)   (sizeof(a)/sizeof(*a))
40 
41 // -=-= inlines =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Divide(long nDividend,long nDivisor)42 inline long Divide( long nDividend, long nDivisor )
43 { return (nDividend + nDivisor/2) / nDivisor; }
44 
DPI(long pixel,long mm)45 inline long DPI( long pixel, long mm )
46 { return Divide( pixel*254, mm*10 ); }
47 
48 // -=-= timeval =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
49 inline int operator >= ( const timeval &t1, const timeval &t2 )
50 {
51     if( t1.tv_sec == t2.tv_sec )
52         return t1.tv_usec >= t2.tv_usec;
53     return t1.tv_sec > t2.tv_sec;
54 }
55 
56 inline int operator > ( const timeval &t1, const timeval &t2 )
57 {
58     if( t1.tv_sec == t2.tv_sec )
59         return t1.tv_usec > t2.tv_usec;
60     return t1.tv_sec > t2.tv_sec;
61 }
62 
63 inline int operator == ( const timeval &t1, const timeval &t2 )
64 {
65     if( t1.tv_sec == t2.tv_sec )
66         return t1.tv_usec == t2.tv_usec;
67     return sal_False;
68 }
69 
70 inline timeval &operator -= ( timeval &t1, const timeval &t2 )
71 {
72     if( t1.tv_usec < t2.tv_usec )
73     {
74         t1.tv_sec--;
75         t1.tv_usec += 1000000;
76     }
77     t1.tv_sec  -= t2.tv_sec;
78     t1.tv_usec -= t2.tv_usec;
79     return t1;
80 }
81 
82 inline timeval &operator += ( timeval &t1, const timeval &t2 )
83 {
84     t1.tv_sec  += t2.tv_sec;
85     t1.tv_usec += t2.tv_usec;
86     if( t1.tv_usec > 1000000 )
87     {
88         t1.tv_sec++;
89         t1.tv_usec -= 1000000;
90     }
91     return t1;
92 }
93 
94 inline timeval &operator += ( timeval &t1, sal_uIntPtr t2 )
95 {
96     t1.tv_sec  += t2 / 1000;
97     t1.tv_usec += t2 ? (t2 % 1000) * 1000 : 500;
98     if( t1.tv_usec > 1000000 )
99     {
100         t1.tv_sec++;
101         t1.tv_usec -= 1000000;
102     }
103     return t1;
104 }
105 
106 inline timeval operator + ( const timeval &t1, const timeval &t2 )
107 {
108     timeval t0 = t1;
109     return t0 += t2;
110 }
111 
112 inline timeval operator + ( const timeval &t1, sal_uIntPtr t2 )
113 {
114     timeval t0 = t1;
115     return t0 += t2;
116 }
117 
118 inline timeval operator - ( const timeval &t1, const timeval &t2 )
119 {
120     timeval t0 = t1;
121     return t0 -= t2;
122 }
123 #endif
124 
125