Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the way to instanciate links via worsktation_ptask_L07 model when bypassing the...
[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
25 #ifdef HAVE_ERRNO_H
26 #  include <errno.h>
27 #endif
28
29 #ifdef HAVE_UNISTD_H
30 #  include <unistd.h>
31 #endif
32
33 /****
34  **** Networking 
35  ****/
36
37
38 #ifdef HAVE_SYS_SOCKET_H
39 #  include <sys/socket.h>
40 #  include <netinet/in.h>       /* sometimes required for #include <arpa/inet.h> */
41 #  include <netinet/tcp.h>      /* TCP_NODELAY */
42 #  include <netdb.h>            /* getprotobyname() */
43 #  include <arpa/inet.h>        /* inet_ntoa() */
44 #  include <sys/types.h>        /* sometimes required for fd_set */
45 # endif
46
47
48 #ifndef HAVE_WINSOCK_H
49 #       define tcp_read( s, buf, len)   read( s, buf, len )
50 #       define tcp_write( s, buf, len)  write( s, buf, len )
51 #       define sock_errno        errno
52 #       define sock_errstr(err)  strerror(err)
53
54 #       ifdef SHUT_RDWR
55 #               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
56 #       else
57 #               define tcp_close( s )   close( s )
58 #       endif
59 #endif /* windows or unix ? */
60
61 /****
62  **** File handling
63  ****/
64
65 #include <fcntl.h>
66
67 #ifdef HAVE_SYS_STAT_H
68 #  include <sys/stat.h>
69 #endif
70
71 #ifndef O_BINARY
72 #  define O_BINARY 0
73 #endif
74
75 /****
76  **** Time handling
77  ****/
78
79 #ifdef TIME_WITH_SYS_TIME
80 # include <sys/time.h>
81 # include <time.h>
82 #else
83 # if HAVE_SYS_TIME_H
84 #  include <sys/time.h>
85 # else
86 #  include <time.h>
87 # endif
88 #endif
89
90 /****
91  **** Signals
92  ****/
93 #ifdef HAVE_SIGNAL_H
94 # include <signal.h>
95 #endif
96
97 /****
98  **** string handling (parts from http://www.ijs.si/software/snprintf/)
99  ****/
100
101 /* prototype of C99 functions */
102 #if defined(HAVE_SNPRINTF)
103 #include <stdio.h>
104 #else
105 XBT_PUBLIC(int) snprintf(char *, size_t, const char *, /*args */ ...);
106 XBT_PUBLIC(int) vsnprintf(char *, size_t, const char *, va_list);
107 #endif
108
109
110 /* use internal functions when OS provided ones are borken */
111 #if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
112      extern int portable_snprintf(char *str, size_t str_m, const char *fmt,
113                                   /*args */ ...);
114      extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt,
115                                    va_list ap);
116 #define snprintf  portable_snprintf
117 #define vsnprintf portable_vsnprintf
118 #endif
119
120 /* prototype of GNU functions  */
121 #if (defined(__GNUC__) && !defined(__cplusplus))
122      extern int asprintf(char **ptr, const char *fmt, /*args */ ...);
123      extern int vasprintf(char **ptr, const char *fmt, va_list ap);
124 #endif
125
126      extern int asnprintf(char **ptr, size_t str_m, const char *fmt,    /*args */
127                           ...);
128      extern int vasnprintf(char **ptr, size_t str_m, const char *fmt,
129                            va_list ap);
130
131 /*
132  * That's needed to protect solaris's printf from ever seing NULL associated to a %s format
133  * (without adding an extra check on working platforms :)
134  */
135
136 #ifdef PRINTF_NULL_WORKING
137 #  define PRINTF_STR(a) (a)
138 #else
139 #  define PRINTF_STR(a) (a)?:"(null)"
140 #endif
141
142 /*
143  * What we need to extract the backtrace in exception handling code
144  */
145 #ifdef HAVE_EXECINFO_H
146 #  include <execinfo.h>
147 #endif
148
149 /****
150  **** Some debugging functions. Can't we find a better place for this??
151  ****/
152      void hexa_print(const char *name, unsigned char *data, int size);
153      const char *hexa_str(unsigned char *data, int size, int downside);
154
155 #endif /* GRAS_PORTABLE_H */