add function fc_parse_version

pull/12/merge
YuQing 2026-06-25 15:13:06 +08:00
parent 724b008b0e
commit 1edcae9cf4
4 changed files with 33 additions and 21 deletions

View File

@ -1,4 +1,7 @@
Version 1.86 2026-06-25
* add function fc_parse_version
Version 1.85 2026-06-23
* add functions fc_safe_srand and fc_safe_rand for more security under Linux
* add function seconds_to_human_str

View File

@ -4691,3 +4691,27 @@ int fc_safe_rand()
return (n & RAND_MAX);
}
#endif
int fc_parse_version(const char *src, Version *version)
{
const char *p;
int numbers[2];
int i;
numbers[0] = numbers[1] = 0;
p = src;
for (i=0; i<2; i++) {
p = strchr(p, '.');
if (p == NULL) {
break;
}
p++;
numbers[i] = strtol(p, NULL, 10);
}
version->major = strtol(src, NULL, 10);
version->minor = numbers[0];
version->patch = numbers[1];
return FC_VERSION_TO_INT1(*version);
}

View File

@ -1877,6 +1877,8 @@ int fc_safe_rand();
#define fc_safe_rand() rand()
#endif
int fc_parse_version(const char *src, Version *version);
#ifdef __cplusplus
}
#endif

View File

@ -960,33 +960,16 @@ int get_sysinfo(struct fast_sysinfo *info)
int get_kernel_version(Version *version)
{
struct utsname name;
char *p;
int numbers[2];
int i;
if (uname(&name) < 0)
{
logError("file: "__FILE__", line: %d, "
"call uname fail, errno: %d, error info: %s",
__LINE__, errno, STRERROR(errno));
logError("file: "__FILE__", line: %d, "
"call uname fail, errno: %d, error info: %s",
__LINE__, errno, STRERROR(errno));
return errno != 0 ? errno : EFAULT;
}
numbers[0] = numbers[1] = 0;
p = name.release;
for (i=0; i<2; i++) {
p = strchr(p, '.');
if (p == NULL) {
break;
}
p++;
numbers[i] = strtol(p, NULL, 10);
}
version->major = strtol(name.release, NULL, 10);
version->minor = numbers[0];
version->patch = numbers[1];
fc_parse_version(name.release, version);
return 0;
}