os.h 4.5 KB
Newer Older
S
slguan 已提交
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
/*
* 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 TDENGINE_PLATFORM_WINDOWS_H
#define TDENGINE_PLATFORM_WINDOWS_H

#include <io.h>
#include <stdio.h>
#include <signal.h>
#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>
#include <direct.h>
#include "winsock2.h"
#include <WS2tcpip.h>

#ifdef __cplusplus
extern "C" {
#endif

// for function open in stat.h 
#define S_IRWXU                  _S_IREAD
#define S_IRWXG                  _S_IWRITE
#define S_IRWXO                  _S_IWRITE

// for access function in io.h
#define F_OK 00  //Existence only
#define W_OK 02  //Write - only
#define R_OK 04  //Read - only
#define X_OK 06  //Read and write

// for send function in tsocket.c
#define MSG_NOSIGNAL             0
#define SO_NO_CHECK              0x1234
#define SOL_TCP                  0x1234
#define TCP_KEEPCNT              0x1234
#define TCP_KEEPIDLE             0x1234
#define TCP_KEEPINTVL            0x1234

#define LOCK_EX 1
#define LOCK_NB 2
#define LOCK_UN 3

#define bzero(ptr, size) memset((ptr), 0, (size))
#define mkdir(pathname, mode) _mkdir(pathname)
#define strcasecmp  _stricmp
#define strncasecmp _strnicmp
#define wcsncasecmp _wcsnicmp
#define strtok_r strtok_s
#define str2int64 _atoi64
#define snprintf _snprintf
#define in_addr_t unsigned long
#define socklen_t int
#define htobe64 htonll
S
slguan 已提交
67 68 69 70 71 72 73 74 75 76 77 78
#define twrite write

#ifndef PATH_MAX
  #define PATH_MAX 256
#endif

#define taosCloseSocket(fd) closesocket(fd)
#define taosWriteSocket(fd, buf, len) send(fd, buf, len, 0)
#define taosReadSocket(fd, buf, len) recv(fd, buf, len, 0)

int32_t __sync_val_compare_and_swap_32(int32_t *ptr, int32_t oldval, int32_t newval);
int32_t __sync_add_and_fetch_32(int32_t *ptr, int32_t val);
79
int32_t __sync_sub_and_fetch_32(int32_t *ptr, int32_t val);
S
slguan 已提交
80 81
int64_t __sync_val_compare_and_swap_64(int64_t *ptr, int64_t oldval, int64_t newval);
int64_t __sync_add_and_fetch_64(int64_t *ptr, int64_t val);
82
int64_t __sync_sub_and_fetch_64(int64_t *ptr, int64_t val);
S
slguan 已提交
83 84
int32_t __sync_val_load_32(int32_t *ptr);
void __sync_val_restore_32(int32_t *ptr, int32_t newval);
S
slguan 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

#define SWAP(a, b, c)      \
  do {                     \
    c __tmp = (c)(a);      \
    (a) = (c)(b);          \
    (b) = __tmp;           \
  } while (0)

#define MAX(a,b)  (((a)>(b))?(a):(b))
#define MIN(a,b)  (((a)<(b))?(a):(b))

#define MILLISECOND_PER_SECOND (1000i64)

#define tsem_t sem_t
#define tsem_init sem_init
#define tsem_wait sem_wait
#define tsem_post sem_post
#define tsem_destroy sem_destroy
S
slguan 已提交
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

int getline(char **lineptr, size_t *n, FILE *stream);

int taosWinSetTimer(int ms, void(*callback)(int));

int gettimeofday(struct timeval *tv, struct timezone *tz);

struct tm *localtime_r(const time_t *timep, struct tm *result);

char *strptime(const char *buf, const char *fmt, struct tm *tm);

bool taosCheckPthreadValid(pthread_t thread);

void taosResetPthread(pthread_t *thread);

int64_t taosGetPthreadId();

int taosSetNonblocking(int sock, int on);

int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen);

char *taosCharsetReplace(char *charsetstr);

void tsPrintOsInfo();

void taosGetSystemInfo();

void taosKillSystem();

S
slguan 已提交
132 133 134 135 136
int32_t BUILDIN_CLZL(uint64_t val);
int32_t BUILDIN_CLZ(uint32_t val);
int32_t BUILDIN_CTZL(uint64_t val);
int32_t BUILDIN_CTZ(uint32_t val);

S
slguan 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
//for signal, not dispose
#define SIGALRM 1234
typedef int sigset_t;

struct sigaction {
  void (*sa_handler)(int);
};

typedef struct {
  int we_wordc;
  char **we_wordv;
  int we_offs;
  char wordPos[20];
} wordexp_t;

int wordexp(const char *words, wordexp_t *pwordexp, int flags);

void wordfree(wordexp_t *pwordexp);

int flock(int fd, int option);

S
slguan 已提交
158 159
int fsync(int filedes);

S
slguan 已提交
160 161 162 163 164 165 166 167 168 169
char *getpass(const char *prefix);

char *strsep(char **stringp, const char *delim);

typedef int(*__compar_fn_t)(const void *, const void *);

int sigaction(int, struct sigaction *, void *);

void sleep(int mseconds);

S
slguan 已提交
170
bool taosSkipSocketCheck();
S
slguan 已提交
171

S
slguan 已提交
172 173 174 175
int fsendfile(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count);

#define ssize_t int

S
slguan 已提交
176 177 178 179
#ifdef __cplusplus
}
#endif
#endif