From b7cbe133c87be75e8e372542393e28eaf948c4fa Mon Sep 17 00:00:00 2001 From: Ariel Abreu Date: Mon, 22 Feb 2021 23:07:51 -0500 Subject: [PATCH] Implement os_system_version_get_current_version --- scripts/exported-symbols.exp | 2 +- src/misc.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/scripts/exported-symbols.exp b/scripts/exported-symbols.exp index 876b82d..23a308f 100644 --- a/scripts/exported-symbols.exp +++ b/scripts/exported-symbols.exp @@ -281,7 +281,7 @@ _launchd_msg_send _load_launchd_jobs_at_loginwindow_prompt _mpm_uncork_fork _mpm_wait -#_os_system_version_get_current_version +_os_system_version_get_current_version #_os_system_version_sim_get_current_host_version #_os_transaction_copy_description _os_transaction_create diff --git a/src/misc.c b/src/misc.c index f3a808b..1f4004f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -38,6 +38,7 @@ #include #include #include +#include #define RECV_BUFFER_SIZE 65536 @@ -618,3 +619,35 @@ int launch_activate_socket(const char* key, int** fds, size_t* count) { *count = 0; return -1; }; + +struct os_system_version { + unsigned int major; + unsigned int minor; + unsigned int patch; +}; + +int os_system_version_get_current_version(struct os_system_version* version_info) { + char version_string[48] = {0}; + size_t version_string_length = sizeof(version_string); + char* ptr = NULL; + int status = 0; + + if ((status = sysctlbyname("kern.osproductversion", version_string, &version_string_length, NULL, 0)) != 0) + goto out; + + version_info->major = strtoul(version_string, &ptr, 10); + if (*ptr != '\0') { + version_info->minor = strtoul(ptr + 1, &ptr, 10); + if (*ptr != '\0') { + version_info->patch = strtoul(ptr + 1, &ptr, 10); + } else { + version_info->patch = 0; + } + } else { + version_info->minor = 0; + version_info->patch = 0; + } + +out: + return status; +};