TDengine/include/os/osDef.h

260 lines
6 KiB
C
Raw Normal View History

2021-09-22 03:04:14 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_OS_DEF_H_
#define _TD_OS_DEF_H_
#ifdef __cplusplus
extern "C" {
#endif
2021-09-30 13:21:51 +00:00
#if defined(_TD_DARWIN_64)
2022-10-13 03:09:43 +00:00
// specific
2022-07-14 05:58:23 +00:00
#ifndef __COMPAR_FN_T
#define __COMPAR_FN_T
2022-10-13 03:09:43 +00:00
typedef int (*__compar_fn_t)(const void *, const void *);
2022-07-14 05:58:23 +00:00
#endif
2021-09-30 13:21:51 +00:00
2022-10-13 03:09:43 +00:00
// for send function in tsocket.c
#if defined(MSG_NOSIGNAL)
#undef MSG_NOSIGNAL
#endif
2021-09-30 13:21:51 +00:00
2022-10-13 03:09:43 +00:00
#define MSG_NOSIGNAL 0
2021-09-30 13:21:51 +00:00
2022-10-13 03:09:43 +00:00
#define SO_NO_CHECK 0x1234
#define SOL_TCP 0x1234
#define TCP_KEEPIDLE 0x1234
2021-09-30 13:21:51 +00:00
2022-10-13 03:09:43 +00:00
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
#endif
2021-09-30 13:21:51 +00:00
#endif
#if defined(_ALPINE)
2022-07-14 05:58:23 +00:00
#ifndef __COMPAR_FN_T
#define __COMPAR_FN_T
2022-10-13 03:09:43 +00:00
typedef int (*__compar_fn_t)(const void *, const void *);
#endif
void error(int, int, const char *);
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
2022-07-14 05:58:23 +00:00
#endif
2021-09-30 13:21:51 +00:00
#endif
#if defined(WINDOWS)
2022-10-13 03:09:43 +00:00
char *stpcpy(char *dest, const char *src);
char *stpncpy(char *dest, const char *src, int n);
2021-09-30 13:21:51 +00:00
2022-10-13 03:09:43 +00:00
// specific
2022-07-14 05:58:23 +00:00
#ifndef __COMPAR_FN_T
#define __COMPAR_FN_T
2022-10-13 03:09:43 +00:00
typedef int (*__compar_fn_t)(const void *, const void *);
#endif
#define ssize_t int
#define _SSIZE_T_
2024-07-24 08:37:54 +00:00
#define bzero(ptr, size) (void)memset((ptr), 0, (size))
2022-10-13 03:09:43 +00:00
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define wcsncasecmp _wcsnicmp
#define strtok_r strtok_s
// #define snprintf _snprintf
#define in_addr_t unsigned long
// #define socklen_t int
2021-09-30 13:21:51 +00:00
2022-10-13 03:09:43 +00:00
char *strsep(char **stringp, const char *delim);
char *getpass(const char *prefix);
char *strndup(const char *s, int n);
// for send function in tsocket.c
#define MSG_NOSIGNAL 0
#define SO_NO_CHECK 0x1234
#define SOL_TCP 0x1234
#define SHUT_RDWR SD_BOTH
#define SHUT_RD SD_RECEIVE
#define SHUT_WR SD_SEND
#define LOCK_EX 1
#define LOCK_NB 2
#define LOCK_UN 3
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
typedef struct {
int we_wordc;
char *we_wordv[1];
int we_offs;
char wordPos[1025];
} wordexp_t;
int wordexp(char *words, wordexp_t *pwordexp, int flags);
void wordfree(wordexp_t *pwordexp);
#define openlog(a, b, c)
#define closelog()
#define LOG_ERR 0
#define LOG_INFO 1
void syslog(int unused, const char *format, ...);
#endif // WINDOWS
2022-01-06 10:11:28 +00:00
#ifndef WINDOWS
2022-10-13 03:09:43 +00:00
#ifndef O_BINARY
#define O_BINARY 0
#endif
2022-01-06 10:11:28 +00:00
#endif
2022-10-13 03:09:43 +00:00
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
2021-09-30 13:21:51 +00:00
#ifndef UNUSED
#define UNUSED(x) ((void)(x))
#endif
#ifdef UNUSED_FUNC
#undefine UNUSED_FUNC
#endif
#ifdef UNUSED_PARAM
#undef UNUSED_PARAM
#endif
#if defined(__GNUC__)
#define UNUSED_PARAM(x) _UNUSED##x __attribute__((unused))
2022-10-13 03:09:43 +00:00
#define UNUSED_FUNC __attribute__((unused))
2021-09-30 13:21:51 +00:00
#else
#define UNUSED_PARAM(x) x
#define UNUSED_FUNC
#endif
#ifdef tListLen
#undefine tListLen
#endif
#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
2021-09-22 03:04:14 +00:00
#if defined(__GNUC__)
#define FORCE_INLINE inline __attribute__((always_inline))
#else
#define FORCE_INLINE
#endif
2021-09-30 13:21:51 +00:00
#define DEFAULT_UNICODE_ENCODEC "UCS-4LE"
#define DEFAULT_COMP(x, y) \
do { \
if ((x) == (y)) { \
return 0; \
} else { \
return (x) < (y) ? -1 : 1; \
} \
} while (0)
2022-11-11 06:16:13 +00:00
#define DEFAULT_DOUBLE_COMP(x, y) \
do { \
if (isnan(x) && isnan(y)) { \
return 0; \
} \
if (isnan(x)) { \
return -1; \
} \
if (isnan(y)) { \
return 1; \
} \
if (fabs((x) - (y)) <= DBL_EPSILON) { \
return 0; \
} else { \
return (x) < (y) ? -1 : 1; \
} \
2021-09-30 13:21:51 +00:00
} while (0)
#define DEFAULT_FLOAT_COMP(x, y) DEFAULT_DOUBLE_COMP(x, y)
#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1)))
// align to 8bytes
#define ALIGN8(n) ALIGN_NUM(n, 8)
#undef threadlocal
2024-08-02 07:50:17 +00:00
//#ifdef _ISOC11_SOURCE
//#define threadlocal _Thread_local
//#elif defined(__APPLE__)
#if defined(__APPLE__)
2022-10-13 03:09:43 +00:00
#define threadlocal __thread
2021-09-30 13:21:51 +00:00
#elif defined(__GNUC__) && !defined(threadlocal)
2022-10-13 03:09:43 +00:00
#define threadlocal __thread
2021-09-30 13:21:51 +00:00
#else
2022-10-13 03:09:43 +00:00
#define threadlocal __declspec(thread)
2021-09-30 13:21:51 +00:00
#endif
2022-04-22 01:54:27 +00:00
#ifdef WINDOWS
2022-10-13 03:09:43 +00:00
#define PRIzu "ld"
2021-09-30 13:21:51 +00:00
#else
2022-10-13 03:09:43 +00:00
#define PRIzu "zu"
2021-09-30 13:21:51 +00:00
#endif
#if !defined(WINDOWS)
2022-10-13 03:09:43 +00:00
#if defined(_TD_DARWIN_64)
// MacOS
#if !defined(_GNU_SOURCE)
#define setThreadName(name) \
do { \
pthread_setname_np((name)); \
} while (0)
#else
// pthread_setname_np not defined
#define setThreadName(name)
#endif
#else
// Linux, length of name must <= 16 (the last '\0' included)
#define setThreadName(name) \
do { \
2024-07-18 06:13:29 +00:00
(void)prctl(PR_SET_NAME, (name)); \
2022-10-13 03:09:43 +00:00
} while (0)
2023-12-21 04:11:00 +00:00
#define getThreadName(name) \
do { \
prctl(PR_GET_NAME, (name)); \
} while (0)
2022-10-13 03:09:43 +00:00
#endif
#else
2022-10-13 03:09:43 +00:00
// Windows
2023-10-12 09:27:16 +00:00
#define setThreadName(name) \
do { \
pthread_setname_np(taosThreadSelf(), (name)); \
} while (0)
#endif
2021-10-17 09:10:45 +00:00
#if defined(_WIN32)
2022-10-13 03:09:43 +00:00
#define TD_DIRSEP "\\"
2021-10-17 09:10:45 +00:00
#else
2022-10-13 03:09:43 +00:00
#define TD_DIRSEP "/"
2021-10-17 09:10:45 +00:00
#endif
2023-11-08 02:28:45 +00:00
#if defined(_WIN32)
#define TD_DIRSEP_CHAR '\\'
#else
#define TD_DIRSEP_CHAR '/'
#endif
2022-02-24 13:37:19 +00:00
#define TD_LOCALE_LEN 64
#define TD_CHARSET_LEN 64
#define TD_TIMEZONE_LEN 96
2021-09-22 03:04:14 +00:00
#ifdef __cplusplus
}
#endif
#endif /*_TD_OS_DEF_H_*/