genericopenlibs/openenvcore/include/sys/time.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*-
       
     2  * Copyright (c) 1982, 1986, 1993
       
     3  *	The Regents of the University of California.  All rights reserved.
       
     4  *
       
     5  * Redistribution and use in source and binary forms, with or without
       
     6  * modification, are permitted provided that the following conditions
       
     7  * are met:
       
     8  * 1. Redistributions of source code must retain the above copyright
       
     9  *    notice, this list of conditions and the following disclaimer.
       
    10  * 2. Redistributions in binary form must reproduce the above copyright
       
    11  *    notice, this list of conditions and the following disclaimer in the
       
    12  *    documentation and/or other materials provided with the distribution.
       
    13  * 4. Neither the name of the University nor the names of its contributors
       
    14  *    may be used to endorse or promote products derived from this software
       
    15  *    without specific prior written permission.
       
    16  *
       
    17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
       
    18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       
    20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
       
    21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
       
    22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
       
    23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
       
    24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
       
    25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
       
    26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
       
    27  * SUCH DAMAGE.
       
    28  * © * Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
       
    29  *	@(#)time.h	8.5 (Berkeley) 5/4/95
       
    30  * $FreeBSD: src/sys/sys/time.h,v 1.69 2005/04/02 12:33:27 das Exp $
       
    31  */
       
    32 
       
    33 #ifndef _SYS_TIME_H_
       
    34 #define _SYS_TIME_H_
       
    35 
       
    36 #include <sys/_timeval.h>
       
    37 #include <sys/types.h>
       
    38 #include <sys/timespec.h>
       
    39 
       
    40 struct timezone {
       
    41 	int	tz_minuteswest;	/* minutes west of Greenwich */
       
    42 	int	tz_dsttime;	/* type of dst correction */
       
    43 };
       
    44 #define	DST_NONE	0	/* not on dst */
       
    45 #define	DST_USA		1	/* USA style dst */
       
    46 #define	DST_AUST	2	/* Australian style dst */
       
    47 #define	DST_WET		3	/* Western European dst */
       
    48 #define	DST_MET		4	/* Middle European dst */
       
    49 #define	DST_EET		5	/* Eastern European dst */
       
    50 #define	DST_CAN		6	/* Canada */
       
    51 
       
    52 #if __BSD_VISIBLE
       
    53 struct bintime {
       
    54 	time_t	sec;
       
    55 	uint64_t frac;
       
    56 };
       
    57 
       
    58 static __inline void
       
    59 bintime_addx(struct bintime *bt, uint64_t x)
       
    60 {
       
    61 	uint64_t u;
       
    62 
       
    63 	u = bt->frac;
       
    64 	bt->frac += x;
       
    65 	if (u > bt->frac)
       
    66 		bt->sec++;
       
    67 }
       
    68 
       
    69 static __inline void
       
    70 bintime_add(struct bintime *bt, const struct bintime *bt2)
       
    71 {
       
    72 	uint64_t u;
       
    73 
       
    74 	u = bt->frac;
       
    75 	bt->frac += bt2->frac;
       
    76 	if (u > bt->frac)
       
    77 		bt->sec++;
       
    78 	bt->sec += bt2->sec;
       
    79 }
       
    80 
       
    81 static __inline void
       
    82 bintime_sub(struct bintime *bt, const struct bintime *bt2)
       
    83 {
       
    84 	uint64_t u;
       
    85 
       
    86 	u = bt->frac;
       
    87 	bt->frac -= bt2->frac;
       
    88 	if (u < bt->frac)
       
    89 		bt->sec--;
       
    90 	bt->sec -= bt2->sec;
       
    91 }
       
    92 
       
    93 /*-
       
    94  * Background information:
       
    95  *
       
    96  * When converting between timestamps on parallel timescales of differing
       
    97  * resolutions it is historical and scientific practice to round down rather
       
    98  * than doing 4/5 rounding.
       
    99  *
       
   100  *   The date changes at midnight, not at noon.
       
   101  *
       
   102  *   Even at 15:59:59.999999999 it's not four'o'clock.
       
   103  *
       
   104  *   time_second ticks after N.999999999 not after N.4999999999
       
   105  */
       
   106 
       
   107 static __inline void
       
   108 bintime2timespec(const struct bintime *bt, struct timespec *ts)
       
   109 {
       
   110 
       
   111 	ts->tv_sec = bt->sec;
       
   112 	ts->tv_nsec = ((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32;
       
   113 }
       
   114 
       
   115 static __inline void
       
   116 timespec2bintime(const struct timespec *ts, struct bintime *bt)
       
   117 {
       
   118 
       
   119 	bt->sec = ts->tv_sec;
       
   120 	/* 18446744073 = int(2^64 / 1000000000) */
       
   121 	bt->frac = ts->tv_nsec * (uint64_t)18446744073LL; 
       
   122 }
       
   123 
       
   124 static __inline void
       
   125 bintime2timeval(const struct bintime *bt, struct timeval *tv)
       
   126 {
       
   127 
       
   128 	tv->tv_sec = bt->sec;
       
   129 	tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32;
       
   130 }
       
   131 
       
   132 static __inline void
       
   133 timeval2bintime(const struct timeval *tv, struct bintime *bt)
       
   134 {
       
   135 
       
   136 	bt->sec = tv->tv_sec;
       
   137 	/* 18446744073709 = int(2^64 / 1000000) */
       
   138 	bt->frac = tv->tv_usec * (uint64_t)18446744073709LL;
       
   139 }
       
   140 #endif /* __BSD_VISIBLE */
       
   141 
       
   142 /*
       
   143  * Names of the interval timers, and structure
       
   144  * defining a timer setting.
       
   145  */
       
   146 #define	ITIMER_REAL	0
       
   147 #define	ITIMER_VIRTUAL	1
       
   148 #define	ITIMER_PROF	2
       
   149 
       
   150 struct itimerval {
       
   151 	struct	timeval it_interval;	/* timer interval */
       
   152 	struct	timeval it_value;	/* current value */
       
   153 };
       
   154 
       
   155 /*
       
   156  * Getkerninfo clock information structure
       
   157  */
       
   158 struct clockinfo {
       
   159 	int	hz;		/* clock frequency */
       
   160 	int	tick;		/* micro-seconds per hz tick */
       
   161 	int	spare;
       
   162 	int	stathz;		/* statistics clock frequency */
       
   163 	int	profhz;		/* profiling clock frequency */
       
   164 };
       
   165 
       
   166 #include <time.h>
       
   167 
       
   168 #include <sys/cdefs.h>
       
   169 
       
   170 __BEGIN_DECLS
       
   171 IMPORT_C int	adjtime(const struct timeval *, struct timeval *);
       
   172 IMPORT_C int	gettimeofday(struct timeval *, struct timezone *);
       
   173 int	settimeofday(const struct timeval *, const struct timezone *);
       
   174 IMPORT_C int	utimes(const char *, const struct timeval *);
       
   175 __END_DECLS
       
   176 
       
   177 
       
   178 #endif /* !_SYS_TIME_H_ */