E-MailRelay
gdef.h
1 /*
2  Copyright (C) 2001-2018 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 some portability issues, and
24  * is a good candidate for precompilation. It requires
25  * either G_UNIX or G_WIN32 to be defined on the compiler
26  * command line.
27  */
28 
29 #ifndef G_DEF__H
30 #define G_DEF__H
31 
32  /* Pull in GCONFIG definitions. Use 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 tweak the
36  * values that are defaulted below.
37  */
38  #include <gconfig_defs.h>
39 
40  /* Check target operating-system switches
41  */
42  #if !defined(G_WIN32) && !defined(G_UNIX)
43  #if defined(_WIN32)
44  #define G_WIN32 1
45  #else
46  #define G_UNIX 1
47  #endif
48  #endif
49  #if defined(G_WIN32) && defined(G_UNIX)
50  #error invalid compilation switches - define G_WIN32 or G_UNIX but not both
51  #endif
52 
53  /* Define supplementary o/s switches
54  */
55  #if defined(__MINGW32__) && !defined(G_MINGW)
56  #define G_MINGW 1
57  #endif
58  #if defined(G_MINGW) && !defined(G_WIN32)
59  #error invalid compilation switches - G_MINGW requires G_WIN32
60  #endif
61  #if defined(G_WIN32) && !defined(G_WINDOWS)
62  #define G_WINDOWS 1
63  #endif
64  #if defined(__NetBSD__)
65  #define G_UNIX_BSD 1
66  #define G_UNIX_NETBSD 1
67  #endif
68  #if defined(__OpenBSD__)
69  #define G_UNIX_BSD 1
70  #define G_UNIX_OPENBSD 1
71  #endif
72  #if defined(__FreeBSD__)
73  #define G_UNIX_BSD 1
74  #define G_UNIX_FREEBSD 1
75  #endif
76  #if defined(__APPLE__)
77  #define G_UNIX_BSD 1
78  #define G_UNIX_MAC 1
79  #endif
80  #if defined(linux) || defined(__linux__)
81  #define G_UNIX_LINUX 1
82  #endif
83 
84  /* Define the compiler family and capabilities
85  */
86  #if !defined(G_COMPILER_CXX_11)
87  #if defined(_MSC_VER)
88  /* MSV_VER 1500=>VS9(2008) 1700=>VS11(2012), 1800=>VS12(2013) 1900=>VS14(2015) */
89  #define G_COMPILER_CXX_11 (_MSC_VER >= 1900)
90  #else
91  #if __cplusplus > 199711L
92  #define G_COMPILER_CXX_11 1
93  #endif
94  #endif
95  #endif
96 
97  /* Fill in any GCONFIG gaps
98  */
99  #if !defined(GCONFIG_HAVE_CXX_NULLPTR)
100  #ifdef G_COMPILER_CXX_11
101  #define GCONFIG_HAVE_CXX_NULLPTR 1
102  #else
103  #define GCONFIG_HAVE_CXX_NULLPTR 0
104  #endif
105  #endif
106  #if !defined(GCONFIG_HAVE_CXX_CONSTEXPR)
107  #ifdef G_COMPILER_CXX_11
108  #define GCONFIG_HAVE_CXX_CONSTEXPR 1
109  #else
110  #define GCONFIG_HAVE_CXX_CONSTEXPR 0
111  #endif
112  #endif
113  #if !defined(GCONFIG_HAVE_CXX_NOEXCEPT)
114  #ifdef G_COMPILER_CXX_11
115  #define GCONFIG_HAVE_CXX_NOEXCEPT 1
116  #else
117  #define GCONFIG_HAVE_CXX_NOEXCEPT 0
118  #endif
119  #endif
120  #if !defined(GCONFIG_HAVE_CXX_OVERRIDE)
121  #if defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800
122  #define GCONFIG_HAVE_CXX_OVERRIDE 1
123  #else
124  #define GCONFIG_HAVE_CXX_OVERRIDE 0
125  #endif
126  #endif
127  #if !defined(GCONFIG_HAVE_CXX_FINAL)
128  #if defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800
129  #define GCONFIG_HAVE_CXX_FINAL 1
130  #else
131  #define GCONFIG_HAVE_CXX_FINAL 0
132  #endif
133  #endif
134  #if !defined(GCONFIG_HAVE_CXX_ALIGNMENT)
135  /* no std::align in gcc 4.8 with -std=c++11 */
136  #if defined(G_COMPILER_CXX_11) && defined(_MSC_VER)
137  #define GCONFIG_HAVE_CXX_ALIGNMENT 0
138  #else
139  #define GCONFIG_HAVE_CXX_ALIGNMENT 0
140  #endif
141  #endif
142  #if !defined(GCONFIG_HAVE_CXX_SHARED_PTR)
143  #if defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800
144  #define GCONFIG_HAVE_CXX_SHARED_PTR 1
145  #else
146  #define GCONFIG_HAVE_CXX_SHARED_PTR 0
147  #endif
148  #endif
149  #if !defined(GCONFIG_HAVE_CXX_STD_THREAD)
150  #if defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800
151  #define GCONFIG_HAVE_CXX_STD_THREAD 1
152  #else
153  #define GCONFIG_HAVE_CXX_STD_THREAD 0
154  #endif
155  #endif
156  #if !defined(GCONFIG_HAVE_CXX_TYPE_TRAITS_MAKE_UNSIGNED)
157  #if defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800
158  #define GCONFIG_HAVE_CXX_TYPE_TRAITS_MAKE_UNSIGNED 1
159  #else
160  #define GCONFIG_HAVE_CXX_TYPE_TRAITS_MAKE_UNSIGNED 0
161  #endif
162  #endif
163  #if !defined(GCONFIG_HAVE_CXX_EMPLACE)
164  #if defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800
165  #define GCONFIG_HAVE_CXX_EMPLACE 1
166  #else
167  #define GCONFIG_HAVE_CXX_EMPLACE 0
168  #endif
169  #endif
170  #if !defined(GCONFIG_HAVE_DIRENT_H)
171  #define GCONFIG_HAVE_DIRENT_H 1
172  #endif
173  #if !defined(GCONFIG_HAVE_READLINK)
174  #ifdef G_UNIX
175  #define GCONFIG_HAVE_READLINK 1
176  #else
177  #define GCONFIG_HAVE_READLINK 0
178  #endif
179  #endif
180  #if !defined(GCONFIG_HAVE_ERRNO_T)
181  #ifdef G_WIN32
182  #define GCONFIG_HAVE_ERRNO_T 1
183  #else
184  #define GCONFIG_HAVE_ERRNO_T 0
185  #endif
186  #endif
187  #if !defined(GCONFIG_HAVE_GETENV_S)
188  #if defined(G_WIN32) || defined(getenv_s)
189  #define GCONFIG_HAVE_GETENV_S 1
190  #else
191  #define GCONFIG_HAVE_GETENV_S 0
192  #endif
193  #endif
194  #if !defined(GCONFIG_HAVE_GETPWNAM)
195  #define GCONFIG_HAVE_GETPWNAM 1
196  #endif
197  #if !defined(GCONFIG_HAVE_GETPWNAM_R)
198  #define GCONFIG_HAVE_GETPWNAM_R 1
199  #endif
200  #if !defined(GCONFIG_HAVE_GMTIME_R)
201  #define GCONFIG_HAVE_GMTIME_R 1
202  #endif
203  #if !defined(GCONFIG_HAVE_GMTIME_S)
204  #if defined(G_WIN32) || defined(gmtime_s)
205  #define GCONFIG_HAVE_GMTIME_S 1
206  #else
207  #define GCONFIG_HAVE_GMTIME_S 0
208  #endif
209  #endif
210  #if !defined(GCONFIG_HAVE_INTTYPES_H)
211  #define GCONFIG_HAVE_INTTYPES_H 1
212  #endif
213  #if !defined(GCONFIG_HAVE_IPV6)
214  #define GCONFIG_HAVE_IPV6 1
215  #endif
216  #if !defined(GCONFIG_HAVE_LOCALTIME_R)
217  #define GCONFIG_HAVE_LOCALTIME_R 1
218  #endif
219  #if !defined(GCONFIG_HAVE_LOCALTIME_S)
220  #if defined(G_WIN32) || defined(localtime_s)
221  #define GCONFIG_HAVE_LOCALTIME_S 1
222  #else
223  #define GCONFIG_HAVE_LOCALTIME_S 0
224  #endif
225  #endif
226  #if !defined(GCONFIG_HAVE_MEMORY_H)
227  #define GCONFIG_HAVE_MEMORY_H 1
228  #endif
229  #if !defined(GCONFIG_HAVE_NDIR_H)
230  #define GCONFIG_HAVE_NDIR_H 0
231  #endif
232  #if !defined(GCONFIG_HAVE_SETPGRP_BSD)
233  #if defined(G_UNIX_LINUX)
234  #define GCONFIG_HAVE_SETPGRP_BSD 0
235  #else
236  #define GCONFIG_HAVE_SETPGRP_BSD 1
237  #endif
238  #endif
239  #if !defined(GCONFIG_HAVE_SETGROUPS)
240  #ifdef G_UNIX
241  #define GCONFIG_HAVE_SETGROUPS 1
242  #else
243  #define GCONFIG_HAVE_SETGROUPS 0
244  #endif
245  #endif
246  #if !defined(GCONFIG_HAVE_STATBUF_NSEC)
247  #define GCONFIG_HAVE_STATBUF_NSEC 0
248  #endif
249  #if !defined(GCONFIG_HAVE_SIN6_LEN)
250  #define GCONFIG_HAVE_SIN6_LEN 0
251  #endif
252  #if !defined(GCONFIG_HAVE_SOCKLEN_T)
253  #define GCONFIG_HAVE_SOCKLEN_T 1
254  #endif
255  #if !defined(GCONFIG_HAVE_STDINT_H)
256  #define GCONFIG_HAVE_STDINT_H 1
257  #endif
258  #if !defined(GCONFIG_HAVE_STDLIB_H)
259  #define GCONFIG_HAVE_STDLIB_H 1
260  #endif
261  #if !defined(GCONFIG_HAVE_STRNCPY_S)
262  #if defined(G_WIN32) || defined(strncpy_s)
263  #define GCONFIG_HAVE_STRNCPY_S 1
264  #else
265  #define GCONFIG_HAVE_STRNCPY_S 0
266  #endif
267  #endif
268  #if !defined(GCONFIG_HAVE_STRINGS_H)
269  #define GCONFIG_HAVE_STRINGS_H 1
270  #endif
271  #if !defined(GCONFIG_HAVE_STRING_H)
272  #define GCONFIG_HAVE_STRING_H 1
273  #endif
274  #if !defined(GCONFIG_HAVE_SYS_DIR_H)
275  #define GCONFIG_HAVE_SYS_DIR_H 0
276  #endif
277  #if !defined(GCONFIG_HAVE_SYS_NDIR_H)
278  #define GCONFIG_HAVE_SYS_NDIR_H 0
279  #endif
280  #if !defined(GCONFIG_HAVE_SYS_STAT_H)
281  #define GCONFIG_HAVE_SYS_STAT_H 1
282  #endif
283  #if !defined(GCONFIG_HAVE_SYS_TIME_H)
284  #define GCONFIG_HAVE_SYS_TIME_H 1
285  #endif
286  #if !defined(GCONFIG_HAVE_SYS_TYPES_H)
287  #define GCONFIG_HAVE_SYS_TYPES_H 1
288  #endif
289  #if !defined(GCONFIG_HAVE_INET_NTOP)
290  #define GCONFIG_HAVE_INET_NTOP 1
291  #endif
292  #if !defined(GCONFIG_HAVE_IF_NAMETOINDEX)
293  #if G_WINDOWS
294  #define GCONFIG_HAVE_IF_NAMETOINDEX 0
295  #else
296  #define GCONFIG_HAVE_IF_NAMETOINDEX 1
297  #endif
298  #endif
299  #if !defined(GCONFIG_HAVE_INET_PTON)
300  #define GCONFIG_HAVE_INET_PTON 1
301  #endif
302  #if !defined(GCONFIG_HAVE_MISSING_STD_ABORT)
303  #ifdef G_WINDOWS
304  #define GCONFIG_HAVE_MISSING_STD_ABORT 1
305  #else
306  #define GCONFIG_HAVE_MISSING_STD_ABORT 0
307  #endif
308  #endif
309  #if !defined(GCONFIG_HAVE_MISSING_STD_EXIT)
310  #if defined(G_WINDOWS)
311  #define GCONFIG_HAVE_MISSING_STD_EXIT 0
312  #else
313  #define GCONFIG_HAVE_MISSING_STD_EXIT 1
314  #endif
315  #endif
316  #if !defined(GCONFIG_HAVE_MISSING_STD_SYSTEM)
317  #if defined(G_WINDOWS)
318  #define GCONFIG_HAVE_MISSING_STD_SYSTEM 1
319  #else
320  #define GCONFIG_HAVE_MISSING_STD_SYSTEM 0
321  #endif
322  #endif
323  #if !defined(GCONFIG_HAVE_MISSING_STD_MEMSET)
324  #if defined(G_WINDOWS)
325  #define GCONFIG_HAVE_MISSING_STD_MEMSET 1
326  #else
327  #define GCONFIG_HAVE_MISSING_STD_MEMSET 0
328  #endif
329  #endif
330  #if !defined(GCONFIG_HAVE_MISSING_STD_MEMCPY)
331  #if defined(G_WINDOWS)
332  #define GCONFIG_HAVE_MISSING_STD_MEMCPY 1
333  #else
334  #define GCONFIG_HAVE_MISSING_STD_MEMCPY 0
335  #endif
336  #endif
337  #if !defined(GCONFIG_HAVE_MISSING_STD_STRERROR)
338  #if defined(G_WINDOWS)
339  #define GCONFIG_HAVE_MISSING_STD_STRERROR 1
340  #else
341  #define GCONFIG_HAVE_MISSING_STD_STRERROR 0
342  #endif
343  #endif
344  #if !defined(GCONFIG_HAVE_MISSING_STD_FOPEN)
345  #if defined(G_WINDOWS)
346  #define GCONFIG_HAVE_MISSING_STD_FOPEN 1
347  #else
348  #define GCONFIG_HAVE_MISSING_STD_FOPEN 0
349  #endif
350  #endif
351  #if !defined(GCONFIG_HAVE_MISSING_STD_FCLOSE)
352  #if defined(G_WINDOWS)
353  #define GCONFIG_HAVE_MISSING_STD_FCLOSE 1
354  #else
355  #define GCONFIG_HAVE_MISSING_STD_FCLOSE 0
356  #endif
357  #endif
358  #if !defined(GCONFIG_HAVE_MISSING_STD_FPUTS)
359  #if defined(G_WINDOWS)
360  #define GCONFIG_HAVE_MISSING_STD_FPUTS 1
361  #else
362  #define GCONFIG_HAVE_MISSING_STD_FPUTS 0
363  #endif
364  #endif
365  #if !defined(GCONFIG_HAVE_UID_T)
366  #if defined(G_UNIX)
367  #define GCONFIG_HAVE_UID_T 1
368  #else
369  #define GCONFIG_HAVE_UID_T 0
370  #endif
371  #endif
372  #if !defined(GCONFIG_HAVE_GID_T)
373  #define GCONFIG_HAVE_GID_T GCONFIG_HAVE_UID_T
374  #endif
375  #if !defined(GCONFIG_HAVE_SSIZE_T)
376  #if defined(G_UNIX) || defined(G_MINGW)
377  #define GCONFIG_HAVE_SSIZE_T 1
378  #else
379  #define GCONFIG_HAVE_SSIZE_T 0
380  #endif
381  #endif
382  #if !defined(GCONFIG_HAVE_PID_T)
383  #if defined(G_UNIX) || defined(G_MINGW)
384  #define GCONFIG_HAVE_PID_T 1
385  #else
386  #define GCONFIG_HAVE_PID_T 0
387  #endif
388  #endif
389  #if !defined(GCONFIG_HAVE_GET_WINDOW_LONG_PTR)
390  #if defined(G_WIN32)
391  #define GCONFIG_HAVE_GET_WINDOW_LONG_PTR 1
392  #else
393  #define GCONFIG_HAVE_GET_WINDOW_LONG_PTR 0
394  #endif
395  #endif
396  #if !defined(GCONFIG_HAVE_MREMAP)
397  #if defined(G_UNIX_LINUX)
398  #define GCONFIG_HAVE_MREMAP 1
399  #else
400  #define GCONFIG_HAVE_MREMAP 0
401  #endif
402  #endif
403  #if !defined(GCONFIG_HAVE_TIMERFD)
404  #if defined(G_UNIX_LINUX)
405  #define GCONFIG_HAVE_TIMERFD 1
406  #else
407  #define GCONFIG_HAVE_TIMERFD 0
408  #endif
409  #endif
410  #if !defined(GCONFIG_HAVE_PAM)
411  #if defined(G_UNIX)
412  #define GCONFIG_HAVE_PAM 1
413  #else
414  #define GCONFIG_HAVE_PAM 0
415  #endif
416  #endif
417  #if !defined(GCONFIG_HAVE_PAM_IN_SECURITY)
418  #if defined(G_UNIX)
419  #define GCONFIG_HAVE_PAM_IN_SECURITY 1
420  #else
421  #define GCONFIG_HAVE_PAM_IN_SECURITY 0
422  #endif
423  #endif
424  #if !defined(GCONFIG_HAVE_PAM_IN_INCLUDE)
425  #define GCONFIG_HAVE_PAM_IN_INCLUDE 0
426  #endif
427  #if !defined(GCONFIG_HAVE_PAM_IN_PAM)
428  #define GCONFIG_HAVE_PAM_IN_PAM 0
429  #endif
430  #if !defined(GCONFIG_HAVE_GET_NATIVE_SYSTEM_INFO)
431  #if defined(G_WIN32)
432  #define GCONFIG_HAVE_GET_NATIVE_SYSTEM_INFO 1
433  #else
434  #define GCONFIG_HAVE_GET_NATIVE_SYSTEM_INFO 0
435  #endif
436  #endif
437  #if !defined(GCONFIG_HAVE_LIBJPEG)
438  #define GCONFIG_HAVE_LIBJPEG 0
439  #endif
440  #if !defined(GCONFIG_HAVE_LIBPNG)
441  #define GCONFIG_HAVE_LIBPNG 0
442  #endif
443  #if !defined(GCONFIG_HAVE_LIBAV)
444  #define GCONFIG_HAVE_LIBAV 0
445  #endif
446  #if !defined(GCONFIG_HAVE_CURSES)
447  #define GCONFIG_HAVE_CURSES 0
448  #endif
449  #if !defined(GCONFIG_HAVE_LIBEXIV)
450  #define GCONFIG_HAVE_LIBEXIV 0
451  #endif
452  #if !defined(GCONFIG_HAVE_V4L)
453  #if defined(G_UNIX_LINUX)
454  #define GCONFIG_HAVE_V4L 1
455  #else
456  #define GCONFIG_HAVE_V4L 0
457  #endif
458  #endif
459  #if !defined(GCONFIG_HAVE_LIBV4L)
460  #define GCONFIG_HAVE_LIBV4L 0
461  #endif
462  #if !defined(GCONFIG_ENABLE_IPV6)
463  #define GCONFIG_ENABLE_IPV6 GCONFIG_HAVE_IPV6
464  #endif
465  #if !defined(GCONFIG_ENABLE_STD_THREAD)
466  #define GCONFIG_ENABLE_STD_THREAD GCONFIG_HAVE_CXX_STD_THREAD
467  #endif
468  #if !defined(GCONFIG_HAVE_SEM_INIT)
469  #if defined(G_UNIX_LINUX) || defined(G_UNIX_FREEBSD)
470  #define GCONFIG_HAVE_SEM_INIT 1
471  #else
472  #define GCONFIG_HAVE_SEM_INIT 0
473  #endif
474  #endif
475  #if !defined(GCONFIG_HAVE_X11)
476  #if defined(G_UNIX)
477  #define GCONFIG_HAVE_X11 1
478  #else
479  #define GCONFIG_HAVE_X11 0
480  #endif
481  #endif
482  #if !defined(GCONFIG_HAVE_MBEDTLS)
483  #define GCONFIG_HAVE_MBEDTLS 1
484  #endif
485  #if !defined(GCONFIG_HAVE_MBEDTLS_NET_H)
486  #define GCONFIG_HAVE_MBEDTLS_NET_H 0
487  #endif
488  #if !defined(GCONFIG_HAVE_OPENSSL)
489  #if defined(G_UNIX)
490  #define GCONFIG_HAVE_OPENSSL 1
491  #else
492  #define GCONFIG_HAVE_OPENSSL 0
493  #endif
494  #endif
495  #if !defined(GCONFIG_HAVE_OPENSSL_MIN_MAX)
496  #define GCONFIG_HAVE_OPENSSL_MIN_MAX 0
497  #endif
498  #if !defined(GCONFIG_HAVE_OPENSSL_SSLv3)
499  #define GCONFIG_HAVE_OPENSSL_SSLv3 1
500  #endif
501  #if !defined(GCONFIG_HAVE_OPENSSL_TLSv1_1)
502  #define GCONFIG_HAVE_OPENSSL_TLSv1_1 1
503  #endif
504  #if !defined(GCONFIG_HAVE_OPENSSL_TLSv1_2)
505  #define GCONFIG_HAVE_OPENSSL_TLSv1_2 1
506  #endif
507  #if !defined(GCONFIG_HAVE_BOOST)
508  #if defined(G_UNIX_LINUX)
509  #define GCONFIG_HAVE_BOOST 1
510  #else
511  #define GCONFIG_HAVE_BOOST 0
512  #endif
513  #endif
514  #if !defined(GCONFIG_HAVE_ALSA)
515  #if defined(G_UNIX_LINUX)
516  #define GCONFIG_HAVE_ALSA 1
517  #else
518  #define GCONFIG_HAVE_ALSA 0
519  #endif
520  #endif
521  #if !defined(GCONFIG_HAVE_FMEMOPEN)
522  #if !defined(G_UNIX_OPENBSD)
523  #define GCONFIG_HAVE_FMEMOPEN 1
524  #else
525  #define GCONFIG_HAVE_FMEMOPEN 0
526  #endif
527  #endif
528  #if !defined(GCONFIG_HAVE_X11)
529  #if defined(G_UNIX)
530  #define GCONFIG_HAVE_X11 1
531  #else
532  #define GCONFIG_HAVE_X11 0
533  #endif
534  #endif
535  #if !defined(GCONFIG_HAVE_IP_MREQN)
536  #if defined(G_UNIX_LINUX) || defined(G_UNIX_FREEBSD)
537  #define GCONFIG_HAVE_IP_MREQN 1
538  #else
539  #define GCONFIG_HAVE_IP_MREQN 0
540  #endif
541  #endif
542  #if !defined(GCONFIG_HAVE_EXECVPE)
543  #if defined(G_UNIX_LINUX)
544  #define GCONFIG_HAVE_EXECVPE 1
545  #else
546  #define GCONFIG_HAVE_EXECVPE 0
547  #endif
548  #endif
549  #if !defined(GCONFIG_HAVE_WINDOWS_CREATE_WAITABLE_TIMER_EX)
550  #if defined(G_UNIX)
551  #define GCONFIG_HAVE_WINDOWS_CREATE_WAITABLE_TIMER_EX 0
552  #else
553  #define GCONFIG_HAVE_WINDOWS_CREATE_WAITABLE_TIMER_EX 1
554  #endif
555  #endif
556  #if !defined(GCONFIG_HAVE_WINDOWS_CREATE_EVENT_EX)
557  #if defined(G_UNIX)
558  #define GCONFIG_HAVE_WINDOWS_CREATE_EVENT_EX 0
559  #else
560  #define GCONFIG_HAVE_WINDOWS_CREATE_EVENT_EX 1
561  #endif
562  #endif
563  #if !defined(GCONFIG_HAVE_CXX_STD_WSTRING)
564  #define GCONFIG_HAVE_CXX_STD_WSTRING 1
565  #endif
566 
567  /* Include main o/s headers
568  */
569  #if defined(G_WINDOWS)
570  #ifdef G_MINGW
571  #define __USE_W32_SOCKETS
572  #ifndef _WIN32_WINNT
573  #define _WIN32_WINNT _WIN32_WINNT_VISTA
574  #endif
575  #if (_WIN32_WINNT < _WIN32_WINNT_VISTA)
576  #undef _WIN32_WINNT
577  #define _WIN32_WINNT _WIN32_WINNT_VISTA
578  #endif
579  #endif
580  #ifndef WIN32_LEAN_AND_MEAN
581  #define WIN32_LEAN_AND_MEAN
582  #endif
583  #ifdef G_WIN32_IE
584  #ifndef _WIN32_IE
585  #define _WIN32_IE 0x600
586  #endif
587  #endif
588  #include <windows.h>
589  #include <winsock2.h>
590  #include <ws2tcpip.h>
591  #include <shellapi.h>
592  #include <direct.h>
593  #ifdef G_MINGW
594  #include <sys/stat.h>
595  #include <unistd.h>
596  #endif
597  #else
598  #include <unistd.h>
599  #include <sys/stat.h>
600  #include <sys/types.h>
601  #include <sys/wait.h>
602  #include <sys/utsname.h>
603  #include <sys/select.h>
604  #include <sys/socket.h>
605  #ifndef MSG_NOSIGNAL
606  #define MSG_NOSIGNAL 0
607  #endif
608  #include <sys/mman.h>
609  #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
610  #define MAP_ANONYMOUS MAP_ANON
611  #endif
612  #ifndef MREMAP_MAYMOVE
613  #define MREMAP_MAYMOVE 0
614  #endif
615  #include <netinet/in.h>
616  #include <netdb.h>
617  #include <arpa/inet.h>
618  #if GCONFIG_HAVE_IF_NAMETOINDEX
619  #include <net/if.h>
620  #endif
621  #include <errno.h>
622  #endif
623 
624  /* Undefine some out-dated macros
625  */
626  #ifdef __cplusplus
627  #ifdef max
628  #undef max
629  #endif
630  #ifdef min
631  #undef min
632  #endif
633  #endif
634 
635  /* Include commonly-used system headers (good for pre-compilation)
636  */
637  #ifdef __cplusplus
638  #include <cstddef>
639  #include <cstdlib>
640  #include <exception>
641  #include <fstream>
642  #include <iostream>
643  #include <memory>
644  #include <sstream>
645  #include <string>
646  #include <ctime>
647  #else
648  #include <stddef.h>
649  #endif
650 
651  /* Define a few Windows-style types under unix
652  */
653  #if ! defined(G_WINDOWS)
654  typedef unsigned char BOOL ;
655  typedef unsigned int HDC ;
656  typedef unsigned int HWND ;
657  typedef unsigned int HINSTANCE ;
658  typedef unsigned int HANDLE ;
659  typedef wchar_t TCHAR ;
660  typedef int SOCKET ;
661  #endif
662 
663  /* Define fixed-size types
664  */
665  #if defined(G_WINDOWS)
666  typedef UINT32 g_uint32_t ;
667  typedef UINT16 g_uint16_t ;
668  typedef INT32 g_int32_t ;
669  typedef INT16 g_int16_t ;
670  #else
671  #include <stdint.h>
672  typedef uint32_t g_uint32_t ;
673  typedef uint16_t g_uint16_t ;
674  typedef int32_t g_int32_t ;
675  typedef int16_t g_int16_t ;
676  #endif
677  #if __cplusplus
678  typedef char assert_sizeof_uint16_is_2[sizeof(g_uint16_t)==2U?1:-1] ;
679  typedef char assert_sizeof_uint32_is_4[sizeof(g_uint32_t)==4U?1:-1] ;
680  #endif
681 
682  /* Define missing standard types
683  */
684  #if ! GCONFIG_HAVE_UID_T
685  typedef int uid_t ;
686  #endif
687  #if ! GCONFIG_HAVE_GID_T
688  typedef int gid_t ;
689  #endif
690  #if ! GCONFIG_HAVE_SSIZE_T
691  #if defined(SSIZE_T)
692  typedef SSIZE_T ssize_t ;
693  #else
694  typedef int ssize_t ;
695  #endif
696  #endif
697  #if ! GCONFIG_HAVE_PID_T
698  typedef unsigned int pid_t ;
699  #endif
700  #if ! GCONFIG_HAVE_SOCKLEN_T
701  typedef int socklen_t ;
702  #endif
703  #if ! GCONFIG_HAVE_ERRNO_T
704  typedef int errno_t ; /* for _s() return type */
705  #endif
706  #if ! GCONFIG_HAVE_CXX_STD_WSTRING
707  #if __cplusplus
708  namespace std
709  {
710  typedef basic_string<wchar_t> wstring ;
711  }
712  #endif
713  #endif
714 
715  /* Pull some std types into the global namespace
716  */
717  #ifdef __cplusplus
718  using std::size_t ;
719  #endif
720 
721  /* Pull other stuff into the std namespace
722  */
723  #ifdef __cplusplus
724  #include <cstdio>
725  #include <cstring>
726  #include <ctime>
727  #include <cstdlib>
728  namespace std
729  {
730  #if GCONFIG_HAVE_MISSING_STD_ABORT
731  using ::abort ; // stdlib
732  #endif
733  #if GCONFIG_HAVE_MISSING_STD_EXIT
734  using ::exit ; // stdlib
735  #endif
736  #if GCONFIG_HAVE_MISSING_STD_SYSTEM
737  using ::system ; // stdlib
738  #endif
739  #if GCONFIG_HAVE_MISSING_STD_MEMSET
740  using ::memset ; // string
741  #endif
742  #if GCONFIG_HAVE_MISSING_STD_MEMCPY
743  using ::memcpy ; // string
744  #endif
745  #if GCONFIG_HAVE_MISSING_STD_STRERROR
746  using ::strerror ; // string
747  #endif
748  #if GCONFIG_HAVE_MISSING_STD_FOPEN
749  using ::fopen ; // stdio
750  #endif
751  #if GCONFIG_HAVE_MISSING_STD_FCLOSE
752  using ::fclose ; // stdio
753  #endif
754  #if GCONFIG_HAVE_MISSING_STD_FPUTS
755  using ::fputs ; // stdio
756  #endif
757  #if GCONFIG_HAVE_MISSING_STD_STRUCT_TM
758  using ::tm ; // time
759  #endif
760  #if GCONFIG_HAVE_MISSING_STD_TIME_T
761  using ::time_t ; // time
762  #endif
763  }
764  #endif
765 
766  /* Use smaller buffers and limits if building with the uClibc run-time library.
767  * See glimits.h. This assumes that the uClibc header "features.h" has been
768  * included as a side-effect of including system headers above.
769  */
770  #ifdef __UCLIBC__
771  #ifndef G_NOT_SMALL
772  #define G_SMALL
773  #endif
774  #endif
775 
776  /* Macros to explicitly ignore unused values
777  */
778  #define G_IGNORE_PASTE_IMP(a,b) a##b
779  #define G_IGNORE_PASTE(a,b) G_IGNORE_PASTE_IMP(a,b)
780  #define G_IGNORE_RETURN(type,expr) do { type G_IGNORE_PASTE(ignore_,__LINE__) = expr ; (void) G_IGNORE_PASTE(ignore_,__LINE__) ; } while(0)
781  #define G_IGNORE_PARAMETER(type,name) (void)name
782  #define G_IGNORE_VARIABLE(name) (void)name
783 
784  /* C++ language backwards compatibility
785  */
786  #ifdef __cplusplus
787 
788  #if ! GCONFIG_HAVE_CXX_NULLPTR
789  #ifndef nullptr
790  #define nullptr NULL
791  #endif
792  #endif
793 
794  #if GCONFIG_HAVE_CXX_CONSTEXPR
795  #define g__constexpr constexpr
796  #else
797  /* for in-class initialisation of static integer-type constants only */
798  #define g__constexpr const
799  #endif
800 
801  #if GCONFIG_HAVE_CXX_NOEXCEPT
802  #define g__noexcept noexcept
803  #else
804  #define g__noexcept throw()
805  #endif
806 
807  #if ! GCONFIG_HAVE_CXX_OVERRIDE
808  #define override
809  #endif
810 
811  #if GCONFIG_HAVE_CXX_FINAL
812  #define g__final final
813  #else
814  #define g__final
815  #endif
816 
817  #if GCONFIG_HAVE_CXX_SHARED_PTR
818  #include <memory>
819  using std::shared_ptr ;
820  using std::unique_ptr ;
821  using std::const_pointer_cast ;
822  #else
823  namespace G {
824  template <typename T>
825  struct shared_ptr_deleter
826  {
827  static void fn( void * p ) { delete static_cast<T*>(p) ; }
828  } ;
829  struct shared_ptr_control
830  {
831  explicit shared_ptr_control( void * object , void (*deleter)(void*) ) :
832  m_object(object) , m_deleter(deleter) , m_n(1U) {}
833  explicit shared_ptr_control( const void * object , void (*deleter)(void*) ) :
834  m_object(const_cast<void*>(object)) , m_deleter(deleter) , m_n(1U) {}
835  void inc() { m_n++ ; }
836  bool dec() { m_n-- ; return m_n == 0 ; }
837  void * m_object ;
838  void (*m_deleter)(void *) ;
839  unsigned int m_n ;
840  } ;
841  template <typename T> class shared_ptr
842  {
843  public:
844  typedef shared_ptr<T> ptr ;
845  explicit shared_ptr( T * p = 0 ) : m_control(new shared_ptr_control(p,&shared_ptr_deleter<T>::fn)) , m_p(p) {}
846  shared_ptr( T * p , void (*d)(void*) ) : m_control(new shared_ptr_control(p,d)) , m_p(p) {}
847  template <typename Y> shared_ptr( const shared_ptr<Y> & obj , T * p ) : m_control(obj.m_control) , m_p(p) { inc(); }
848  ~shared_ptr() { dec(); }
849  void reset( T * p = 0 ) { ptr tmp(p); swap(tmp); }
850  void reset( T * p , void (*d)(void*) ) { ptr tmp(p,d); swap(tmp); }
851  T * get() { return m_p; }
852  const T * get() const { return m_p; }
853  T * operator->() { return m_p; }
854  const T * operator->() const { return m_p; }
855  T & operator*() { return *m_p; }
856  const T & operator*() const { return *m_p; }
857  operator bool () const { return m_p != nullptr; }
858  template <typename D> shared_ptr( const shared_ptr<D> & o ) : m_control(o.m_control) , m_p(o.m_p) { inc(); }
859  shared_ptr( const shared_ptr<T> & o ) : m_control(o.m_control) , m_p(o.m_p) { inc(); }
860  void operator=( const shared_ptr<T> & o ) { ptr tmp(o); swap(tmp); }
861  unsigned int use_count() const { return m_control->m_n ; }
862  bool unique() const { return use_count() == 1; }
863  private:
864  void swap( shared_ptr<T> & o ) { std::swap(m_p,o.m_p); std::swap(m_control,o.m_control); }
865  void dec()
866  {
867  if( m_control->dec() )
868  {
869  m_control->m_deleter( m_control->m_object ) ;
870  delete m_control ;
871  m_control = nullptr ;
872  m_p = nullptr ;
873  }
874  }
875  void inc() { m_control->inc(); }
876  public:
877  shared_ptr_control * m_control ;
878  T * m_p ;
879  } ;
880  template <typename T, typename U>
881  shared_ptr<T> const_pointer_cast( const shared_ptr<U> & ptr_in ) g__noexcept
882  {
883  T * p = const_cast<T*>(ptr_in.get()) ;
884  return shared_ptr<T>( ptr_in , p ) ;
885  }
886  template <typename T> class default_delete
887  {
888  public: void operator()( T * p ) { delete p ; }
889  } ;
890  template <typename T, typename D=default_delete<T> > class unique_ptr
891  {
892  public:
893  unique_ptr() : m_p(0) {}
894  explicit unique_ptr( T * p ) : m_p(p) {}
895  unique_ptr( T * p , D d ) : m_p(p) , m_d(d) {}
896  explicit unique_ptr( std::auto_ptr<T> p ) : m_p(p.release()) {}
897  ~unique_ptr() { reset(); }
898  void reset( T * p ) { m_d(m_p); m_p = p; }
899  void reset() { reset(nullptr); }
900  T * get() { return m_p; }
901  T & operator*() { return *m_p; }
902  const T * get() const { return m_p; }
903  const T & operator*() const { return *m_p; }
904  T * operator->() { return m_p; }
905  const T * operator->() const { return m_p; }
906  T * release() { T * p = m_p; m_p = 0; return p; }
907  operator bool () const { return m_p != nullptr; }
908  unique_ptr( const unique_ptr<T> & rhs ) { m_p = rhs.m_p ; const_cast<unique_ptr<T>&>(rhs).m_p = 0 ; } // for c++98, mimic auto_ptr
909  private:
910  void operator=( const unique_ptr<T> & ) ;
911  private:
912  T * m_p ;
913  D m_d ;
914  } ;
915  }
916  using G::shared_ptr ;
917  using G::unique_ptr ;
918  using G::const_pointer_cast ;
919  #endif
920 
921  #if GCONFIG_ENABLE_STD_THREAD
922  #include <thread>
923  #include <mutex>
924  #include <cstring>
925  namespace G
926  {
927  struct threading /// Helper class for std::thread capabilities.
928  {
929  enum { using_std_thread = 1 } ;
930  typedef std::thread thread_type ;
931  typedef std::mutex mutex_type ;
932  typedef std::lock_guard<std::mutex> lock_type ;
933  static bool works() ; // run-time test -- see gthread.cpp
934  } ;
935  }
936  #else
937  namespace G
938  {
939  class dummy_thread
940  {
941  public:
942  typedef int id ;
943  template <typename T_fn> dummy_thread( T_fn fn ) { fn() ; }
944  template <typename T_fn,typename T_arg1> dummy_thread( T_fn fn , T_arg1 arg1 ) { fn(arg1) ; }
945  template <typename T_fn,typename T_arg1,typename T_arg2> dummy_thread( T_fn fn , T_arg1 arg1 , T_arg2 arg2 ) { fn(arg1,arg2) ; }
946  dummy_thread() {}
947  bool joinable() const { return false ; }
948  void detach() {}
949  void join() {}
950  id get_id() const { return 0 ; }
951  } ;
952  class dummy_mutex {} ;
953  class dummy_lock { public: explicit dummy_lock( dummy_mutex & ) {} } ;
954  struct threading
955  {
956  enum { using_std_thread = 0 } ;
957  typedef G::dummy_thread thread_type ;
958  typedef G::dummy_mutex mutex_type ;
959  typedef G::dummy_lock lock_type ;
960  static bool works() ;
961  } ;
962  }
963  #endif
964 
965  #if ! GCONFIG_HAVE_CXX_TYPE_TRAITS_MAKE_UNSIGNED
966  namespace std
967  {
968  template <typename T> struct make_unsigned {} ;
969  template <> struct make_unsigned<unsigned char> { typedef unsigned char type ; } ;
970  template <> struct make_unsigned<char> { typedef unsigned char type ; } ;
971  template <> struct make_unsigned<signed char> { typedef unsigned char type ; } ;
972  template <> struct make_unsigned<unsigned short> { typedef unsigned short type ; } ;
973  template <> struct make_unsigned<short> { typedef unsigned short type ; } ;
974  template <> struct make_unsigned<unsigned int> { typedef unsigned int type ; } ;
975  template <> struct make_unsigned<int> { typedef unsigned int type ; } ;
976  template <> struct make_unsigned<unsigned long> { typedef unsigned long type ; } ;
977  template <> struct make_unsigned<long> { typedef unsigned long type ; } ;
978  }
979  #endif
980 
981  #endif
982 
983  /* Run-time o/s identification */
984  #ifdef __cplusplus
985  namespace G
986  {
987  #ifdef G_WINDOWS
988  inline bool is_windows() { return true ; }
989  #else
990  inline bool is_windows() { return false ; }
991  #endif
992  #ifdef G_UNIX_LINUX
993  inline bool is_linux() { return true ; }
994  #else
995  inline bool is_linux() { return false ; }
996  #endif
997  #ifdef G_UNIX_FREEBSD
998  inline bool is_free_bsd() { return true ; }
999  #else
1000  inline bool is_free_bsd() { return false ; }
1001  #endif
1002  #ifdef G_UNIX_OPENBSD
1003  inline bool is_open_bsd() { return true ; }
1004  #else
1005  inline bool is_open_bsd() { return false ; }
1006  #endif
1007  #ifdef G_UNIX_BSD
1008  inline bool is_bsd() { return true ; }
1009  #else
1010  inline bool is_bsd() { return false ; }
1011  #endif
1012  }
1013  #endif
1014 
1015  /* Network code fix-ups
1016  */
1017 
1018  typedef g_uint16_t g_port_t ; /* since 'in_port_t' not always available */
1019 
1020  #ifdef G_WINDOWS
1021  #ifdef G_MINGW
1022  #ifndef AI_NUMERICSERV
1023  #define AI_NUMERICSERV 0
1024  #endif
1025  #ifndef AI_ADDRCONFIG
1026  #define AI_ADDRCONFIG 0
1027  #endif
1028  #endif
1029  #ifndef MSG_NOSIGNAL
1030  #define MSG_NOSIGNAL 0
1031  #endif
1032  #endif
1033 
1034  #ifndef INADDR_NONE
1035  /* (should be in netinet/in.h) */
1036  #define INADDR_NONE 0xffffffff
1037  #endif
1038 
1039  /* Inline portability shims
1040  */
1041 
1042  #ifdef __cplusplus
1043  #if GCONFIG_HAVE_IPV6
1044  inline void gnet_address6_init( sockaddr_in6 & s )
1045  {
1046  #if GCONFIG_HAVE_SIN6_LEN
1047  s.sin6_len = sizeof(s) ;
1048  #else
1049  (void) s ;
1050  #endif
1051  }
1052  #endif
1053  #endif
1054 
1055  /* Inline definitions of missing functions
1056  */
1057 
1058  #if ! GCONFIG_HAVE_INET_PTON
1059  #ifdef __cplusplus
1060  namespace GNet { int inet_pton_imp( int f , const char * p , void * result ) ; }
1061  inline int inet_pton( int f , const char * p , void * result )
1062  {
1063  return GNet::inet_pton_imp( f , p , result ) ;
1064  }
1065  #endif
1066  #endif
1067 
1068  #if ! GCONFIG_HAVE_INET_NTOP
1069  #ifdef __cplusplus
1070  namespace GNet { const char * inet_ntop_imp( int f , void * ap , char * buffer , size_t n ) ; }
1071  inline const char * inet_ntop( int f , void * ap , char * buffer , size_t n )
1072  {
1073  return GNet::inet_ntop_imp( f , ap , buffer , n ) ;
1074  }
1075  #endif
1076  #endif
1077 
1078  #if ! GCONFIG_HAVE_IF_NAMETOINDEX
1079  #ifdef __cplusplus
1080  inline unsigned int if_nametoindex( const char * )
1081  {
1082  return 0U ;
1083  }
1084  #endif
1085  #endif
1086 
1087  #if ! GCONFIG_HAVE_READLINK && !defined(readlink)
1088  #ifdef __cplusplus
1089  inline ssize_t readlink( const char * , char * , size_t )
1090  {
1091  return -1 ;
1092  }
1093  #endif
1094  #endif
1095 
1096  #if GCONFIG_HAVE_GETPWNAM && ! GCONFIG_HAVE_GETPWNAM_R
1097  #ifdef __cplusplus
1098  #include <sys/types.h>
1099  #include <pwd.h>
1100  inline int getpwnam_r( const char * name , struct passwd * pwd ,
1101  char * buf , size_t buflen , struct passwd ** result )
1102  {
1103  struct passwd * p = ::getpwnam( name ) ;
1104  if( p )
1105  {
1106  *pwd = *p ; /* string pointers still point into library storage */
1107  *result = pwd ;
1108  return 0 ;
1109  }
1110  else
1111  {
1112  *result = nullptr ;
1113  return 0 ; /* or errno */
1114  }
1115  }
1116  #endif
1117  #endif
1118 
1119  #if ! GCONFIG_HAVE_GMTIME_R && !defined(gmtime_r) && defined(G_UNIX)
1120  #ifdef __cplusplus
1121  #include <ctime>
1122  inline std::tm * gmtime_r( const std::time_t * tp , std::tm * tm_p )
1123  {
1124  const struct std::tm * p = std::gmtime( tp ) ;
1125  if( p == 0 ) return 0 ;
1126  *tm_p = *p ;
1127  return tm_p ;
1128  }
1129  #endif
1130  #endif
1131 
1132  #if ! GCONFIG_HAVE_LOCALTIME_R && !defined(localtime_r) && defined(G_UNIX)
1133  #ifdef __cplusplus
1134  #include <ctime>
1135  inline struct std::tm * localtime_r( const std::time_t * tp , struct std::tm * tm_p )
1136  {
1137  const struct std::tm * p = std::localtime( tp ) ;
1138  if( p == 0 ) return 0 ;
1139  *tm_p = *p ;
1140  return tm_p ;
1141  }
1142  #endif
1143  #endif
1144 
1145  #if ! GCONFIG_HAVE_LOCALTIME_S && !defined(localtime_s)
1146  #ifdef __cplusplus
1147  inline errno_t localtime_s( struct std::tm * tm_p , const std::time_t * tp )
1148  {
1149  const errno_t e_inval = 22 ;
1150  if( tm_p == nullptr ) return e_inval ;
1151  tm_p->tm_sec = tm_p->tm_min = tm_p->tm_hour = tm_p->tm_mday = tm_p->tm_mon =
1152  tm_p->tm_year = tm_p->tm_wday = tm_p->tm_yday = tm_p->tm_isdst = -1 ;
1153  if( tp == nullptr || *tp < 0 ) return e_inval ;
1154  const struct std::tm * p = std::localtime( tp ) ;
1155  if( p == 0 ) return e_inval ;
1156  *tm_p = *p ;
1157  return 0 ;
1158  }
1159  #endif
1160  #endif
1161 
1162  #if ! GCONFIG_HAVE_GMTIME_S && !defined(gmtime_s)
1163  #ifdef __cplusplus
1164  inline errno_t gmtime_s( struct std::tm * tm_p , const std::time_t * tp )
1165  {
1166  const errno_t e_inval = 22 ;
1167  if( tm_p == nullptr ) return e_inval ;
1168  tm_p->tm_sec = tm_p->tm_min = tm_p->tm_hour = tm_p->tm_mday = tm_p->tm_mon =
1169  tm_p->tm_year = tm_p->tm_wday = tm_p->tm_yday = tm_p->tm_isdst = -1 ;
1170  if( tp == nullptr || *tp < 0 ) return e_inval ;
1171  const struct std::tm * p = std::gmtime( tp ) ;
1172  if( p == 0 ) return e_inval ;
1173  *tm_p = *p ;
1174  return 0 ;
1175  }
1176  #endif
1177  #endif
1178 
1179  #if GCONFIG_HAVE_SETGROUPS
1180  #include <grp.h>
1181  #else
1182  #ifdef __cplusplus
1183  inline int setgroups( size_t , const gid_t * )
1184  {
1185  return 0 ;
1186  }
1187  #endif
1188  #endif
1189 
1190  #if ! GCONFIG_HAVE_GETENV_S
1191  #ifdef __cplusplus
1192  #include <cstdlib>
1193  inline errno_t getenv_s( size_t * n_out , char * buffer , size_t n_in , const char * name )
1194  {
1195  const errno_t e_inval = 22 ;
1196  const errno_t e_range = 34 ;
1197  if( n_out == nullptr || name == nullptr ) return e_inval ;
1198  const char * p = ::getenv( name ) ;
1199  *n_out = p ? (strlen(p) + 1U) : 0 ;
1200  if( p && *n_out > n_in ) return e_range ;
1201  if( p && buffer ) strcpy( buffer , p ) ;
1202  return 0 ;
1203  }
1204 
1205  #endif
1206  #endif
1207 
1208  #if ! GCONFIG_HAVE_STRNCPY_S
1209  #ifndef _TRUNCATE
1210  #define _TRUNCATE (~((size_t)(0U)))
1211  #endif
1212  #ifdef __cplusplus
1213  inline errno_t strncpy_s( char * dst , size_t n_dst , const char * src , size_t n_src )
1214  {
1215  if( dst == nullptr ) return EINVAL ;
1216  if( src == nullptr ) { *dst = '\0' ; return EINVAL ; }
1217  if( n_dst == 0U ) { return EINVAL ; }
1218  size_t d = strlen(src) ; if( n_src != _TRUNCATE && n_src < d ) d = n_src ;
1219  if( d >= n_dst && n_src == _TRUNCATE )
1220  {
1221  strncpy( dst , src , n_dst ) ;
1222  dst[n_dst-1U] = '\0' ;
1223  }
1224  else if( d >= n_dst )
1225  {
1226  *dst = '\0' ;
1227  return ERANGE ;
1228  }
1229  else
1230  {
1231  strncpy( dst , src , d ) ;
1232  dst[d] = '\0' ;
1233  }
1234  return 0 ;
1235  }
1236 
1237  #endif
1238  #endif
1239 
1240  #if ! GCONFIG_HAVE_GET_WINDOW_LONG_PTR && defined(G_WINDOWS)
1241  #ifdef __cplusplus
1242  typedef char assert_thirty_two_bit_windows[sizeof(void*)==4U?1:-1] ; // if this fails then we are on win64 so no need for this block at all
1243  const int GWLP_HINSTANCE = GWL_HINSTANCE ;
1244  const int GWLP_WNDPROC = GWL_WNDPROC ;
1245  const int DWLP_USER = DWL_USER ;
1246  inline LONG_PTR GetWindowLongPtr( HWND h , int id )
1247  {
1248  return static_cast<LONG_PTR>(::GetWindowLong(h,id)) ;
1249  }
1250  inline LONG_PTR SetWindowLongPtr( HWND h , int id , LONG_PTR value )
1251  {
1252  return static_cast<LONG_PTR>(::SetWindowLong(h,id,static_cast<LONG>(value))) ;
1253  }
1254  #endif
1255  #endif
1256 
1257  #if ! GCONFIG_HAVE_MREMAP && defined(G_UNIX)
1258  #ifdef __cplusplus
1259  inline void * mremap( void * , size_t , size_t , int )
1260  {
1261  errno = ENOSYS ;
1262  return (void*)(-1) ;
1263  }
1264  #endif
1265  #endif
1266 
1267  #if GCONFIG_HAVE_SETPGRP_BSD && defined(G_UNIX)
1268  #ifdef __cplusplus
1269  inline int setpgrp()
1270  {
1271  return ::setpgrp( 0 , 0 ) ;
1272  }
1273  #endif
1274  #endif
1275 
1276 #endif
Network classes.
Definition: gaddress.h:29
STL namespace.
Low-level classes.
Definition: garg.h:29
Helper class for std::thread capabilities.
Definition: gdef.h:927