xref: /titanic_52/usr/src/cmd/sendmail/include/sm/time.h (revision 49218d4f8e4d84d1c08aeb267bcf6e451f2056dc)
1*49218d4fSjbeck /*
2*49218d4fSjbeck  * Copyright (c) 2005 Sendmail, Inc. and its suppliers.
3*49218d4fSjbeck  *	All rights reserved.
4*49218d4fSjbeck  *
5*49218d4fSjbeck  * By using this file, you agree to the terms and conditions set
6*49218d4fSjbeck  * forth in the LICENSE file which can be found at the top level of
7*49218d4fSjbeck  * the sendmail distribution.
8*49218d4fSjbeck  *
9*49218d4fSjbeck  *	$Id: time.h,v 1.1 2005/06/14 23:07:19 ca Exp $
10*49218d4fSjbeck  */
11*49218d4fSjbeck 
12*49218d4fSjbeck #pragma ident	"%Z%%M%	%I%	%E% SMI"
13*49218d4fSjbeck 
14*49218d4fSjbeck #ifndef SM_TIME_H
15*49218d4fSjbeck # define SM_TIME_H 1
16*49218d4fSjbeck 
17*49218d4fSjbeck # include <sm/config.h>
18*49218d4fSjbeck 
19*49218d4fSjbeck # include <sys/time.h>
20*49218d4fSjbeck 
21*49218d4fSjbeck /* should be defined in sys/time.h */
22*49218d4fSjbeck #ifndef timersub
23*49218d4fSjbeck # define timersub(tvp, uvp, vvp)					\
24*49218d4fSjbeck 	do								\
25*49218d4fSjbeck 	{								\
26*49218d4fSjbeck 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
27*49218d4fSjbeck 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
28*49218d4fSjbeck 		if ((vvp)->tv_usec < 0)					\
29*49218d4fSjbeck 		{							\
30*49218d4fSjbeck 			(vvp)->tv_sec--;				\
31*49218d4fSjbeck 			(vvp)->tv_usec += 1000000;			\
32*49218d4fSjbeck 		}							\
33*49218d4fSjbeck 	} while (0)
34*49218d4fSjbeck #endif /* !timersub */
35*49218d4fSjbeck 
36*49218d4fSjbeck #ifndef timeradd
37*49218d4fSjbeck # define timeradd(tvp, uvp, vvp)					\
38*49218d4fSjbeck 	do								\
39*49218d4fSjbeck 	{								\
40*49218d4fSjbeck 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
41*49218d4fSjbeck 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
42*49218d4fSjbeck 		if ((vvp)->tv_usec >= 1000000)				\
43*49218d4fSjbeck 		{							\
44*49218d4fSjbeck 			(vvp)->tv_sec++;				\
45*49218d4fSjbeck 			(vvp)->tv_usec -= 1000000;			\
46*49218d4fSjbeck 		}							\
47*49218d4fSjbeck 	} while (0)
48*49218d4fSjbeck #endif /* !timeradd */
49*49218d4fSjbeck 
50*49218d4fSjbeck #ifndef timercmp
51*49218d4fSjbeck # define timercmp(tvp, uvp, cmp)					\
52*49218d4fSjbeck 	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
53*49218d4fSjbeck 	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
54*49218d4fSjbeck 	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
55*49218d4fSjbeck #endif /* !timercmp */
56*49218d4fSjbeck 
57*49218d4fSjbeck 
58*49218d4fSjbeck #endif /* ! SM_TIME_H */
59