LibreOffice Module vcl (master) 1
salunxtime.h
Go to the documentation of this file.
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 INCLUDED_VCL_INC_UNX_SALUNXTIME_H
21#define INCLUDED_VCL_INC_UNX_SALUNXTIME_H
22
23#if defined LINUX || defined FREEBSD || \
24 defined NETBSD || defined OPENBSD || defined DRAGONFLY
25#include <sys/time.h>
26#endif
27#include <sal/types.h>
28
29inline bool operator >= ( const timeval &t1, const timeval &t2 )
30{
31 if( t1.tv_sec == t2.tv_sec )
32 return t1.tv_usec >= t2.tv_usec;
33 return t1.tv_sec > t2.tv_sec;
34}
35
36inline bool operator > ( const timeval &t1, const timeval &t2 )
37{
38 if( t1.tv_sec == t2.tv_sec )
39 return t1.tv_usec > t2.tv_usec;
40 return t1.tv_sec > t2.tv_sec;
41}
42
43inline timeval &operator -= ( timeval &t1, const timeval &t2 )
44{
45 if( t1.tv_usec < t2.tv_usec )
46 {
47 t1.tv_sec--;
48 t1.tv_usec += 1000000;
49 }
50 t1.tv_sec -= t2.tv_sec;
51 t1.tv_usec -= t2.tv_usec;
52 return t1;
53}
54
55inline timeval &operator += ( timeval &t1, sal_uIntPtr t2 )
56{
57 t1.tv_sec += t2 / 1000;
58 t1.tv_usec += (t2 % 1000) * 1000;
59 if( t1.tv_usec > 1000000 )
60 {
61 t1.tv_sec++;
62 t1.tv_usec -= 1000000;
63 }
64 return t1;
65}
66
67inline timeval operator - ( const timeval &t1, const timeval &t2 )
68{
69 timeval t0 = t1;
70 t0 -= t2;
71 return t0;
72}
73
74#endif // INCLUDED_VCL_INC_UNX_SALUNXTIME_H
75
76/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
timeval & operator+=(timeval &t1, sal_uIntPtr t2)
Definition: salunxtime.h:55
timeval operator-(const timeval &t1, const timeval &t2)
Definition: salunxtime.h:67
bool operator>(const timeval &t1, const timeval &t2)
Definition: salunxtime.h:36
timeval & operator-=(timeval &t1, const timeval &t2)
Definition: salunxtime.h:43
bool operator>=(const timeval &t1, const timeval &t2)
Definition: salunxtime.h:29