Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
some simple cleanups in the routing code
[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 "src/internal_config.h"
14 #include "xbt/base.h"
15 #include "xbt/misc.h"
16 #ifdef _XBT_WIN32
17 # include <windows.h>
18 #endif
19
20 #include <stdarg.h>
21 #include <stdio.h>
22
23 #ifdef HAVE_ERRNO_H
24 #  include <errno.h>
25 #endif
26
27 #ifdef HAVE_UNISTD_H
28 #  include <unistd.h>
29 #endif
30
31 #ifdef HAVE_SYS_PARAM_H
32 # include <sys/param.h>
33 #endif
34 #ifdef HAVE_SYS_SYSCTL_H
35 # include <sys/sysctl.h>
36 #endif
37
38 /****
39  **** File handling
40  ****/
41
42 #include <fcntl.h>
43
44 #ifdef _XBT_WIN32
45   #ifndef EWOULDBLOCK
46   #define EWOULDBLOCK WSAEWOULDBLOCK
47   #endif
48
49   #ifndef EINPROGRESS
50   #define EINPROGRESS WSAEINPROGRESS
51   #endif
52
53   #ifndef ETIMEDOUT
54   #define ETIMEDOUT   WSAETIMEDOUT
55   #endif
56
57   #ifdef S_IRGRP
58     #undef S_IRGRP
59   #endif
60   #define S_IRGRP 0
61
62   #ifdef S_IWGRP
63     #undef S_IWGRP
64   #endif
65   #define S_IWGRP 0
66 #endif
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 #if HAVE_SYS_TIME_H
81 #  include <sys/time.h>
82 #endif
83 #include <time.h>
84
85 /****
86  **** Signals
87  ****/
88 #ifdef HAVE_SIGNAL_H
89 # include <signal.h>
90 #endif
91
92 /****
93  **** string handling (parts from http://www.ijs.si/software/snprintf/)
94  ****/
95
96 /* prototype of C99 functions */
97 #if defined(HAVE_SNPRINTF)
98 #include <stdio.h>
99 #else
100 XBT_PUBLIC(int) snprintf(char *, size_t, const char *, /*args */ ...);
101 XBT_PUBLIC(int) vsnprintf(char *, size_t, const char *, va_list);
102 #endif
103
104
105 /* use internal functions when OS provided ones are borken */
106 #if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
107 XBT_PRIVATE int portable_snprintf(char *str, size_t str_m, const char *fmt,
108                              /*args */ ...);
109 XBT_PRIVATE int portable_vsnprintf(char *str, size_t str_m, const char *fmt,
110                               va_list ap);
111 #define snprintf  portable_snprintf
112 #define vsnprintf portable_vsnprintf
113 #endif
114
115 /* prototype of GNU functions  */
116 #if (defined(__GNUC__) && !defined(__cplusplus))
117 XBT_PUBLIC(int) asprintf(char **ptr, const char *fmt, /*args */ ...);
118 XBT_PUBLIC(int) vasprintf(char **ptr, const char *fmt, va_list ap);
119 #endif
120
121 extern int asnprintf(char **ptr, size_t str_m, const char *fmt, /*args */
122                      ...);
123 extern int vasnprintf(char **ptr, size_t str_m, const char *fmt,
124                       va_list ap);
125
126 /*
127  * What we need to extract the backtrace in exception handling code
128  */
129 #ifdef HAVE_EXECINFO_H
130 #  include <execinfo.h>
131 #endif
132
133 #endif                          /* SIMGRID_PORTABLE_H */