fixing os name parsing from /etc/os-release for single-quoted values

gentoo (and possibly others) write ID='gentoo' with single quotes in
/etc/os-release. ParseOsRelease was only stripping double quotes and
using ascii comparison to find the end of the value, which caused
single quotes to be embedded in the os string, producing invalid oberon
like os* = ''gentoo''.

stripping both quote styles at start and stopping at either kind at end.
works for unquoted values (raspbian, devuan) and double-quoted values too.
This commit is contained in:
Norayr Chilingarian 2026-07-09 23:20:02 +04:00
parent 851aadcaf4
commit f6f4c904fa

View file

@ -74,9 +74,9 @@ void ParseOsRelease(FILE *fd) {
while (fgets(osrelease, sizeof(osrelease), fd) != NULL) { while (fgets(osrelease, sizeof(osrelease), fd) != NULL) {
if (strncasecmp(osrelease, "id=", 3) == 0) { if (strncasecmp(osrelease, "id=", 3) == 0) {
int i=3; int i=3;
while (osrelease[i] == '"') {i++;} while (osrelease[i] == '"' || osrelease[i] == '\'') {i++;}
int j=i; int j=i;
while (osrelease[j] > '"') {j++;} while (osrelease[j] != 0 && osrelease[j] != '\n' && osrelease[j] != '"' && osrelease[j] != '\'') {j++;}
if (j>i) { if (j>i) {
osrelease[j] = 0; osrelease[j] = 0;
os = osrelease + i; os = osrelease + i;