Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
got a number (not a table?) with Task_splay_irecv
[simgrid.git] / src / portable.h
1 /* portable -- header loading to write portable code                         */
2 /* loads much more stuff than sysdep.h since the latter is in public interface*/
3
4 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
5  * All rights reserved.                                                     */
6
7 /* This program is free software; you can redistribute it and/or modify it
8   * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #ifndef GRAS_PORTABLE_H
11 #define GRAS_PORTABLE_H
12
13 #include "gras_config.h"
14 #include "xbt/misc.h"
15 /* 
16  * win32 or win64 (__XBT_WIN32 is defined for win32 and win64 applications, __TOS_WIN__ is defined by xlC).
17 */
18 #ifdef _XBT_WIN32
19 # include "win32/config.h"
20 # include <windows.h>
21 #endif
22
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #ifdef HAVE_ERRNO_H
27 #  include <errno.h>
28 #endif
29
30 #ifdef HAVE_UNISTD_H
31 #  include <unistd.h>
32 #endif
33
34 /****
35  **** Networking 
36  ****/
37
38
39 #ifdef HAVE_SYS_SOCKET_H
40 #  include <sys/socket.h>
41 #  include <netinet/in.h>       /* sometimes required for #include <arpa/inet.h> */
42 #  include <netinet/tcp.h>      /* TCP_NODELAY */
43 #  include <netdb.h>            /* getprotobyname() */
44 #  include <arpa/inet.h>        /* inet_ntoa() */
45 #  include <sys/types.h>        /* sometimes required for fd_set */
46 # endif
47
48
49 #ifndef HAVE_WINSOCK_H
50 #       define tcp_read( s, buf, len)   read( s, buf, len )
51 #       define tcp_write( s, buf, len)  write( s, buf, len )
52 #       define sock_errno        errno
53 #       define sock_errstr(err)  strerror(err)
54
55 #       ifdef SHUT_RDWR
56 #               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
57 #       else
58 #               define tcp_close( s )   close( s )
59 #       endif
60 #endif                          /* windows or unix ? */
61
62 /****
63  **** File handling
64  ****/
65
66 #include <fcntl.h>
67
68 #ifdef HAVE_SYS_STAT_H
69 #  include <sys/stat.h>
70 #endif
71
72 #ifndef O_BINARY
73 #  define O_BINARY 0
74 #endif
75
76 /****
77  **** Time handling
78  ****/
79
80 #ifdef TIME_WITH_SYS_TIME
81 # include <sys/time.h>
82 # include <time.h>
83 #else
84 # if HAVE_SYS_TIME_H
85 #  include <sys/time.h>
86 # else
87 #  include <time.h>
88 # endif
89 #endif
90
91 /****
92  **** Signals
93  ****/
94 #ifdef HAVE_SIGNAL_H
95 # include <signal.h>
96 #endif
97
98 /****
99  **** string handling (parts from http://www.ijs.si/software/snprintf/)
100  ****/
101
102 /* prototype of C99 functions */
103 #if defined(HAVE_SNPRINTF)
104 #include <stdio.h>
105 #else
106 XBT_PUBLIC(int) snprintf(char *, size_t, const char *, /*args */ ...);
107 XBT_PUBLIC(int) vsnprintf(char *, size_t, const char *, va_list);
108 #endif
109
110
111 /* use internal functions when OS provided ones are borken */
112 #if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
113 extern int portable_snprintf(char *str, size_t str_m, const char *fmt,
114                              /*args */ ...);
115 extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt,
116                               va_list ap);
117 #define snprintf  portable_snprintf
118 #define vsnprintf portable_vsnprintf
119 #endif
120
121 /* prototype of GNU functions  */
122 #if (defined(__GNUC__) && !defined(__cplusplus))
123 extern int asprintf(char **ptr, const char *fmt, /*args */ ...);
124 extern int vasprintf(char **ptr, const char *fmt, va_list ap);
125 #endif
126
127 extern int asnprintf(char **ptr, size_t str_m, const char *fmt, /*args */
128                      ...);
129 extern int vasnprintf(char **ptr, size_t str_m, const char *fmt,
130                       va_list ap);
131
132 /*
133  * That's needed to protect solaris's printf from ever seing NULL associated to a %s format
134  * (without adding an extra check on working platforms :)
135  */
136
137 #ifdef PRINTF_NULL_WORKING
138 #  define PRINTF_STR(a) (a)
139 #else
140 #  define PRINTF_STR(a) (a)?:"(null)"
141 #endif
142
143 /*
144  * What we need to extract the backtrace in exception handling code
145  */
146 #ifdef HAVE_EXECINFO_H
147 #  include <execinfo.h>
148 #endif
149
150 /****
151  **** Some debugging functions. Can't we find a better place for this??
152  ****/
153 void hexa_print(const char *name, unsigned char *data, int size);
154 const char *hexa_str(unsigned char *data, int size, int downside);
155
156 #endif                          /* GRAS_PORTABLE_H */