3 /* portable -- header loading to write portable code */
4 /* loads much more stuff than sysdep.h since the latter is in public interface*/
6 /* Copyright (c) 2004 Martin Quinson. All rights reserved. */
8 /* This program is free software; you can redistribute it and/or modify it
9 * under the terms of the license (GNU LGPL) which comes with this package. */
11 #ifndef GRAS_PORTABLE_H
12 #define GRAS_PORTABLE_H
15 * win32 or win64 (__WIN32 is defined for win32 and win64 applications, __TOS_WIN__ is defined by xlC).
18 # include "win32/config.h"
21 # include "gras_config.h"
24 /* Load this asap to make sure that GNU_SOURCE is defined on need when stdio gets loaded by some random system header */
45 #ifdef HAVE_SYS_SOCKET_H
46 # include <sys/socket.h>
47 # include <netinet/in.h> /* sometimes required for #include <arpa/inet.h> */
48 # include <netinet/tcp.h> /* TCP_NODELAY */
49 # include <netdb.h> /* getprotobyname() */
50 # include <arpa/inet.h> /* inet_ntoa() */
51 # include <sys/types.h> /* sometimes required for fd_set */
55 #ifndef HAVE_WINSOCK_H
56 # define tcp_read( s, buf, len) read( s, buf, len )
57 # define tcp_write( s, buf, len) write( s, buf, len )
58 # define sock_errno errno
59 # define sock_errstr(err) strerror(err)
62 # define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
64 # define tcp_close( s ) close( s )
66 #endif /* windows or unix ? */
74 #ifdef HAVE_SYS_STAT_H
75 # include <sys/stat.h>
86 #ifdef TIME_WITH_SYS_TIME
87 # include <sys/time.h>
91 # include <sys/time.h>
105 **** string handling (parts from http://www.ijs.si/software/snprintf/)
108 /* prototype of C99 functions */
112 # if (defined(_MSC_VER) && defined(DLL_EXPORT))
113 __declspec(dllexport) int snprintf(char *, size_t, const char *, /*args*/ ...);
114 __declspec(dllexport) int vsnprintf(char *, size_t, const char *, va_list);
115 # elif (defined(_MSC_VER) && !defined(DLL_EXPORT) && !defined(DLL_STATIC) )
116 __declspec(dllimport) int snprintf(char *, size_t, const char *, /*args*/ ...);
117 __declspec(dllimport) int vsnprintf(char *, size_t, const char *, va_list);
119 extern int snprintf(char *, size_t, const char *, /*args*/ ...);
120 extern int vsnprintf(char *, size_t, const char *, va_list);
125 /* use internal functions when OS provided ones are borken */
126 #if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
127 extern int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...);
128 extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
129 #define snprintf portable_snprintf
130 #define vsnprintf portable_vsnprintf
133 /* prototype of GNU functions */
135 extern int asprintf (char **ptr, const char *fmt, /*args*/ ...);
136 extern int vasprintf (char **ptr, const char *fmt, va_list ap);
138 extern int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...);
139 extern int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap);
142 * That's needed to protect solaris's printf from ever seing NULL associated to a %s format
143 * (without adding an extra check on working platforms :)
146 #ifdef PRINTF_NULL_WORKING
147 # define PRINTF_STR(a) (a)
149 # define PRINTF_STR(a) (a)?:"(null)"
153 * What we need to extract the backtrace in exception handling code
155 #ifdef HAVE_EXECINFO_H
156 # include <execinfo.h>
160 **** Some debugging functions. Can't we find a better place for this??
162 void hexa_print(const char*name, unsigned char *data, int size);
163 const char *hexa_str(unsigned char *data, int size, int downside);
165 #endif /* GRAS_PORTABLE_H */