zhangmeng
2024-04-09 2561a007b8d8999a4750046d0cfb3b1ad5af50ac
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
150
151
152
153
154
155
156
157
158
/*
 * Our own header, to be included before all standard system headers.
 */
 
#ifndef __USG_COMMON_H__
#define __USG_COMMON_H__
 
#ifdef __cplusplus
extern "C" {
#endif
 
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <setjmp.h>
#include <signal.h>
#include <dirent.h>
#include <time.h>
#include <sched.h>
 
#include <sys/time.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/file.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <math.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <libgen.h>
/*
 * define int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t uint64_t
*/
#include <stdint.h>
#include <assert.h>
 
 
#ifdef __cplusplus
}
#endif
 
 
 
//c++ header
#ifdef __cplusplus
 
 
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
 
#include <cstdlib>
#include <atomic>
#include <algorithm>
#include <iomanip>
#include <limits>
 
#include <initializer_list>
#include <vector>
#include <map>
#include <set>
 
#include <functional>
#include <thread>
#endif
 
#include "usg_typedef.h"
 
#ifdef __cplusplus
extern "C" {
#endif
 
/* Signal wrappers */
typedef void handler_t(int);
handler_t *Signal(int signum, handler_t *handler);
 
 
 
/* Our own error-handling functions */
 
void err_exit(int error, const char *fmt, ...);
void err_msg(int error, const char *fmt, ...);
 
char *ltrim(char *str, const char *seps);
char *rtrim(char *str, const char *seps);
char *trim(char *str, const char *seps);
 
/**
 * @ seperator 分割符
 */
char * str_join( const char *seperator, const char *first, ...);
/**
 * 把字符串以@delim分割为数组,数组的地址存放在@arr_addr
 */
int str_split(const char *str, const char *delim, char *** arr_addr);
char * array_join(char * const arr[], const char *seperator);
char * path_join(const char *path, ...);
// 反向查询
char *strstr_r(char *str,  char * needle);
// 递归创建文件夹
int mkdir_r(const char *pathname, mode_t mode);
 
int mkdiratfd_r(int dirfd, const char *pathname, mode_t mode);
int mkdirat_r(const char * dir, const char *pathname, mode_t mode);
 
 
static inline int 
strtoi(int num, char *str) 
{
    return sprintf(str, "%d", num); 
 
}
 
 
 
 
#ifdef __cplusplus
}
#endif
 
 
 
#ifdef __cplusplus
 
// static inline std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
// {
//     str.erase(0, str.find_first_not_of(chars));
//     return str;
// }
 
// static inline std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
// {
//     str.erase(str.find_last_not_of(chars) + 1);
//     return str;
// }
 
// static inline std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
// {
//     return ltrim(rtrim(str, chars), chars);
// }
 
 
#endif
 
#endif