38 #include <gconfig_defs.h>
42 #if defined(_WIN32) && !defined(G_WIN32)
45 #if !defined(_WIN32) && !defined(G_UNIX)
48 #if defined(G_WIN32) && defined(G_UNIX)
49 #error invalid compilation switches - define G_WIN32 or G_UNIX but not both
54 #if defined(__MINGW32__) && !defined(G_MINGW)
57 #if defined(G_MINGW) && !defined(G_WIN32)
58 #error invalid compilation switches - G_MINGW requires G_WIN32
60 #if defined(G_WIN32) && ! defined(G_WINDOWS)
63 #if defined(__NetBSD__)
65 #define G_UNIX_NETBSD 1
67 #if defined(__OpenBSD__)
69 #define G_UNIX_OPENBSD 1
71 #if defined(__FreeBSD__)
73 #define G_UNIX_FREEBSD 1
75 #if defined(__APPLE__)
79 #if defined(linux) || defined(__linux__)
80 #define G_UNIX_LINUX 1
85 #if !defined(G_COMPILER_CXX_11)
88 #define G_COMPILER_CXX_11 (_MSC_VER >= 1900)
90 #if __cplusplus > 199711L
91 #define G_COMPILER_CXX_11 1
98 #if !defined(GCONFIG_HAVE_CXX_NULLPTR)
99 #define GCONFIG_HAVE_CXX_NULLPTR defined(G_COMPILER_CXX_11)
101 #if !defined(GCONFIG_HAVE_CXX_CONSTEXPR)
102 #define GCONFIG_HAVE_CXX_CONSTEXPR defined(G_COMPILER_CXX_11)
104 #if !defined(GCONFIG_HAVE_CXX_NOEXCEPT)
105 #define GCONFIG_HAVE_CXX_NOEXCEPT defined(G_COMPILER_CXX_11)
107 #if !defined(GCONFIG_HAVE_CXX_OVERRIDE)
108 #define GCONFIG_HAVE_CXX_OVERRIDE (defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800)
110 #if !defined(GCONFIG_HAVE_CXX_FINAL)
111 #define GCONFIG_HAVE_CXX_FINAL (defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800)
113 #if !defined(GCONFIG_HAVE_CXX_SHARED_PTR)
114 #define GCONFIG_HAVE_CXX_SHARED_PTR (defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800)
116 #if !defined(GCONFIG_HAVE_CXX_STD_THREAD)
117 #define GCONFIG_HAVE_CXX_STD_THREAD (defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800)
119 #if !defined(GCONFIG_HAVE_CXX_TYPE_TRAITS_MAKE_UNSIGNED)
120 #define GCONFIG_HAVE_CXX_TYPE_TRAITS_MAKE_UNSIGNED (defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800)
122 #if !defined(GCONFIG_HAVE_CXX_EMPLACE)
123 #define GCONFIG_HAVE_CXX_EMPLACE (defined(G_COMPILER_CXX_11) || _MSC_VER >= 1800)
125 #if !defined(GCONFIG_HAVE_DIRENT_H)
126 #define GCONFIG_HAVE_DIRENT_H 1
128 #if !defined(GCONFIG_HAVE_READLINK)
129 #define GCONFIG_HAVE_READLINK defined(G_UNIX)
131 #if !defined(GCONFIG_HAVE_ERRNO_T)
132 #define GCONFIG_HAVE_ERRNO_T defined(G_WIN32)
134 #if !defined(GCONFIG_HAVE_GETENV_S)
135 #define GCONFIG_HAVE_GETENV_S ( defined(G_WIN32) || defined(getenv_s) )
137 #if !defined(GCONFIG_HAVE_GETPWNAM)
138 #define GCONFIG_HAVE_GETPWNAM 1
140 #if !defined(GCONFIG_HAVE_GETPWNAM_R)
141 #define GCONFIG_HAVE_GETPWNAM_R 1
143 #if !defined(GCONFIG_HAVE_GMTIME_R)
144 #define GCONFIG_HAVE_GMTIME_R 1
146 #if !defined(GCONFIG_HAVE_GMTIME_S)
147 #define GCONFIG_HAVE_GMTIME_S ( defined(G_WIN32) || defined(gmtime_s) )
149 #if !defined(GCONFIG_HAVE_INTTYPES_H)
150 #define GCONFIG_HAVE_INTTYPES_H 1
152 #if !defined(GCONFIG_HAVE_IPV6)
153 #define GCONFIG_HAVE_IPV6 1
155 #if !defined(GCONFIG_HAVE_LOCALTIME_R)
156 #define GCONFIG_HAVE_LOCALTIME_R 1
158 #if !defined(GCONFIG_HAVE_LOCALTIME_S)
159 #define GCONFIG_HAVE_LOCALTIME_S ( defined(G_WIN32) || defined(localtime_s) )
161 #if !defined(GCONFIG_HAVE_MEMORY_H)
162 #define GCONFIG_HAVE_MEMORY_H 1
164 #if !defined(GCONFIG_HAVE_NDIR_H)
165 #define GCONFIG_HAVE_NDIR_H 0
167 #if !defined(GCONFIG_HAVE_SETGROUPS)
168 #define GCONFIG_HAVE_SETGROUPS defined(G_UNIX)
170 #if !defined(GCONFIG_HAVE_STATBUF_NSEC)
171 #define GCONFIG_HAVE_STATBUF_NSEC 0
173 #if !defined(GCONFIG_HAVE_SIN6_LEN)
174 #define GCONFIG_HAVE_SIN6_LEN 0
176 #if !defined(GCONFIG_HAVE_SOCKLEN_T)
177 #define GCONFIG_HAVE_SOCKLEN_T 1
179 #if !defined(GCONFIG_HAVE_STDINT_H)
180 #define GCONFIG_HAVE_STDINT_H 1
182 #if !defined(GCONFIG_HAVE_STDLIB_H)
183 #define GCONFIG_HAVE_STDLIB_H 1
185 #if !defined(GCONFIG_HAVE_STRNCPY_S)
186 #define GCONFIG_HAVE_STRNCPY_S ( defined(G_WIN32) || defined(strncpy_s) )
188 #if !defined(GCONFIG_HAVE_STRINGS_H)
189 #define GCONFIG_HAVE_STRINGS_H 1
191 #if !defined(GCONFIG_HAVE_STRING_H)
192 #define GCONFIG_HAVE_STRING_H 1
194 #if !defined(GCONFIG_HAVE_SYS_DIR_H)
195 #define GCONFIG_HAVE_SYS_DIR_H 0
197 #if !defined(GCONFIG_HAVE_SYS_NDIR_H)
198 #define GCONFIG_HAVE_SYS_NDIR_H 0
200 #if !defined(GCONFIG_HAVE_SYS_STAT_H)
201 #define GCONFIG_HAVE_SYS_STAT_H 1
203 #if !defined(GCONFIG_HAVE_SYS_TIME_H)
204 #define GCONFIG_HAVE_SYS_TIME_H 1
206 #if !defined(GCONFIG_HAVE_SYS_TYPES_H)
207 #define GCONFIG_HAVE_SYS_TYPES_H 1
209 #if !defined(GCONFIG_HAVE_INET_NTOP)
210 #define GCONFIG_HAVE_INET_NTOP 1
212 #if !defined(GCONFIG_HAVE_IF_NAMETOINDEX)
213 #define GCONFIG_HAVE_IF_NAMETOINDEX 1
215 #if !defined(GCONFIG_HAVE_INET_PTON)
216 #define GCONFIG_HAVE_INET_PTON 1
218 #if !defined(GCONFIG_HAVE_MISSING_STD_ABORT)
219 #define GCONFIG_HAVE_MISSING_STD_ABORT defined(G_WINDOWS)
221 #if !defined(GCONFIG_HAVE_MISSING_STD_EXIT)
222 #define GCONFIG_HAVE_MISSING_STD_EXIT defined(G_WINDOWS)
224 #if !defined(GCONFIG_HAVE_MISSING_STD_SYSTEM)
225 #define GCONFIG_HAVE_MISSING_STD_SYSTEM defined(G_WINDOWS)
227 #if !defined(GCONFIG_HAVE_MISSING_STD_MEMSET)
228 #define GCONFIG_HAVE_MISSING_STD_MEMSET defined(G_WINDOWS)
230 #if !defined(GCONFIG_HAVE_MISSING_STD_MEMCPY)
231 #define GCONFIG_HAVE_MISSING_STD_MEMCPY defined(G_WINDOWS)
233 #if !defined(GCONFIG_HAVE_MISSING_STD_STRERROR)
234 #define GCONFIG_HAVE_MISSING_STD_STRERROR defined(G_WINDOWS)
236 #if !defined(GCONFIG_HAVE_MISSING_STD_FOPEN)
237 #define GCONFIG_HAVE_MISSING_STD_FOPEN defined(G_WINDOWS)
239 #if !defined(GCONFIG_HAVE_MISSING_STD_FCLOSE)
240 #define GCONFIG_HAVE_MISSING_STD_FCLOSE defined(G_WINDOWS)
242 #if !defined(GCONFIG_HAVE_MISSING_STD_FPUTS)
243 #define GCONFIG_HAVE_MISSING_STD_FPUTS defined(G_WINDOWS)
245 #if !defined(GCONFIG_HAVE_UID_T)
246 #define GCONFIG_HAVE_UID_T defined(G_UNIX)
248 #if !defined(GCONFIG_HAVE_GID_T)
249 #define GCONFIG_HAVE_GID_T GCONFIG_HAVE_UID_T
251 #if !defined(GCONFIG_HAVE_SSIZE_T)
252 #define GCONFIG_HAVE_SSIZE_T ( defined(G_UNIX) || defined(G_MINGW) )
254 #if !defined(GCONFIG_HAVE_PID_T)
255 #define GCONFIG_HAVE_PID_T ( defined(G_UNIX) || defined(G_MINGW) )
257 #if !defined(GCONFIG_HAVE_GET_WINDOW_LONG_PTR)
258 #define GCONFIG_HAVE_GET_WINDOW_LONG_PTR defined(G_WIN32)
260 #if !defined(GCONFIG_HAVE_MREMAP)
261 #define GCONFIG_HAVE_MREMAP defined(G_UNIX_LINUX)
263 #if !defined(GCONFIG_HAVE_TIMERFD)
264 #define GCONFIG_HAVE_TIMERFD defined(G_UNIX_LINUX)
266 #if !defined(GCONFIG_HAVE_PAM)
267 #define GCONFIG_HAVE_PAM defined(G_UNIX)
269 #if !defined(GCONFIG_HAVE_PAM_IN_SECURITY)
270 #define GCONFIG_HAVE_PAM_IN_SECURITY defined(G_UNIX)
272 #if !defined(GCONFIG_HAVE_PAM_IN_INCLUDE)
273 #define GCONFIG_HAVE_PAM_IN_INCLUDE 0
275 #if !defined(GCONFIG_HAVE_PAM_IN_PAM)
276 #define GCONFIG_HAVE_PAM_IN_PAM 0
278 #if !defined(GCONFIG_HAVE_GET_NATIVE_SYSTEM_INFO)
279 #define GCONFIG_HAVE_GET_NATIVE_SYSTEM_INFO defined(G_WIN32)
281 #if !defined(GCONFIG_HAVE_LIBJPEG)
282 #define GCONFIG_HAVE_LIBJPEG 0
284 #if !defined(GCONFIG_HAVE_LIBPNG)
285 #define GCONFIG_HAVE_LIBPNG 0
287 #if !defined(GCONFIG_HAVE_LIBAV)
288 #define GCONFIG_HAVE_LIBAV 0
290 #if !defined(GCONFIG_HAVE_CURSES)
291 #define GCONFIG_HAVE_CURSES 0
293 #if !defined(GCONFIG_HAVE_LIBEXIV)
294 #define GCONFIG_HAVE_LIBEXIV 0
296 #if !defined(GCONFIG_HAVE_V4L)
297 #define GCONFIG_HAVE_V4L defined(G_UNIX_LINUX)
299 #if !defined(GCONFIG_HAVE_LIBV4L)
300 #define GCONFIG_HAVE_LIBV4L 0
302 #if !defined(GCONFIG_ENABLE_IPV6)
303 #define GCONFIG_ENABLE_IPV6 GCONFIG_HAVE_IPV6
305 #if !defined(GCONFIG_ENABLE_STD_THREAD)
306 #define GCONFIG_ENABLE_STD_THREAD GCONFIG_HAVE_CXX_STD_THREAD
308 #if !defined(GCONFIG_HAVE_SEM_INIT)
309 #define GCONFIG_HAVE_SEM_INIT ( defined(G_UNIX_LINUX) || defined(G_UNIX_FREEBSD) )
311 #if !defined(GCONFIG_HAVE_X11)
312 #define GCONFIG_HAVE_X11 defined(G_UNIX)
314 #if !defined(GCONFIG_HAVE_OPENSSL)
315 #define GCONFIG_HAVE_OPENSSL defined(G_UNIX)
317 #if !defined(GCONFIG_HAVE_OPENSSL_SSLv3)
318 #define GCONFIG_HAVE_OPENSSL_SSLv3 1
320 #if !defined(GCONFIG_HAVE_OPENSSL_TLSv1_1)
321 #define GCONFIG_HAVE_OPENSSL_TLSv1_1 1
323 #if !defined(GCONFIG_HAVE_OPENSSL_TLSv1_2)
324 #define GCONFIG_HAVE_OPENSSL_TLSv1_2 1
326 #if !defined(GCONFIG_HAVE_BOOST)
327 #define GCONFIG_HAVE_BOOST defined(G_UNIX_LINUX)
329 #if !defined(GCONFIG_HAVE_ALSA)
330 #define GCONFIG_HAVE_ALSA defined(G_UNIX_LINUX)
332 #if !defined(GCONFIG_HAVE_FMEMOPEN)
333 #define GCONFIG_HAVE_FMEMOPEN !defined(G_UNIX_OPENBSD)
335 #if !defined(GCONFIG_HAVE_X11)
336 #define GCONFIG_HAVE_X11 defined(G_UNIX)
338 #if !defined(GCONFIG_HAVE_IP_MREQN)
339 #define GCONFIG_HAVE_IP_MREQN ( defined(G_UNIX_LINUX) || defined(G_UNIX_FREEBSD) )
344 #if defined(G_WINDOWS)
346 #define __USE_W32_SOCKETS
348 #define _WIN32_WINNT _WIN32_WINNT_WINXP
350 #if (_WIN32_WINNT < _WIN32_WINNT_WINXP)
352 #define _WIN32_WINNT _WIN32_WINNT_WINXP
355 #ifndef WIN32_LEAN_AND_MEAN
356 #define WIN32_LEAN_AND_MEAN
360 #define _WIN32_IE 0x600
364 #include <shellapi.h>
367 #include <sys/stat.h>
370 #include <winsock2.h>
371 #include <ws2tcpip.h>
374 #include <sys/stat.h>
375 #include <sys/types.h>
376 #include <sys/wait.h>
377 #include <sys/utsname.h>
378 #include <sys/select.h>
379 #include <sys/socket.h>
381 #define MSG_NOSIGNAL 0
383 #include <sys/mman.h>
384 #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
385 #define MAP_ANONYMOUS MAP_ANON
387 #ifndef MREMAP_MAYMOVE
388 #define MREMAP_MAYMOVE 0
390 #include <netinet/in.h>
392 #include <arpa/inet.h>
393 #if GCONFIG_HAVE_IF_NAMETOINDEX
428 #if ! defined(G_WINDOWS)
429 typedef unsigned char BOOL ;
430 typedef unsigned int HDC ;
431 typedef unsigned int HWND ;
432 typedef unsigned int HINSTANCE ;
433 typedef unsigned int HANDLE ;
434 typedef wchar_t TCHAR ;
440 #if defined(G_WINDOWS)
441 typedef UINT32 g_uint32_t ;
442 typedef UINT16 g_uint16_t ;
443 typedef INT32 g_int32_t ;
444 typedef INT16 g_int16_t ;
447 typedef uint32_t g_uint32_t ;
448 typedef uint16_t g_uint16_t ;
449 typedef int32_t g_int32_t ;
450 typedef int16_t g_int16_t ;
453 typedef char assert_sizeof_uint16_is_2[
sizeof(g_uint16_t)==2U?1:-1] ;
454 typedef char assert_sizeof_uint32_is_4[
sizeof(g_uint32_t)==4U?1:-1] ;
459 #if ! GCONFIG_HAVE_UID_T
462 #if ! GCONFIG_HAVE_GID_T
465 #if ! GCONFIG_HAVE_SSIZE_T
467 typedef SSIZE_T ssize_t ;
469 typedef int ssize_t ;
472 #if ! GCONFIG_HAVE_PID_T
473 typedef unsigned int pid_t ;
475 #if ! GCONFIG_HAVE_SOCKLEN_T
476 typedef int socklen_t ;
478 #if ! GCONFIG_HAVE_ERRNO_T
479 typedef int errno_t ;
497 #if GCONFIG_HAVE_MISSING_STD_ABORT
500 #if GCONFIG_HAVE_MISSING_STD_EXIT
503 #if GCONFIG_HAVE_MISSING_STD_SYSTEM
506 #if GCONFIG_HAVE_MISSING_STD_MEMSET
509 #if GCONFIG_HAVE_MISSING_STD_MEMCPY
512 #if GCONFIG_HAVE_MISSING_STD_STRERROR
515 #if GCONFIG_HAVE_MISSING_STD_FOPEN
518 #if GCONFIG_HAVE_MISSING_STD_FCLOSE
521 #if GCONFIG_HAVE_MISSING_STD_FPUTS
524 #if GCONFIG_HAVE_MISSING_STD_STRUCT_TM
527 #if GCONFIG_HAVE_MISSING_STD_TIME_T
545 #define G_IGNORE_PASTE_IMP(a,b) a##b
546 #define G_IGNORE_PASTE(a,b) G_IGNORE_PASTE_IMP(a,b)
547 #define G_IGNORE_RETURN(type,expr) do { type G_IGNORE_PASTE(ignore_,__LINE__) = expr ; (void) G_IGNORE_PASTE(ignore_,__LINE__) ; } while(0)
548 #define G_IGNORE_PARAMETER(type,name) (void)name
549 #define G_IGNORE_VARIABLE(name) name=name
555 #if ! GCONFIG_HAVE_CXX_NULLPTR
561 #if GCONFIG_HAVE_CXX_CONSTEXPR
562 #define g__constexpr constexpr
565 #define g__constexpr const
568 #if GCONFIG_HAVE_CXX_NOEXCEPT
569 #define g__noexcept noexcept
571 #define g__noexcept throw()
574 #if ! GCONFIG_HAVE_CXX_OVERRIDE
578 #if GCONFIG_HAVE_CXX_FINAL
579 #define g__final final
584 #if GCONFIG_HAVE_CXX_SHARED_PTR
586 using std::shared_ptr ;
587 using std::unique_ptr ;
588 using std::const_pointer_cast ;
591 template <
typename T>
592 struct shared_ptr_deleter
594 static void fn(
void * p ) {
delete static_cast<T*
>(p) ; }
596 struct shared_ptr_control
598 explicit shared_ptr_control(
void *
object ,
void (*deleter)(
void*) ) :
599 m_object(object) , m_deleter(deleter) , m_n(1U) {}
600 explicit shared_ptr_control(
const void *
object ,
void (*deleter)(
void*) ) :
601 m_object(const_cast<void*>(object)) , m_deleter(deleter) , m_n(1U) {}
602 void inc() { m_n++ ; }
603 bool dec() { m_n-- ;
return m_n == 0 ; }
605 void (*m_deleter)(
void *) ;
608 template <
typename T>
class shared_ptr
611 typedef shared_ptr<T> ptr ;
612 explicit shared_ptr( T * p = 0 ) : m_control(new shared_ptr_control(p,&shared_ptr_deleter<T>::fn)) , m_p(p) {}
613 shared_ptr( T * p ,
void (*d)(
void*) ) : m_control(new shared_ptr_control(p,d)) , m_p(p) {}
614 template <
typename Y> shared_ptr(
const shared_ptr<Y> & obj , T * p ) : m_control(obj.m_control) , m_p(p) { inc(); }
615 ~shared_ptr() { dec(); }
616 void reset( T * p = 0 ) { ptr tmp(p); swap(tmp); }
617 void reset( T * p ,
void (*d)(
void*) ) { ptr tmp(p,d); swap(tmp); }
618 T *
get() {
return m_p; }
619 const T *
get()
const {
return m_p; }
620 T * operator->() {
return m_p; }
621 const T * operator->()
const {
return m_p; }
622 T & operator*() {
return *m_p; }
623 const T & operator*()
const {
return *m_p; }
624 operator bool ()
const {
return m_p !=
nullptr; }
625 template <
typename D> shared_ptr(
const shared_ptr<D> & o ) : m_control(o.m_control) , m_p(o.m_p) { inc(); }
626 shared_ptr(
const shared_ptr<T> & o ) : m_control(o.m_control) , m_p(o.m_p) { inc(); }
627 void operator=(
const shared_ptr<T> & o ) { ptr tmp(o); swap(tmp); }
628 unsigned int use_count()
const {
return m_control->m_n ; }
629 bool unique()
const {
return use_count() == 1; }
631 void swap( shared_ptr<T> & o ) { std::swap(m_p,o.m_p); std::swap(m_control,o.m_control); }
634 if( m_control->dec() )
636 m_control->m_deleter( m_control->m_object ) ;
638 m_control = nullptr ;
642 void inc() { m_control->inc(); }
644 shared_ptr_control * m_control ;
647 template <
typename T,
typename U>
648 shared_ptr<T> const_pointer_cast(
const shared_ptr<U> & ptr_in ) g__noexcept
650 T * p =
const_cast<T*
>(ptr_in.get()) ;
651 return shared_ptr<T>( ptr_in , p ) ;
653 template <
typename T>
class unique_ptr
656 unique_ptr() : m_p(0) {}
657 explicit unique_ptr( T * p ) : m_p(p) {}
658 explicit unique_ptr( std::auto_ptr<T> p ) : m_p(p.release()) {}
659 ~unique_ptr() {
delete m_p; }
660 void reset( T * p ) {
delete m_p; m_p = p; }
661 void reset() {
delete m_p; m_p = 0; }
662 T *
get() {
return m_p; }
663 T & operator*() {
return *m_p; }
664 const T *
get()
const {
return m_p; }
665 const T & operator*()
const {
return *m_p; }
666 T * operator->() {
return m_p; }
667 const T * operator->()
const {
return m_p; }
668 T * release() { T * p = m_p; m_p = 0;
return p; }
669 operator bool ()
const {
return m_p !=
nullptr; }
670 unique_ptr(
const unique_ptr<T> & rhs ) { m_p = rhs.m_p ;
const_cast<unique_ptr<T>&
>(rhs).m_p = 0 ; }
672 void operator=(
const unique_ptr<T> & ) ;
677 using G::shared_ptr ;
678 using G::unique_ptr ;
679 using G::const_pointer_cast ;
682 #if GCONFIG_ENABLE_STD_THREAD
690 enum { using_std_thread = 1 } ;
691 typedef std::thread thread_type ;
692 typedef std::mutex mutex_type ;
693 typedef std::lock_guard<std::mutex> lock_type ;
694 static bool works() ;
703 template <
typename T_fn> dummy_thread( T_fn fn ) { fn() ; }
704 template <
typename T_fn,
typename T_arg1> dummy_thread( T_fn fn , T_arg1 arg1 ) { fn(arg1) ; }
705 template <
typename T_fn,
typename T_arg1,
typename T_arg2> dummy_thread( T_fn fn , T_arg1 arg1 , T_arg2 arg2 ) { fn(arg1,arg2) ; }
707 bool joinable()
const {
return false ; }
711 class dummy_mutex {} ;
712 class dummy_lock {
public:
explicit dummy_lock( dummy_mutex & ) {} } ;
715 enum { using_std_thread = 0 } ;
716 typedef G::dummy_thread thread_type ;
717 typedef G::dummy_mutex mutex_type ;
718 typedef G::dummy_lock lock_type ;
719 static bool works() ;
724 #if ! GCONFIG_HAVE_CXX_TYPE_TRAITS_MAKE_UNSIGNED
727 template <
typename T>
struct make_unsigned {} ;
728 template <>
struct make_unsigned<unsigned char> {
typedef unsigned char type ; } ;
729 template <>
struct make_unsigned<char> {
typedef unsigned char type ; } ;
730 template <>
struct make_unsigned<signed char> {
typedef unsigned char type ; } ;
731 template <>
struct make_unsigned<unsigned short> {
typedef unsigned short type ; } ;
732 template <>
struct make_unsigned<short> {
typedef unsigned short type ; } ;
733 template <>
struct make_unsigned<unsigned int> {
typedef unsigned int type ; } ;
734 template <>
struct make_unsigned<int> {
typedef unsigned int type ; } ;
735 template <>
struct make_unsigned<unsigned long> {
typedef unsigned long type ; } ;
736 template <>
struct make_unsigned<long> {
typedef unsigned long type ; } ;
747 inline bool is_windows() {
return true ; }
749 inline bool is_windows() {
return false ; }
752 inline bool is_linux() {
return true ; }
754 inline bool is_linux() {
return false ; }
756 #ifdef G_UNIX_FREEBSD
757 inline bool is_free_bsd() {
return true ; }
759 inline bool is_free_bsd() {
return false ; }
761 #ifdef G_UNIX_OPENBSD
762 inline bool is_open_bsd() {
return true ; }
764 inline bool is_open_bsd() {
return false ; }
767 inline bool is_bsd() {
return true ; }
769 inline bool is_bsd() {
return false ; }
777 typedef g_uint16_t g_port_t ;
781 #ifndef AI_NUMERICSERV
782 #define AI_NUMERICSERV 0
784 #ifndef AI_ADDRCONFIG
785 #define AI_ADDRCONFIG 0
789 #define MSG_NOSIGNAL 0
795 #define INADDR_NONE 0xffffffff
802 #if GCONFIG_HAVE_IPV6
803 inline void gnet_address6_init( sockaddr_in6 & s )
805 #if GCONFIG_HAVE_SIN6_LEN
806 s.sin6_len =
sizeof(s) ;
820 #if ! GCONFIG_HAVE_INET_PTON
822 namespace GNet {
int inet_pton_imp(
int f ,
const char * p ,
void * result ) ; }
823 inline int inet_pton(
int f ,
const char * p ,
void * result )
825 return GNet::inet_pton_imp( f , p , result ) ;
830 #if ! GCONFIG_HAVE_INET_NTOP
832 namespace GNet {
const char * inet_ntop_imp(
int f ,
void * ap ,
char * buffer ,
size_t n ) ; }
833 inline const char * inet_ntop(
int f ,
void * ap ,
char * buffer ,
size_t n )
835 return GNet::inet_ntop_imp( f , ap , buffer , n ) ;
840 #if ! GCONFIG_HAVE_IF_NAMETOINDEX
842 inline unsigned int if_nametoindex(
const char * )
849 #if ! GCONFIG_HAVE_READLINK && !defined(readlink)
851 inline ssize_t readlink(
const char * ,
char * ,
size_t )
858 #if GCONFIG_HAVE_GETPWNAM && ! GCONFIG_HAVE_GETPWNAM_R
860 #include <sys/types.h>
862 inline int getpwnam_r(
const char * name ,
struct passwd * pwd ,
863 char * buf ,
size_t buflen ,
struct passwd ** result )
865 struct passwd * p = ::getpwnam( name ) ;
881 #if ! GCONFIG_HAVE_GMTIME_R && !defined(gmtime_r) && defined(G_UNIX)
884 inline std::tm * gmtime_r(
const std::time_t * tp , std::tm * tm_p )
886 const struct std::tm * p = std::gmtime( tp ) ;
887 if( p == 0 )
return 0 ;
894 #if ! GCONFIG_HAVE_LOCALTIME_R && !defined(localtime_r) && defined(G_UNIX)
897 inline struct std::tm * localtime_r(
const std::time_t * tp ,
struct std::tm * tm_p )
899 const struct std::tm * p = std::localtime( tp ) ;
900 if( p == 0 )
return 0 ;
907 #if ! GCONFIG_HAVE_LOCALTIME_S && !defined(localtime_s)
909 inline errno_t localtime_s(
struct std::tm * tm_p ,
const std::time_t * tp )
911 const errno_t e_inval = 22 ;
912 if( tm_p ==
nullptr )
return e_inval ;
913 tm_p->tm_sec = tm_p->tm_min = tm_p->tm_hour = tm_p->tm_mday = tm_p->tm_mon =
914 tm_p->tm_year = tm_p->tm_wday = tm_p->tm_yday = tm_p->tm_isdst = -1 ;
915 if( tp ==
nullptr || *tp < 0 )
return e_inval ;
916 const struct std::tm * p = std::localtime( tp ) ;
917 if( p == 0 )
return e_inval ;
924 #if ! GCONFIG_HAVE_GMTIME_S && !defined(gmtime_s)
926 inline errno_t gmtime_s(
struct std::tm * tm_p ,
const std::time_t * tp )
928 const errno_t e_inval = 22 ;
929 if( tm_p ==
nullptr )
return e_inval ;
930 tm_p->tm_sec = tm_p->tm_min = tm_p->tm_hour = tm_p->tm_mday = tm_p->tm_mon =
931 tm_p->tm_year = tm_p->tm_wday = tm_p->tm_yday = tm_p->tm_isdst = -1 ;
932 if( tp ==
nullptr || *tp < 0 )
return e_inval ;
933 const struct std::tm * p = std::gmtime( tp ) ;
934 if( p == 0 )
return e_inval ;
941 #if GCONFIG_HAVE_SETGROUPS
945 inline int setgroups(
size_t ,
const gid_t * )
952 #if ! GCONFIG_HAVE_GETENV_S
955 inline errno_t getenv_s(
size_t * n_out ,
char * buffer ,
size_t n_in ,
const char * name )
957 const errno_t e_inval = 22 ;
958 const errno_t e_range = 34 ;
959 if( n_out ==
nullptr || name ==
nullptr )
return e_inval ;
960 const char * p = ::getenv( name ) ;
961 *n_out = p ? (strlen(p) + 1U) : 0 ;
962 if( p && *n_out > n_in )
return e_range ;
963 if( p && buffer ) strcpy( buffer , p ) ;
970 #if ! GCONFIG_HAVE_STRNCPY_S
972 #define _TRUNCATE (~((size_t)(0U)))
975 inline errno_t strncpy_s(
char * dst ,
size_t n ,
const char * src ,
size_t c )
977 if( dst ==
nullptr )
return EINVAL ;
978 if( src ==
nullptr ) { *dst =
'\0' ;
return EINVAL ; }
979 if( n == 0 ) {
return EINVAL ; }
980 size_t d = strlen(src) ;
if( c != _TRUNCATE && c < d ) d = c ;
983 if( c != _TRUNCATE ) { *dst =
'\0' ;
return ERANGE ; }
984 strncpy( dst , src , n ) ;
989 strncpy( dst , src , d ) ;
998 #if ! GCONFIG_HAVE_GET_WINDOW_LONG_PTR && defined(G_WINDOWS)
1000 typedef char assert_thirty_two_bit_windows[
sizeof(
void*)==4U?1:-1] ;
1001 const int GWLP_HINSTANCE = GWL_HINSTANCE ;
1002 const int GWLP_WNDPROC = GWL_WNDPROC ;
1003 const int DWLP_USER = DWL_USER ;
1004 inline LONG_PTR GetWindowLongPtr( HWND h ,
int id )
1006 return static_cast<LONG_PTR
>(::GetWindowLong(h,
id)) ;
1008 inline LONG_PTR SetWindowLongPtr( HWND h ,
int id , LONG_PTR value )
1010 return static_cast<LONG_PTR
>(::SetWindowLong(h,
id,static_cast<LONG>(value))) ;
1015 #if ! GCONFIG_HAVE_MREMAP && defined(G_UNIX)
1017 inline void * mremap(
void * ,
size_t ,
size_t ,
int )
1020 return (
void*)(-1) ;
Helper class for std::thread capabilities.