sys/time.h

Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1982, 1986, 1993
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 4. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  * © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved.
00029  *      @(#)time.h      8.5 (Berkeley) 5/4/95
00030  * © Portions copyright (c) 2005-2006 Nokia Corporation.  All rights reserved.
00031  * $FreeBSD: src/sys/sys/time.h,v 1.69 2005/04/02 12:33:27 das Exp $
00032  */
00033 
00034 #ifndef _SYS_TIME_H_
00035 #define _SYS_TIME_H_
00036 
00037 #include <sys/_timeval.h>
00038 #include <sys/types.h>
00039 #include <sys/timespec.h>
00040 
00041 struct timezone {
00042         int     tz_minuteswest; /* minutes west of Greenwich */
00043         int     tz_dsttime;     /* type of dst correction */
00044 };
00045 #define DST_NONE        0       /* not on dst */
00046 #define DST_USA         1       /* USA style dst */
00047 #define DST_AUST        2       /* Australian style dst */
00048 #define DST_WET         3       /* Western European dst */
00049 #define DST_MET         4       /* Middle European dst */
00050 #define DST_EET         5       /* Eastern European dst */
00051 #define DST_CAN         6       /* Canada */
00052 
00053 #if __BSD_VISIBLE
00054 struct bintime {
00055         time_t  sec;
00056         uint64_t frac;
00057 };
00058 
00059 static __inline void
00060 bintime_addx(struct bintime *bt, uint64_t x)
00061 {
00062         uint64_t u;
00063 
00064         u = bt->frac;
00065         bt->frac += x;
00066         if (u > bt->frac)
00067                 bt->sec++;
00068 }
00069 
00070 static __inline void
00071 bintime_add(struct bintime *bt, const struct bintime *bt2)
00072 {
00073         uint64_t u;
00074 
00075         u = bt->frac;
00076         bt->frac += bt2->frac;
00077         if (u > bt->frac)
00078                 bt->sec++;
00079         bt->sec += bt2->sec;
00080 }
00081 
00082 static __inline void
00083 bintime_sub(struct bintime *bt, const struct bintime *bt2)
00084 {
00085         uint64_t u;
00086 
00087         u = bt->frac;
00088         bt->frac -= bt2->frac;
00089         if (u < bt->frac)
00090                 bt->sec--;
00091         bt->sec -= bt2->sec;
00092 }
00093 
00094 /*-
00095  * Background information:
00096  *
00097  * When converting between timestamps on parallel timescales of differing
00098  * resolutions it is historical and scientific practice to round down rather
00099  * than doing 4/5 rounding.
00100  *
00101  *   The date changes at midnight, not at noon.
00102  *
00103  *   Even at 15:59:59.999999999 it's not four'o'clock.
00104  *
00105  *   time_second ticks after N.999999999 not after N.4999999999
00106  */
00107 
00108 static __inline void
00109 bintime2timespec(const struct bintime *bt, struct timespec *ts)
00110 {
00111 
00112         ts->tv_sec = bt->sec;
00113         ts->tv_nsec = ((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32;
00114 }
00115 
00116 static __inline void
00117 timespec2bintime(const struct timespec *ts, struct bintime *bt)
00118 {
00119 
00120         bt->sec = ts->tv_sec;
00121         /* 18446744073 = int(2^64 / 1000000000) */
00122         bt->frac = ts->tv_nsec * (uint64_t)18446744073LL; 
00123 }
00124 
00125 static __inline void
00126 bintime2timeval(const struct bintime *bt, struct timeval *tv)
00127 {
00128 
00129         tv->tv_sec = bt->sec;
00130         tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32;
00131 }
00132 
00133 static __inline void
00134 timeval2bintime(const struct timeval *tv, struct bintime *bt)
00135 {
00136 
00137         bt->sec = tv->tv_sec;
00138         /* 18446744073709 = int(2^64 / 1000000) */
00139         bt->frac = tv->tv_usec * (uint64_t)18446744073709LL;
00140 }
00141 #endif /* __BSD_VISIBLE */
00142 
00143 /*
00144  * Names of the interval timers, and structure
00145  * defining a timer setting.
00146  */
00147 #define ITIMER_REAL     0
00148 #define ITIMER_VIRTUAL  1
00149 #define ITIMER_PROF     2
00150 
00151 struct itimerval {
00152         struct  timeval it_interval;    /* timer interval */
00153         struct  timeval it_value;       /* current value */
00154 };
00155 
00156 /*
00157  * Getkerninfo clock information structure
00158  */
00159 struct clockinfo {
00160         int     hz;             /* clock frequency */
00161         int     tick;           /* micro-seconds per hz tick */
00162         int     spare;
00163         int     stathz;         /* statistics clock frequency */
00164         int     profhz;         /* profiling clock frequency */
00165 };
00166 
00167 #include <time.h>
00168 
00169 #include <sys/cdefs.h>
00170 
00171 __BEGIN_DECLS
00172 IMPORT_C int    adjtime(const struct timeval *, struct timeval *);
00173 IMPORT_C int    gettimeofday(struct timeval *, struct timezone *);
00174 int     settimeofday(const struct timeval *, const struct timezone *);
00175 IMPORT_C int    utimes(const char *, const struct timeval *);
00176 __END_DECLS
00177 
00178 
00179 #endif /* !_SYS_TIME_H_ */

Copyright © Nokia Corporation 2001-2008
Back to top