summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@heap.zone>2019-04-23 02:12:17 +0200
committerJonathan Schleifer <js@heap.zone>2019-04-23 02:12:17 +0200
commitbcb2da8ff8b08561ce8697dd22b7a0f560957fcb (patch)
tree3f21aec89d1e7f9590505779042092b06a69378e
parent6808023a1cf99f4853814d3c1206b8ab421578c9 (diff)
OFSystemInfo: Add +[CPUModel]
-rw-r--r--src/OFSystemInfo.h10
-rw-r--r--src/OFSystemInfo.m34
-rw-r--r--tests/OFSystemInfoTests.m2
3 files changed, 45 insertions, 1 deletions
diff --git a/src/OFSystemInfo.h b/src/OFSystemInfo.h
index 186c57ff..b4e0abd1 100644
--- a/src/OFSystemInfo.h
+++ b/src/OFSystemInfo.h
@@ -40,6 +40,7 @@ OF_ASSUME_NONNULL_BEGIN
@property (class, readonly, nullable, nonatomic) OFString *userConfigPath;
# endif
@property (class, readonly, nullable, nonatomic) OFString *CPUVendor;
+@property (class, readonly, nullable, nonatomic) OFString *CPUModel;
# if defined(OF_X86_64) || defined(OF_X86) || defined(DOXYGEN)
@property (class, readonly, nonatomic) bool supportsMMX;
@property (class, readonly, nonatomic) bool supportsSSE;
@@ -146,6 +147,15 @@ OF_ASSUME_NONNULL_BEGIN
*/
+ (nullable OFString *)CPUVendor;
+/*!
+ * @brief Returns the model of the CPU.
+ *
+ * If the model could not be determined, `nil` is returned instead.
+ *
+ * @return The model of the CPU
+ */
++ (nullable OFString *)CPUModel;
+
#if defined(OF_X86_64) || defined(OF_X86) || defined(DOXYGEN)
/*!
* @brief Returns whether the CPU supports MMX.
diff --git a/src/OFSystemInfo.m b/src/OFSystemInfo.m
index c26b8108..56c99c25 100644
--- a/src/OFSystemInfo.m
+++ b/src/OFSystemInfo.m
@@ -28,7 +28,7 @@
#ifdef HAVE_SYS_UTSNAME_H
# include <sys/utsname.h>
#endif
-#ifdef OF_MACOS
+#if defined(OF_MACOS) || defined(OF_NETBSD)
# include <sys/sysctl.h>
#endif
@@ -574,6 +574,38 @@ x86_cpuid(uint32_t eax, uint32_t ecx)
#endif
}
++ (OFString *)CPUModel
+{
+#if defined(OF_MACOS) || defined(OF_NETBSD)
+ char value[256];
+ size_t length = sizeof(value);
+
+# if defined(OF_MACOS)
+ if (sysctlbyname("machdep.cpu.brand_string",
+# elif defined(OF_NETBSD)
+ if (sysctlbyname("machdep.cpu_brand",
+# endif
+ &value, &length, NULL, 0) != 0)
+ return nil;
+
+ return [OFString stringWithCString: value
+ encoding: OF_STRING_ENCODING_ASCII];
+#elif defined(OF_AMIGAOS4)
+ CONST_STRPTR model, version;
+
+ GetCPUInfoTags(GCIT_ModelString, &model,
+ GCIT_VersionString, &version, TAG_END);
+
+ if (version != NULL)
+ return [OFString stringWithFormat: @"%s V%s", model, version];
+ else
+ return [OFString stringWithCString: model
+ encoding: OF_STRING_ENCODING_ASCII];
+#else
+ return nil;
+#endif
+}
+
#if defined(OF_X86_64) || defined(OF_X86)
+ (bool)supportsMMX
{
diff --git a/tests/OFSystemInfoTests.m b/tests/OFSystemInfoTests.m
index 21aa9c59..7dfda072 100644
--- a/tests/OFSystemInfoTests.m
+++ b/tests/OFSystemInfoTests.m
@@ -65,6 +65,8 @@ static OFString *module = @"OFSystemInfo";
PRINT(GREEN, @"CPU vendor: %@", [OFSystemInfo CPUVendor]);
+ PRINT(GREEN, @"CPU model: %@", [OFSystemInfo CPUModel]);
+
#if defined(OF_X86_64) || defined(OF_X86)
PRINT(GREEN, @"Supports MMX: %d", [OFSystemInfo supportsMMX]);