pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
portability.h
Go to the documentation of this file.
1 /*
2  * Copyright 2001-2020 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 #ifndef PORTABILITY_H
10 # define PORTABILITY_H
11 
12 # define EOS '\0'
13 # define DIMOF(a) ((int) (sizeof(a)/sizeof(a[0])) )
14 
15 /* Needs to be defined before any other includes, otherwise some system
16  * headers do not behave as expected! Major black magic... */
17 # undef _GNU_SOURCE /* in case it was defined on the command line */
18 # define _GNU_SOURCE
19 
20 /* Please leave this as the first #include - Solaris needs it there */
21 # ifdef HAVE_CONFIG_H
22 # ifndef PCMK__CONFIG_H
23 # define PCMK__CONFIG_H
24 # include <config.h>
25 # endif
26 # endif
27 
28 /* Prototypes for libreplace functions */
29 
30 # ifndef HAVE_DAEMON
31  /* We supply a replacement function, but need a prototype */
32 int daemon(int nochdir, int noclose);
33 # endif /* HAVE_DAEMON */
34 
35 # ifndef HAVE_SETENV
36  /* We supply a replacement function, but need a prototype */
37 int setenv(const char *name, const char *value, int why);
38 # endif /* HAVE_SETENV */
39 
40 # ifndef HAVE_STRERROR
41  /* We supply a replacement function, but need a prototype */
42 char *strerror(int errnum);
43 # endif /* HAVE_STRERROR */
44 
45 # ifndef HAVE_STRCHRNUL
46  /* We supply a replacement function, but need a prototype */
47 char *strchrnul(const char *s, int c_in);
48 # endif /* HAVE_STRCHRNUL */
49 
50 # ifndef HAVE_ALPHASORT
51 # include <dirent.h>
52 int
53  alphasort(const void *dirent1, const void *dirent2);
54 # endif /* HAVE_ALPHASORT */
55 
56 # ifndef HAVE_STRNLEN
57 size_t strnlen(const char *s, size_t maxlen);
58 # else
59 # define USE_GNU
60 # endif
61 
62 # ifndef HAVE_STRNDUP
63 char *strndup(const char *str, size_t len);
64 # else
65 # define USE_GNU
66 # endif
67 
68 // This test could be better, but it covers platforms of interest
69 # if defined(ON_BSD) || defined(ON_SOLARIS)
70 # define SUPPORT_PROCFS 0
71 # else
72 # define SUPPORT_PROCFS 1
73 # endif
74 
75 # include <glib.h>
76 
77 # if !GLIB_CHECK_VERSION(2,28,0)
78 # include <string.h>
79 /* Since: 2.28 */
80 static inline void
81 g_list_free_full(GList * list, GDestroyNotify free_func)
82 {
83  g_list_foreach(list, (GFunc) free_func, NULL);
84  g_list_free(list);
85 }
86 # endif
87 
88 # if SUPPORT_DBUS
89 # ifndef HAVE_DBUSBASICVALUE
90 # include <stdint.h>
91 # include <dbus/dbus.h>
96 typedef struct
97 {
98  uint32_t first32;
99  uint32_t second32;
100 } DBus8ByteStruct;
101 
112 typedef union
113 {
114  unsigned char bytes[8];
115  int16_t i16;
116  uint16_t u16;
117  int32_t i32;
118  uint32_t u32;
119  uint32_t bool_val;
120 # ifdef DBUS_HAVE_INT64
121  int64_t i64;
122  uint64_t u64;
123 # endif
124  DBus8ByteStruct eight;
125  double dbl;
126  unsigned char byt;
127  char *str;
128  int fd;
129 } DBusBasicValue;
130 # endif
131 # endif
132 
133 /* Replacement error codes for non-linux */
134 # include <errno.h>
135 
136 # ifndef ENOTUNIQ
137 # define ENOTUNIQ 190
138 # endif
139 
140 # ifndef ECOMM
141 # define ECOMM 191
142 # endif
143 
144 # ifndef ELIBACC
145 # define ELIBACC 192
146 # endif
147 
148 # ifndef EREMOTEIO
149 # define EREMOTEIO 193
150 # endif
151 
152 # ifndef EUNATCH
153 # define EUNATCH 194
154 # endif
155 
156 # ifndef ENOKEY
157 # define ENOKEY 195
158 # endif
159 
160 # ifndef ENODATA
161 # define ENODATA 196
162 # endif
163 
164 # ifndef ETIME
165 # define ETIME 197
166 # endif
167 
168 # ifndef ENOSR
169 # define ENOSR 198
170 # endif
171 
172 # ifndef ENOSTR
173 # define ENOSTR 199
174 # endif
175 
176 # ifndef EKEYREJECTED
177 # define EKEYREJECTED 200
178 # endif
179 
180 #endif /* PORTABILITY_H */
int alphasort(const void *dirent1, const void *dirent2)
char * strerror(int errnum)
char * strndup(const char *str, size_t len)
int daemon(int nochdir, int noclose)
int setenv(const char *name, const char *value, int why)
size_t strnlen(const char *s, size_t maxlen)
char * strchrnul(const char *s, int c_in)
char * name
Definition: pcmk_fence.c:31