uint32 hz;
size_t hzSize = sizeof hz;
- /* 'cpuNumber' is ignored: Intel Macs are always perfectly symetric. */
+ /* 'cpuNumber' is ignored: Intel Macs are always perfectly symmetric. */
if (sysctlbyname(CPUMHZ_SYSCTL_NAME, &hz, &hzSize, NULL, 0) == -1) {
return FALSE;
}
+#if defined(__APPLE__) || defined(__FreeBSD__)
/*
*-----------------------------------------------------------------------------
*
- * Hostinfo_GetCpuDescription --
+ * HostinfoGetSysctlStringAlloc --
*
- * Get the descriptive name associated with a given CPU.
+ * Obtains the value of a string-type host sysctl.
*
* Results:
* On success: Allocated, NUL-terminated string.
*-----------------------------------------------------------------------------
*/
-char *
-Hostinfo_GetCpuDescription(uint32 cpuNumber) // IN:
+static char *
+HostinfoGetSysctlStringAlloc(char const *sysctlName) // IN
{
-#if defined(__APPLE__) || defined(__FreeBSD__)
-# if defined(__APPLE__)
-# define CPUDESC_SYSCTL_NAME "machdep.cpu.brand_string"
-# else
-# define CPUDESC_SYSCTL_NAME "hw.model"
-# endif
-
char *desc;
size_t descSize;
- /* 'cpuNumber' is ignored: Intel Macs are always perfectly symetric. */
-
- if (sysctlbyname(CPUDESC_SYSCTL_NAME, NULL, &descSize, NULL, 0) == -1) {
+ if (sysctlbyname(sysctlName, NULL, &descSize, NULL, 0) == -1) {
return NULL;
}
return NULL;
}
- if (sysctlbyname(CPUDESC_SYSCTL_NAME, desc, &descSize, NULL, 0) == -1) {
+ if (sysctlbyname(sysctlName, desc, &descSize, NULL, 0) == -1) {
free(desc);
return NULL;
}
return desc;
+}
+#endif
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Hostinfo_GetCpuDescription --
+ *
+ * Get the descriptive name associated with a given CPU.
+ *
+ * Results:
+ * On success: Allocated, NUL-terminated string.
+ * On failure: NULL.
+ *
+ * Side effects:
+ * None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+char *
+Hostinfo_GetCpuDescription(uint32 cpuNumber) // IN:
+{
+#if defined(__APPLE__)
+ /* 'cpuNumber' is ignored: Intel Macs are always perfectly symmetric. */
+ return HostinfoGetSysctlStringAlloc("machdep.cpu.brand_string");
+#elif defined(__FreeBSD__)
+ return HostinfoGetSysctlStringAlloc("hw.model");
#else
#ifdef VMX86_SERVER
if (HostType_OSIsVMK()) {
mName[0] = '\0';
if (VMKernel_GetCPUModelName(cpuNumber, mName,
sizeof(mName)) == VMK_OK) {
- mName[sizeof(mName) - 1] = '\0';
+ mName[sizeof(mName) - 1] = '\0';
return strdup(mName);
}
return retval;
}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Hostinfo_GetHardwareModel --
+ *
+ * Obtains the hardware model identifier (i.e. "MacPro5,1") from the host.
+ *
+ * Results:
+ * On success: Allocated, NUL-terminated string.
+ * On failure: NULL.
+ *
+ * Side effects:
+ * None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+char *
+Hostinfo_GetHardwareModel(void)
+{
+ return HostinfoGetSysctlStringAlloc("hw.model");
+}
#endif /* __APPLE__ */