os/ossrv/genericopenlibs/openenvcore/include/sys/time.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/include/sys/time.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,178 @@
     1.4 +/*-
     1.5 + * Copyright (c) 1982, 1986, 1993
     1.6 + *	The Regents of the University of California.  All rights reserved.
     1.7 + *
     1.8 + * Redistribution and use in source and binary forms, with or without
     1.9 + * modification, are permitted provided that the following conditions
    1.10 + * are met:
    1.11 + * 1. Redistributions of source code must retain the above copyright
    1.12 + *    notice, this list of conditions and the following disclaimer.
    1.13 + * 2. Redistributions in binary form must reproduce the above copyright
    1.14 + *    notice, this list of conditions and the following disclaimer in the
    1.15 + *    documentation and/or other materials provided with the distribution.
    1.16 + * 4. Neither the name of the University nor the names of its contributors
    1.17 + *    may be used to endorse or promote products derived from this software
    1.18 + *    without specific prior written permission.
    1.19 + *
    1.20 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    1.21 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.22 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.23 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    1.24 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.25 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    1.26 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.27 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    1.28 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    1.29 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.30 + * SUCH DAMAGE.
    1.31 + * © * Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
    1.32 + *	@(#)time.h	8.5 (Berkeley) 5/4/95
    1.33 + * $FreeBSD: src/sys/sys/time.h,v 1.69 2005/04/02 12:33:27 das Exp $
    1.34 + */
    1.35 +
    1.36 +#ifndef _SYS_TIME_H_
    1.37 +#define _SYS_TIME_H_
    1.38 +
    1.39 +#include <sys/_timeval.h>
    1.40 +#include <sys/types.h>
    1.41 +#include <sys/timespec.h>
    1.42 +
    1.43 +struct timezone {
    1.44 +	int	tz_minuteswest;	/* minutes west of Greenwich */
    1.45 +	int	tz_dsttime;	/* type of dst correction */
    1.46 +};
    1.47 +#define	DST_NONE	0	/* not on dst */
    1.48 +#define	DST_USA		1	/* USA style dst */
    1.49 +#define	DST_AUST	2	/* Australian style dst */
    1.50 +#define	DST_WET		3	/* Western European dst */
    1.51 +#define	DST_MET		4	/* Middle European dst */
    1.52 +#define	DST_EET		5	/* Eastern European dst */
    1.53 +#define	DST_CAN		6	/* Canada */
    1.54 +
    1.55 +#if __BSD_VISIBLE
    1.56 +struct bintime {
    1.57 +	time_t	sec;
    1.58 +	uint64_t frac;
    1.59 +};
    1.60 +
    1.61 +static __inline void
    1.62 +bintime_addx(struct bintime *bt, uint64_t x)
    1.63 +{
    1.64 +	uint64_t u;
    1.65 +
    1.66 +	u = bt->frac;
    1.67 +	bt->frac += x;
    1.68 +	if (u > bt->frac)
    1.69 +		bt->sec++;
    1.70 +}
    1.71 +
    1.72 +static __inline void
    1.73 +bintime_add(struct bintime *bt, const struct bintime *bt2)
    1.74 +{
    1.75 +	uint64_t u;
    1.76 +
    1.77 +	u = bt->frac;
    1.78 +	bt->frac += bt2->frac;
    1.79 +	if (u > bt->frac)
    1.80 +		bt->sec++;
    1.81 +	bt->sec += bt2->sec;
    1.82 +}
    1.83 +
    1.84 +static __inline void
    1.85 +bintime_sub(struct bintime *bt, const struct bintime *bt2)
    1.86 +{
    1.87 +	uint64_t u;
    1.88 +
    1.89 +	u = bt->frac;
    1.90 +	bt->frac -= bt2->frac;
    1.91 +	if (u < bt->frac)
    1.92 +		bt->sec--;
    1.93 +	bt->sec -= bt2->sec;
    1.94 +}
    1.95 +
    1.96 +/*-
    1.97 + * Background information:
    1.98 + *
    1.99 + * When converting between timestamps on parallel timescales of differing
   1.100 + * resolutions it is historical and scientific practice to round down rather
   1.101 + * than doing 4/5 rounding.
   1.102 + *
   1.103 + *   The date changes at midnight, not at noon.
   1.104 + *
   1.105 + *   Even at 15:59:59.999999999 it's not four'o'clock.
   1.106 + *
   1.107 + *   time_second ticks after N.999999999 not after N.4999999999
   1.108 + */
   1.109 +
   1.110 +static __inline void
   1.111 +bintime2timespec(const struct bintime *bt, struct timespec *ts)
   1.112 +{
   1.113 +
   1.114 +	ts->tv_sec = bt->sec;
   1.115 +	ts->tv_nsec = ((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32;
   1.116 +}
   1.117 +
   1.118 +static __inline void
   1.119 +timespec2bintime(const struct timespec *ts, struct bintime *bt)
   1.120 +{
   1.121 +
   1.122 +	bt->sec = ts->tv_sec;
   1.123 +	/* 18446744073 = int(2^64 / 1000000000) */
   1.124 +	bt->frac = ts->tv_nsec * (uint64_t)18446744073LL; 
   1.125 +}
   1.126 +
   1.127 +static __inline void
   1.128 +bintime2timeval(const struct bintime *bt, struct timeval *tv)
   1.129 +{
   1.130 +
   1.131 +	tv->tv_sec = bt->sec;
   1.132 +	tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32;
   1.133 +}
   1.134 +
   1.135 +static __inline void
   1.136 +timeval2bintime(const struct timeval *tv, struct bintime *bt)
   1.137 +{
   1.138 +
   1.139 +	bt->sec = tv->tv_sec;
   1.140 +	/* 18446744073709 = int(2^64 / 1000000) */
   1.141 +	bt->frac = tv->tv_usec * (uint64_t)18446744073709LL;
   1.142 +}
   1.143 +#endif /* __BSD_VISIBLE */
   1.144 +
   1.145 +/*
   1.146 + * Names of the interval timers, and structure
   1.147 + * defining a timer setting.
   1.148 + */
   1.149 +#define	ITIMER_REAL	0
   1.150 +#define	ITIMER_VIRTUAL	1
   1.151 +#define	ITIMER_PROF	2
   1.152 +
   1.153 +struct itimerval {
   1.154 +	struct	timeval it_interval;	/* timer interval */
   1.155 +	struct	timeval it_value;	/* current value */
   1.156 +};
   1.157 +
   1.158 +/*
   1.159 + * Getkerninfo clock information structure
   1.160 + */
   1.161 +struct clockinfo {
   1.162 +	int	hz;		/* clock frequency */
   1.163 +	int	tick;		/* micro-seconds per hz tick */
   1.164 +	int	spare;
   1.165 +	int	stathz;		/* statistics clock frequency */
   1.166 +	int	profhz;		/* profiling clock frequency */
   1.167 +};
   1.168 +
   1.169 +#include <time.h>
   1.170 +
   1.171 +#include <sys/cdefs.h>
   1.172 +
   1.173 +__BEGIN_DECLS
   1.174 +IMPORT_C int	adjtime(const struct timeval *, struct timeval *);
   1.175 +IMPORT_C int	gettimeofday(struct timeval *, struct timezone *);
   1.176 +int	settimeofday(const struct timeval *, const struct timezone *);
   1.177 +IMPORT_C int	utimes(const char *, const struct timeval *);
   1.178 +__END_DECLS
   1.179 +
   1.180 +
   1.181 +#endif /* !_SYS_TIME_H_ */