Implement os_system_version_get_current_version

This commit is contained in:
Ariel Abreu 2021-02-22 23:07:51 -05:00
parent 8596b6c39a
commit b7cbe133c8
No known key found for this signature in database
GPG Key ID: BB20848279B910AC
2 changed files with 34 additions and 1 deletions

View File

@ -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

View File

@ -38,6 +38,7 @@
#include <stdio.h>
#include <xpc/internal.h>
#include <libkern/OSByteOrder.h>
#include <sys/sysctl.h>
#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;
};