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