Back to index

lightning-sunbird  0.9+nobinonly
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  * [3 Deleted as of 22Jul99, see
00014  *     ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
00015  *        for details]
00016  * 4. Neither the name of the University nor the names of its contributors
00017  *    may be used to endorse or promote products derived from this software
00018  *    without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00024  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00025  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00026  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00027  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00028  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00029  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00030  * SUCH DAMAGE.
00031  *
00032  *     @(#)time.h    8.1 (Berkeley) 6/2/93
00033  */
00034 
00035 /* Adapted for GUSI by Matthias Neeracher <neeri@iis.ee.ethz.ch> */
00036 
00037 #ifndef _SYS_TIME_H_
00038 #define _SYS_TIME_H_
00039 
00040 #include <time.h>
00041 #include <sys/types.h>
00042 
00043 /*
00044  * Structure returned by gettimeofday(2) system call,
00045  * and used in other calls.
00046  */
00047 struct timeval {
00048        time_t        tv_sec;              /* seconds */
00049        suseconds_t   tv_usec;      /* and microseconds */
00050 };
00051 
00052 /*
00053  * Structure defined by POSIX.4 to be like a timeval.
00054  */
00055 struct timespec {
00056        time_t tv_sec;              /* seconds */
00057        long   tv_nsec;      /* and nanoseconds */
00058 };
00059 
00060 #define       TIMEVAL_TO_TIMESPEC(tv, ts) {                                  \
00061        (ts)->tv_sec = (tv)->tv_sec;                                   \
00062        (ts)->tv_nsec = (tv)->tv_usec * 1000;                          \
00063 }
00064 #define       TIMESPEC_TO_TIMEVAL(tv, ts) {                                  \
00065        (tv)->tv_sec = (ts)->tv_sec;                                   \
00066        (tv)->tv_usec = (ts)->tv_nsec / 1000;                          \
00067 }
00068 
00069 struct timezone {
00070        int    tz_minuteswest;      /* minutes west of Greenwich */
00071        int    tz_dsttime;   /* type of dst correction */
00072 };
00073 #define       DST_NONE      0      /* not on dst */
00074 #define       DST_USA              1      /* USA style dst */
00075 #define       DST_AUST      2      /* Australian style dst */
00076 #define       DST_WET              3      /* Western European dst */
00077 #define       DST_MET              4      /* Middle European dst */
00078 #define       DST_EET              5      /* Eastern European dst */
00079 #define       DST_CAN              6      /* Canada */
00080 
00081 /* Operations on timevals. */
00082 #define       timerclear(tvp)             (tvp)->tv_sec = (tvp)->tv_usec = 0
00083 #define       timerisset(tvp)             ((tvp)->tv_sec || (tvp)->tv_usec)
00084 #define       timercmp(tvp, uvp, cmp)                                        \
00085        (((tvp)->tv_sec == (uvp)->tv_sec) ?                            \
00086            ((tvp)->tv_usec cmp (uvp)->tv_usec) :               \
00087            ((tvp)->tv_sec cmp (uvp)->tv_sec))
00088 
00089 /*
00090  * Names of the interval timers, and structure
00091  * defining a timer setting.
00092  */
00093 #define       ITIMER_REAL   0
00094 #define       ITIMER_VIRTUAL       1
00095 #define       ITIMER_PROF   2
00096 
00097 struct itimerval {
00098        struct timeval it_interval; /* timer interval */
00099        struct timeval it_value;    /* current value */
00100 };
00101 
00102 /*
00103  * Getkerninfo clock information structure
00104  */
00105 struct clockinfo {
00106        int    hz;           /* clock frequency */
00107        int    tick;         /* micro-seconds per hz tick */
00108        int    stathz;              /* statistics clock frequency */
00109        int    profhz;              /* profiling clock frequency */
00110 };
00111 
00112 #define       NBBY   8             /* number of bits in a byte */
00113 
00114 /*
00115  * Select uses bit masks of file descriptors in longs.  These macros
00116  * manipulate such bit fields (the filesystem macros use chars).
00117  * FD_SETSIZE may be defined by the user, but the default here should
00118  * be enough for most uses.
00119  */
00120 #ifndef       FD_SETSIZE
00121 #define       FD_SETSIZE    256
00122 #endif
00123 
00124 typedef long  fd_mask;
00125 #define NFDBITS      (sizeof(fd_mask) * NBBY)    /* bits per mask */
00126 
00127 #ifndef howmany
00128 #define       howmany(x, y) (((x)+((y)-1))/(y))
00129 #endif
00130 
00131 typedef       struct fd_set {
00132        fd_mask       fds_bits[howmany(FD_SETSIZE, NFDBITS)];
00133 } fd_set;
00134 
00135 #define       FD_SET(n, p)  ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
00136 #define       FD_CLR(n, p)  ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
00137 #define       FD_ISSET(n, p)       ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
00138 #define       FD_COPY(f, t) memcpy(t, f, sizeof(*(f)))
00139 #define       FD_ZERO(p)    memset(p, 0, sizeof(*(p)))
00140 
00141 #include <time.h>
00142 
00143 #include <sys/cdefs.h>
00144 
00145 __BEGIN_DECLS
00146 int    getitimer __P((int, struct itimerval *));
00147 int    gettimeofday __P((struct timeval *, struct timezone *));
00148 int    setitimer __P((int, const struct itimerval *, struct itimerval *));
00149 int    utimes __P((const char *, const struct timeval *));
00150 int select __P((int, fd_set *, fd_set *, fd_set *, struct timeval *));
00151 __END_DECLS
00152 
00153 #endif /* !_SYS_TIME_H_ */