diff --git a/libcpuid/libcpuid_util.c b/libcpuid/libcpuid_util.c index c907f5c..6c02783 100644 --- a/libcpuid/libcpuid_util.c +++ b/libcpuid/libcpuid_util.c @@ -174,6 +174,21 @@ int match_pattern(const char* s, const char* p) return 0; } +int cpu_vendor(void) +{ + int r; + struct cpu_raw_data_t raw; + struct cpu_id_t data; + if ((r = cpuid_get_raw_data(&raw)) < 0) + return set_error(r); + if ((r = cpu_identify(&raw, &data)) < 0) + return set_error(r); + if (0 <= data.vendor && data.vendor < NUM_CPU_VENDORS) + return data.vendor; + else + return set_error(r); +} + struct cpu_id_t* get_cached_cpuid(void) { static int initialized = 0; diff --git a/libcpuid/libcpuid_util.h b/libcpuid/libcpuid_util.h index 34e1efe..f045db6 100644 --- a/libcpuid/libcpuid_util.h +++ b/libcpuid/libcpuid_util.h @@ -70,6 +70,12 @@ void generic_get_cpu_list(const struct match_entry_t* matchtable, int count, */ int match_pattern(const char* haystack, const char* pattern); +/* + * Get the CPU vendor + * Return val: see enum cpu_vendor_t +*/ +int cpu_vendor(void); + /* * Gets an initialized cpu_id_t. It is cached, so that internal libcpuid * machinery doesn't need to issue cpu_identify more than once.