forked from viabtc/viabtc_exchange_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ut_misc.h
92 lines (75 loc) · 1.92 KB
/
ut_misc.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
/*
* Description: misc functions
* History: [email protected], 2016/03/15, create
*/
# ifndef _MISC_H_
# define _MISC_H_
# include <endian.h>
# include <byteswap.h>
# include "ut_sds.h"
# include "ut_log.h"
int process_exist(const char *fmt, ...);
int process_keepalive(void);
int set_core_limit(size_t limit);
int set_file_limit(size_t limit);
sds hexdump(const void *mem, size_t len);
sds bin2hex(const void *mem, size_t len);
sds hex2bin(const char *hex);
double current_timestamp(void);
char *strftimestamp(time_t t);
char *human_number(double num);
double to_fixed(double val, int num);
void reverse_mem(char *mem, size_t len);
void strtolower(char *str);
void strtoupper(char *str);
void strclearblank(char *str);
int urandom(void *buf, size_t size);
char *sstrncpy(char *dest, const char *src, size_t n);
time_t get_timezone_offset(void);
# undef ERR_RET
# define ERR_RET(x) do { \
int __ret = (x); \
if (__ret < 0) { \
return __ret; \
} \
} while (0)
# undef ERR_RET_LN
# define ERR_RET_LN(x) do { \
if ((x) < 0) { \
return -__LINE__; \
} \
} while (0)
# undef htobe16
# undef htobe32
# undef htobe64
# undef be16toh
# undef be32toh
# undef be64toh
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define htole16(x) (x)
# define htole32(x) (x)
# define htole64(x) (x)
# define le16toh(x) (x)
# define le32toh(x) (x)
# define le64toh(x) (x)
# define htobe16(x) bswap_16(x)
# define htobe32(x) bswap_32(x)
# define htobe64(x) bswap_64(x)
# define be16toh(x) bswap_16(x)
# define be32toh(x) bswap_32(x)
# define be64toh(x) bswap_64(x)
# else
# define htole16(x) bswap_16(x)
# define htole32(x) bswap_32(x)
# define htole64(x) bswap_64(x)
# define le16toh(x) bswap_16(x)
# define le32toh(x) bswap_32(x)
# define le64toh(x) bswap_64(x)
# define htobe16(x) (x)
# define htobe32(x) (x)
# define htobe64(x) (x)
# define be16toh(x) (x)
# define be32toh(x) (x)
# define be64toh(x) (x)
# endif
# endif