12321c474SPedro F. Giffuni /*- 22321c474SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 32321c474SPedro F. Giffuni * 459deaec5SRodney W. Grimes * Copyright (c) 1989, 1993 559deaec5SRodney W. Grimes * The Regents of the University of California. All rights reserved. 659deaec5SRodney W. Grimes * (c) UNIX System Laboratories, Inc. 759deaec5SRodney W. Grimes * All or some portions of this file are derived from material licensed 859deaec5SRodney W. Grimes * to the University of California by American Telephone and Telegraph 959deaec5SRodney W. Grimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 1059deaec5SRodney W. Grimes * the permission of UNIX System Laboratories, Inc. 1159deaec5SRodney W. Grimes * 1259deaec5SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 1359deaec5SRodney W. Grimes * modification, are permitted provided that the following conditions 1459deaec5SRodney W. Grimes * are met: 1559deaec5SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 1659deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 1759deaec5SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 1859deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 1959deaec5SRodney W. Grimes * documentation and/or other materials provided with the distribution. 20f2556687SWarner Losh * 3. Neither the name of the University nor the names of its contributors 2159deaec5SRodney W. Grimes * may be used to endorse or promote products derived from this software 2259deaec5SRodney W. Grimes * without specific prior written permission. 2359deaec5SRodney W. Grimes * 2459deaec5SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2559deaec5SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2659deaec5SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2759deaec5SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2859deaec5SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2959deaec5SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3059deaec5SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3159deaec5SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3259deaec5SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3359deaec5SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3459deaec5SRodney W. Grimes * SUCH DAMAGE. 3559deaec5SRodney W. Grimes * 3659deaec5SRodney W. Grimes * @(#)time.h 8.3 (Berkeley) 1/21/94 3759deaec5SRodney W. Grimes */ 3859deaec5SRodney W. Grimes 395b32a38aSPoul-Henning Kamp /* 405b32a38aSPoul-Henning Kamp */ 415b32a38aSPoul-Henning Kamp 4259deaec5SRodney W. Grimes #ifndef _TIME_H_ 4359deaec5SRodney W. Grimes #define _TIME_H_ 4459deaec5SRodney W. Grimes 451cb2a9aeSGarrett Wollman #include <sys/cdefs.h> 4612eb46c8SMarcel Moolenaar #include <sys/_null.h> 47abbd8902SMike Barcroft #include <sys/_types.h> 487b797ba2SWarner Losh #include <sys/_clock_id.h> 49abbd8902SMike Barcroft 5073cf72f5SGarrett Wollman #if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE 51339b0f68SBruce Evans /* 52339b0f68SBruce Evans * Frequency of the clock ticks reported by times(). Deprecated - use 531cb2a9aeSGarrett Wollman * sysconf(_SC_CLK_TCK) instead. (Removed in 1003.1-2001.) 54339b0f68SBruce Evans */ 55dd1b6791SMike Barcroft #define CLK_TCK 128 56339b0f68SBruce Evans #endif 57339b0f68SBruce Evans 58339b0f68SBruce Evans /* Frequency of the clock ticks reported by clock(). */ 59dd1b6791SMike Barcroft #define CLOCKS_PER_SEC 128 60339b0f68SBruce Evans 61abbd8902SMike Barcroft #ifndef _CLOCK_T_DECLARED 62abbd8902SMike Barcroft typedef __clock_t clock_t; 63abbd8902SMike Barcroft #define _CLOCK_T_DECLARED 6459deaec5SRodney W. Grimes #endif 6559deaec5SRodney W. Grimes 66abbd8902SMike Barcroft #ifndef _TIME_T_DECLARED 67abbd8902SMike Barcroft typedef __time_t time_t; 68abbd8902SMike Barcroft #define _TIME_T_DECLARED 6959deaec5SRodney W. Grimes #endif 7059deaec5SRodney W. Grimes 71abbd8902SMike Barcroft #ifndef _SIZE_T_DECLARED 72abbd8902SMike Barcroft typedef __size_t size_t; 73abbd8902SMike Barcroft #define _SIZE_T_DECLARED 74f154fbdaSPeter Wemm #endif 75f154fbdaSPeter Wemm 761cb2a9aeSGarrett Wollman #if __POSIX_VISIBLE >= 199309 77f154fbdaSPeter Wemm /* 78f154fbdaSPeter Wemm * New in POSIX 1003.1b-1993. 79f154fbdaSPeter Wemm */ 80abbd8902SMike Barcroft #ifndef _CLOCKID_T_DECLARED 81abbd8902SMike Barcroft typedef __clockid_t clockid_t; 82abbd8902SMike Barcroft #define _CLOCKID_T_DECLARED 839e0eb33eSAndrey A. Chernov #endif 849e0eb33eSAndrey A. Chernov 85abbd8902SMike Barcroft #ifndef _TIMER_T_DECLARED 86abbd8902SMike Barcroft typedef __timer_t timer_t; 87abbd8902SMike Barcroft #define _TIMER_T_DECLARED 8859deaec5SRodney W. Grimes #endif 8959deaec5SRodney W. Grimes 901cb2a9aeSGarrett Wollman #include <sys/timespec.h> 911cb2a9aeSGarrett Wollman #endif /* __POSIX_VISIBLE >= 199309 */ 92f154fbdaSPeter Wemm 93224ee591SDavid Xu #if __POSIX_VISIBLE >= 200112 94224ee591SDavid Xu #ifndef _PID_T_DECLARED 95224ee591SDavid Xu typedef __pid_t pid_t; 96224ee591SDavid Xu #define _PID_T_DECLARED 97224ee591SDavid Xu #endif 98224ee591SDavid Xu #endif 99224ee591SDavid Xu 10059deaec5SRodney W. Grimes struct tm { 10159deaec5SRodney W. Grimes int tm_sec; /* seconds after the minute [0-60] */ 10259deaec5SRodney W. Grimes int tm_min; /* minutes after the hour [0-59] */ 10359deaec5SRodney W. Grimes int tm_hour; /* hours since midnight [0-23] */ 10459deaec5SRodney W. Grimes int tm_mday; /* day of the month [1-31] */ 10559deaec5SRodney W. Grimes int tm_mon; /* months since January [0-11] */ 10659deaec5SRodney W. Grimes int tm_year; /* years since 1900 */ 10759deaec5SRodney W. Grimes int tm_wday; /* days since Sunday [0-6] */ 10859deaec5SRodney W. Grimes int tm_yday; /* days since January 1 [0-365] */ 10959deaec5SRodney W. Grimes int tm_isdst; /* Daylight Savings Time flag */ 1105b32a38aSPoul-Henning Kamp long tm_gmtoff; /* offset from UTC in seconds */ 11159deaec5SRodney W. Grimes char *tm_zone; /* timezone abbreviation */ 11259deaec5SRodney W. Grimes }; 11359deaec5SRodney W. Grimes 1141cb2a9aeSGarrett Wollman #if __POSIX_VISIBLE 1152bd32397SJoseph Koshy extern char *tzname[]; 1162bd32397SJoseph Koshy #endif 1172bd32397SJoseph Koshy 11859deaec5SRodney W. Grimes __BEGIN_DECLS 119bb28f3c2SWarner Losh char *asctime(const struct tm *); 120bb28f3c2SWarner Losh clock_t clock(void); 121bb28f3c2SWarner Losh char *ctime(const time_t *); 122ef1fcaf0SWarner Losh #ifndef _STANDALONE 123bb28f3c2SWarner Losh double difftime(time_t, time_t); 124ef1fcaf0SWarner Losh #endif 1256d2f64c1SDavid Schultz /* XXX missing: getdate() */ 126bb28f3c2SWarner Losh struct tm *gmtime(const time_t *); 127bb28f3c2SWarner Losh struct tm *localtime(const time_t *); 128bb28f3c2SWarner Losh time_t mktime(struct tm *); 129620035efSRobert Drehmel size_t strftime(char * __restrict, size_t, const char * __restrict, 130620035efSRobert Drehmel const struct tm * __restrict); 131bb28f3c2SWarner Losh time_t time(time_t *); 132bd3e40ceSDavid Xu #if __POSIX_VISIBLE >= 200112 133bd3e40ceSDavid Xu struct sigevent; 134bd3e40ceSDavid Xu int timer_create(clockid_t, struct sigevent *__restrict, timer_t *__restrict); 135bd3e40ceSDavid Xu int timer_delete(timer_t); 136bd3e40ceSDavid Xu int timer_gettime(timer_t, struct itimerspec *); 137bd3e40ceSDavid Xu int timer_getoverrun(timer_t); 138bd3e40ceSDavid Xu int timer_settime(timer_t, int, const struct itimerspec *__restrict, 139bd3e40ceSDavid Xu struct itimerspec *__restrict); 140bd3e40ceSDavid Xu #endif 1411cb2a9aeSGarrett Wollman #if __POSIX_VISIBLE 142bb28f3c2SWarner Losh void tzset(void); 1431cb2a9aeSGarrett Wollman #endif 1441cb2a9aeSGarrett Wollman 145b8c54054SGarrett Wollman #if __POSIX_VISIBLE >= 199309 146b8c54054SGarrett Wollman int clock_getres(clockid_t, struct timespec *); 147b8c54054SGarrett Wollman int clock_gettime(clockid_t, struct timespec *); 148b8c54054SGarrett Wollman int clock_settime(clockid_t, const struct timespec *); 149b8c54054SGarrett Wollman int nanosleep(const struct timespec *, struct timespec *); 150b8c54054SGarrett Wollman #endif /* __POSIX_VISIBLE >= 199309 */ 151b8c54054SGarrett Wollman 152224ee591SDavid Xu #if __POSIX_VISIBLE >= 200112 153224ee591SDavid Xu int clock_getcpuclockid(pid_t, clockid_t *); 1543f8455b0SEric van Gyzen int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); 155224ee591SDavid Xu #endif 156224ee591SDavid Xu 157b3ab54e1SGarrett Wollman #if __POSIX_VISIBLE >= 199506 158b3ab54e1SGarrett Wollman char *asctime_r(const struct tm *, char *); 159b3ab54e1SGarrett Wollman char *ctime_r(const time_t *, char *); 160b3ab54e1SGarrett Wollman struct tm *gmtime_r(const time_t *, struct tm *); 161b3ab54e1SGarrett Wollman struct tm *localtime_r(const time_t *, struct tm *); 162b3ab54e1SGarrett Wollman #endif 163b3ab54e1SGarrett Wollman 1641cb2a9aeSGarrett Wollman #if __XSI_VISIBLE 165d542f511SRobert Drehmel char *strptime(const char * __restrict, const char * __restrict, 166d542f511SRobert Drehmel struct tm * __restrict); 1671cb2a9aeSGarrett Wollman #endif 1681cb2a9aeSGarrett Wollman 1691cb2a9aeSGarrett Wollman #if __BSD_VISIBLE 1706d2f64c1SDavid Schultz char *timezone(int, int); /* XXX XSI conflict */ 171bb28f3c2SWarner Losh time_t timelocal(struct tm * const); 172bb28f3c2SWarner Losh time_t timegm(struct tm * const); 173ddce1c3dSKonstantin Belousov int timer_oshandle_np(timer_t timerid); 174fe9fbe22SEitan Adler time_t time2posix(time_t t); 175fe9fbe22SEitan Adler time_t posix2time(time_t t); 1761cb2a9aeSGarrett Wollman #endif /* __BSD_VISIBLE */ 177a8ed63bbSDavid Chisnall 1783ac9d659SDavid Chisnall #if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) 179a8ed63bbSDavid Chisnall #include <xlocale/_time.h> 180a8ed63bbSDavid Chisnall #endif 1817e299411SWarner Losh 182d02489d1SBrooks Davis #if defined(__BSD_VISIBLE) || __ISO_C_VISIBLE >= 2011 || \ 183bc053cafSDimitry Andric (defined(__cplusplus) && __cplusplus >= 201703) 184d02489d1SBrooks Davis #include <sys/_timespec.h> 185*9b5d724cSDag-Erling Smørgrav /* ISO/IEC 9899:2011 7.27.2.5 The timespec_get function */ 1867e299411SWarner Losh #define TIME_UTC 1 /* time elapsed since epoch */ 1877e299411SWarner Losh int timespec_get(struct timespec *ts, int base); 188*9b5d724cSDag-Erling Smørgrav #if defined (__BSD_VISIBLE) || __ISO_C_VISIBLE >= 2023 189*9b5d724cSDag-Erling Smørgrav /* ISO/IEC 9899:2024 7.29.1 Components of time */ 190*9b5d724cSDag-Erling Smørgrav #define TIME_MONOTONIC 2 /* monotonic time */ 191*9b5d724cSDag-Erling Smørgrav /* ISO/IEC 9899:2024 7.29.2.7 The timespec_getres function */ 192*9b5d724cSDag-Erling Smørgrav int timespec_getres(struct timespec *, int); 193*9b5d724cSDag-Erling Smørgrav #endif 194d02489d1SBrooks Davis #endif 1957e299411SWarner Losh 19659deaec5SRodney W. Grimes __END_DECLS 19759deaec5SRodney W. Grimes 19859deaec5SRodney W. Grimes #endif /* !_TIME_H_ */ 199