sl@0: /*- sl@0: * Copyright (c) 1982, 1986, 1993 sl@0: * The Regents of the University of California. All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the above copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * 4. Neither the name of the University nor the names of its contributors sl@0: * may be used to endorse or promote products derived from this software sl@0: * without specific prior written permission. sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND sl@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE sl@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL sl@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS sl@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT sl@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY sl@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF sl@0: * SUCH DAMAGE. sl@0: * © * Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: * @(#)time.h 8.5 (Berkeley) 5/4/95 sl@0: * $FreeBSD: src/sys/sys/time.h,v 1.69 2005/04/02 12:33:27 das Exp $ sl@0: */ sl@0: sl@0: #ifndef _SYS_TIME_H_ sl@0: #define _SYS_TIME_H_ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: struct timezone { sl@0: int tz_minuteswest; /* minutes west of Greenwich */ sl@0: int tz_dsttime; /* type of dst correction */ sl@0: }; sl@0: #define DST_NONE 0 /* not on dst */ sl@0: #define DST_USA 1 /* USA style dst */ sl@0: #define DST_AUST 2 /* Australian style dst */ sl@0: #define DST_WET 3 /* Western European dst */ sl@0: #define DST_MET 4 /* Middle European dst */ sl@0: #define DST_EET 5 /* Eastern European dst */ sl@0: #define DST_CAN 6 /* Canada */ sl@0: sl@0: #if __BSD_VISIBLE sl@0: struct bintime { sl@0: time_t sec; sl@0: uint64_t frac; sl@0: }; sl@0: sl@0: static __inline void sl@0: bintime_addx(struct bintime *bt, uint64_t x) sl@0: { sl@0: uint64_t u; sl@0: sl@0: u = bt->frac; sl@0: bt->frac += x; sl@0: if (u > bt->frac) sl@0: bt->sec++; sl@0: } sl@0: sl@0: static __inline void sl@0: bintime_add(struct bintime *bt, const struct bintime *bt2) sl@0: { sl@0: uint64_t u; sl@0: sl@0: u = bt->frac; sl@0: bt->frac += bt2->frac; sl@0: if (u > bt->frac) sl@0: bt->sec++; sl@0: bt->sec += bt2->sec; sl@0: } sl@0: sl@0: static __inline void sl@0: bintime_sub(struct bintime *bt, const struct bintime *bt2) sl@0: { sl@0: uint64_t u; sl@0: sl@0: u = bt->frac; sl@0: bt->frac -= bt2->frac; sl@0: if (u < bt->frac) sl@0: bt->sec--; sl@0: bt->sec -= bt2->sec; sl@0: } sl@0: sl@0: /*- sl@0: * Background information: sl@0: * sl@0: * When converting between timestamps on parallel timescales of differing sl@0: * resolutions it is historical and scientific practice to round down rather sl@0: * than doing 4/5 rounding. sl@0: * sl@0: * The date changes at midnight, not at noon. sl@0: * sl@0: * Even at 15:59:59.999999999 it's not four'o'clock. sl@0: * sl@0: * time_second ticks after N.999999999 not after N.4999999999 sl@0: */ sl@0: sl@0: static __inline void sl@0: bintime2timespec(const struct bintime *bt, struct timespec *ts) sl@0: { sl@0: sl@0: ts->tv_sec = bt->sec; sl@0: ts->tv_nsec = ((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32; sl@0: } sl@0: sl@0: static __inline void sl@0: timespec2bintime(const struct timespec *ts, struct bintime *bt) sl@0: { sl@0: sl@0: bt->sec = ts->tv_sec; sl@0: /* 18446744073 = int(2^64 / 1000000000) */ sl@0: bt->frac = ts->tv_nsec * (uint64_t)18446744073LL; sl@0: } sl@0: sl@0: static __inline void sl@0: bintime2timeval(const struct bintime *bt, struct timeval *tv) sl@0: { sl@0: sl@0: tv->tv_sec = bt->sec; sl@0: tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32; sl@0: } sl@0: sl@0: static __inline void sl@0: timeval2bintime(const struct timeval *tv, struct bintime *bt) sl@0: { sl@0: sl@0: bt->sec = tv->tv_sec; sl@0: /* 18446744073709 = int(2^64 / 1000000) */ sl@0: bt->frac = tv->tv_usec * (uint64_t)18446744073709LL; sl@0: } sl@0: #endif /* __BSD_VISIBLE */ sl@0: sl@0: /* sl@0: * Names of the interval timers, and structure sl@0: * defining a timer setting. sl@0: */ sl@0: #define ITIMER_REAL 0 sl@0: #define ITIMER_VIRTUAL 1 sl@0: #define ITIMER_PROF 2 sl@0: sl@0: struct itimerval { sl@0: struct timeval it_interval; /* timer interval */ sl@0: struct timeval it_value; /* current value */ sl@0: }; sl@0: sl@0: /* sl@0: * Getkerninfo clock information structure sl@0: */ sl@0: struct clockinfo { sl@0: int hz; /* clock frequency */ sl@0: int tick; /* micro-seconds per hz tick */ sl@0: int spare; sl@0: int stathz; /* statistics clock frequency */ sl@0: int profhz; /* profiling clock frequency */ sl@0: }; sl@0: sl@0: #include sl@0: sl@0: #include sl@0: sl@0: __BEGIN_DECLS sl@0: IMPORT_C int adjtime(const struct timeval *, struct timeval *); sl@0: IMPORT_C int gettimeofday(struct timeval *, struct timezone *); sl@0: int settimeofday(const struct timeval *, const struct timezone *); sl@0: IMPORT_C int utimes(const char *, const struct timeval *); sl@0: __END_DECLS sl@0: sl@0: sl@0: #endif /* !_SYS_TIME_H_ */