-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathhversion.c
48 lines (39 loc) · 986 Bytes
/
hversion.c
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
#include "hversion.h"
#include "htime.h"
const char* hv_compile_version() {
static char s_version[16] = {0};
datetime_t dt = hv_compile_datetime();
snprintf(s_version, sizeof(s_version), "%d.%d.%d.%d",
HV_VERSION_MAJOR, dt.year%100, dt.month, dt.day);
return s_version;
}
int version_atoi(const char* str) {
int hex = 0;
// trim v1.2.3.4
const char* pv = strchr(str, 'v');
const char* pdot = pv ? pv+1 : str;
while (1) {
hex = (hex << 8) | atoi(pdot);
pdot = strchr(pdot, '.');
if (pdot == NULL) break;
++pdot;
}
return hex;
}
void version_itoa(int num, char* str) {
char* ch = (char*)#
sprintf(str, "%d.%d.%d.%d", ch[3], ch[2], ch[1], ch[0]);
// trim 0.1.2.3
const char* p = str;
while (1) {
if (p[0] == '0' && p[1] == '.') {
p += 2;
}
else {
break;
}
}
if (p != str) {
strcpy(str, p);
}
}