@@ -484,36 +484,55 @@ str_t sys_version () {
484484
485485str_t sys_firmware () {
486486 // Try to read firmware version from system files
487- // Check /etc/mlinux-version first ( mLinux specific )
487+ // Prefer /etc/os-release PRETTY_NAME (standard, works on mLinux and most Linux )
488488 if ( firmwareTxt == NULL ) {
489- FILE * f = fopen ("/etc/mlinux-version" , "r" );
490- if ( f == NULL )
491- f = fopen ("/etc/issue" , "r" );
489+ FILE * f = fopen ("/etc/os-release" , "r" );
492490 if ( f ) {
493- char buf [128 ];
494- if ( fgets (buf , sizeof (buf ), f ) ) {
495- // Trim trailing whitespace and escape sequences (like \n \l in /etc/issue)
496- int n = strlen (buf );
497- while ( n > 0 && strchr (" \t\r\n" , buf [n - 1 ]) ) -- n ;
498- buf [n ] = 0 ;
499- // Remove escape sequences like \n, \l, etc. from /etc/issue
500- char * p = buf ;
501- while ( (p = strchr (p , '\\' )) != NULL ) {
502- if ( p [1 ] ) {
503- memmove (p , p + 2 , strlen (p + 2 )+ 1 );
504- } else {
505- * p = 0 ;
506- break ;
507- }
491+ char buf [256 ];
492+ while ( fgets (buf , sizeof (buf ), f ) ) {
493+ if ( strncmp (buf , "PRETTY_NAME=" , 12 ) == 0 ) {
494+ char * val = buf + 12 ;
495+ // Remove quotes if present
496+ if ( * val == '"' ) val ++ ;
497+ int n = strlen (val );
498+ while ( n > 0 && strchr (" \t\r\n\"" , val [n - 1 ]) ) -- n ;
499+ val [n ] = 0 ;
500+ firmwareTxt = rt_strdup (val );
501+ break ;
508502 }
509- // Trim again after removing escapes
510- n = strlen (buf );
511- while ( n > 0 && strchr (" \t\r\n" , buf [n - 1 ]) ) -- n ;
512- buf [n ] = 0 ;
513- firmwareTxt = rt_strdup (buf );
514503 }
515504 fclose (f );
516505 }
506+ // Fallback to /etc/issue if os-release didn't work
507+ if ( firmwareTxt == NULL ) {
508+ f = fopen ("/etc/issue" , "r" );
509+ if ( f ) {
510+ char buf [128 ];
511+ if ( fgets (buf , sizeof (buf ), f ) ) {
512+ // Trim trailing whitespace and escape sequences (like \n \l in /etc/issue)
513+ int n = strlen (buf );
514+ while ( n > 0 && strchr (" \t\r\n" , buf [n - 1 ]) ) -- n ;
515+ buf [n ] = 0 ;
516+ // Remove escape sequences like \n, \l, etc. from /etc/issue
517+ char * p = buf ;
518+ while ( (p = strchr (p , '\\' )) != NULL ) {
519+ if ( p [1 ] ) {
520+ memmove (p , p + 2 , strlen (p + 2 )+ 1 );
521+ } else {
522+ * p = 0 ;
523+ break ;
524+ }
525+ }
526+ // Trim again after removing escapes
527+ n = strlen (buf );
528+ while ( n > 0 && strchr (" \t\r\n" , buf [n - 1 ]) ) -- n ;
529+ buf [n ] = 0 ;
530+ if ( n > 0 )
531+ firmwareTxt = rt_strdup (buf );
532+ }
533+ fclose (f );
534+ }
535+ }
517536 }
518537 return firmwareTxt ;
519538}
0 commit comments