diff --git a/HISTORY b/HISTORY index c38d713..4a20fc1 100644 --- a/HISTORY +++ b/HISTORY @@ -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 diff --git a/src/shared_func.c b/src/shared_func.c index aaa817f..353be05 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -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); +} diff --git a/src/shared_func.h b/src/shared_func.h index c79a278..0114683 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -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 diff --git a/src/system_info.c b/src/system_info.c index 769ddca..393e7d8 100644 --- a/src/system_info.c +++ b/src/system_info.c @@ -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; }