@@ -84,6 +84,11 @@ static char *cpuname[] = {
84
84
"CPU_RISCV64_ZVL128B"
85
85
};
86
86
87
+ static char * cpuname_lower [] = {
88
+ "riscv64_generic" ,
89
+ "c910v"
90
+ };
91
+
87
92
int detect (void ){
88
93
#ifdef __linux
89
94
FILE * infile ;
@@ -92,23 +97,29 @@ int detect(void){
92
97
char * pmodel = NULL , * pisa = NULL ;
93
98
94
99
infile = fopen ("/proc/cpuinfo" , "r" );
100
+ if (!infile )
101
+ return CPU_GENERIC ;
95
102
while (fgets (buffer , sizeof (buffer ), infile )){
96
103
if (!strncmp (buffer , "model name" , 10 )){
97
104
strcpy (model_buffer , buffer );
98
- pmodel = strchr (isa_buffer , ':' ) + 1 ;
105
+ pmodel = strchr (model_buffer , ':' );
106
+ if (pmodel )
107
+ pmodel ++ ;
99
108
}
100
109
101
110
if (!strncmp (buffer , "isa" , 3 )){
102
111
strcpy (isa_buffer , buffer );
103
- pisa = strchr (isa_buffer , '4' ) + 1 ;
112
+ pisa = strchr (isa_buffer , '4' );
113
+ if (pisa )
114
+ pisa ++ ;
104
115
}
105
116
}
106
117
107
118
fclose (infile );
108
119
109
- if (!pmodel )
120
+ if (!pmodel || ! pisa )
110
121
return (CPU_GENERIC );
111
-
122
+
112
123
if (strstr (pmodel , check_c910_str ) && strchr (pisa , 'v' ))
113
124
return CPU_C910V ;
114
125
@@ -146,5 +157,5 @@ void get_cpuconfig(void){
146
157
}
147
158
148
159
void get_libname (void ){
149
- printf ("riscv64\n" );
160
+ printf ("%s" , cpuname_lower [ detect ()] );
150
161
}
0 commit comments