mirror of
https://github.com/darlinghq/darling-libxpc.git
synced 2024-11-23 03:39:40 +00:00
Implement os_system_version_get_current_version
This commit is contained in:
parent
8596b6c39a
commit
b7cbe133c8
@ -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
|
||||
|
33
src/misc.c
33
src/misc.c
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user