forked from aremmell/libsir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsirplatform.h
149 lines (129 loc) · 3.98 KB
/
sirplatform.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* @file sirplatform.h
* @brief Platform specific configuration.
*
* This file and accompanying source code originated from <https://github.com/aremmell/libsir>.
* If you obtained it elsewhere, all bets are off.
*
* @author Ryan M. Lederman <[email protected]>
* @copyright
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Ryan M. Lederman
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _SIR_PLATFORM_H_INCLUDED
#define _SIR_PLATFORM_H_INCLUDED
#if defined(__APPLE__) && defined(__MACH__)
# define __MACOS__
# define _DARWIN_C_SOURCE
#elif defined(_WIN32)
# define _WIN32_WINNT 0x0600
#elif defined(__FreeBSD__) && !defined(_DEFAULT_SOURCE)
# define _DEFAULT_SOURCE
#else
# if defined(__GNUC__) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE
# endif
# if !defined(_POSIX_C_SOURCE)
# define _POSIX_C_SOURCE 200809L
# endif
# if !defined(_DEFAULT_SOURCE)
# define _DEFAULT_SOURCE
# endif
#endif
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#if !defined(_WIN32)
#include <pthread.h>
#if defined(__FreeBSD__)
#include <pthread_np.h>
#endif
#include <sys/syscall.h>
#include <syslog.h>
#include <unistd.h>
#include <strings.h>
#if defined(__linux__)
# include <linux/limits.h>
#endif
#if defined(PATH_MAX)
# define SIR_MAXPATH PATH_MAX
#endif
#if _POSIX_TIMERS > 0
# define SIR_MSEC_TIMER
# define SIR_MSEC_POSIX
#else
# undef SIR_MSEC_TIMER
#endif
/** The mutex type. */
typedef pthread_mutex_t sirmutex_t;
/** The one-time type. */
typedef pthread_once_t sironce_t;
/** The one-time execution function type. */
typedef void (*sir_once_fn)(void);
/** The one-time initializer. */
#define SIR_ONCE_INIT PTHREAD_ONCE_INIT
#else
#define WIN32_LEAN_AND_MEAN
#include <io.h>
#include <synchapi.h>
#include <windows.h>
#define SIR_MAXPATH MAX_PATH
#define SIR_NO_SYSLOG
#define SIR_MSEC_TIMER
#define SIR_MSEC_WIN32
/** The mutex type. */
typedef HANDLE sirmutex_t;
/** The one-time type. */
typedef INIT_ONCE sironce_t;
/** Process/thread ID. */
typedef int pid_t;
/** The one-time execution function type. */
typedef BOOL(CALLBACK* sir_once_fn)(PINIT_ONCE, PVOID, PVOID*);
/** The one-time initializer. */
#define SIR_ONCE_INIT INIT_ONCE_STATIC_INIT
#endif
#if !defined(thread_local)
# if __STDC_VERSION__ >= 201112 && !defined(__STDC_NO_THREADS__)
# define thread_local _Thread_local
# elif defined(_WIN32)
# define thread_local __declspec(thread)
# elif defined(__GNUC__)
# define thread_local __thread
# else
# error "Unable to configure thread_local!"
# endif
#endif
/** A sensible (?) constraint for the limit of a file's path. Note that this value
* is only used in the absence of PATH_MAX (or MAX_PATH on windows). */
#if !defined(SIR_MAXPATH)
# define SIR_MAXPATH 65535
#endif
#endif /* !_SIR_PLATFORM_H_INCLUDED */