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