Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into S4U
[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 /* 
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 #ifdef HAVE_SYS_PARAM_H
35 # include <sys/param.h>
36 #endif
37 #ifdef HAVE_SYS_SYSCTL_H
38 # include <sys/sysctl.h>
39 #endif
40
41 /****
42  **** File handling
43  ****/
44
45 #include <fcntl.h>
46
47 #ifdef HAVE_SYS_STAT_H
48 #  include <sys/stat.h>
49 #endif
50
51 #ifndef O_BINARY
52 #  define O_BINARY 0
53 #endif
54
55 /****
56  **** Time handling
57  ****/
58
59 #ifdef TIME_WITH_SYS_TIME
60 # include <sys/time.h>
61 # include <time.h>
62 #else
63 # if HAVE_SYS_TIME_H
64 #  include <sys/time.h>
65 # else
66 #  include <time.h>
67 # endif
68 #endif
69
70 /****
71  **** Signals
72  ****/
73 #ifdef HAVE_SIGNAL_H
74 # include <signal.h>
75 #endif
76
77 /****
78  **** string handling (parts from http://www.ijs.si/software/snprintf/)
79  ****/
80
81 /* prototype of C99 functions */
82 #if defined(HAVE_SNPRINTF)
83 #include <stdio.h>
84 #else
85 XBT_PUBLIC(int) snprintf(char *, size_t, const char *, /*args */ ...);
86 XBT_PUBLIC(int) vsnprintf(char *, size_t, const char *, va_list);
87 #endif
88
89
90 /* use internal functions when OS provided ones are borken */
91 #if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
92 extern int portable_snprintf(char *str, size_t str_m, const char *fmt,
93                              /*args */ ...);
94 extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt,
95                               va_list ap);
96 #define snprintf  portable_snprintf
97 #define vsnprintf portable_vsnprintf
98 #endif
99
100 /* prototype of GNU functions  */
101 #if (defined(__GNUC__) && !defined(__cplusplus))
102 XBT_PUBLIC(int) asprintf(char **ptr, const char *fmt, /*args */ ...);
103 XBT_PUBLIC(int) vasprintf(char **ptr, const char *fmt, va_list ap);
104 #endif
105
106 extern int asnprintf(char **ptr, size_t str_m, const char *fmt, /*args */
107                      ...);
108 extern int vasnprintf(char **ptr, size_t str_m, const char *fmt,
109                       va_list ap);
110
111 /*
112  * What we need to extract the backtrace in exception handling code
113  */
114 #ifdef HAVE_EXECINFO_H
115 #  include <execinfo.h>
116 #endif
117
118 #endif                          /* SIMGRID_PORTABLE_H */