Skip to content

Commit bfa95d5

Browse files
authored
Merge pull request #12 from compnerd/config
config: generalise more things to be detected
2 parents 4c3a7ae + 18306eb commit bfa95d5

File tree

1 file changed

+15
-45
lines changed

1 file changed

+15
-45
lines changed

src/config.h

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,28 @@
55
extern "C" {
66
#endif
77

8-
#define HAVE_STDBOOL_H
8+
#if !defined(__has_builtin)
9+
#define __has_builtin(builtin) 0
10+
#endif
11+
12+
#if !defined(__has_include)
13+
#define __has_include(include) 0
14+
#endif
915

10-
#ifdef HAVE_STDBOOL_H
16+
#if __STDC_VERSION__-0 >= 199901l || __has_include(<stdbool.h>)
17+
#define HAVE_STDBOOL_H
1118
#include <stdbool.h>
1219
#elif !defined(__cplusplus)
1320
typedef char bool;
1421
#endif
1522

16-
#define HAVE___BUILTIN_EXPECT
17-
18-
#define HAVE___ATTRIBUTE__
23+
#if __has_builtin(__builtin_expect)
24+
#define HAVE___BUILTIN_EXPECT
25+
#endif
1926

20-
#ifdef HAVE___ATTRIBUTE__
21-
#define CMARK_ATTRIBUTE(list) __attribute__ (list)
27+
#if defined(__GNUC__)
28+
#define HAVE___ATTRIBUTE__
29+
#define CMARK_ATTRIBUTE(list) __attribute__(list)
2230
#else
2331
#define CMARK_ATTRIBUTE(list)
2432
#endif
@@ -31,44 +39,6 @@ extern "C" {
3139
#endif
3240
#endif
3341

34-
/* snprintf and vsnprintf fallbacks for MSVC before 2015,
35-
due to Valentin Milea http://stackoverflow.com/questions/2915672/
36-
*/
37-
38-
#if defined(_MSC_VER) && _MSC_VER < 1900
39-
40-
#include <stdio.h>
41-
#include <stdarg.h>
42-
43-
#define snprintf c99_snprintf
44-
#define vsnprintf c99_vsnprintf
45-
46-
CMARK_INLINE int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
47-
{
48-
int count = -1;
49-
50-
if (size != 0)
51-
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
52-
if (count == -1)
53-
count = _vscprintf(format, ap);
54-
55-
return count;
56-
}
57-
58-
CMARK_INLINE int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
59-
{
60-
int count;
61-
va_list ap;
62-
63-
va_start(ap, format);
64-
count = c99_vsnprintf(outBuf, size, format, ap);
65-
va_end(ap);
66-
67-
return count;
68-
}
69-
70-
#endif
71-
7242
#ifdef __cplusplus
7343
}
7444
#endif

0 commit comments

Comments
 (0)