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
16 * win32 or win64 (__WIN32 is defined for win32 and win64 applications, __TOS_WIN__ is defined by xlC).
19 # include "win32/config.h"
22 # include "gras_config.h"
25 /* Load this asap to make sure that GNU_SOURCE is defined on need when stdio gets loaded by some random system header */
48 #ifdef HAVE_SYS_SOCKET_H
49 # include <sys/socket.h>
50 # include <netinet/in.h> /* sometimes required for #include <arpa/inet.h> */
51 # include <netinet/tcp.h> /* TCP_NODELAY */
52 # include <netdb.h> /* getprotobyname() */
53 # include <arpa/inet.h> /* inet_ntoa() */
54 # include <sys/types.h> /* sometimes required for fd_set */
58 #ifndef HAVE_WINSOCK_H
59 # define tcp_read( s, buf, len) read( s, buf, len )
60 # define tcp_write( s, buf, len) write( s, buf, len )
61 # define sock_errno errno
62 # define sock_errstr(err) strerror(err)
65 # define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
67 # define tcp_close( s ) close( s )
69 #endif /* windows or unix ? */
77 #ifdef HAVE_SYS_STAT_H
78 # include <sys/stat.h>
89 #ifdef TIME_WITH_SYS_TIME
90 # include <sys/time.h>
94 # include <sys/time.h>
108 **** string handling (parts from http://www.ijs.si/software/snprintf/)
111 /* prototype of C99 functions */
112 #if defined(HAVE_SNPRINTF)
115 XBT_PUBLIC(int) snprintf(char *, size_t, const char *, /*args*/ ...);
116 XBT_PUBLIC(int) vsnprintf(char *, size_t, const char *, va_list);
120 /* use internal functions when OS provided ones are borken */
121 #if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
122 extern int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...);
123 extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
124 #define snprintf portable_snprintf
125 #define vsnprintf portable_vsnprintf
128 /* prototype of GNU functions */
129 #if (defined(__GNUC__) && !defined(__cplusplus))
130 extern int asprintf (char **ptr, const char *fmt, /*args*/ ...);
131 extern int vasprintf (char **ptr, const char *fmt, va_list ap);
134 extern int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...);
135 extern int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap);
138 * That's needed to protect solaris's printf from ever seing NULL associated to a %s format
139 * (without adding an extra check on working platforms :)
142 #ifdef PRINTF_NULL_WORKING
143 # define PRINTF_STR(a) (a)
145 # define PRINTF_STR(a) (a)?:"(null)"
149 * What we need to extract the backtrace in exception handling code
151 #ifdef HAVE_EXECINFO_H
152 # include <execinfo.h>
156 **** Some debugging functions. Can't we find a better place for this??
158 void hexa_print(const char*name, unsigned char *data, int size);
159 const char *hexa_str(unsigned char *data, int size, int downside);
161 #endif /* GRAS_PORTABLE_H */