xref: /trunk/main/vcl/inc/unx/salunx.h (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SALUNX_H
29 #define _SALUNX_H
30 
31 // -=-= #includes =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
32 #if defined SCO || defined LINUX || defined HPUX || defined FREEBSD || defined NETBSD
33 #include <sys/time.h>
34 #elif defined AIX
35 #include <time.h>
36 #include <sys/time.h>
37 #include <strings.h>
38 #endif
39 #include <unx/svunx.h>
40 #include <unx/salstd.hxx>
41 
42 // -=-= #defines -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
43 #define capacityof(a)	(sizeof(a)/sizeof(*a))
44 
45 // -=-= inlines =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
46 inline long Divide( long nDividend, long nDivisor )
47 { return (nDividend + nDivisor/2) / nDivisor; }
48 
49 inline long DPI( long pixel, long mm )
50 { return Divide( pixel*254, mm*10 ); }
51 
52 // -=-= timeval =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
53 inline int operator >= ( const timeval &t1, const timeval &t2 )
54 {
55 	if( t1.tv_sec == t2.tv_sec )
56 		return t1.tv_usec >= t2.tv_usec;
57 	return t1.tv_sec > t2.tv_sec;
58 }
59 
60 inline int operator > ( const timeval &t1, const timeval &t2 )
61 {
62 	if( t1.tv_sec == t2.tv_sec )
63 		return t1.tv_usec > t2.tv_usec;
64 	return t1.tv_sec > t2.tv_sec;
65 }
66 
67 inline int operator == ( const timeval &t1, const timeval &t2 )
68 {
69 	if( t1.tv_sec == t2.tv_sec )
70 		return t1.tv_usec == t2.tv_usec;
71 	return sal_False;
72 }
73 
74 inline timeval &operator -= ( timeval &t1, const timeval &t2 )
75 {
76 	if( t1.tv_usec < t2.tv_usec )
77 	{
78 		t1.tv_sec--;
79 		t1.tv_usec += 1000000;
80 	}
81 	t1.tv_sec  -= t2.tv_sec;
82 	t1.tv_usec -= t2.tv_usec;
83 	return t1;
84 }
85 
86 inline timeval &operator += ( timeval &t1, const timeval &t2 )
87 {
88 	t1.tv_sec  += t2.tv_sec;
89 	t1.tv_usec += t2.tv_usec;
90 	if( t1.tv_usec > 1000000 )
91 	{
92 		t1.tv_sec++;
93 		t1.tv_usec -= 1000000;
94 	}
95 	return t1;
96 }
97 
98 inline timeval &operator += ( timeval &t1, sal_uIntPtr t2 )
99 {
100 	t1.tv_sec  += t2 / 1000;
101 	t1.tv_usec += t2 ? (t2 % 1000) * 1000 : 500;
102 	if( t1.tv_usec > 1000000 )
103 	{
104 		t1.tv_sec++;
105 		t1.tv_usec -= 1000000;
106 	}
107 	return t1;
108 }
109 
110 inline timeval operator + ( const timeval &t1, const timeval &t2 )
111 {
112 	timeval t0 = t1;
113 	return t0 += t2;
114 }
115 
116 inline timeval operator + ( const timeval &t1, sal_uIntPtr t2 )
117 {
118 	timeval t0 = t1;
119 	return t0 += t2;
120 }
121 
122 inline timeval operator - ( const timeval &t1, const timeval &t2 )
123 {
124 	timeval t0 = t1;
125 	return t0 -= t2;
126 }
127 #endif
128 
129