xref: /titanic_44/usr/src/lib/libast/common/features/tmx (revision db8b037b5616a366b7dfdc01ef9552f02f9adfdd)
1set	prototyped
2set	explicit
3iff	TMX
4
5cat{
6	/*
7	 * AT&T Research
8	 *
9	 * high resolution Time_t support
10	 */
11
12	#include <tm.h>
13	#include <tv.h>
14}end
15
16inc	FEATURE/common
17
18if ( _ast_int8_t ) {
19	#define TMX_MAXDATE	"2554-07-21+23:34:33.709551614 UTC"
20	#define TMX_MAXYEAR	2554
21	#define TMX_MAXSEC	((Time_t)18446744073)
22	#define TMX_MAXNSEC	709551614
23	#define TMX_RESOLUTION	1000000000
24
25	typedef uint64_t Time_t;
26	typedef uint64_t Tmxsec_t;
27	typedef uint32_t Tmxnsec_t;
28
29	#define tmxsec(t)	((Tmxsec_t)((t)/1000000000))
30	#define tmxnsec(t)	((Tmxnsec_t)((t)%1000000000))
31	#define tmxsns(s,n)	(((((Time_t)(s))*1000000000))+((Time_t)(n)))
32}
33elif ( _ast_flt8_t ) {
34	#define TMX_FLOAT	1
35	#define TMX_MAXDATE	"2106-02-07+06:28:15.999 UTC"
36	#define TMX_MAXYEAR	2106
37	#define TMX_MAXSEC	0xffffffffL
38	#define TMX_MAXNSEC	999000000L
39	#define TMX_RESOLUTION	1000
40
41	typedef _ast_flt8_t Time_t;
42	typedef uint32_t Tmxsec_t;
43	typedef uint32_t Tmxnsec_t;
44
45	#define tmxsec(t)	((Tmxsec_t)(t))
46	#define tmxnsec(t)	(((Tmxnsec_t)(((t)-((uint32_t)(t))+0.0000005)*1000L))*1000000L)
47	#define tmxsns(s,n)	(((Time_t)(s))+((((uint32_t)(n))/1000L)/1e6))
48}
49else {
50	#define TMX_MAXDATE	"2106-02-07+06:28:14 UTC"
51	#define TMX_MAXYEAR	2106
52	#define TMX_MAXSEC	0xfffffffeL
53	#define TMX_MAXNSEC	0L
54	#define TMX_RESOLUTION	1
55
56	typedef uint32_t Time_t;
57	typedef uint32_t Tmxsec_t;
58	typedef uint32_t Tmxnsec_t;
59
60	#define tmxsec(t)	((Tmxsec_t)(t))
61	#define tmxnsec(t)	(0)
62	#define tmxsns(s,n)	((Time_t)(s))
63}
64endif
65
66cat{
67	#define TMX_NOTIME	((Time_t)(-1))
68	#define TMX_NOW		tmxgettime()
69	#define TMX_MAXTIME	tmxsns(TMX_MAXSEC,TMX_MAXNSEC)
70
71	#define tmx2tv(t,v)	((v)->tv_nsec=tmxnsec(t),(v)->tv_sec=tmxsec(t))
72	#define tv2tmx(v)	tmxsns((v)->tv_sec,(v)->tv_nsec)
73
74	#define tmxclock(p)	tmxsns(((p)?*(p):time(NiL)),0)
75
76	#define tmxgetatime(s)	tmxsns((s)->st_atime,ST_ATIME_NSEC_GET(s))
77	#define tmxgetctime(s)	tmxsns((s)->st_ctime,ST_CTIME_NSEC_GET(s))
78	#define tmxgetmtime(s)	tmxsns((s)->st_mtime,ST_MTIME_NSEC_GET(s))
79
80	#define tmxsetatime(s,t) ((s)->st_atime=tmxsec(t),ST_ATIME_NSEC_SET(s,tmxnsec(t)))
81	#define tmxsetctime(s,t) ((s)->st_ctime=tmxsec(t),ST_CTIME_NSEC_SET(s,tmxnsec(t)))
82	#define tmxsetmtime(s,t) ((s)->st_mtime=tmxsec(t),ST_MTIME_NSEC_SET(s,tmxnsec(t)))
83
84	#if _BLD_ast && defined(__EXPORT__)
85	#define extern		__EXPORT__
86	#endif
87
88	extern Time_t		tmxdate(const char*, char**, Time_t);
89	extern Time_t		tmxduration(const char*, char**);
90	extern char*		tmxfmt(char*, size_t, const char*, Time_t);
91	extern Time_t		tmxleap(Time_t);
92	extern Tm_t*		tmxmake(Time_t);
93	extern Time_t		tmxscan(const char*, char**, const char*, char**, Time_t, long);
94	extern int		tmxsleep(Time_t);
95	extern Time_t		tmxtime(Tm_t*, int);
96	extern Tm_t*		tmxtm(Tm_t*, Time_t, Tm_zone_t*);
97
98	extern Time_t		tmxgettime(void);
99	extern int		tmxsettime(Time_t);
100
101	extern int		tmxtouch(const char*, Time_t, Time_t, Time_t, int);
102
103	extern char*		fmttmx(const char*, Time_t);
104
105	#undef	extern
106}end
107