pacemaker  2.0.4-2deceaa
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
portability.h
Go to the documentation of this file.
1 /*
2  * Copyright 2001-2018 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 # include <config.h>
23 # endif
24 
25 /* Prototypes for libreplace functions */
26 
27 # ifndef HAVE_DAEMON
28  /* We supply a replacement function, but need a prototype */
29 int daemon(int nochdir, int noclose);
30 # endif /* HAVE_DAEMON */
31 
32 # ifndef HAVE_SETENV
33  /* We supply a replacement function, but need a prototype */
34 int setenv(const char *name, const char *value, int why);
35 # endif /* HAVE_SETENV */
36 
37 # ifndef HAVE_STRERROR
38  /* We supply a replacement function, but need a prototype */
39 char *strerror(int errnum);
40 # endif /* HAVE_STRERROR */
41 
42 # ifndef HAVE_STRCHRNUL
43  /* We supply a replacement function, but need a prototype */
44 char *strchrnul(const char *s, int c_in);
45 # endif /* HAVE_STRCHRNUL */
46 
47 # ifndef HAVE_ALPHASORT
48 # include <dirent.h>
49 int
50  alphasort(const void *dirent1, const void *dirent2);
51 # endif /* HAVE_ALPHASORT */
52 
53 # ifndef HAVE_STRNLEN
54 size_t strnlen(const char *s, size_t maxlen);
55 # else
56 # define USE_GNU
57 # endif
58 
59 # ifndef HAVE_STRNDUP
60 char *strndup(const char *str, size_t len);
61 # else
62 # define USE_GNU
63 # endif
64 
65 // This test could be better, but it covers platforms of interest
66 # if defined(ON_BSD) || defined(ON_SOLARIS)
67 # define SUPPORT_PROCFS 0
68 # else
69 # define SUPPORT_PROCFS 1
70 # endif
71 
72 # include <glib.h>
73 
74 # if !GLIB_CHECK_VERSION(2,28,0)
75 # include <string.h>
76 /* Since: 2.28 */
77 static inline void
78 g_list_free_full(GList * list, GDestroyNotify free_func)
79 {
80  g_list_foreach(list, (GFunc) free_func, NULL);
81  g_list_free(list);
82 }
83 # endif
84 
85 # if SUPPORT_DBUS
86 # ifndef HAVE_DBUSBASICVALUE
87 # include <stdint.h>
88 # include <dbus/dbus.h>
93 typedef struct
94 {
95  uint32_t first32;
96  uint32_t second32;
97 } DBus8ByteStruct;
98 
109 typedef union
110 {
111  unsigned char bytes[8];
112  int16_t i16;
113  uint16_t u16;
114  int32_t i32;
115  uint32_t u32;
116  uint32_t bool_val;
117 # ifdef DBUS_HAVE_INT64
118  int64_t i64;
119  uint64_t u64;
120 # endif
121  DBus8ByteStruct eight;
122  double dbl;
123  unsigned char byt;
124  char *str;
125  int fd;
126 } DBusBasicValue;
127 # endif
128 # endif
129 
130 /* Replacement error codes for non-linux */
131 # include <errno.h>
132 
133 # ifndef ENOTUNIQ
134 # define ENOTUNIQ 190
135 # endif
136 
137 # ifndef ECOMM
138 # define ECOMM 191
139 # endif
140 
141 # ifndef ELIBACC
142 # define ELIBACC 192
143 # endif
144 
145 # ifndef EREMOTEIO
146 # define EREMOTEIO 193
147 # endif
148 
149 # ifndef EUNATCH
150 # define EUNATCH 194
151 # endif
152 
153 # ifndef ENOKEY
154 # define ENOKEY 195
155 # endif
156 
157 # ifndef ENODATA
158 # define ENODATA 196
159 # endif
160 
161 # ifndef ETIME
162 # define ETIME 197
163 # endif
164 
165 # ifndef ENOSR
166 # define ENOSR 198
167 # endif
168 
169 # ifndef ENOSTR
170 # define ENOSTR 199
171 # endif
172 
173 # ifndef EKEYREJECTED
174 # define EKEYREJECTED 200
175 # endif
176 
177 /*
178  * Some compilers (eg. Sun studio) do not define __FUNCTION__
179  */
180 # ifdef __SUNPRO_C
181 # define __FUNCTION__ __func__
182 # endif
183 
184 # ifdef __MY_UNKNOWN_C
185 # define __FUNCTION__ "__FUNCTION__"
186 # endif
187 
188 #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:30