]> git.ozlabs.org Git - ccan/commitdiff
cpuid: cpuid_write_info(): have outfile a file pointer instead
authorA. Samy <f.fallen45@gmail.com>
Tue, 11 Aug 2015 05:14:57 +0000 (05:14 +0000)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 12 Aug 2015 07:38:14 +0000 (17:08 +0930)
ccan/cpuid/cpuid.c
ccan/cpuid/cpuid.h

index d0c06465847c6a4965c2bf40aa7123cc31c2c3b5..c3a2da707e9e0669d87a77f9b9b57dc4730a7e5e 100644 (file)
@@ -368,32 +368,12 @@ void cpuid(cpuid_t request, uint32_t *buf)
        }
 }
 
-bool cpuid_write_info(uint32_t info, uint32_t featureset, const char *outfile)
+bool cpuid_write_info(uint32_t info, uint32_t featureset, FILE *file)
 {
-       FILE *file;
-       char filename[256];
-       char cpu_information[64];
-
-       if (!cpuid_sprintf_cputype(cpuid_get_cpu_type(), cpu_information))
-               return false;
-
        char brand[48];
        cpuid(CPUID_PROC_BRAND_STRING, (uint32_t *)brand);
 
-       cpu_information[12] = '_';
-       memcpy(&cpu_information[13], brand, sizeof brand);
-
-       if (!outfile)
-               strncpy(filename, cpu_information, sizeof cpu_information);
-       else
-               strncpy(filename, outfile, sizeof filename);
-
-       file = fopen(filename, "w");
-       if (!file)
-               return false;
-
-       fprintf(file, "-- CPU Information for CPU: %s --\n\n", cpu_information);
-
+       fprintf(file, "-- CPU Information for: %s_%s --\n\n", cpuid_get_name(), brand);
        if (info & CPUID_HIGHEST_EXTENDED_FUNCTION_SUPPORTED)
                fprintf(file, "Highest extended function supported: %#010x\n\n", cpuid_highest_ext_func_supported());
 
@@ -675,7 +655,6 @@ bool cpuid_write_info(uint32_t info, uint32_t featureset, const char *outfile)
        }
 #undef YON
 
-       fclose(file);
        return true;
 }
 
index 86f200d635e42c097eeb91ea7d90bc4ad06b93e8..eea6c31019db46c41baff0b1ef9ca5fcbb78d805 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <stdbool.h>
 #include <stdint.h>
+#include <stdio.h>
 
 /**
  * enum cpuid - stuff to get information about from the CPU.
@@ -371,20 +372,17 @@ void cpuid(cpuid_t request, uint32_t *buf);
  * cpuid_write_info - Write specified CPU information to a file.
  * @info: Bit set of information to write.
  * @featureset: Bit set of features to write.
- * @outfile: Output filename (Max 256).
- *
- * If @outfile is NULL, a name is choosen in the following format:
- *     CPUVENDOR_PROCESSORBRAND.cpuid
+ * @outfile: Output file pointer
  *
  * Returns true on success, false otherwise.
  *
  * Example usage:
  *     if (!cpuid_write_info(CPUID_VENDORID | CPUID_PROC_BRAND_STRING,
  *                             CPUID_FEAT_ECX_SSE3 | CPUID_FEAT_EDX_FPU,
- *                             "cpuinfo.cpuid"))
+ *                             fp))
  *             ... error ...
  */
-bool cpuid_write_info(uint32_t info, uint32_t featureset, const char *outfile);
+bool cpuid_write_info(uint32_t info, uint32_t featureset, FILE *outfile);
 
 /**
  * cpuid_test_feature - Test if @feature is available