Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
display more info about the local data model
[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-2010, 2012-2015. 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 SIMGRID_PORTABLE_H
11 #define SIMGRID_PORTABLE_H
12
13 #include "internal_config.h"
14 #include "xbt/misc.h"
15 #ifdef _XBT_WIN32
16 # include <windows.h>
17 #endif
18
19 #include <stdarg.h>
20 #include <stdio.h>
21
22 #ifdef HAVE_ERRNO_H
23 #  include <errno.h>
24 #endif
25
26 #ifdef HAVE_UNISTD_H
27 #  include <unistd.h>
28 #endif
29
30 #ifdef HAVE_SYS_PARAM_H
31 # include <sys/param.h>
32 #endif
33 #ifdef HAVE_SYS_SYSCTL_H
34 # include <sys/sysctl.h>
35 #endif
36
37 /****
38  **** File handling
39  ****/
40
41 #include <fcntl.h>
42
43 #ifdef _XBT_WIN32
44   #ifndef EWOULDBLOCK
45   #define EWOULDBLOCK WSAEWOULDBLOCK
46   #endif
47
48   #ifndef EINPROGRESS
49   #define EINPROGRESS WSAEINPROGRESS
50   #endif
51
52   #ifndef ETIMEDOUT
53   #define ETIMEDOUT   WSAETIMEDOUT
54   #endif
55
56   #ifdef S_IRGRP
57     #undef S_IRGRP
58   #endif
59   #define S_IRGRP 0
60
61   #ifdef S_IWGRP
62     #undef S_IWGRP
63   #endif
64   #define S_IWGRP 0
65 #endif
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 XBT_PUBLIC(int) asprintf(char **ptr, const char *fmt, /*args */ ...);
123 XBT_PUBLIC(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  * What we need to extract the backtrace in exception handling code
133  */
134 #ifdef HAVE_EXECINFO_H
135 #  include <execinfo.h>
136 #endif
137
138 #endif                          /* SIMGRID_PORTABLE_H */