summaryrefslogtreecommitdiff
path: root/usr/src/lib/libast/common/features/tmx
blob: ebf5c0ff81a7f36de5b85931aa0008badb779a3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
set	prototyped
set	explicit
iff	TMX

cat{
	/*
	 * AT&T Research
	 *
	 * high resolution Time_t support
	 */

	#include <tm.h>
	#include <tv.h>
}end

inc	FEATURE/common

if ( _ast_int8_t ) {
	#define TMX_MAXDATE	"2554-07-21+23:34:33.709551614 UTC"
	#define TMX_MAXYEAR	2554
	#define TMX_MAXSEC	((Time_t)18446744073)
	#define TMX_MAXNSEC	709551614
	#define TMX_RESOLUTION	1000000000

	typedef uint64_t Time_t;
	typedef uint64_t Tmxsec_t;
	typedef uint32_t Tmxnsec_t;

	#define tmxsec(t)	((Tmxsec_t)((t)/1000000000))
	#define tmxnsec(t)	((Tmxnsec_t)((t)%1000000000))
	#define tmxsns(s,n)	(((((Time_t)(s))*1000000000))+((Time_t)(n)))
}
elif ( _ast_flt8_t ) {
	#define TMX_FLOAT	1
	#define TMX_MAXDATE	"2106-02-07+06:28:15.999 UTC"
	#define TMX_MAXYEAR	2106
	#define TMX_MAXSEC	0xffffffffL
	#define TMX_MAXNSEC	999000000L
	#define TMX_RESOLUTION	1000

	typedef _ast_flt8_t Time_t;
	typedef uint32_t Tmxsec_t;
	typedef uint32_t Tmxnsec_t;

	#define tmxsec(t)	((Tmxsec_t)(t))
	#define tmxnsec(t)	(((Tmxnsec_t)(((t)-((uint32_t)(t))+0.0000005)*1000L))*1000000L)
	#define tmxsns(s,n)	(((Time_t)(s))+((((uint32_t)(n))/1000L)/1e6))
}
else {
	#define TMX_MAXDATE	"2106-02-07+06:28:14 UTC"
	#define TMX_MAXYEAR	2106
	#define TMX_MAXSEC	0xfffffffeL
	#define TMX_MAXNSEC	0L
	#define TMX_RESOLUTION	1

	typedef uint32_t Time_t;
	typedef uint32_t Tmxsec_t;
	typedef uint32_t Tmxnsec_t;

	#define tmxsec(t)	((Tmxsec_t)(t))
	#define tmxnsec(t)	(0)
	#define tmxsns(s,n)	((Time_t)(s))
}
endif

cat{
	#define TMX_NOTIME	((Time_t)(-1))
	#define TMX_NOW		tmxgettime()
	#define TMX_MAXTIME	tmxsns(TMX_MAXSEC,TMX_MAXNSEC)

	#define tmx2tv(t,v)	((v)->tv_nsec=tmxnsec(t),(v)->tv_sec=tmxsec(t))
	#define tv2tmx(v)	tmxsns((v)->tv_sec,(v)->tv_nsec)

	#define tmxclock(p)	tmxsns(((p)?*(p):time(NiL)),0)

	#define tmxgetatime(s)	tmxsns((s)->st_atime,ST_ATIME_NSEC_GET(s))
	#define tmxgetctime(s)	tmxsns((s)->st_ctime,ST_CTIME_NSEC_GET(s))
	#define tmxgetmtime(s)	tmxsns((s)->st_mtime,ST_MTIME_NSEC_GET(s))

	#define tmxsetatime(s,t) ((s)->st_atime=tmxsec(t),ST_ATIME_NSEC_SET(s,tmxnsec(t)))
	#define tmxsetctime(s,t) ((s)->st_ctime=tmxsec(t),ST_CTIME_NSEC_SET(s,tmxnsec(t)))
	#define tmxsetmtime(s,t) ((s)->st_mtime=tmxsec(t),ST_MTIME_NSEC_SET(s,tmxnsec(t)))

	#if _BLD_ast && defined(__EXPORT__)
	#define extern		__EXPORT__
	#endif

	extern Time_t		tmxdate(const char*, char**, Time_t);
	extern Time_t		tmxduration(const char*, char**);
	extern char*		tmxfmt(char*, size_t, const char*, Time_t);
	extern Time_t		tmxleap(Time_t);
	extern Tm_t*		tmxmake(Time_t);
	extern Time_t		tmxscan(const char*, char**, const char*, char**, Time_t, long);
	extern int		tmxsleep(Time_t);
	extern Time_t		tmxtime(Tm_t*, int);
	extern Tm_t*		tmxtm(Tm_t*, Time_t, Tm_zone_t*);

	extern Time_t		tmxgettime(void);
	extern int		tmxsettime(Time_t);

	extern int		tmxtouch(const char*, Time_t, Time_t, Time_t, int);

	extern char*		fmttmx(const char*, Time_t);

	#undef	extern
}end