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