1 | /* |
---|
2 | * dhcpcd - DHCP client daemon |
---|
3 | * Copyright (c) 2006-2013 Roy Marples <roy@marples.name> |
---|
4 | * All rights reserved |
---|
5 | |
---|
6 | * Redistribution and use in source and binary forms, with or without |
---|
7 | * modification, are permitted provided that the following conditions |
---|
8 | * are met: |
---|
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. |
---|
14 | * |
---|
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 |
---|
25 | * SUCH DAMAGE. |
---|
26 | */ |
---|
27 | |
---|
28 | #ifndef COMMON_H |
---|
29 | #define COMMON_H |
---|
30 | |
---|
31 | #include <sys/time.h> |
---|
32 | #include <stdio.h> |
---|
33 | |
---|
34 | #include "config.h" |
---|
35 | #include "defs.h" |
---|
36 | |
---|
37 | #ifndef HOSTNAME_MAX_LEN |
---|
38 | #define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */ |
---|
39 | #endif |
---|
40 | |
---|
41 | #define UNCONST(a) ((void *)(unsigned long)(const void *)(a)) |
---|
42 | #define STRINGIFY(a) #a |
---|
43 | #define TOSTRING(a) STRINGIFY(a) |
---|
44 | |
---|
45 | #define timeval_to_double(tv) ((tv)->tv_sec * 1.0 + (tv)->tv_usec * 1.0e-6) |
---|
46 | #define timernorm(tv) do { \ |
---|
47 | while ((tv)->tv_usec >= 1000000) { \ |
---|
48 | (tv)->tv_sec++; \ |
---|
49 | (tv)->tv_usec -= 1000000; \ |
---|
50 | } \ |
---|
51 | } while (0 /* CONSTCOND */); |
---|
52 | #define tv_to_ms(ms, tv) do { \ |
---|
53 | ms = (tv)->tv_sec * 1000; \ |
---|
54 | ms += (tv)->tv_usec / 1000; \ |
---|
55 | } while (0 /* CONSTCOND */); |
---|
56 | #define ms_to_tv(tv, ms) do { \ |
---|
57 | (tv)->tv_sec = ms / 1000; \ |
---|
58 | (tv)->tv_usec = (ms - ((tv)->tv_sec * 1000)) * 1000; \ |
---|
59 | } while (0 /* CONSTCOND */); |
---|
60 | |
---|
61 | #ifndef TIMEVAL_TO_TIMESPEC |
---|
62 | #define TIMEVAL_TO_TIMESPEC(tv, ts) do { \ |
---|
63 | (ts)->tv_sec = (tv)->tv_sec; \ |
---|
64 | (ts)->tv_nsec = (tv)->tv_usec * 1000; \ |
---|
65 | } while (0 /* CONSTCOND */) |
---|
66 | #endif |
---|
67 | |
---|
68 | #if __GNUC__ > 2 || defined(__INTEL_COMPILER) |
---|
69 | # ifndef __dead |
---|
70 | # define __dead __attribute__((__noreturn__)) |
---|
71 | # endif |
---|
72 | # ifndef __packed |
---|
73 | # define __packed __attribute__((__packed__)) |
---|
74 | # endif |
---|
75 | # ifndef __unused |
---|
76 | # define __unused __attribute__((__unused__)) |
---|
77 | # endif |
---|
78 | #else |
---|
79 | # ifndef __dead |
---|
80 | # define __dead |
---|
81 | # endif |
---|
82 | # ifndef __packed |
---|
83 | # define __packed |
---|
84 | # endif |
---|
85 | # ifndef __unused |
---|
86 | # define __unused |
---|
87 | # endif |
---|
88 | #endif |
---|
89 | |
---|
90 | /* We don't really need this as our supported systems define __restrict |
---|
91 | * automatically for us, but it is here for completeness. */ |
---|
92 | #ifndef __restrict |
---|
93 | # if defined(__lint__) |
---|
94 | # define __restrict |
---|
95 | # elif __STDC_VERSION__ >= 199901L |
---|
96 | # define __restrict restrict |
---|
97 | # elif !(2 < __GNUC__ || (2 == __GNU_C && 95 <= __GNUC_VERSION__)) |
---|
98 | # define __restrict |
---|
99 | # endif |
---|
100 | #endif |
---|
101 | |
---|
102 | int set_cloexec(int); |
---|
103 | int set_nonblock(int); |
---|
104 | char *get_line(FILE * __restrict); |
---|
105 | const char *get_hostname(int); |
---|
106 | extern int clock_monotonic; |
---|
107 | int get_monotonic(struct timeval *); |
---|
108 | ssize_t setvar(char ***, const char *, const char *, const char *); |
---|
109 | ssize_t setvard(char ***, const char *, const char *, int); |
---|
110 | time_t uptime(void); |
---|
111 | int writepid(int, pid_t); |
---|
112 | |
---|
113 | #endif |
---|