E-MailRelay
gdef.h
1/*
2 Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/*
19 * gdef.h
20 */
21
22/* This header is always the first header included in source
23 * files. It takes care of a lot of portability concerns
24 * and it works best when autoconf is used to set GCONFIG
25 * preprocessor switches. Either G_UNIX or G_WINDOWS are expected
26 * to be defined on the compiler command-line.
27 */
28
29#ifndef G_DEF_H
30#define G_DEF_H
31
32 /* Pull in GCONFIG definitions. Uses an odd file name to avoid
33 * picking up a header from some third-party library. If this
34 * file does not exist then there might be a suitable template
35 * file to copy, or just create an empty file and maybe tweak
36 * the values that are defaulted below.
37 */
38 #include <gconfig_defs.h>
39
40 /* Check target operating-system switches
41 */
42 #if !defined(G_WINDOWS) && !defined(G_UNIX)
43 #if defined(_WIN32)
44 #define G_WINDOWS 1
45 #else
46 #define G_UNIX 1
47 #endif
48 #endif
49 #if defined(G_WINDOWS) && defined(G_UNIX)
50 #error invalid compilation switches - define G_WINDOWS or G_UNIX but not both
51 #endif
52
53 /* Define supplementary o/s switches
54 */
55 #if defined(__MINGW32__) && !defined(G_MINGW)
56 /* mingw-w64 */
57 #define G_MINGW 1
58 #endif
59 #if defined(G_MINGW) && !defined(G_WINDOWS)
60 #error invalid compilation switches - G_MINGW requires G_WINDOWS
61 #endif
62 #if defined(__NetBSD__)
63 #define G_UNIX_BSD 1
64 #define G_UNIX_NETBSD 1
65 #endif
66 #if defined(__OpenBSD__)
67 #define G_UNIX_BSD 1
68 #define G_UNIX_OPENBSD 1
69 #endif
70 #if defined(__FreeBSD__)
71 #define G_UNIX_BSD 1
72 #define G_UNIX_FREEBSD 1
73 #endif
74 #if defined(__APPLE__)
75 #define G_UNIX_BSD 1
76 #define G_UNIX_MAC 1
77 #endif
78 #if defined(linux) || defined(__linux__)
79 #define G_UNIX_LINUX 1
80 #endif
81
82 /* Define the compiler c++ dialect
83 */
84 #define G_COMPILER_CXX_11 1
85
86 /* Apply GCONFIG defaults in case of no autoconf
87 */
88 #if !defined(GCONFIG_HAVE_CXX_NULLPTR)
89 #define GCONFIG_HAVE_CXX_NULLPTR 1
90 #endif
91 #if !defined(GCONFIG_HAVE_CXX_CONSTEXPR)
92 #define GCONFIG_HAVE_CXX_CONSTEXPR 1
93 #endif
94 #if !defined(GCONFIG_HAVE_CXX_ENUM_CLASS)
95 #define GCONFIG_HAVE_CXX_ENUM_CLASS 1
96 #endif
97 #if !defined(GCONFIG_HAVE_CXX_NOEXCEPT)
98 #define GCONFIG_HAVE_CXX_NOEXCEPT 1
99 #endif
100 #if !defined(GCONFIG_HAVE_CXX_OVERRIDE)
101 #define GCONFIG_HAVE_CXX_OVERRIDE 1
102 #endif
103 #if !defined(GCONFIG_HAVE_CXX_FINAL)
104 #define GCONFIG_HAVE_CXX_FINAL 1
105 #endif
106 #if !defined(GCONFIG_HAVE_CXX_ALIGNMENT)
107 #define GCONFIG_HAVE_CXX_ALIGNMENT 1
108 #endif
109 #if !defined(GCONFIG_HAVE_CXX_SHARED_PTR)
110 #define GCONFIG_HAVE_CXX_SHARED_PTR 1
111 #endif
112 #if !defined(GCONFIG_HAVE_CXX_STD_THREAD)
113 #define GCONFIG_HAVE_CXX_STD_THREAD 1
114 #endif
115 #if !defined(GCONFIG_HAVE_CXX_TYPE_TRAITS_MAKE_UNSIGNED)
116 #define GCONFIG_HAVE_CXX_TYPE_TRAITS_MAKE_UNSIGNED 1
117 #endif
118 #if !defined(GCONFIG_HAVE_CXX_EMPLACE)
119 #define GCONFIG_HAVE_CXX_EMPLACE 1
120 #endif
121 #if !defined(GCONFIG_HAVE_CXX_MOVE)
122 #define GCONFIG_HAVE_CXX_MOVE 1
123 #endif
124 #if !defined(GCONFIG_HAVE_CXX_DELETED)
125 #define GCONFIG_HAVE_CXX_DELETED 1
126 #endif
127 #if !defined(GCONFIG_HAVE_CXX_DEFAULTED)
128 #define GCONFIG_HAVE_CXX_DEFAULTED
129 #endif
130 #if !defined(GCONFIG_HAVE_CXX_INITIALIZER_LIST)
131 #define GCONFIG_HAVE_CXX_INITIALIZER_LIST 1
132 #endif
133 #if !defined(GCONFIG_HAVE_CXX_STD_WSTRING)
134 #define GCONFIG_HAVE_CXX_STD_WSTRING 1
135 #endif
136 #if !defined(GCONFIG_HAVE_CXX_STD_MAKE_UNIQUE)
137 #if defined(_MSC_VER)
138 #define GCONFIG_HAVE_CXX_STD_MAKE_UNIQUE 1
139 #else
140 #if __cplusplus >= 201400L
141 #define GCONFIG_HAVE_CXX_STD_MAKE_UNIQUE 1
142 #else
143 #define GCONFIG_HAVE_CXX_STD_MAKE_UNIQUE 0
144 #endif
145 #endif
146 #endif
147 #if !defined(GCONFIG_HAVE_SYS_UTSNAME_H)
148 #ifdef G_UNIX
149 #define GCONFIG_HAVE_SYS_UTSNAME_H 1
150 #else
151 #define GCONFIG_HAVE_SYS_UTSNAME_H 0
152 #endif
153 #endif
154 #if !defined(GCONFIG_HAVE_SYS_SELECT_H)
155 #ifdef G_UNIX
156 #define GCONFIG_HAVE_SYS_SELECT_H 1
157 #else
158 #define GCONFIG_HAVE_SYS_SELECT_H 0
159 #endif
160 #endif
161 #if !defined(GCONFIG_HAVE_SYS_SOCKET_H)
162 #ifdef G_UNIX
163 #define GCONFIG_HAVE_SYS_SOCKET_H 1
164 #else
165 #define GCONFIG_HAVE_SYS_SOCKET_H 0
166 #endif
167 #endif
168 #if !defined(GCONFIG_HAVE_SYS_MMAN_H)
169 #ifdef G_UNIX
170 #define GCONFIG_HAVE_SYS_MMAN_H 1
171 #else
172 #define GCONFIG_HAVE_SYS_MMAN_H 0
173 #endif
174 #endif
175 #if !defined(GCONFIG_HAVE_NETINET_IN_H)
176 #ifdef G_UNIX
177 #define GCONFIG_HAVE_NETINET_IN_H 1
178 #else
179 #define GCONFIG_HAVE_NETINET_IN_H 0
180 #endif
181 #endif
182 #if !defined(GCONFIG_HAVE_NETDB_H)
183 #ifdef G_UNIX
184 #define GCONFIG_HAVE_NETDB_H 1
185 #else
186 #define GCONFIG_HAVE_NETDB_H 0
187 #endif
188 #endif
189 #if !defined(GCONFIG_HAVE_ARPA_INET_H)
190 #ifdef G_UNIX
191 #define GCONFIG_HAVE_ARPA_INET_H 1
192 #else
193 #define GCONFIG_HAVE_ARPA_INET_H 0
194 #endif
195 #endif
196 #if !defined(GCONFIG_HAVE_LONG_LONG)
197 #define GCONFIG_HAVE_LONG_LONG 1
198 #endif
199 #if !defined(GCONFIG_HAVE_LONG_LONG_LONG)
200 /* "long long" is longer than "long" */
201 #define GCONFIG_HAVE_LONG_LONG_LONG 0
202 #endif
203 #if !defined(GCONFIG_HAVE_STDINT_H)
204 #define GCONFIG_HAVE_STDINT_H 1
205 #endif
206 #if !defined(GCONFIG_HAVE_INTTYPES_H)
207 #define GCONFIG_HAVE_INTTYPES_H 1
208 #endif
209 #if !defined(GCONFIG_HAVE_INT64)
210 #define GCONFIG_HAVE_INT64 1
211 #endif
212 #if !defined(GCONFIG_HAVE_INT32)
213 #define GCONFIG_HAVE_INT32 1
214 #endif
215 #if !defined(GCONFIG_HAVE_INT16)
216 #define GCONFIG_HAVE_INT16 1
217 #endif
218 #if !defined(GCONFIG_HAVE_DIRENT_H)
219 #define GCONFIG_HAVE_DIRENT_H 1
220 #endif
221 #if !defined(GCONFIG_HAVE_READLINK)
222 #ifdef G_UNIX
223 #define GCONFIG_HAVE_READLINK 1
224 #else
225 #define GCONFIG_HAVE_READLINK 0
226 #endif
227 #endif
228 #if !defined(GCONFIG_HAVE_ERRNO_T)
229 #ifdef G_WINDOWS
230 #define GCONFIG_HAVE_ERRNO_T 1
231 #else
232 #define GCONFIG_HAVE_ERRNO_T 0
233 #endif
234 #endif
235 #if !defined(GCONFIG_HAVE_GETENV_S)
236 #if ( defined(G_WINDOWS) && !defined(G_MINGW) ) || defined(getenv_s)
237 #define GCONFIG_HAVE_GETENV_S 1
238 #else
239 #define GCONFIG_HAVE_GETENV_S 0
240 #endif
241 #endif
242 #if !defined(GCONFIG_HAVE_PUTENV_S)
243 #if ( defined(G_WINDOWS) && !defined(G_MINGW) ) || defined(putenv_s)
244 #define GCONFIG_HAVE_PUTENV_S 1
245 #else
246 #define GCONFIG_HAVE_PUTENV_S 0
247 #endif
248 #endif
249 #if !defined(GCONFIG_HAVE_PUTENV)
250 #define GCONFIG_HAVE_PUTENV 1
251 #endif
252 #if !defined(GCONFIG_HAVE_GETPWNAM)
253 #define GCONFIG_HAVE_GETPWNAM 1
254 #endif
255 #if !defined(GCONFIG_HAVE_GETPWNAM_R)
256 #define GCONFIG_HAVE_GETPWNAM_R 1
257 #endif
258 #if !defined(GCONFIG_HAVE_GETGRNAM)
259 #define GCONFIG_HAVE_GETGRNAM 1
260 #endif
261 #if !defined(GCONFIG_HAVE_GETGRNAM_R)
262 #define GCONFIG_HAVE_GETGRNAM_R 1
263 #endif
264 #if !defined(GCONFIG_HAVE_GMTIME_R)
265 #if defined(G_WINDOWS) && !defined(gmtime_r)
266 #define GCONFIG_HAVE_GMTIME_R 0
267 #else
268 #define GCONFIG_HAVE_GMTIME_R 1
269 #endif
270 #endif
271 #if !defined(GCONFIG_HAVE_GMTIME_S)
272 #if defined(G_WINDOWS) || defined(gmtime_s)
273 #define GCONFIG_HAVE_GMTIME_S 1
274 #else
275 #define GCONFIG_HAVE_GMTIME_S 0
276 #endif
277 #endif
278 #if !defined(GCONFIG_HAVE_IPV6)
279 #define GCONFIG_HAVE_IPV6 1
280 #endif
281 #if !defined(GCONFIG_HAVE_EXECVPE)
282 #ifdef G_UNIX_LINUX
283 #define GCONFIG_HAVE_EXECVPE 1
284 #else
285 #define GCONFIG_HAVE_EXECVPE 0
286 #endif
287 #endif
288 #if !defined(GCONFIG_HAVE_RTNETLINK)
289 #ifdef G_UNIX_LINUX
290 #define GCONFIG_HAVE_RTNETLINK 1
291 #else
292 #define GCONFIG_HAVE_RTNETLINK 0
293 #endif
294 #endif
295 #if !defined(GCONFIG_HAVE_NETROUTE)
296 #ifdef G_UNIX_BSD
297 #define GCONFIG_HAVE_NETROUTE 1
298 #else
299 #define GCONFIG_HAVE_NETROUTE 0
300 #endif
301 #endif
302 #if !defined(GCONFIG_HAVE_LOCALTIME_R)
303 #if defined(G_WINDOWS) && !defined(localtime_r)
304 #define GCONFIG_HAVE_LOCALTIME_R 0
305 #else
306 #define GCONFIG_HAVE_LOCALTIME_R 1
307 #endif
308 #endif
309 #if !defined(GCONFIG_HAVE_LOCALTIME_S)
310 #if defined(G_WINDOWS) || defined(localtime_s)
311 #define GCONFIG_HAVE_LOCALTIME_S 1
312 #else
313 #define GCONFIG_HAVE_LOCALTIME_S 0
314 #endif
315 #endif
316 #if !defined(GCONFIG_HAVE_MEMORY_H)
317 #define GCONFIG_HAVE_MEMORY_H 1
318 #endif
319 #if !defined(GCONFIG_HAVE_SETPGRP_BSD)
320 #if defined(G_UNIX_LINUX) || defined(G_UNIX_MAC)
321 #define GCONFIG_HAVE_SETPGRP_BSD 0
322 #else
323 #define GCONFIG_HAVE_SETPGRP_BSD 1
324 #endif
325 #endif
326 #if !defined(GCONFIG_HAVE_SETGROUPS)
327 #ifdef G_UNIX
328 #define GCONFIG_HAVE_SETGROUPS 1
329 #else
330 #define GCONFIG_HAVE_SETGROUPS 0
331 #endif
332 #endif
333 #if !defined(GCONFIG_HAVE_STATBUF_TIMESPEC)
334 #if defined(G_UNIX_MAC)
335 #define GCONFIG_HAVE_STATBUF_TIMESPEC 1
336 #else
337 #define GCONFIG_HAVE_STATBUF_TIMESPEC 0
338 #endif
339 #endif
340 #if !defined(GCONFIG_HAVE_STATBUF_NSEC)
341 #define GCONFIG_HAVE_STATBUF_NSEC 0
342 #endif
343 #if !defined(GCONFIG_HAVE_SIN6_LEN)
344 #define GCONFIG_HAVE_SIN6_LEN 0
345 #endif
346 #if !defined(GCONFIG_HAVE_SOCKLEN_T)
347 #define GCONFIG_HAVE_SOCKLEN_T 1
348 #endif
349 #if !defined(GCONFIG_HAVE_STDLIB_H)
350 #define GCONFIG_HAVE_STDLIB_H 1
351 #endif
352 #if !defined(GCONFIG_HAVE_STRNCPY_S)
353 #if ( defined(G_WINDOWS) && !defined(G_MINGW) ) || defined(strncpy_s)
354 #define GCONFIG_HAVE_STRNCPY_S 1
355 #else
356 #define GCONFIG_HAVE_STRNCPY_S 0
357 #endif
358 #endif
359 #if !defined(GCONFIG_HAVE_STRINGS_H)
360 #define GCONFIG_HAVE_STRINGS_H 1
361 #endif
362 #if !defined(GCONFIG_HAVE_STRING_H)
363 #define GCONFIG_HAVE_STRING_H 1
364 #endif
365 #if !defined(GCONFIG_HAVE_NDIR_H)
366 #define GCONFIG_HAVE_NDIR_H 0
367 #endif
368 #if !defined(GCONFIG_HAVE_SYS_DIR_H)
369 #define GCONFIG_HAVE_SYS_DIR_H 0
370 #endif
371 #if !defined(GCONFIG_HAVE_SYS_NDIR_H)
372 #define GCONFIG_HAVE_SYS_NDIR_H 0
373 #endif
374 #if !defined(GCONFIG_HAVE_SYS_STAT_H)
375 #define GCONFIG_HAVE_SYS_STAT_H 1
376 #endif
377 #if !defined(GCONFIG_HAVE_SYS_WAIT_H)
378 #ifdef G_UNIX
379 #define GCONFIG_HAVE_SYS_WAIT_H 1
380 #else
381 #define GCONFIG_HAVE_SYS_WAIT_H 0
382 #endif
383 #endif
384 #if !defined(GCONFIG_HAVE_SYS_TIME_H)
385 #define GCONFIG_HAVE_SYS_TIME_H 1
386 #endif
387 #if !defined(GCONFIG_HAVE_SYS_TYPES_H)
388 #define GCONFIG_HAVE_SYS_TYPES_H 1
389 #endif
390 #if !defined(GCONFIG_HAVE_UNISTD_H)
391 #ifdef G_UNIX
392 #define GCONFIG_HAVE_UNISTD_H 1
393 #else
394 #define GCONFIG_HAVE_UNISTD_H 0
395 #endif
396 #endif
397 #if !defined(GCONFIG_HAVE_ERRNO_H)
398 #define GCONFIG_HAVE_ERRNO_H 1
399 #endif
400 #if !defined(GCONFIG_HAVE_NET_IF_H)
401 #ifdef G_UNIX
402 #define GCONFIG_HAVE_NET_IF_H 1
403 #else
404 #define GCONFIG_HAVE_NET_IF_H 0
405 #endif
406 #endif
407 #if !defined(GCONFIG_HAVE_WINDOWS_IPHLPAPI_H)
408 #ifdef G_UNIX
409 #define GCONFIG_HAVE_WINDOWS_IPHLPAPI_H 0
410 #else
411 #define GCONFIG_HAVE_WINDOWS_IPHLPAPI_H 1
412 #endif
413 #endif
414 #if !defined(GCONFIG_HAVE_GAISTRERROR)
415 #define GCONFIG_HAVE_GAISTRERROR 1
416 #endif
417 #if !defined(GCONFIG_HAVE_INET_NTOP)
418 #define GCONFIG_HAVE_INET_NTOP 1
419 #endif
420 #if !defined(GCONFIG_HAVE_IFNAMETOINDEX)
421 #define GCONFIG_HAVE_IFNAMETOINDEX 1
422 #endif
423 #if !defined(GCONFIG_HAVE_IFNAMETOLUID)
424 #ifdef G_UNIX
425 #define GCONFIG_HAVE_IFNAMETOLUID 0
426 #else
427 #define GCONFIG_HAVE_IFNAMETOLUID 1
428 #endif
429 #endif
430 #if !defined(GCONFIG_HAVE_INET_PTON)
431 #define GCONFIG_HAVE_INET_PTON 1
432 #endif
433 #if !defined(GCONFIG_HAVE_UID_T)
434 #ifdef G_UNIX
435 #define GCONFIG_HAVE_UID_T 1
436 #else
437 #define GCONFIG_HAVE_UID_T 0
438 #endif
439 #endif
440 #if !defined(GCONFIG_HAVE_GID_T)
441 #define GCONFIG_HAVE_GID_T GCONFIG_HAVE_UID_T
442 #endif
443 #if !defined(GCONFIG_HAVE_UINTPTR_T)
444 #define GCONFIG_HAVE_UINTPTR_T 0
445 #endif
446 #if !defined(GCONFIG_HAVE_SSIZE_T)
447 #if defined(G_UNIX) || defined(G_MINGW)
448 #define GCONFIG_HAVE_SSIZE_T 1
449 #else
450 #define GCONFIG_HAVE_SSIZE_T 0
451 #endif
452 #endif
453 #if !defined(GCONFIG_HAVE_PID_T)
454 #if defined(G_UNIX) || defined(G_MINGW)
455 #define GCONFIG_HAVE_PID_T 1
456 #else
457 #define GCONFIG_HAVE_PID_T 0
458 #endif
459 #endif
460 #if !defined(GCONFIG_HAVE_GET_WINDOW_LONG_PTR)
461 #ifdef G_WINDOWS
462 #define GCONFIG_HAVE_GET_WINDOW_LONG_PTR 1
463 #else
464 #define GCONFIG_HAVE_GET_WINDOW_LONG_PTR 0
465 #endif
466 #endif
467 #if !defined(GCONFIG_HAVE_MREMAP)
468 #ifdef G_UNIX_LINUX
469 #define GCONFIG_HAVE_MREMAP 1
470 #else
471 #define GCONFIG_HAVE_MREMAP 0
472 #endif
473 #endif
474 #if !defined(GCONFIG_HAVE_TIMERFD)
475 #ifdef G_UNIX_LINUX
476 #define GCONFIG_HAVE_TIMERFD 1
477 #else
478 #define GCONFIG_HAVE_TIMERFD 0
479 #endif
480 #endif
481 #if !defined(GCONFIG_HAVE_PAM)
482 #ifdef G_UNIX
483 #define GCONFIG_HAVE_PAM 1
484 #else
485 #define GCONFIG_HAVE_PAM 0
486 #endif
487 #endif
488 #if !defined(GCONFIG_HAVE_PAM_IN_SECURITY)
489 #ifdef G_UNIX
490 #define GCONFIG_HAVE_PAM_IN_SECURITY 1
491 #else
492 #define GCONFIG_HAVE_PAM_IN_SECURITY 0
493 #endif
494 #endif
495 #if !defined(GCONFIG_HAVE_PAM_IN_INCLUDE)
496 #define GCONFIG_HAVE_PAM_IN_INCLUDE 0
497 #endif
498 #if !defined(GCONFIG_HAVE_PAM_IN_PAM)
499 #define GCONFIG_HAVE_PAM_IN_PAM 0
500 #endif
501 #if !defined(GCONFIG_PAM_CONST)
502 #if defined(G_UNIX_LINUX) || defined(G_UNIX_BSD)
503 #define GCONFIG_PAM_CONST 1
504 #else
505 #define GCONFIG_PAM_CONST 0
506 #endif
507 #endif
508 #if !defined(GCONFIG_HAVE_GET_NATIVE_SYSTEM_INFO)
509 #ifdef G_WINDOWS
510 #define GCONFIG_HAVE_GET_NATIVE_SYSTEM_INFO 1
511 #else
512 #define GCONFIG_HAVE_GET_NATIVE_SYSTEM_INFO 0
513 #endif
514 #endif
515 #if !defined(GCONFIG_HAVE_LIBJPEG)
516 #define GCONFIG_HAVE_LIBJPEG 0
517 #endif
518 #if !defined(GCONFIG_HAVE_LIBPNG)
519 #define GCONFIG_HAVE_LIBPNG 0
520 #endif
521 #if !defined(GCONFIG_HAVE_LIBAV)
522 #define GCONFIG_HAVE_LIBAV 0
523 #endif
524 #if !defined(GCONFIG_HAVE_CURSES)
525 #define GCONFIG_HAVE_CURSES 0
526 #endif
527 #if !defined(GCONFIG_HAVE_LIBEXIV)
528 #define GCONFIG_HAVE_LIBEXIV 0
529 #endif
530 #if !defined(GCONFIG_HAVE_V4L)
531 #ifdef G_UNIX_LINUX
532 #define GCONFIG_HAVE_V4L 1
533 #else
534 #define GCONFIG_HAVE_V4L 0
535 #endif
536 #endif
537 #if !defined(GCONFIG_HAVE_LIBV4L)
538 #define GCONFIG_HAVE_LIBV4L 0
539 #endif
540 #if !defined(GCONFIG_HAVE_GETTEXT)
541 #define GCONFIG_HAVE_GETTEXT 0
542 #endif
543 #if !defined(GCONFIG_ENABLE_IPV6)
544 #define GCONFIG_ENABLE_IPV6 GCONFIG_HAVE_IPV6
545 #endif
546 #if !defined(GCONFIG_ENABLE_STD_THREAD)
547 #define GCONFIG_ENABLE_STD_THREAD 1
548 #endif
549 #if !defined(GCONFIG_HAVE_SEM_INIT)
550 #if defined(G_UNIX_LINUX) || defined(G_UNIX_FREEBSD)
551 #define GCONFIG_HAVE_SEM_INIT 1
552 #else
553 #define GCONFIG_HAVE_SEM_INIT 0
554 #endif
555 #endif
556 #if !defined(GCONFIG_HAVE_X11)
557 #ifdef G_UNIX
558 #define GCONFIG_HAVE_X11 1
559 #else
560 #define GCONFIG_HAVE_X11 0
561 #endif
562 #endif
563 #if !defined(GCONFIG_HAVE_MBEDTLS)
564 #define GCONFIG_HAVE_MBEDTLS 1
565 #endif
566 #if !defined(GCONFIG_HAVE_MBEDTLS_NET_H)
567 #define GCONFIG_HAVE_MBEDTLS_NET_H 0
568 #endif
569 #if !defined(GCONFIG_HAVE_OPENSSL)
570 #ifdef G_UNIX
571 #define GCONFIG_HAVE_OPENSSL 1
572 #else
573 #define GCONFIG_HAVE_OPENSSL 0
574 #endif
575 #endif
576 #if !defined(GCONFIG_HAVE_OPENSSL_MIN_MAX)
577 #define GCONFIG_HAVE_OPENSSL_MIN_MAX 1
578 #endif
579 #if !defined(GCONFIG_HAVE_OPENSSL_SSLv23_METHOD)
580 #define GCONFIG_HAVE_OPENSSL_SSLv23_METHOD 0
581 #endif
582 #if !defined(GCONFIG_HAVE_OPENSSL_SSLv3_METHOD)
583 #define GCONFIG_HAVE_OPENSSL_SSLv3_METHOD 0
584 #endif
585 #if !defined(GCONFIG_HAVE_OPENSSL_TLSv1_1_METHOD)
586 #define GCONFIG_HAVE_OPENSSL_TLSv1_1_METHOD 1
587 #endif
588 #if !defined(GCONFIG_HAVE_OPENSSL_TLSv1_2_METHOD)
589 #define GCONFIG_HAVE_OPENSSL_TLSv1_2_METHOD 1
590 #endif
591 #if !defined(GCONFIG_HAVE_BOOST)
592 #ifdef G_UNIX_LINUX
593 #define GCONFIG_HAVE_BOOST 1
594 #else
595 #define GCONFIG_HAVE_BOOST 0
596 #endif
597 #endif
598 #if !defined(GCONFIG_HAVE_ALSA)
599 #ifdef G_UNIX_LINUX
600 #define GCONFIG_HAVE_ALSA 1
601 #else
602 #define GCONFIG_HAVE_ALSA 0
603 #endif
604 #endif
605 #if !defined(GCONFIG_HAVE_FMEMOPEN)
606 #if !defined(G_UNIX_OPENBSD)
607 #define GCONFIG_HAVE_FMEMOPEN 1
608 #else
609 #define GCONFIG_HAVE_FMEMOPEN 0
610 #endif
611 #endif
612 #if !defined(GCONFIG_HAVE_IP_MREQN)
613 #if defined(G_UNIX_LINUX) || defined(G_UNIX_FREEBSD)
614 #define GCONFIG_HAVE_IP_MREQN 1
615 #else
616 #define GCONFIG_HAVE_IP_MREQN 0
617 #endif
618 #endif
619 #if !defined(GCONFIG_HAVE_EXECVPE)
620 #ifdef G_UNIX_LINUX
621 #define GCONFIG_HAVE_EXECVPE 1
622 #else
623 #define GCONFIG_HAVE_EXECVPE 0
624 #endif
625 #endif
626 #if !defined(GCONFIG_HAVE_WINDOWS_CREATE_WAITABLE_TIMER_EX)
627 #if defined(G_WINDOWS) && !defined(G_MINGW)
628 #define GCONFIG_HAVE_WINDOWS_CREATE_WAITABLE_TIMER_EX 1
629 #else
630 #define GCONFIG_HAVE_WINDOWS_CREATE_WAITABLE_TIMER_EX 0
631 #endif
632 #endif
633 #if !defined(GCONFIG_HAVE_WINDOWS_CREATE_EVENT_EX)
634 #if defined(G_WINDOWS) && !defined(G_MINGW)
635 #define GCONFIG_HAVE_WINDOWS_CREATE_EVENT_EX 1
636 #else
637 #define GCONFIG_HAVE_WINDOWS_CREATE_EVENT_EX 0
638 #endif
639 #endif
640 #if !defined(GCONFIG_HAVE_WINDOWS_INIT_COMMON_CONTROLS_EX)
641 #if defined(G_WINDOWS) && !defined(G_MINGW)
642 #define GCONFIG_HAVE_WINDOWS_INIT_COMMON_CONTROLS_EX 1
643 #else
644 #define GCONFIG_HAVE_WINDOWS_INIT_COMMON_CONTROLS_EX 0
645 #endif
646 #endif
647 #if !defined(GCONFIG_HAVE_WINDOWS_VERSIONHELPERS_H)
648 #if defined(G_WINDOWS)
649 #define GCONFIG_HAVE_WINDOWS_VERSIONHELPERS_H 1
650 #else
651 #define GCONFIG_HAVE_WINDOWS_VERSIONHELPERS_H 0
652 #endif
653 #endif
654 #if !defined(GCONFIG_HAVE_DLOPEN)
655 #ifdef G_UNIX
656 #define GCONFIG_HAVE_DLOPEN 1
657 #else
658 #define GCONFIG_HAVE_DLOPEN 0
659 #endif
660 #endif
661 #if !defined(GCONFIG_HAVE_FSOPEN)
662 #if defined(G_UNIX) || defined(G_MINGW)
663 #define GCONFIG_HAVE_FSOPEN 0
664 #else
665 #define GCONFIG_HAVE_FSOPEN 1
666 #endif
667 #endif
668 #if !defined(GCONFIG_HAVE_SOPEN)
669 #if defined(G_UNIX) || defined(G_MINGW)
670 #define GCONFIG_HAVE_SOPEN 0
671 #else
672 #define GCONFIG_HAVE_SOPEN 1
673 #endif
674 #endif
675 #if !defined(GCONFIG_HAVE_SOPEN_S)
676 #if defined(G_UNIX) || defined(G_MINGW)
677 #define GCONFIG_HAVE_SOPEN_S 0
678 #else
679 #define GCONFIG_HAVE_SOPEN_S 1
680 #endif
681 #endif
682 #if !defined(GCONFIG_HAVE_EXTENDED_OPEN)
683 #if defined(G_UNIX) || defined(G_MINGW)
684 #define GCONFIG_HAVE_EXTENDED_OPEN 0
685 #else
686 #define GCONFIG_HAVE_EXTENDED_OPEN 1
687 #endif
688 #endif
689 #if !defined(GCONFIG_HAVE_SIGPROCMASK)
690 #if defined(G_UNIX)
691 #define GCONFIG_HAVE_SIGPROCMASK 1
692 #else
693 #define GCONFIG_HAVE_SIGPROCMASK 0
694 #endif
695 #endif
696 #if !defined(GCONFIG_HAVE_PTHREAD_SIGMASK)
697 #if defined(G_UNIX)
698 #define GCONFIG_HAVE_PTHREAD_SIGMASK 1
699 #else
700 #define GCONFIG_HAVE_PTHREAD_SIGMASK 0
701 #endif
702 #endif
703 #if !defined(GCONFIG_HAVE_UDS)
704 #ifdef G_UNIX
705 #define GCONFIG_HAVE_UDS 1
706 #else
707 #define GCONFIG_HAVE_UDS 0
708 #endif
709 #endif
710
711 /* Include early o/s headers
712 */
713 #if defined(G_WINDOWS)
714 #ifndef WIN32_LEAN_AND_MEAN
715 #define WIN32_LEAN_AND_MEAN
716 #endif
717 #include <winsock2.h>
718 #include <windows.h>
719 #include <ws2tcpip.h>
720 #if GCONFIG_HAVE_WINDOWS_IPHLPAPI_H
721 #include <iphlpapi.h>
722 #endif
723 #if GCONFIG_HAVE_WINDOWS_VERSIONHELPERS_H
724 #include <versionhelpers.h>
725 #endif
726 #endif
727
728 /* Include commonly-used c++ headers
729 */
730 #ifdef __cplusplus
731 #include <cstddef>
732 #include <cstdlib>
733 #include <ios>
734 #include <iosfwd>
735 #else
736 #include <stddef.h>
737 #include <stdlib.h>
738 #endif
739
740 /* Include main o/s headers
741 */
742 #if defined(G_WINDOWS)
743 #include <shellapi.h>
744 #include <direct.h>
745 #include <share.h>
746 #endif
747 #if GCONFIG_HAVE_SYS_TYPES_H
748 #include <sys/types.h>
749 #endif
750 #if GCONFIG_HAVE_SYS_STAT_H
751 #include <sys/stat.h>
752 #endif
753 #if GCONFIG_HAVE_INTTYPES_H
754 #ifdef __cplusplus
755 #include <cinttypes>
756 #else
757 #include <inttypes.h>
758 #endif
759 #endif
760 #if GCONFIG_HAVE_STDINT_H
761 #ifdef __cplusplus
762 #include <cstdint>
763 #else
764 #include <stdint.h>
765 #endif
766 #endif
767 #if GCONFIG_HAVE_UNISTD_H
768 #include <unistd.h>
769 #endif
770 #if GCONFIG_HAVE_ERRNO_H
771 #ifdef __cplusplus
772 #include <cerrno>
773 #else
774 #include <errno.h>
775 #endif
776 #endif
777 #if GCONFIG_HAVE_SYS_WAIT_H
778 #include <sys/wait.h>
779 #endif
780 #if GCONFIG_HAVE_SYS_UTSNAME_H
781 #include <sys/utsname.h>
782 #endif
783 #if GCONFIG_HAVE_SYS_SELECT_H
784 #include <sys/select.h>
785 #endif
786 #if GCONFIG_HAVE_SYS_SOCKET_H
787 #include <sys/socket.h>
788 #endif
789 #ifndef MSG_NOSIGNAL
790 #define MSG_NOSIGNAL 0
791 #endif
792 #if GCONFIG_HAVE_SYS_MMAN_H
793 #include <sys/mman.h>
794 #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
795 #define MAP_ANONYMOUS MAP_ANON
796 #endif
797 #ifndef MREMAP_MAYMOVE
798 #define MREMAP_MAYMOVE 0
799 #endif
800 #endif
801 #if GCONFIG_HAVE_NETINET_IN_H
802 #include <netinet/in.h>
803 #endif
804 #if GCONFIG_HAVE_NETDB_H
805 #include <netdb.h>
806 #endif
807 #if GCONFIG_HAVE_ARPA_INET_H
808 #include <arpa/inet.h>
809 #endif
810 #if GCONFIG_HAVE_NET_IF_H
811 #include <net/if.h>
812 #endif
813 #if GCONFIG_HAVE_PWD_H
814 #include <pwd.h>
815 #endif
816 #if GCONFIG_HAVE_GRP_H
817 #include <grp.h>
818 #endif
819 #ifndef __cplusplus
820 #include <wchar.h>
821 #endif
822
823 #ifdef __cplusplus
824
825 /* Undefine some unwanted macros
826 */
827 #ifdef max
828 #undef max
829 #endif
830 #ifdef min
831 #undef min
832 #endif
833 #ifdef alignas
834 #undef alignas
835 #endif
836 #ifdef G_WINDOWS
837 #ifdef stdin
838 #undef stdin
839 #endif
840 #ifdef stdout
841 #undef stdout
842 #endif
843 #ifdef stderr
844 #undef stderr
845 #endif
846 #endif
847
848 /* Define a few Windows-style types under unix
849 */
850 #if ! defined(G_WINDOWS)
851 using BOOL = unsigned char ;
852 using HDC = unsigned int ;
853 using HWND = unsigned int ;
854 using HINSTANCE = unsigned int ;
855 using HANDLE = unsigned int ;
856 using TCHAR = wchar_t ;
857 using SOCKET = int ;
858 #endif
859
860 /* Define a null value for opaque pointer types that are
861 * never dereferenced
862 */
863 #define HNULL 0
864
865 /* Define fixed-size types - the underlying types should come
866 * from C99's stdint.h, but they are all optional
867 */
868 #if defined(G_WINDOWS)
869 #if GCONFIG_HAVE_INT64
870 using g_int64_t = INT64 ;
871 using g_uint64_t = UINT64 ;
872 #endif
873 #if GCONFIG_HAVE_INT32
874 using g_int32_t = INT32 ;
875 using g_uint32_t = UINT32 ;
876 #endif
877 #if GCONFIG_HAVE_INT16
878 using g_int16_t = INT16 ;
879 using g_uint16_t = UINT16 ;
880 #endif
881 #else
882 #if GCONFIG_HAVE_INT64
883 using g_int64_t = int64_t ;
884 using g_uint64_t = uint64_t ;
885 #endif
886 #if GCONFIG_HAVE_INT32
887 using g_int32_t = int32_t ;
888 using g_uint32_t = uint32_t ;
889 #endif
890 #if GCONFIG_HAVE_INT16
891 using g_int16_t = int16_t ;
892 using g_uint16_t = uint16_t ;
893 #endif
894 #endif
895 #if GCONFIG_HAVE_UINTPTR_T
896 using g_uintptr_t = uintptr_t ; // uintptr_t in C99 and C++2011
897 #else
898 using g_uintptr_t = std::size_t ; // assumes a non-segmented architecture - see also windows LONG_PTR
899 #endif
900 #if __cplusplus
901 #if GCONFIG_HAVE_INT64
902 static_assert( sizeof(g_int64_t) == 8U , "uint64 wrong size" ) ;
903 static_assert( sizeof(g_uint64_t) == 8U , "int64 wrong size" ) ;
904 #endif
905 #if GCONFIG_HAVE_INT32
906 static_assert( sizeof(g_uint32_t) == 4U , "uint32 wrong size" ) ;
907 static_assert( sizeof(g_int32_t) == 4U , "int32 wrong size" ) ;
908 #endif
909 #if GCONFIG_HAVE_INT16
910 static_assert( sizeof(g_uint16_t) == 2U , "uint16 wrong size" ) ;
911 static_assert( sizeof(g_int16_t) == 2U , "int16 wrong size" ) ;
912 #endif
913 static_assert( sizeof(g_uintptr_t) >= sizeof(void*) , "uintptr_t wrong size; try using g_uintptr_t = unsigned long" ) ;
914 #endif
915
916 /* Define missing standard types
917 */
918 #if ! GCONFIG_HAVE_UID_T
919 using uid_t = int ;
920 #endif
921 #if ! GCONFIG_HAVE_GID_T
922 using gid_t = int ;
923 #endif
924 #if ! GCONFIG_HAVE_SSIZE_T
925 #if defined(SSIZE_T)
926 using ssize_t = SSIZE_T ;
927 #else
928 /* read(2) return type -- 'int' on some unix systems */
929 using ssize_t = int ;
930 #endif
931 #endif
932 #if ! GCONFIG_HAVE_PID_T
933 using pid_t = unsigned int ;
934 #endif
935 #if ! GCONFIG_HAVE_SOCKLEN_T
936 using socklen_t = int ;
937 #endif
938 #if ! GCONFIG_HAVE_ERRNO_T
939 using errno_t = int ; // whatever_s() return type
940 #endif
941
942 /* Attributes
943 */
944 #if __cplusplus >= 201700L
945 #define GDEF_UNUSED [[maybe_unused]]
946 #define GDEF_NORETURN [[noreturn]]
947 #define GDEF_FALLTHROUGH [[fallthrough]]
948 #else
949 #if defined(__GNUC__) || defined(__clang__)
950 #define GDEF_UNUSED __attribute__((__unused__))
951 #define GDEF_NORETURN __attribute__((__noreturn__))
952 #endif
953 #ifdef _MSC_VER
954 // __declspec(noreturn) goes on the lhs
955 #endif
956 #endif
957 #ifndef GDEF_UNUSED
958 #define GDEF_UNUSED
959 #endif
960 #ifndef GDEF_NORETURN
961 #define GDEF_NORETURN
962 #endif
963 #ifndef GDEF_FALLTHROUGH
964 #define GDEF_FALLTHROUGH
965 #endif
966 #ifdef __cplusplus
967 #include <tuple>
968 namespace G { template <typename... T> inline void ignore( T&& ... ) {} }
969 #define GDEF_IGNORE_PARAMS(...) G::ignore(__VA_ARGS__)
970 #define GDEF_IGNORE_RETURN std::ignore =
971 #define GDEF_IGNORE_PARAM(name) std::ignore = name
972 #endif
973
974 /* C++ language backwards compatibility
975 */
976 #if !GCONFIG_HAVE_CXX_STD_MAKE_UNIQUE
977 #include <memory>
978 #include <utility>
979 namespace std // NOLINT
980 {
981 template <typename T, typename... Args>
982 std::unique_ptr<T> make_unique( Args&&... args )
983 {
984 return std::unique_ptr<T>( new T( std::forward<Args>(args)... ) ) ; // NOLINT
985 }
986 }
987 #endif
988
989 /* Threading helper
990 */
991 #if GCONFIG_ENABLE_STD_THREAD
992 #include <thread>
993 #include <mutex>
994 #include <cstring>
995 namespace G
996 {
997 struct threading /// Helper class for std::thread capabilities.
998 {
999 static constexpr bool using_std_thread = true ;
1000 using thread_type = std::thread ;
1001 using mutex_type = std::mutex ;
1002 using lock_type = std::lock_guard<std::mutex> ;
1003 static bool works() ; // run-time test -- see gthread.cpp
1004 static void yield() noexcept { std::this_thread::yield() ; }
1005 } ;
1006 }
1007 #else
1008 namespace G
1009 {
1010 class dummy_thread
1011 {
1012 public:
1013 typedef int id ;
1014 template <typename T_fn> explicit dummy_thread( T_fn fn ) { fn() ; }
1015 template <typename T_fn,typename T_arg1> dummy_thread( T_fn fn , T_arg1 arg1 ) { fn(arg1) ; }
1016 template <typename T_fn,typename T_arg1,typename T_arg2> dummy_thread( T_fn fn , T_arg1 arg1 , T_arg2 arg2 ) { fn(arg1,arg2) ; }
1017 dummy_thread() {}
1018 bool joinable() const noexcept { return false ; }
1019 void detach() {}
1020 void join() {}
1021 id get_id() const { return 0 ; }
1022 } ;
1023 class dummy_mutex {} ;
1024 class dummy_lock { public: explicit dummy_lock( dummy_mutex & ) {} } ;
1025 struct threading
1026 {
1027 static constexpr bool using_std_thread = false ;
1028 using thread_type = G::dummy_thread ;
1029 using mutex_type = G::dummy_mutex ;
1030 using lock_type = G::dummy_lock ;
1031 static bool works() ;
1032 static void yield() noexcept {}
1033 } ;
1034 }
1035 #endif
1036
1037 /* Run-time o/s identification
1038 */
1039 namespace G
1040 {
1041 #ifdef G_WINDOWS
1042 inline constexpr bool is_windows() { return true ; }
1043 #else
1044 inline constexpr bool is_windows() { return false ; }
1045 #endif
1046 #ifdef G_UNIX_LINUX
1047 inline constexpr bool is_linux() { return true ; }
1048 #else
1049 inline constexpr bool is_linux() { return false ; }
1050 #endif
1051 #ifdef G_UNIX_FREEBSD
1052 inline constexpr bool is_free_bsd() { return true ; }
1053 #else
1054 inline constexpr bool is_free_bsd() { return false ; }
1055 #endif
1056 #ifdef G_UNIX_OPENBSD
1057 inline constexpr bool is_open_bsd() { return true ; }
1058 #else
1059 inline constexpr bool is_open_bsd() { return false ; }
1060 #endif
1061 #ifdef G_UNIX_BSD
1062 inline constexpr bool is_bsd() { return true ; }
1063 #else
1064 inline constexpr bool is_bsd() { return false ; }
1065 #endif
1066 }
1067
1068 /* Network code fix-ups
1069 */
1070
1071 using g_port_t = g_uint16_t ; /* since 'in_port_t' not always available */
1072
1073 #ifdef G_WINDOWS
1074 #ifdef G_MINGW
1075 #ifndef AI_NUMERICSERV
1076 #define AI_NUMERICSERV 0
1077 #endif
1078 #endif
1079 #ifndef MSG_NOSIGNAL
1080 #define MSG_NOSIGNAL 0
1081 #endif
1082 #endif
1083 #ifndef AI_ADDRCONFIG
1084 #define AI_ADDRCONFIG 0
1085 #endif
1086 #ifndef INADDR_NONE
1087 /* (should be in netinet/in.h) */
1088 #define INADDR_NONE 0xffffffff
1089 #endif
1090
1091 /* Inline portability shims
1092 */
1093
1094 #if GCONFIG_HAVE_IPV6
1095 inline void gdef_address6_init( sockaddr_in6 & s )
1096 {
1097 #if GCONFIG_HAVE_SIN6_LEN
1098 s.sin6_len = sizeof(s) ;
1099 #else
1100 (void) s ;
1101 #endif
1102 }
1103 #endif
1104
1105 /* Inline definitions of missing functions
1106 */
1107
1108 #if ! GCONFIG_HAVE_GAISTRERROR
1109 inline const char * gai_strerror( int ) // wrt getaddrinfo(3)
1110 {
1111 return nullptr ;
1112 }
1113 #endif
1114
1115 namespace GNet { int inet_pton_imp( int f , const char * p , void * result ) ; }
1116 #if ! GCONFIG_HAVE_INET_PTON
1117 inline int inet_pton( int f , const char * p , void * result )
1118 {
1119 return GNet::inet_pton_imp( f , p , result ) ;
1120 }
1121 #endif
1122
1123 namespace GNet { const char * inet_ntop_imp( int f , void * ap , char * buffer , std::size_t n ) ; }
1124 #if ! GCONFIG_HAVE_INET_NTOP
1125 inline const char * inet_ntop( int f , void * ap , char * buffer , std::size_t n )
1126 {
1127 return GNet::inet_ntop_imp( f , ap , buffer , n ) ;
1128 }
1129 #endif
1130
1131 #if GCONFIG_HAVE_PTHREAD_SIGMASK && GCONFIG_ENABLE_STD_THREAD
1132 #include <csignal>
1133 inline int gdef_pthread_sigmask( int how , const sigset_t * set_p , sigset_t * oldset_p ) noexcept
1134 {
1135 return pthread_sigmask( how , set_p , oldset_p ) ;
1136 }
1137 #else
1138 #if GCONFIG_HAVE_SIGPROCMASK
1139 #include <csignal>
1140 inline int gdef_pthread_sigmask( int how , const sigset_t * set_p , sigset_t * oldset_p ) noexcept
1141 {
1142 return sigprocmask( how , set_p , oldset_p ) ;
1143 }
1144 #else
1145 template <typename... T> int gdef_pthread_sigmask(T...) noexcept { return 0 ; }
1146 #endif
1147 #endif
1148
1149 #if GCONFIG_HAVE_IFNAMETOLUID
1150 #include <iphlpapi.h>
1151 inline unsigned long gdef_if_nametoindex( const char * p )
1152 {
1153 NET_LUID luid ;
1154 if( ConvertInterfaceNameToLuidA( p , &luid ) )
1155 {
1156 _set_errno( EINVAL ) ;
1157 return 0U ;
1158 }
1159 NET_IFINDEX result = 0 ;
1160 if( ConvertInterfaceLuidToIndex( &luid , &result ) != NO_ERROR )
1161 {
1162 _set_errno( EINVAL ) ;
1163 return 0U ;
1164 }
1165 _set_errno( 0 ) ;
1166 return result ;
1167 }
1168 #else
1169 #if GCONFIG_HAVE_IFNAMETOINDEX
1170 inline unsigned long gdef_if_nametoindex( const char * p )
1171 {
1172 #ifdef G_WINDOWS
1173 _set_errno( 0 ) ;
1174 #else
1175 errno = 0 ;
1176 #endif
1177 return if_nametoindex( p ) ; // int->long
1178 }
1179 #else
1180 inline unsigned long gdef_if_nametoindex( const char * )
1181 {
1182 #ifdef G_WINDOWS
1183 _set_errno( EINVAL ) ;
1184 #else
1185 errno = EINVAL ;
1186 #endif
1187 return 0UL ;
1188 }
1189 #endif
1190 #endif
1191 #if ! GCONFIG_HAVE_READLINK && !defined(readlink)
1192 inline ssize_t readlink( const char * , char * , std::size_t )
1193 {
1194 return -1 ;
1195 }
1196 #endif
1197 #if ! GCONFIG_HAVE_EXECVPE && !defined(execvpe) && defined(G_UNIX)
1198 inline int execvpe( const char * , char * [] , char * [] )
1199 {
1200 errno = EINVAL ;
1201 return -1 ;
1202 }
1203 #endif
1204
1205 #if GCONFIG_HAVE_GETPWNAM && ! GCONFIG_HAVE_GETPWNAM_R
1206 #include <pwd.h>
1207 inline int getpwnam_r( const char * name , struct passwd * pwd ,
1208 char * buf , std::size_t buflen , struct passwd ** result )
1209 {
1210 struct passwd * p = ::getpwnam( name ) ;
1211 if( p )
1212 {
1213 *pwd = *p ; /* string pointers still point into library storage */
1214 *result = pwd ;
1215 return 0 ;
1216 }
1217 else
1218 {
1219 *result = nullptr ;
1220 return 0 ;
1221 }
1222 }
1223 #endif
1224
1225 #if GCONFIG_HAVE_GETGRNAM && ! GCONFIG_HAVE_GETGRNAM_R
1226 #include <pwd.h>
1227 inline int getgrnam_r( const char * name , struct group * grp ,
1228 char * buf , std::size_t buflen , struct passwd ** result )
1229 {
1230 struct group * p = ::getgrnam( name ) ;
1231 if( p )
1232 {
1233 *grp = *p ; /* string pointers still point into library storage */
1234 *result = grp ;
1235 return 0 ;
1236 }
1237 else
1238 {
1239 *result = nullptr ;
1240 return 0 ;
1241 }
1242 }
1243 #endif
1244
1245 #if ! GCONFIG_HAVE_GMTIME_R && !defined(gmtime_r)
1246 #include <ctime>
1247 inline std::tm * gmtime_r( const std::time_t * tp , std::tm * tm_p )
1248 {
1249 #if GCONFIG_HAVE_GMTIME_S || defined(gmtime_s)
1250 errno_t e = gmtime_s( tm_p , tp ) ;
1251 if( e ) return nullptr ;
1252 return tm_p ;
1253 #else
1254 const struct std::tm * p = std::gmtime( tp ) ;
1255 if( p == 0 ) return nullptr ;
1256 *tm_p = *p ;
1257 return tm_p ;
1258 #endif
1259 }
1260 #endif
1261
1262 #if ! GCONFIG_HAVE_LOCALTIME_R && !defined(localtime_r)
1263 #include <ctime>
1264 inline struct std::tm * localtime_r( const std::time_t * tp , struct std::tm * tm_p )
1265 {
1266 #if GCONFIG_HAVE_LOCALTIME_S || defined(localtime_s)
1267 errno_t e = localtime_s( tm_p , tp ) ;
1268 if( e ) return nullptr ;
1269 return tm_p ;
1270 #else
1271 const struct std::tm * p = std::localtime( tp ) ;
1272 if( p == 0 ) return nullptr ;
1273 *tm_p = *p ;
1274 return tm_p ;
1275 #endif
1276 }
1277 #endif
1278
1279 #if ! GCONFIG_HAVE_LOCALTIME_S && !defined(localtime_s)
1280 #include <ctime>
1281 inline errno_t localtime_s( struct std::tm * tm_p , const std::time_t * tp )
1282 {
1283 const errno_t e_inval = 22 ;
1284 if( tm_p == nullptr ) return e_inval ;
1285 tm_p->tm_sec = tm_p->tm_min = tm_p->tm_hour = tm_p->tm_mday = tm_p->tm_mon =
1286 tm_p->tm_year = tm_p->tm_wday = tm_p->tm_yday = tm_p->tm_isdst = -1 ;
1287 if( tp == nullptr || *tp < 0 ) return e_inval ;
1288 const struct std::tm * p = std::localtime( tp ) ;
1289 if( p == nullptr ) return e_inval ;
1290 *tm_p = *p ;
1291 return 0 ;
1292 }
1293 #endif
1294
1295 #if ! GCONFIG_HAVE_GMTIME_S && !defined(gmtime_s)
1296 #include <ctime>
1297 inline errno_t gmtime_s( struct std::tm * tm_p , const std::time_t * tp )
1298 {
1299 const errno_t e_inval = 22 ;
1300 if( tm_p == nullptr ) return e_inval ;
1301 tm_p->tm_sec = tm_p->tm_min = tm_p->tm_hour = tm_p->tm_mday = tm_p->tm_mon =
1302 tm_p->tm_year = tm_p->tm_wday = tm_p->tm_yday = tm_p->tm_isdst = -1 ;
1303 if( tp == nullptr || *tp < 0 ) return e_inval ;
1304 const struct std::tm * p = std::gmtime( tp ) ;
1305 if( p == nullptr ) return e_inval ;
1306 *tm_p = *p ;
1307 return 0 ;
1308 }
1309 #endif
1310
1311 #if GCONFIG_HAVE_SETGROUPS
1312 #include <grp.h>
1313 #else
1314 inline int setgroups( std::size_t , const gid_t * )
1315 {
1316 return 0 ;
1317 }
1318 #endif
1319
1320 #if ! GCONFIG_HAVE_GET_WINDOW_LONG_PTR && defined(G_WINDOWS)
1321 static_assert( sizeof(void*) == 4U , "unexpected pointer size" ) ; // if this fails then we are on win64 so no need for this block at all
1322 const int GWLP_HINSTANCE = GWL_HINSTANCE ;
1323 const int GWLP_WNDPROC = GWL_WNDPROC ;
1324 const int DWLP_USER = DWL_USER ;
1325 inline LONG_PTR GetWindowLongPtr( HWND h , int id )
1326 {
1327 return static_cast<LONG_PTR>(::GetWindowLong(h,id)) ;
1328 }
1329 inline LONG_PTR SetWindowLongPtr( HWND h , int id , LONG_PTR value )
1330 {
1331 return static_cast<LONG_PTR>(::SetWindowLong(h,id,static_cast<LONG>(value))) ;
1332 }
1333 #endif
1334
1335 #if ! GCONFIG_HAVE_WINDOWS_VERSIONHELPERS_H && defined(G_WINDOWS)
1336 inline bool IsWindowsVistaOrGreater()
1337 {
1338 WORD major = HIBYTE( _WIN32_WINNT_VISTA ) ;
1339 WORD minor = LOBYTE( _WIN32_WINNT_VISTA ) ;
1340 OSVERSIONINFOEXW info {} ;
1341 info.dwOSVersionInfoSize = sizeof(info) ;
1342 info.dwMajorVersion = major ;
1343 info.dwMinorVersion = minor ;
1344 return !! VerifyVersionInfoW( &info , VER_MAJORVERSION | VER_MINORVERSION ,
1345 VerSetConditionMask( VerSetConditionMask(0,VER_MAJORVERSION,VER_GREATER_EQUAL) ,
1346 VER_MINORVERSION , VER_GREATER_EQUAL ) ) ;
1347 }
1348 #endif
1349
1350 #if ! GCONFIG_HAVE_MREMAP && defined(G_UNIX)
1351 inline void * mremap( void * , std::size_t , std::size_t , int )
1352 {
1353 errno = ENOSYS ;
1354 return (void*)(-1) ;
1355 }
1356 #endif
1357
1358 #if GCONFIG_HAVE_SETPGRP_BSD && defined(G_UNIX)
1359 inline int setpgrp()
1360 {
1361 return ::setpgrp( 0 , 0 ) ;
1362 }
1363 #endif
1364
1365 #if ! GCONFIG_HAVE_CXX_ALIGNMENT
1366 namespace std // NOLINT
1367 {
1368 // missing in gcc 4.8.4 -- original copyright 2001-2016 FSF Inc, GPLv3
1369 inline void * align( size_t align , size_t size , void * & ptr_inout , size_t & space ) noexcept
1370 {
1371 const auto ptr = reinterpret_cast<uintptr_t>( ptr_inout ) ;
1372 const auto aligned = ( ptr - 1U + align ) & -align ;
1373 const auto diff = aligned - ptr ;
1374 if( (size + diff) > space )
1375 {
1376 return nullptr ;
1377 }
1378 else
1379 {
1380 space -= diff ;
1381 ptr_inout = reinterpret_cast<void*>( aligned ) ;
1382 return ptr_inout ;
1383 }
1384 }
1385 }
1386 #endif
1387
1388 #endif
1389
1390#endif
Network classes.
Definition: gdef.h:1115
Low-level classes.
Definition: galign.h:28
void * align(const char *buffer, std::size_t buffer_size)
Returns a pointer inside the given buffer that is aligned for values of type T.
Definition: galign.h:70
Helper class for std::thread capabilities.
Definition: gdef.h:998