time.h 3.0 KB
Newer Older
R
Rich Felker 已提交
1 2 3 4 5 6 7
#ifndef	_TIME_H
#define _TIME_H

#ifdef __cplusplus
extern "C" {
#endif

8
#include <features.h>
9

R
Rich Felker 已提交
10 11 12 13 14 15 16 17
#undef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void*)0)
#endif


18
#define __NEED_size_t
R
Rich Felker 已提交
19 20
#define __NEED_time_t
#define __NEED_clock_t
21 22

#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
23 24
 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
 || defined(_BSD_SOURCE)
25
#define __NEED_struct_timespec
R
Rich Felker 已提交
26 27 28
#define __NEED_clockid_t
#define __NEED_timer_t
#define __NEED_pid_t
29
#define __NEED_locale_t
30
#endif
R
Rich Felker 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

#include <bits/alltypes.h>

struct tm
{
	int tm_sec;
	int tm_min;
	int tm_hour;
	int tm_mday;
	int tm_mon;
	int tm_year;
	int tm_wday;
	int tm_yday;
	int tm_isdst;
	long __tm_gmtoff;
	const char *__tm_zone;
};
48 49 50 51
#if defined(_BSD_SOURCE)
#define tm_gmtoff __tm_gmtoff
#define tm_zone __tm_zone
#endif
R
Rich Felker 已提交
52 53 54 55 56

clock_t clock (void);
time_t time (time_t *);
double difftime (time_t, time_t);
time_t mktime (struct tm *);
57
size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict);
R
Rich Felker 已提交
58 59 60 61 62
struct tm *gmtime (const time_t *);
struct tm *localtime (const time_t *);
char *asctime (const struct tm *);
char *ctime (const time_t *);

63
#define CLOCKS_PER_SEC 1000000UL
R
Rich Felker 已提交
64 65


66
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
67 68
 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
 || defined(_BSD_SOURCE)
R
Rich Felker 已提交
69

70
size_t strftime_l (char *  __restrict, size_t, const char *  __restrict, const struct tm *  __restrict, locale_t);
71

72 73 74
struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict);
struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict);
char *asctime_r (const struct tm *__restrict, char *__restrict);
75
char *ctime_r (const time_t *, char *);
R
Rich Felker 已提交
76

77
void tzset (void);
R
Rich Felker 已提交
78

79 80 81 82 83
struct itimerspec
{
	struct timespec it_interval;
	struct timespec it_value;
};
R
Rich Felker 已提交
84

85 86 87 88 89 90
#define CLOCK_REALTIME           0
#define CLOCK_MONOTONIC          1
#define CLOCK_PROCESS_CPUTIME_ID 2
#define CLOCK_THREAD_CPUTIME_ID  3

#define TIMER_ABSTIME 1
R
Rich Felker 已提交
91

92
int nanosleep (const struct timespec *, struct timespec *);
R
Rich Felker 已提交
93 94 95 96 97 98 99
int clock_getres (clockid_t, struct timespec *);
int clock_gettime (clockid_t, struct timespec *);
int clock_settime (clockid_t, const struct timespec *);
int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *);
int clock_getcpuclockid (pid_t, clockid_t *);

struct sigevent;
100
int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict);
R
Rich Felker 已提交
101
int timer_delete (timer_t);
102
int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict);
R
Rich Felker 已提交
103 104 105
int timer_gettime (timer_t, struct itimerspec *);
int timer_getoverrun (timer_t);

106
#endif
R
Rich Felker 已提交
107

108

109
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
110
char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict);
111 112 113
extern int daylight;
extern long timezone;
extern char *tzname[2];
R
Rich Felker 已提交
114
extern int getdate_err;
115
struct tm *getdate (const char *);
116 117
#endif

R
Rich Felker 已提交
118

R
Rich Felker 已提交
119
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
R
Rich Felker 已提交
120
int stime(time_t *);
121 122
time_t timegm(struct tm *);
#endif
R
Rich Felker 已提交
123

R
Rich Felker 已提交
124 125 126 127 128 129
#ifdef __cplusplus
}
#endif


#endif