mirror of
https://github.com/anrieff/libcpuid
synced 2024-11-10 22:59:13 +00:00
RDMSR: Fix minor mistake in msr_serialize_raw_data()
- Allow to set filename as NULL - Replace printf() by fprintf() - Use a switch case instead multiple if statements
This commit is contained in:
parent
92d3a77105
commit
32d1ac4aff
1 changed files with 8 additions and 9 deletions
|
@ -1021,7 +1021,7 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
|
|||
if (handle == NULL)
|
||||
return set_error(ERR_HANDLE);
|
||||
|
||||
if (!strcmp(filename, ""))
|
||||
if ((filename == NULL) || !strcmp(filename, ""))
|
||||
f = stdout;
|
||||
else
|
||||
f = fopen(filename, "wt");
|
||||
|
@ -1031,22 +1031,21 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
|
|||
return -1;
|
||||
|
||||
fprintf(f, "CPU is %s %s, stock clock is %dMHz.\n", id.vendor_str, id.brand_str, cpu_clock_measure(250, 1));
|
||||
if (id.vendor == VENDOR_INTEL)
|
||||
msr = intel_msr;
|
||||
else if (id.vendor == VENDOR_AMD)
|
||||
msr = amd_msr;
|
||||
else
|
||||
return set_error(ERR_CPU_UNKN);
|
||||
switch (id.vendor) {
|
||||
case VENDOR_AMD: msr = amd_msr; break;
|
||||
case VENDOR_INTEL: msr = intel_msr; break;
|
||||
default: return set_error(ERR_CPU_UNKN);
|
||||
}
|
||||
|
||||
for (i = 0; msr[i] != CPU_INVALID_VALUE; i++) {
|
||||
cpu_rdmsr(handle, msr[i], ®);
|
||||
fprintf(f, "msr[%#08x]=", msr[i]);
|
||||
for (j = 56; j >= 0; j -= 8)
|
||||
fprintf(f, "%02x ", (int) (reg >> j) & 0xff);
|
||||
printf("\n");
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
|
||||
if (strcmp(filename, ""))
|
||||
if ((filename != NULL) && strcmp(filename, ""))
|
||||
fclose(f);
|
||||
return set_error(ERR_OK);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue