X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=includes%2Ftime.h;h=a2b659688cfa4bb661a553a671b8510296e93997;hp=41075dbc81c9f71d090db9e878ed9041d24945f1;hb=da0f3f353d417fed71f358a48d5d5394145e460d;hpb=76ee46321244f74eee3b5df0800ffdee0e8c3c37 diff --git a/includes/time.h b/includes/time.h index 41075db..a2b6596 100644 --- a/includes/time.h +++ b/includes/time.h @@ -1,36 +1,81 @@ -#ifndef _PDCLIB_TIME_H -#define _PDCLIB_TIME_H -#include <_PDCLIB_aux.h> -#include <_PDCLIB_int.h> - -_PDCLIB_BEGIN_EXTERN_C -#ifndef _PDCLIB_SIZE_T_DEFINED -#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED -typedef _PDCLIB_size_t size_t; -#endif - -#ifndef _PDCLIB_NULL_DEFINED -#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED -#define NULL _PDCLIB_NULL -#endif - -typedef _PDCLIB_time_t time_t; -typedef _PDCLIB_clock_t clock_t; - -#define TIME_UTC _PDCLIB_TIME_UTC - -#ifndef _PDCLIB_STRUCT_TIMESPEC_DEFINED -#define _PDCLIB_STRUCT_TIMESPEC_DEFINED -_PDCLIB_DEFINE_STRUCT_TIMESPEC() -#endif - -#ifndef _PDCLIB_STRUCT_TM_DEFINED -#define _PDCLIB_STRUCT_TM_DEFINED -_PDCLIB_DEFINE_STRUCT_TM() -#endif - -time_t time( time_t* t ) _PDCLIB_nothrow; -int timespec_get( struct timespec *ts, int base ) _PDCLIB_nothrow; - -_PDCLIB_END_EXTERN_C -#endif +/* Date and time + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_TIME_H +#define _PDCLIB_TIME_H _PDCLIB_TIME_H +#include "_PDCLIB_aux.h" +#include "_PDCLIB_int.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _PDCLIB_SIZE_T_DEFINED +#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED +typedef _PDCLIB_size_t size_t; +#endif + +#ifndef _PDCLIB_NULL_DEFINED +#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED +#define NULL _PDCLIB_NULL +#endif + +typedef _PDCLIB_time_t time_t; +typedef _PDCLIB_clock_t clock_t; + +#define CLOCKS_PER_SEC _PDCLIB_CLOCKS_PER_SEC +#define TIME_UTC _PDCLIB_TIME_UTC + +struct timespec +{ + time_t tv_sec; + long tv_nsec; +}; + +struct tm +{ + int tm_sec; /* 0-60 */ + int tm_min; /* 0-59 */ + int tm_hour; /* 0-23 */ + int tm_mday; /* 1-31 */ + int tm_mon; /* 0-11 */ + int tm_year; /* years since 1900 */ + int tm_wday; /* 0-6 */ + int tm_yday; /* 0-365 */ + int tm_isdst; /* >0 DST, 0 no DST, <0 information unavailable */ +}; + +/* Returns the number of "clocks" in processor time since the invocation + of the program. Divide by CLOCKS_PER_SEC to get the value in seconds. + Returns -1 if the value cannot be represented in the return type or is + not available. +*/ +clock_t clock( void ) _PDCLIB_nothrow; + +/* Returns the difference between two calendar times in seconds. */ +double difftime( time_t time1, time_t time0 ) _PDCLIB_nothrow; + +time_t mktime( struct tm * timeptr ) _PDCLIB_nothrow; + +time_t time( time_t * timer ) _PDCLIB_nothrow; + +int timespec_get( struct timespec * ts, int base ) _PDCLIB_nothrow; + +char * asctime( const struct tm * timeptr ) _PDCLIB_nothrow; + +char * ctime( const time_t * timer ) _PDCLIB_nothrow; + +struct tm * gmtime( const time_t * timer ) _PDCLIB_nothrow; + +struct tm * localtime( const time_t * timer ) _PDCLIB_nothrow; + +size_t strftime( char * _PDCLIB_restrict s, size_t maxsize, const char * _PDCLIB_restrict format, const struct tm * _PDCLIB_restrict timeptr ); + +#ifdef __cplusplus +} +#endif + +#endif