E-MailRelay

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