Skip to content

Commit e4090c1

Browse files
committed
use prefix hv
1 parent 14008bd commit e4090c1

File tree

17 files changed

+100
-102
lines changed

17 files changed

+100
-102
lines changed

base/array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static inline void atype##_cleanup(atype* p) {\
7979
\
8080
static inline void atype##_resize(atype* p, int maxsize) {\
8181
if (maxsize == 0) maxsize = ARRAY_INIT_SIZE;\
82-
p->ptr = (type*)safe_realloc(p->ptr, sizeof(type) * maxsize, sizeof(type) * p->maxsize);\
82+
p->ptr = (type*)hv_realloc(p->ptr, sizeof(type) * maxsize, sizeof(type) * p->maxsize);\
8383
p->maxsize = maxsize;\
8484
}\
8585
\

base/hbase.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ long hv_free_cnt() {
2121
return s_free_cnt;
2222
}
2323

24-
void* safe_malloc(size_t size) {
24+
void* hv_malloc(size_t size) {
2525
hatomic_inc(&s_alloc_cnt);
2626
void* ptr = malloc(size);
2727
if (!ptr) {
@@ -31,7 +31,7 @@ void* safe_malloc(size_t size) {
3131
return ptr;
3232
}
3333

34-
void* safe_realloc(void* oldptr, size_t newsize, size_t oldsize) {
34+
void* hv_realloc(void* oldptr, size_t newsize, size_t oldsize) {
3535
hatomic_inc(&s_alloc_cnt);
3636
hatomic_inc(&s_free_cnt);
3737
void* ptr = realloc(oldptr, newsize);
@@ -45,7 +45,7 @@ void* safe_realloc(void* oldptr, size_t newsize, size_t oldsize) {
4545
return ptr;
4646
}
4747

48-
void* safe_calloc(size_t nmemb, size_t size) {
48+
void* hv_calloc(size_t nmemb, size_t size) {
4949
hatomic_inc(&s_alloc_cnt);
5050
void* ptr = calloc(nmemb, size);
5151
if (!ptr) {
@@ -55,7 +55,7 @@ void* safe_calloc(size_t nmemb, size_t size) {
5555
return ptr;
5656
}
5757

58-
void* safe_zalloc(size_t size) {
58+
void* hv_zalloc(size_t size) {
5959
hatomic_inc(&s_alloc_cnt);
6060
void* ptr = malloc(size);
6161
if (!ptr) {
@@ -66,15 +66,15 @@ void* safe_zalloc(size_t size) {
6666
return ptr;
6767
}
6868

69-
void safe_free(void* ptr) {
69+
void hv_free(void* ptr) {
7070
if (ptr) {
7171
free(ptr);
7272
ptr = NULL;
7373
hatomic_inc(&s_free_cnt);
7474
}
7575
}
7676

77-
char* strupper(char* str) {
77+
char* hv_strupper(char* str) {
7878
char* p = str;
7979
while (*p != '\0') {
8080
if (*p >= 'a' && *p <= 'z') {
@@ -85,7 +85,7 @@ char* strupper(char* str) {
8585
return str;
8686
}
8787

88-
char* strlower(char* str) {
88+
char* hv_strlower(char* str) {
8989
char* p = str;
9090
while (*p != '\0') {
9191
if (*p >= 'A' && *p <= 'Z') {
@@ -96,7 +96,7 @@ char* strlower(char* str) {
9696
return str;
9797
}
9898

99-
char* strreverse(char* str) {
99+
char* hv_strreverse(char* str) {
100100
if (str == NULL) return NULL;
101101
char* b = str;
102102
char* e = str;
@@ -114,7 +114,7 @@ char* strreverse(char* str) {
114114
}
115115

116116
// n = sizeof(dest_buf)
117-
char* safe_strncpy(char* dest, const char* src, size_t n) {
117+
char* hv_strncpy(char* dest, const char* src, size_t n) {
118118
assert(dest != NULL && src != NULL);
119119
char* ret = dest;
120120
while (*src != '\0' && --n > 0) {
@@ -125,7 +125,7 @@ char* safe_strncpy(char* dest, const char* src, size_t n) {
125125
}
126126

127127
// n = sizeof(dest_buf)
128-
char* safe_strncat(char* dest, const char* src, size_t n) {
128+
char* hv_strncat(char* dest, const char* src, size_t n) {
129129
assert(dest != NULL && src != NULL);
130130
char* ret = dest;
131131
while (*dest) {++dest;--n;}
@@ -136,7 +136,7 @@ char* safe_strncat(char* dest, const char* src, size_t n) {
136136
return ret;
137137
}
138138

139-
bool strstartswith(const char* str, const char* start) {
139+
bool hv_strstartswith(const char* str, const char* start) {
140140
assert(str != NULL && start != NULL);
141141
while (*str && *start && *str == *start) {
142142
++str;
@@ -145,7 +145,7 @@ bool strstartswith(const char* str, const char* start) {
145145
return *start == '\0';
146146
}
147147

148-
bool strendswith(const char* str, const char* end) {
148+
bool hv_strendswith(const char* str, const char* end) {
149149
assert(str != NULL && end != NULL);
150150
int len1 = 0;
151151
int len2 = 0;
@@ -162,12 +162,12 @@ bool strendswith(const char* str, const char* end) {
162162
return true;
163163
}
164164

165-
bool strcontains(const char* str, const char* sub) {
165+
bool hv_strcontains(const char* str, const char* sub) {
166166
assert(str != NULL && sub != NULL);
167167
return strstr(str, sub) != NULL;
168168
}
169169

170-
char* strrchr_dir(const char* filepath) {
170+
char* hv_strrchr_dir(const char* filepath) {
171171
char* p = (char*)filepath;
172172
while (*p) ++p;
173173
while (--p >= filepath) {
@@ -182,12 +182,12 @@ char* strrchr_dir(const char* filepath) {
182182
}
183183

184184
const char* hv_basename(const char* filepath) {
185-
const char* pos = strrchr_dir(filepath);
185+
const char* pos = hv_strrchr_dir(filepath);
186186
return pos ? pos+1 : filepath;
187187
}
188188

189189
const char* hv_suffixname(const char* filename) {
190-
const char* pos = strrchr_dot(filename);
190+
const char* pos = hv_strrchr_dot(filename);
191191
return pos ? pos+1 : "";
192192
}
193193

@@ -196,7 +196,7 @@ int hv_mkdir_p(const char* dir) {
196196
return EEXIST;
197197
}
198198
char tmp[MAX_PATH] = {0};
199-
safe_strncpy(tmp, dir, sizeof(tmp));
199+
hv_strncpy(tmp, dir, sizeof(tmp));
200200
char* p = tmp;
201201
char delim = '/';
202202
while (*p) {
@@ -226,7 +226,7 @@ int hv_rmdir_p(const char* dir) {
226226
return EPERM;
227227
}
228228
char tmp[MAX_PATH] = {0};
229-
safe_strncpy(tmp, dir, sizeof(tmp));
229+
hv_strncpy(tmp, dir, sizeof(tmp));
230230
char* p = tmp;
231231
while (*p) ++p;
232232
while (--p >= tmp) {
@@ -283,20 +283,6 @@ size_t hv_filesize(const char* filepath) {
283283
return st.st_size;
284284
}
285285

286-
bool getboolean(const char* str) {
287-
if (str == NULL) return false;
288-
int len = strlen(str);
289-
if (len == 0) return false;
290-
switch (len) {
291-
case 1: return *str == '1' || *str == 'y' || *str == 'Y';
292-
case 2: return stricmp(str, "on") == 0;
293-
case 3: return stricmp(str, "yes") == 0;
294-
case 4: return stricmp(str, "true") == 0;
295-
case 6: return stricmp(str, "enable") == 0;
296-
default: return false;
297-
}
298-
}
299-
300286
char* get_executable_path(char* buf, int size) {
301287
#ifdef OS_WIN
302288
GetModuleFileName(NULL, buf, size);
@@ -313,7 +299,7 @@ char* get_executable_path(char* buf, int size) {
313299
char* get_executable_dir(char* buf, int size) {
314300
char filepath[MAX_PATH] = {0};
315301
get_executable_path(filepath, sizeof(filepath));
316-
char* pos = strrchr_dir(filepath);
302+
char* pos = hv_strrchr_dir(filepath);
317303
if (pos) {
318304
*pos = '\0';
319305
strncpy(buf, filepath, size);
@@ -324,7 +310,7 @@ char* get_executable_dir(char* buf, int size) {
324310
char* get_executable_file(char* buf, int size) {
325311
char filepath[MAX_PATH] = {0};
326312
get_executable_path(filepath, sizeof(filepath));
327-
char* pos = strrchr_dir(filepath);
313+
char* pos = hv_strrchr_dir(filepath);
328314
if (pos) {
329315
strncpy(buf, pos+1, size);
330316
}
@@ -361,3 +347,17 @@ void hv_random_string(char *buf, int len) {
361347
}
362348
buf[i] = '\0';
363349
}
350+
351+
bool hv_getboolean(const char* str) {
352+
if (str == NULL) return false;
353+
int len = strlen(str);
354+
if (len == 0) return false;
355+
switch (len) {
356+
case 1: return *str == '1' || *str == 'y' || *str == 'Y';
357+
case 2: return stricmp(str, "on") == 0;
358+
case 3: return stricmp(str, "yes") == 0;
359+
case 4: return stricmp(str, "true") == 0;
360+
case 6: return stricmp(str, "enable") == 0;
361+
default: return false;
362+
}
363+
}

base/hbase.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
BEGIN_EXTERN_C
99

10-
//--------------------safe alloc/free---------------------------
11-
HV_EXPORT void* safe_malloc(size_t size);
12-
HV_EXPORT void* safe_realloc(void* oldptr, size_t newsize, size_t oldsize);
13-
HV_EXPORT void* safe_calloc(size_t nmemb, size_t size);
14-
HV_EXPORT void* safe_zalloc(size_t size);
15-
HV_EXPORT void safe_free(void* ptr);
10+
//--------------------alloc/free---------------------------
11+
HV_EXPORT void* hv_malloc(size_t size);
12+
HV_EXPORT void* hv_realloc(void* oldptr, size_t newsize, size_t oldsize);
13+
HV_EXPORT void* hv_calloc(size_t nmemb, size_t size);
14+
HV_EXPORT void* hv_zalloc(size_t size);
15+
HV_EXPORT void hv_free(void* ptr);
1616

1717
#define HV_ALLOC(ptr, size)\
1818
do {\
19-
*(void**)&(ptr) = safe_zalloc(size);\
19+
*(void**)&(ptr) = hv_zalloc(size);\
2020
printd("alloc(%p, size=%llu)\tat [%s:%d:%s]\n", ptr, (unsigned long long)size, __FILE__, __LINE__, __FUNCTION__);\
2121
} while(0)
2222

@@ -25,7 +25,7 @@ HV_EXPORT void safe_free(void* ptr);
2525
#define HV_FREE(ptr)\
2626
do {\
2727
if (ptr) {\
28-
safe_free(ptr);\
28+
hv_free(ptr);\
2929
printd("free( %p )\tat [%s:%d:%s]\n", ptr, __FILE__, __LINE__, __FUNCTION__);\
3030
ptr = NULL;\
3131
}\
@@ -55,33 +55,33 @@ HV_INLINE void hv_memcheck() {
5555
}
5656
#define HV_MEMCHECK atexit(hv_memcheck);
5757

58-
//--------------------safe string-------------------------------
59-
HV_EXPORT char* strupper(char* str);
60-
HV_EXPORT char* strlower(char* str);
61-
HV_EXPORT char* strreverse(char* str);
58+
//--------------------string-------------------------------
59+
HV_EXPORT char* hv_strupper(char* str);
60+
HV_EXPORT char* hv_strlower(char* str);
61+
HV_EXPORT char* hv_strreverse(char* str);
6262

63-
HV_EXPORT bool strstartswith(const char* str, const char* start);
64-
HV_EXPORT bool strendswith(const char* str, const char* end);
65-
HV_EXPORT bool strcontains(const char* str, const char* sub);
63+
HV_EXPORT bool hv_strstartswith(const char* str, const char* start);
64+
HV_EXPORT bool hv_strendswith(const char* str, const char* end);
65+
HV_EXPORT bool hv_strcontains(const char* str, const char* sub);
6666

6767
// strncpy n = sizeof(dest_buf)-1
68-
// safe_strncpy n = sizeof(dest_buf)
69-
HV_EXPORT char* safe_strncpy(char* dest, const char* src, size_t n);
68+
// hv_strncpy n = sizeof(dest_buf)
69+
HV_EXPORT char* hv_strncpy(char* dest, const char* src, size_t n);
7070

7171
// strncat n = sizeof(dest_buf)-1-strlen(dest)
72-
// safe_strncpy n = sizeof(dest_buf)
73-
HV_EXPORT char* safe_strncat(char* dest, const char* src, size_t n);
72+
// hv_strncpy n = sizeof(dest_buf)
73+
HV_EXPORT char* hv_strncat(char* dest, const char* src, size_t n);
7474

7575
#if !HAVE_STRLCPY
76-
#define strlcpy safe_strncpy
76+
#define strlcpy hv_strncpy
7777
#endif
7878

7979
#if !HAVE_STRLCAT
80-
#define strlcat safe_strncat
80+
#define strlcat hv_strncat
8181
#endif
8282

83-
#define strrchr_dot(str) strrchr(str, '.')
84-
HV_EXPORT char* strrchr_dir(const char* filepath);
83+
#define hv_strrchr_dot(str) strrchr(str, '.')
84+
HV_EXPORT char* hv_strrchr_dir(const char* filepath);
8585

8686
// basename
8787
HV_EXPORT const char* hv_basename(const char* filepath);
@@ -97,17 +97,17 @@ HV_EXPORT bool hv_isfile(const char* path);
9797
HV_EXPORT bool hv_islink(const char* path);
9898
HV_EXPORT size_t hv_filesize(const char* filepath);
9999

100-
// 1 y on yes true enable
101-
HV_EXPORT bool getboolean(const char* str);
102-
103100
HV_EXPORT char* get_executable_path(char* buf, int size);
104101
HV_EXPORT char* get_executable_dir(char* buf, int size);
105102
HV_EXPORT char* get_executable_file(char* buf, int size);
106103
HV_EXPORT char* get_run_dir(char* buf, int size);
107104

108105
// random
109-
HV_EXPORT int hv_rand(int min, int max);
110-
HV_EXPORT void hv_random_string(char *buf, int len);
106+
HV_EXPORT int hv_rand(int min, int max);
107+
HV_EXPORT void hv_random_string(char *buf, int len);
108+
109+
// 1 y on yes true enable
110+
HV_EXPORT bool hv_getboolean(const char* str);
111111

112112
END_EXTERN_C
113113

base/hbuf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class HBuf : public hbuf_t {
9595
HV_ALLOC(base, cap);
9696
}
9797
else {
98-
base = (char*)safe_realloc(base, cap, len);
98+
base = (char*)hv_realloc(base, cap, len);
9999
}
100100
len = cap;
101101
cleanup_ = true;
@@ -128,7 +128,7 @@ class HVLBuf : public HBuf {
128128
void push_front(void* ptr, size_t len) {
129129
if (len > this->len - _size) {
130130
size_t newsize = MAX(this->len, len)*2;
131-
base = (char*)safe_realloc(base, newsize, this->len);
131+
base = (char*)hv_realloc(base, newsize, this->len);
132132
this->len = newsize;
133133
}
134134

@@ -146,7 +146,7 @@ class HVLBuf : public HBuf {
146146
void push_back(void* ptr, size_t len) {
147147
if (len > this->len - _size) {
148148
size_t newsize = MAX(this->len, len)*2;
149-
base = (char*)safe_realloc(base, newsize, this->len);
149+
base = (char*)hv_realloc(base, newsize, this->len);
150150
this->len = newsize;
151151
}
152152
else if (len > this->len - _offset - _size) {

base/queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static inline void qtype##_cleanup(qtype* p) {\
7272
\
7373
static inline void qtype##_resize(qtype* p, int maxsize) {\
7474
if (maxsize == 0) maxsize = QUEUE_INIT_SIZE;\
75-
p->ptr = (type*)safe_realloc(p->ptr, sizeof(type) * maxsize, sizeof(type) * p->maxsize);\
75+
p->ptr = (type*)hv_realloc(p->ptr, sizeof(type) * maxsize, sizeof(type) * p->maxsize);\
7676
p->maxsize = maxsize;\
7777
}\
7878
\

cpputil/iniparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void IniParser::SetValue(const std::string& key, const std::string& value, const
330330
template<>
331331
HV_EXPORT bool IniParser::Get(const std::string& key, const std::string& section, bool defvalue) {
332332
std::string str = GetValue(key, section);
333-
return str.empty() ? defvalue : getboolean(str.c_str());
333+
return str.empty() ? defvalue : hv_getboolean(str.c_str());
334334
}
335335

336336
template<>

0 commit comments

Comments
 (0)