2 * dhcpcd - DHCP client daemon
3 * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #define USEC_PER_SEC 1000000L
36 #define USEC_PER_NSEC 1000L
37 #define NSEC_PER_SEC 1000000000L
38 #define MSEC_PER_SEC 1000L
39 #define MSEC_PER_NSEC 1000000L
41 /* Some systems don't define timespec macros */
43 #define timespecclear(tsp) (tsp)->tv_sec = (time_t)((tsp)->tv_nsec = 0L)
44 #define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
45 #define timespeccmp(tsp, usp, cmp) \
46 (((tsp)->tv_sec == (usp)->tv_sec) ? \
47 ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
48 ((tsp)->tv_sec cmp (usp)->tv_sec))
49 #define timespecadd(tsp, usp, vsp) \
51 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
52 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
53 if ((vsp)->tv_nsec >= 1000000000L) { \
55 (vsp)->tv_nsec -= 1000000000L; \
57 } while (/* CONSTCOND */ 0)
58 #define timespecsub(tsp, usp, vsp) \
60 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
61 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
62 if ((vsp)->tv_nsec < 0) { \
64 (vsp)->tv_nsec += 1000000000L; \
66 } while (/* CONSTCOND */ 0)
69 #define timespecnorm(tv) do { \
70 while ((tv)->tv_nsec >= NSEC_PER_SEC) { \
72 (tv)->tv_nsec -= NSEC_PER_SEC; \
74 } while (0 /* CONSTCOND */);
76 #if __GNUC__ > 2 || defined(__INTEL_COMPILER)
78 # define __dead __attribute__((__noreturn__))
81 # define __packed __attribute__((__packed__))
84 # define __unused __attribute__((__unused__))