1
mirror of https://github.com/mpv-player/mpv synced 2024-12-24 07:33:46 +01:00

returns a malloc()'ed string instead of an auto char[]

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@2304 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
pl 2001-10-20 11:16:47 +00:00
parent 746b9acfb6
commit a46e600619
2 changed files with 15 additions and 4 deletions

View File

@ -93,9 +93,13 @@ void GetCpuCaps( CpuCaps *caps)
printf("CPU vendor name: %.4s%.4s%.4s max cpuid level: %d\n",&regs[1],&regs[3],&regs[2],regs[0]);
if (regs[0]>=0x00000001)
{
char *tmpstr;
do_cpuid(0x00000001, regs2);
printf("CPU: %s\n",GetCpuFriendlyName(regs, regs2));
tmpstr=GetCpuFriendlyName(regs, regs2);
printf("CPU: %s\n",tmpstr);
free(tmpstr);
caps->cpuType=(regs2[0] >> 8)&0xf;
if(caps->cpuType==0xf){
@ -153,17 +157,22 @@ void GetCpuCaps( CpuCaps *caps)
char *GetCpuFriendlyName(unsigned int regs[], unsigned int regs2[]){
#include "cputable.h" /* get cpuname and cpuvendors */
char vendor[17];
char retname[255];
char *retname;
int i;
if (NULL==(retname=malloc(256))) {
printf("Error: GetCpuFriendlyName() not enough memory\n");
exit(1);
}
sprintf(vendor,"%.4s%.4s%.4s",&regs[1],&regs[3],&regs[2]);
for(i=0; i<MAX_VENDORS; i++){
if(!strcmp(cpuvendors[i].string,vendor)){
if(cpuname[i][CPUID_FAMILY][CPUID_MODEL]){
sprintf(retname,"%s %s",cpuvendors[i].name,cpuname[i][CPUID_FAMILY][CPUID_MODEL]);
snprintf(retname,255,"%s %s",cpuvendors[i].name,cpuname[i][CPUID_FAMILY][CPUID_MODEL]);
} else {
sprintf(retname,"unknown %s %d. Generation CPU",cpuvendors[i].name,CPUID_FAMILY);
snprintf(retname,255,"unknown %s %d. Generation CPU",cpuvendors[i].name,CPUID_FAMILY);
printf("unknown %s CPU:\n",cpuvendors[i].name);
printf("Vendor: %s\n",cpuvendors[i].string);
printf("Type: %d\n",CPUID_TYPE);

View File

@ -18,6 +18,8 @@ typedef struct cpucaps_s {
extern CpuCaps gCpuCaps;
void GetCpuCaps(CpuCaps *caps);
/* returned value is malloc()'ed so free() it after use */
char *GetCpuFriendlyName(unsigned int regs[], unsigned int regs2[]);
#endif /* ARCH_X86 */