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
14 #include "simgrid_config.h"
17 * win32 or win64 (__WIN32 is defined for win32 and win64 applications, __TOS_WIN__ is defined by xlC).
20 # include "win32/config.h"
23 # include "gras_config.h"
41 #ifdef HAVE_SYS_SOCKET_H
42 # include <sys/socket.h>
43 # include <netinet/in.h> /* sometimes required for #include <arpa/inet.h> */
44 # include <netinet/tcp.h> /* TCP_NODELAY */
45 # include <netdb.h> /* getprotobyname() */
46 # include <arpa/inet.h> /* inet_ntoa() */
47 # include <sys/types.h> /* sometimes required for fd_set */
51 #ifndef HAVE_WINSOCK_H
52 # define tcp_read( s, buf, len) read( s, buf, len )
53 # define tcp_write( s, buf, len) write( s, buf, len )
54 # define sock_errno errno
55 # define sock_errstr(err) strerror(err)
58 # define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
60 # define tcp_close( s ) close( s )
62 #endif /* windows or unix ? */
70 #ifdef HAVE_SYS_STAT_H
71 # include <sys/stat.h>
82 #ifdef TIME_WITH_SYS_TIME
83 # include <sys/time.h>
87 # include <sys/time.h>
101 **** string handling (parts from http://www.ijs.si/software/snprintf/)
104 /* prototype of C99 functions */
105 #if defined(HAVE_SNPRINTF)
108 XBT_PUBLIC(int) snprintf(char *, size_t, const char *, /*args */ ...);
109 XBT_PUBLIC(int) vsnprintf(char *, size_t, const char *, va_list);
113 /* use internal functions when OS provided ones are borken */
114 #if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
115 extern int portable_snprintf(char *str, size_t str_m, const char *fmt,
117 extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt,
119 #define snprintf portable_snprintf
120 #define vsnprintf portable_vsnprintf
123 /* prototype of GNU functions */
124 #if (defined(__GNUC__) && !defined(__cplusplus))
125 extern int asprintf(char **ptr, const char *fmt, /*args */ ...);
126 extern int vasprintf(char **ptr, const char *fmt, va_list ap);
129 extern int asnprintf(char **ptr, size_t str_m, const char *fmt, /*args */
131 extern int vasnprintf(char **ptr, size_t str_m, const char *fmt,
135 * That's needed to protect solaris's printf from ever seing NULL associated to a %s format
136 * (without adding an extra check on working platforms :)
139 #ifdef PRINTF_NULL_WORKING
140 # define PRINTF_STR(a) (a)
142 # define PRINTF_STR(a) (a)?:"(null)"
146 * What we need to extract the backtrace in exception handling code
148 #ifdef HAVE_EXECINFO_H
149 # include <execinfo.h>
153 **** Some debugging functions. Can't we find a better place for this??
155 void hexa_print(const char *name, unsigned char *data, int size);
156 const char *hexa_str(unsigned char *data, int size, int downside);
158 #endif /* GRAS_PORTABLE_H */