Skip to content

Commit

Permalink
feat(IUtils): getOperatingSystemName support linux
Browse files Browse the repository at this point in the history
  • Loading branch information
itas109 committed Jan 26, 2025
1 parent 7b830f6 commit 65119f8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion include/CSerialPort/iutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,26 @@ class IUtils
}

#elif defined(__linux__)
strncpy(productName, "Linux", len);
char prettyName[256] = "Linux";
FILE *fp = fopen("/etc/os-release", "r");
if (NULL != fp)
{
char line[256];

while (fgets(line, sizeof(line), fp))
{
if (0 == strFind(line, "PRETTY_NAME="))
{
// PRETTY_NAME="Ubuntu 22.04.2 LTS" PRETTY_NAME="CentOS Linux 7 (Core)"
strScan(line, "PRETTY_NAME=\"%[^\"]\"", &prettyName);
break;
}
}

fclose(fp);
}

strncpy(productName, prettyName, len);
#elif defined(__APPLE__)
strncpy(productName, "MacOS", len);
#elif defined(__ANDROID__)
Expand Down

0 comments on commit 65119f8

Please sign in to comment.