From 0cfb63013bd23d9820af92cd10035bac461f9845 Mon Sep 17 00:00:00 2001 From: Ahmed Samy Date: Wed, 23 Oct 2013 17:39:25 +0200 Subject: [PATCH] cpuid: use a sprintf-like function to get cputype as a string Signed-off-by: Ahmed Samy --- ccan/cpuid/cpuid.c | 9 +++++++-- ccan/cpuid/cpuid.h | 12 +++++++----- ccan/cpuid/test/run.c | 4 +++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ccan/cpuid/cpuid.c b/ccan/cpuid/cpuid.c index 5c3aa348..026875dc 100644 --- a/ccan/cpuid/cpuid.c +++ b/ccan/cpuid/cpuid.c @@ -220,9 +220,14 @@ cputype_t cpuid_get_cpu_type(void) return cputype; } -const char *cpuid_get_cpu_type_string(const cputype_t cputype) +bool cpuid_sprintf_cputype(const cputype_t cputype, char *buf) { - return cpuids[(int)cputype]; + if (cputype == CT_NONE) + return false; + + memcpy(buf, cpuids[(int)cputype], 12); + buf[12] = '\0'; + return true; } uint32_t cpuid_highest_ext_func_supported(void) diff --git a/ccan/cpuid/cpuid.h b/ccan/cpuid/cpuid.h index ee61da85..7bf903a6 100644 --- a/ccan/cpuid/cpuid.h +++ b/ccan/cpuid/cpuid.h @@ -26,7 +26,7 @@ #include /** - * enum cpuid - stuff to get information on from the CPU. + * enum cpuid - stuff to get information about from the CPU. * * This is used as a parameter in cpuid(). * @@ -124,14 +124,17 @@ typedef enum cputype { * * See also: cpuid_get_cpu_type_string() */ +#define is_intel_cpu() cpuid_get_cpu_type() == CT_INTEL +#define is_amd_cpu() cpuid_get_cpu_type() == CT_AMDK5 || cpuid_get_cpu_type() == CT_AMD cputype_t cpuid_get_cpu_type(void); /** - * cpuid_get_cpu_type_string - Get CPU Type string + * cpuid_sprintf_cputype - Get CPU Type string + * @cputype: a char of atleast 12 bytes in it. * - * Returns the CPU type string based off cputype_t. + * Returns true on success, false on failure */ -const char *cpuid_get_cpu_type_string(const cputype_t cputype); +bool cpuid_sprintf_cputype(const cputype_t cputype, char *buf); /** * cpuid_is_supported - test if the CPUID instruction is supported @@ -275,4 +278,3 @@ bool cpuid_has_feature(int feature, bool extended); #endif #endif - diff --git a/ccan/cpuid/test/run.c b/ccan/cpuid/test/run.c index 88c241a1..843389fa 100644 --- a/ccan/cpuid/test/run.c +++ b/ccan/cpuid/test/run.c @@ -10,7 +10,9 @@ int main(void) return 1; } - printf ("Vendor ID: %s\n", cpuid_get_cpu_type_string (cpuid_get_cpu_type ())); + char cputype[12]; + if (cpuid_sprintf_cputype(cpuid_get_cpu_type(), cputype)) + printf ("Vendor ID: %s\n", cputype); char buf[48]; cpuid(CPU_PROC_BRAND_STRING, (uint32_t *)buf); -- 2.39.2