-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompat.h
More file actions
69 lines (59 loc) · 1.84 KB
/
Copy pathcompat.h
File metadata and controls
69 lines (59 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef STRLIB_COMPAT_H_
#define STRLIB_COMPAT_H_
/* ── Standard detection ── */
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
#error "strlib requires C11 or later (-std=c11)"
#endif
/* ── Compiler detection ── */
#if defined(__clang__)
#define STRLIB_COMPILER_CLANG
#define STRLIB_COMPILER_NAME "clang"
#elif defined(__GNUC__)
#define STRLIB_COMPILER_GCC
#define STRLIB_COMPILER_NAME "gcc"
#elif defined(_MSC_VER)
#define STRLIB_COMPILER_MSVC
#define STRLIB_COMPILER_NAME "msvc"
#else
#define STRLIB_COMPILER_UNKNOWN
#define STRLIB_COMPILER_NAME "unknown"
#endif
#ifdef STRLIB_COMPILER_MSVC
#error "MSVC not supported yet"
#endif
/* ── Compile-time warnings ── */
#define STRLIB_STRINGIFY_(x) #x
#define STRLIB_STRINGIFY(x) STRLIB_STRINGIFY_(x)
#if defined(STRLIB_COMPILER_CLANG)
#define STRLIB_WARN(msg) _Pragma(STRLIB_STRINGIFY(clang warning msg))
#elif defined(STRLIB_COMPILER_GCC)
#define STRLIB_WARN(msg) _Pragma(STRLIB_STRINGIFY(GCC warning msg))
#elif defined(STRLIB_COMPILER_MSVC)
#define STRLIB_WARN(msg) __pragma(message(msg))
#else
#define STRLIB_WARN(msg)
#endif
/* ── Feature flags ── */
#if defined(STRLIB_COMPILER_GCC) || defined(STRLIB_COMPILER_CLANG)
#define STRLIB_HAS_CLEANUP
#define STRLIB_TYPEOF(x) __typeof__(x)
#else
#define STRLIB_TYPEOF(x)
#endif
/* _Generic is C11, already guaranteed by standard check above */
#define STRLIB_HAS_GENERIC
/* ── Portability macros ── */
#if defined(STRLIB_HAS_CLEANUP)
#define STRLIB_AUTO(fn) __attribute__((cleanup(fn)))
#else
STRLIB_WARN("SB_AUTO/STR_AUTO unavailable: no cleanup attribute")
#define STRLIB_AUTO(fn)
#endif
#if defined(STRLIB_COMPILER_GCC) || defined(STRLIB_COMPILER_CLANG)
#define STRLIB_UNUSED __attribute__((unused))
#elif defined(STRLIB_COMPILER_MSVC)
#define STRLIB_UNUSED
#else
#define STRLIB_UNUSED
#endif
#endif /* STRLIB_COMPAT_H_ */