merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / inc / salunx.h
blob827b0b918ae62e1d4698e001e7099226ea7b3c1c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: salunx.h,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SALUNX_H
32 #define _SALUNX_H
34 // -=-= #includes =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
35 #if defined SCO || defined LINUX || defined HPUX || defined FREEBSD || defined NETBSD
36 #include <sys/time.h>
37 #elif defined AIX
38 #include <time.h>
39 #include <sys/time.h>
40 #include <strings.h>
41 #elif defined IRIX
42 #ifdef __cplusplus
43 #include <ctime>
44 #endif
45 #include <sys/time.h>
46 #include <unistd.h>
47 #endif
48 #include <svunx.h>
49 #include <salstd.hxx>
51 // -=-= #defines -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
52 #define capacityof(a) (sizeof(a)/sizeof(*a))
54 // -=-= inlines =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
55 inline long Divide( long nDividend, long nDivisor )
56 { return (nDividend + nDivisor/2) / nDivisor; }
58 inline long DPI( long pixel, long mm )
59 { return Divide( pixel*254, mm*10 ); }
61 // -=-= timeval =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
62 inline int operator >= ( const timeval &t1, const timeval &t2 )
64 if( t1.tv_sec == t2.tv_sec )
65 return t1.tv_usec >= t2.tv_usec;
66 return t1.tv_sec > t2.tv_sec;
69 inline int operator > ( const timeval &t1, const timeval &t2 )
71 if( t1.tv_sec == t2.tv_sec )
72 return t1.tv_usec > t2.tv_usec;
73 return t1.tv_sec > t2.tv_sec;
76 inline int operator == ( const timeval &t1, const timeval &t2 )
78 if( t1.tv_sec == t2.tv_sec )
79 return t1.tv_usec == t2.tv_usec;
80 return FALSE;
83 inline timeval &operator -= ( timeval &t1, const timeval &t2 )
85 if( t1.tv_usec < t2.tv_usec )
87 t1.tv_sec--;
88 t1.tv_usec += 1000000;
90 t1.tv_sec -= t2.tv_sec;
91 t1.tv_usec -= t2.tv_usec;
92 return t1;
95 inline timeval &operator += ( timeval &t1, const timeval &t2 )
97 t1.tv_sec += t2.tv_sec;
98 t1.tv_usec += t2.tv_usec;
99 if( t1.tv_usec > 1000000 )
101 t1.tv_sec++;
102 t1.tv_usec -= 1000000;
104 return t1;
107 inline timeval &operator += ( timeval &t1, ULONG t2 )
109 t1.tv_sec += t2 / 1000;
110 t1.tv_usec += t2 ? (t2 % 1000) * 1000 : 500;
111 if( t1.tv_usec > 1000000 )
113 t1.tv_sec++;
114 t1.tv_usec -= 1000000;
116 return t1;
119 inline timeval operator + ( const timeval &t1, const timeval &t2 )
121 timeval t0 = t1;
122 return t0 += t2;
125 inline timeval operator + ( const timeval &t1, ULONG t2 )
127 timeval t0 = t1;
128 return t0 += t2;
131 inline timeval operator - ( const timeval &t1, const timeval &t2 )
133 timeval t0 = t1;
134 return t0 -= t2;
136 #endif