xref: /freebsd/contrib/sendmail/include/sm/time.h (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1 /*
2  * Copyright (c) 2005 Proofpoint, 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.2 2013-11-22 20:51:32 ca Exp $
10  */
11 
12 #ifndef SM_TIME_H
13 # define SM_TIME_H 1
14 
15 # include <sm/config.h>
16 # include <sys/time.h>
17 
18 /* should be defined in sys/time.h */
19 #ifndef timersub
20 # define timersub(tvp, uvp, vvp)					\
21 	do								\
22 	{								\
23 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
24 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
25 		if ((vvp)->tv_usec < 0)					\
26 		{							\
27 			(vvp)->tv_sec--;				\
28 			(vvp)->tv_usec += 1000000;			\
29 		}							\
30 	} while (0)
31 #endif /* !timersub */
32 
33 #ifndef timeradd
34 # define timeradd(tvp, uvp, vvp)					\
35 	do								\
36 	{								\
37 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
38 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
39 		if ((vvp)->tv_usec >= 1000000)				\
40 		{							\
41 			(vvp)->tv_sec++;				\
42 			(vvp)->tv_usec -= 1000000;			\
43 		}							\
44 	} while (0)
45 #endif /* !timeradd */
46 
47 #ifndef timercmp
48 # define timercmp(tvp, uvp, cmp)					\
49 	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
50 	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
51 	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
52 #endif /* !timercmp */
53 
54 #endif /* ! SM_TIME_H */
55