1 /* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)time.h 8.3 (Berkeley) 1/21/94 35 */ 36 37 /* 38 * $FreeBSD: head/include/time.h 245428 2013-01-14 18:01:19Z dim $ 39 */ 40 41 #ifndef _TIME_H_ 42 #define _TIME_H_ 43 44 #include <sys/cdefs.h> 45 #include <sys/_null.h> 46 #include <machine/stdint.h> 47 48 #if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE < 200112) 49 /* 50 * Frequency of the clock ticks reported by times(). Deprecated - use 51 * sysconf(_SC_CLK_TCK) instead. (Removed in 1003.1-2001.) 52 */ 53 #define CLK_TCK 128 54 #endif 55 56 /* Frequency of the clock ticks reported by clock(). */ 57 #define CLOCKS_PER_SEC ((clock_t)128) 58 59 #ifndef _CLOCK_T_DECLARED 60 #define _CLOCK_T_DECLARED 61 typedef __clock_t clock_t; 62 #endif 63 64 #ifndef _TIME_T_DECLARED 65 #define _TIME_T_DECLARED 66 typedef __time_t time_t; 67 #endif 68 69 #ifndef _SIZE_T_DECLARED 70 #define _SIZE_T_DECLARED 71 typedef __size_t size_t; 72 #endif 73 74 #if __POSIX_VISIBLE >= 199309 75 /* 76 * New in POSIX 1003.1b-1993. 77 */ 78 #include <sys/timespec.h> 79 #ifndef _CLOCKID_T_DECLARED 80 #define _CLOCKID_T_DECLARED 81 typedef __clockid_t clockid_t; 82 #endif 83 84 #ifndef _TIMER_T_DECLARED 85 #define _TIMER_T_DECLARED 86 typedef __timer_t timer_t; 87 #endif 88 #endif /* __POSIX_VISIBLE >= 199309 */ 89 90 #if __POSIX_VISIBLE >= 200112 91 #ifndef _PID_T_DECLARED 92 #define _PID_T_DECLARED 93 typedef __pid_t pid_t; 94 #endif 95 #endif 96 97 #if __BSD_VISIBLE 98 #ifndef _LWPID_T_DECLARED 99 #define _LWPID_T_DECLARED 100 typedef __pid_t lwpid_t; /* light weight process id */ 101 #endif 102 #endif 103 104 /* These macros are also in sys/time.h. */ 105 #if !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 199309 106 #define CLOCK_REALTIME 0 107 #if __BSD_VISIBLE 108 #define CLOCK_VIRTUAL 1 109 #define CLOCK_PROF 2 110 #endif 111 #define CLOCK_MONOTONIC 4 112 #define CLOCK_UPTIME 5 /* FreeBSD-specific. */ 113 #define CLOCK_UPTIME_PRECISE 7 /* FreeBSD-specific. */ 114 #define CLOCK_UPTIME_FAST 8 /* FreeBSD-specific. */ 115 #define CLOCK_REALTIME_PRECISE 9 /* FreeBSD-specific. */ 116 #define CLOCK_REALTIME_FAST 10 /* FreeBSD-specific. */ 117 #define CLOCK_MONOTONIC_PRECISE 11 /* FreeBSD-specific. */ 118 #define CLOCK_MONOTONIC_FAST 12 /* FreeBSD-specific. */ 119 #define CLOCK_SECOND 13 /* FreeBSD-specific. */ 120 #define CLOCK_THREAD_CPUTIME_ID 14 121 #define CLOCK_PROCESS_CPUTIME_ID 15 122 #endif /* !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 199309 */ 123 124 #if !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 199309 125 #if __BSD_VISIBLE 126 #define TIMER_RELTIME 0x0 /* relative timer */ 127 #endif 128 #define TIMER_ABSTIME 0x1 /* absolute timer */ 129 #endif /* !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 199309 */ 130 131 struct tm { 132 int tm_sec; /* seconds after the minute [0-60] */ 133 int tm_min; /* minutes after the hour [0-59] */ 134 int tm_hour; /* hours since midnight [0-23] */ 135 int tm_mday; /* day of the month [1-31] */ 136 int tm_mon; /* months since January [0-11] */ 137 int tm_year; /* years since 1900 */ 138 int tm_wday; /* days since Sunday [0-6] */ 139 int tm_yday; /* days since January 1 [0-365] */ 140 int tm_isdst; /* Daylight Savings Time flag */ 141 long tm_gmtoff; /* offset from UTC in seconds */ 142 char *tm_zone; /* timezone abbreviation */ 143 }; 144 145 #if __POSIX_VISIBLE 146 extern char *tzname[]; 147 #endif 148 149 __BEGIN_DECLS 150 char *asctime(const struct tm *); 151 clock_t clock(void); 152 char *ctime(const time_t *); 153 double difftime(time_t, time_t); 154 struct tm *gmtime(const time_t *); 155 struct tm *localtime(const time_t *); 156 time_t mktime(struct tm *); 157 size_t strftime(char * __restrict, size_t, const char * __restrict, 158 const struct tm * __restrict) __strftimelike(3, 0); 159 time_t time(time_t *); 160 161 #if __POSIX_VISIBLE 162 void tzset(void); 163 #endif 164 165 #if __POSIX_VISIBLE >= 199309 166 int clock_getres(clockid_t, struct timespec *); 167 int clock_gettime(clockid_t, struct timespec *); 168 int clock_settime(clockid_t, const struct timespec *); 169 int nanosleep(const struct timespec *, struct timespec *); 170 #endif /* __POSIX_VISIBLE >= 199309 */ 171 172 #if __POSIX_VISIBLE >= 199506 173 char *asctime_r(const struct tm * __restrict, char * __restrict); 174 char *ctime_r(const time_t *, char *); 175 struct tm *gmtime_r(const time_t * __restrict, struct tm * __restrict); 176 struct tm *localtime_r(const time_t * __restrict, struct tm * __restrict); 177 #endif 178 179 #if __POSIX_VISIBLE >= 200112 180 int clock_getcpuclockid(pid_t, clockid_t *); 181 #if 0 /* XXX missing */ 182 struct sigevent; 183 int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); 184 int timer_create(clockid_t, struct sigevent *__restrict, timer_t *__restrict); 185 int timer_delete(timer_t); 186 int timer_gettime(timer_t, struct itimerspec *); 187 int timer_getoverrun(timer_t); 188 int timer_settime(timer_t, int, const struct itimerspec *__restrict, 189 struct itimerspec *__restrict); 190 #endif 191 #endif 192 193 #if __XSI_VISIBLE 194 extern int daylight; 195 extern int getdate_err; 196 extern long timezone; 197 struct tm *getdate(const char *) __strftimelike(1, 0); 198 char *strptime(const char * __restrict, const char * __restrict, 199 struct tm * __restrict) __strftimelike(2, 0); 200 #endif 201 202 #if __BSD_VISIBLE 203 int getcpuclockid(pid_t, lwpid_t, clockid_t *); 204 void tzsetwall(void); 205 time_t timelocal(struct tm * const); 206 time_t timegm(struct tm * const); 207 time_t time2posix(time_t); 208 time_t posix2time(time_t); 209 struct tm *offtime(const time_t * const, const long); 210 time_t timeoff(struct tm * const, const long); 211 #endif /* __BSD_VISIBLE */ 212 213 #if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) 214 #include <xlocale/_time.h> 215 #endif 216 217 #if __ISO_C_VISIBLE >= 2011 || (defined(__cplusplus) && __cplusplus >= 201703) 218 #include <sys/_timespec.h> 219 #define TIME_UTC 1 220 int timespec_get(struct timespec *ts, int base); 221 #endif 222 __END_DECLS 223 224 #endif /* !_TIME_H_ */ 225