Coverage Report

Created: 2026-05-23 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tdengine/include/os/osDef.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15
16
#ifndef _TD_OS_DEF_H_
17
#define _TD_OS_DEF_H_
18
19
#ifdef __cplusplus
20
extern "C" {
21
#endif
22
23
#if defined(_TD_DARWIN_64)
24
// specific
25
#ifndef __COMPAR_FN_T
26
#define __COMPAR_FN_T
27
typedef int (*__compar_fn_t)(const void *, const void *);
28
#endif
29
30
// for send function in tsocket.c
31
#if defined(MSG_NOSIGNAL)
32
#undef MSG_NOSIGNAL
33
#endif
34
35
#define MSG_NOSIGNAL 0
36
37
#define SO_NO_CHECK  0x1234
38
#define SOL_TCP      0x1234
39
#define TCP_KEEPIDLE 0x1234
40
41
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
42
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
43
#endif
44
#endif
45
46
#if defined(_ALPINE)
47
#ifndef __COMPAR_FN_T
48
#define __COMPAR_FN_T
49
typedef int (*__compar_fn_t)(const void *, const void *);
50
#endif
51
void error(int, int, const char *);
52
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
53
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
54
#endif
55
#endif
56
57
#if defined(WINDOWS)
58
char *stpcpy(char *dest, const char *src);
59
char *stpncpy(char *dest, const char *src, int n);
60
61
// specific
62
#ifndef __COMPAR_FN_T
63
#define __COMPAR_FN_T
64
typedef int (*__compar_fn_t)(const void *, const void *);
65
#endif
66
#define ssize_t int
67
#define _SSIZE_T_
68
#define bzero(ptr, size) (void)memset((ptr), 0, (size))
69
#define strcasecmp       _stricmp
70
#define strncasecmp      _strnicmp
71
#define wcsncasecmp      _wcsnicmp
72
#define strtok_r         strtok_s
73
// #define snprintf _snprintf
74
#define in_addr_t unsigned long
75
//  #define socklen_t int
76
77
char *strsep(char **stringp, const char *delim);
78
char *getpass(const char *prefix);
79
80
// for send function in tsocket.c
81
#define MSG_NOSIGNAL 0
82
#define SO_NO_CHECK  0x1234
83
#define SOL_TCP      0x1234
84
85
#define SHUT_RDWR SD_BOTH
86
#define SHUT_RD   SD_RECEIVE
87
#define SHUT_WR   SD_SEND
88
89
#define LOCK_EX 1
90
#define LOCK_NB 2
91
#define LOCK_UN 3
92
93
#ifndef PATH_MAX
94
#define PATH_MAX 256
95
#endif
96
97
typedef struct {
98
  int   we_wordc;
99
  char *we_wordv[1];
100
  int   we_offs;
101
  char  wordPos[1025];
102
} wordexp_t;
103
int  wordexp(char *words, wordexp_t *pwordexp, int flags);
104
void wordfree(wordexp_t *pwordexp);
105
106
#define openlog(a, b, c)
107
#define closelog()
108
#define LOG_ERR  0
109
#define LOG_INFO 1
110
void syslog(int unused, const char *format, ...);
111
#elif defined(TD_ASTRA)
112
char *stpncpy(char *dest, const char *src, int n);
113
char *strsep(char **stringp, const char *delim);
114
#endif  // WINDOWS
115
116
#ifndef WINDOWS
117
#ifndef O_BINARY
118
0
#define O_BINARY 0
119
#endif
120
#endif
121
122
0
#define POINTER_SHIFT(p, b)      ((void *)((char *)(p) + (b)))
123
0
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
124
125
#ifndef UNUSED
126
#define UNUSED(x) ((void)(x))
127
#endif
128
129
#ifdef UNUSED_FUNC
130
#undefine UNUSED_FUNC
131
#endif
132
133
#ifdef UNUSED_PARAM
134
#undef UNUSED_PARAM
135
#endif
136
137
#if defined(__GNUC__)
138
#define UNUSED_PARAM(x) _UNUSED##x __attribute__((unused))
139
#define UNUSED_FUNC     __attribute__((unused))
140
#else
141
#define UNUSED_PARAM(x) x
142
#define UNUSED_FUNC
143
#endif
144
145
#ifdef tListLen
146
#undefine tListLen
147
#endif
148
183k
#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
149
150
#if defined(__GNUC__)
151
#define FORCE_INLINE inline __attribute__((always_inline))
152
#else
153
#define FORCE_INLINE
154
#endif
155
156
0
#define DEFAULT_UNICODE_ENCODEC "UCS-4LE"
157
158
#define DEFAULT_COMP(x, y)       \
159
0
  do {                           \
160
0
    if ((x) == (y)) {            \
161
0
      return 0;                  \
162
0
    } else {                     \
163
0
      return (x) < (y) ? -1 : 1; \
164
0
    }                            \
165
0
  } while (0)
166
167
#define DEFAULT_DOUBLE_COMP(x, y)         \
168
0
  do {                                    \
169
0
    if (isnan(x) && isnan(y)) {           \
170
0
      return 0;                           \
171
0
    }                                     \
172
0
    if (isnan(x)) {                       \
173
0
      return -1;                          \
174
0
    }                                     \
175
0
    if (isnan(y)) {                       \
176
0
      return 1;                           \
177
0
    }                                     \
178
0
    if (fabs((x) - (y)) <= DBL_EPSILON) { \
179
0
      return 0;                           \
180
0
    } else {                              \
181
0
      return (x) < (y) ? -1 : 1;          \
182
0
    }                                     \
183
0
  } while (0)
184
185
#define DEFAULT_FLOAT_COMP(x, y) DEFAULT_DOUBLE_COMP(x, y)
186
187
0
#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1)))
188
189
// align to 8bytes
190
#define ALIGN8(n) ALIGN_NUM(n, 8)
191
192
#undef threadlocal
193
//#ifdef _ISOC11_SOURCE
194
//#define threadlocal _Thread_local
195
//#elif defined(__APPLE__)
196
#if defined(__APPLE__)
197
#define threadlocal __thread
198
#elif defined(__GNUC__) && !defined(threadlocal)
199
#define threadlocal __thread
200
#else
201
#define threadlocal __declspec(thread)
202
#endif
203
204
#ifdef WINDOWS
205
#define PRIzu "ld"
206
#else
207
#define PRIzu "zu"
208
#endif
209
210
#if !defined(WINDOWS)
211
#if defined(_TD_DARWIN_64)
212
// MacOS
213
#if !defined(_GNU_SOURCE)
214
#define setThreadName(name)     \
215
  do {                          \
216
    pthread_setname_np((name)); \
217
  } while (0)
218
#else
219
// pthread_setname_np not defined
220
#define setThreadName(name)
221
#endif
222
#elif defined(TD_ASTRA)
223
#define setThreadName(name)
224
#define getThreadName(name)
225
#else
226
// Linux, length of name must <= 16 (the last '\0' included)
227
#define setThreadName(name)     \
228
0
  do {                          \
229
0
    (void)prctl(PR_SET_NAME, (name)); \
230
0
  } while (0)
231
#define getThreadName(name)     \
232
  do {                          \
233
    prctl(PR_GET_NAME, (name)); \
234
  } while (0)
235
#endif
236
#else
237
// Windows
238
#define setThreadName(name)                       \
239
  do {                                            \
240
    pthread_setname_np(taosThreadSelf(), (name)); \
241
  } while (0)
242
#endif
243
244
#if defined(_WIN32)
245
#define TD_DIRSEP "\\"
246
#elif defined(TD_ASTRA)
247
#ifdef TD_ASTRA_TARGET
248
#define TD_DIRSEP "/"
249
#else
250
#define TD_DIRSEP "\\"
251
#endif
252
#else
253
0
#define TD_DIRSEP "/"
254
#endif
255
256
#if defined(_WIN32)
257
#define TD_DIRSEP_CHAR '\\'
258
#elif defined(TD_ASTRA)
259
#ifdef TD_ASTRA_TARGET
260
#define TD_DIRSEP_CHAR '/'
261
#else
262
#define TD_DIRSEP_CHAR '\\'
263
#endif
264
#else
265
0
#define TD_DIRSEP_CHAR '/'
266
#endif
267
268
0
#define TD_FQDN_LEN     128
269
#define TD_LOCALE_LEN   64
270
#define TD_CHARSET_LEN  64
271
0
#define TD_TIMEZONE_LEN 96
272
0
#define TD_TIME_STR_LEN 128
273
0
#define TD_IP_LEN       128
274
275
#ifdef __cplusplus
276
}
277
#endif
278
279
#endif /*_TD_OS_DEF_H_*/