json-gen-c  0.1.5
json-gen-c generate C code for json manipulation
compat.h
Go to the documentation of this file.
1
12#ifndef COMPAT_H
13#define COMPAT_H
14
15#ifdef _WIN32
16
17/* ---- Windows ---- */
18#ifndef WIN32_LEAN_AND_MEAN
19#define WIN32_LEAN_AND_MEAN
20#endif
21#include <windows.h>
22#include <io.h>
23
24typedef CRITICAL_SECTION compat_mutex_t;
25
26static inline int compat_mutex_init(compat_mutex_t *m) {
27 InitializeCriticalSection(m);
28 return 0;
29}
30static inline void compat_mutex_lock(compat_mutex_t *m) {
31 EnterCriticalSection(m);
32}
33static inline void compat_mutex_unlock(compat_mutex_t *m) {
34 LeaveCriticalSection(m);
35}
36static inline void compat_mutex_destroy(compat_mutex_t *m) {
37 DeleteCriticalSection(m);
38}
39
40#define compat_isatty(fd) _isatty(fd)
41#define compat_fileno(f) _fileno(f)
42#define compat_strdup(s) _strdup(s)
43
44#else
45
46/* ---- POSIX ---- */
47#include <pthread.h>
48#include <unistd.h>
49
50typedef pthread_mutex_t compat_mutex_t;
51
52static inline int compat_mutex_init(compat_mutex_t *m) {
53 return pthread_mutex_init(m, NULL);
54}
55static inline void compat_mutex_lock(compat_mutex_t *m) {
56 pthread_mutex_lock(m);
57}
58static inline void compat_mutex_unlock(compat_mutex_t *m) {
59 pthread_mutex_unlock(m);
60}
61static inline void compat_mutex_destroy(compat_mutex_t *m) {
62 pthread_mutex_destroy(m);
63}
64
65#define compat_isatty(fd) isatty(fd)
66#define compat_fileno(f) fileno(f)
67#define compat_strdup(s) strdup(s)
68
69#endif /* _WIN32 */
70
71/* Path separator detection: true for '/' on all platforms, also '\' on Windows */
72static inline int compat_is_path_sep(char c) {
73#ifdef _WIN32
74 return c == '/' || c == '\\';
75#else
76 return c == '/';
77#endif
78}
79
80#endif /* COMPAT_H */
File operation helper functions.