Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix SD_task_get_execution_time() when communication or computation arrays are NULL
[simgrid.git] / src / portable.h
1 /* $Id$ */
2
3 /* portable -- header loading to write portable code                         */
4 /* loads much more stuff than sysdep.h since the latter is in public interface*/
5
6 /* Copyright (c) 2004 Martin Quinson. All rights reserved.                   */
7
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. */
10
11 #ifndef GRAS_PORTABLE_H
12 #define GRAS_PORTABLE_H
13
14 #include "simgrid_config.h"
15 #include "xbt/misc.h"
16 /* 
17  * win32 or win64 (__WIN32 is defined for win32 and win64 applications, __TOS_WIN__ is defined by xlC). 
18 */
19 #ifdef _WIN32
20 # include "win32/config.h"
21 # include <windows.h>
22 #else
23 #  include "gras_config.h"
24 #endif
25
26 #include <stdarg.h>
27
28 #ifdef HAVE_ERRNO_H
29 #  include <errno.h>
30 #endif
31
32 #ifdef HAVE_UNISTD_H
33 #  include <unistd.h>
34 #endif
35
36 /****
37  **** Networking 
38  ****/
39
40
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 */
48 # endif
49
50
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)
56
57 #       ifdef SHUT_RDWR
58 #               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
59 #       else
60 #               define tcp_close( s )   close( s )
61 #       endif
62 #endif /* windows or unix ? */
63
64 /****
65  **** File handling
66  ****/
67
68 #include <fcntl.h>
69
70 #ifdef HAVE_SYS_STAT_H
71 #  include <sys/stat.h>
72 #endif
73
74 #ifndef O_BINARY
75 #  define O_BINARY 0
76 #endif
77
78 /****
79  **** Time handling
80  ****/
81
82 #ifdef TIME_WITH_SYS_TIME
83 # include <sys/time.h>
84 # include <time.h>
85 #else
86 # if HAVE_SYS_TIME_H
87 #  include <sys/time.h>
88 # else
89 #  include <time.h>
90 # endif
91 #endif
92
93 /****
94  **** Signals
95  ****/
96 #ifdef HAVE_SIGNAL_H
97 # include <signal.h>
98 #endif
99
100 /****
101  **** string handling (parts from http://www.ijs.si/software/snprintf/)
102  ****/
103
104 /* prototype of C99 functions */
105 #if defined(HAVE_SNPRINTF)
106 #include <stdio.h>
107 #else
108 XBT_PUBLIC(int) snprintf(char *, size_t, const char *, /*args */ ...);
109 XBT_PUBLIC(int) vsnprintf(char *, size_t, const char *, va_list);
110 #endif
111
112
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,
116                                   /*args */ ...);
117      extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt,
118                                    va_list ap);
119 #define snprintf  portable_snprintf
120 #define vsnprintf portable_vsnprintf
121 #endif
122
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);
127 #endif
128
129      extern int asnprintf(char **ptr, size_t str_m, const char *fmt,    /*args */
130                           ...);
131      extern int vasnprintf(char **ptr, size_t str_m, const char *fmt,
132                            va_list ap);
133
134 /*
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 :)
137  */
138
139 #ifdef PRINTF_NULL_WORKING
140 #  define PRINTF_STR(a) (a)
141 #else
142 #  define PRINTF_STR(a) (a)?:"(null)"
143 #endif
144
145 /*
146  * What we need to extract the backtrace in exception handling code
147  */
148 #ifdef HAVE_EXECINFO_H
149 #  include <execinfo.h>
150 #endif
151
152 /****
153  **** Some debugging functions. Can't we find a better place for this??
154  ****/
155      void hexa_print(const char *name, unsigned char *data, int size);
156      const char *hexa_str(unsigned char *data, int size, int downside);
157
158 #endif /* GRAS_PORTABLE_H */