string get_system_id()
{
static string sysid = "";
if(sysid == "")
{
int fd = open("/etc/os-release",O_RDONLY);
char buf[1024] = {0};
read(fd,buf,1024);
close(fd);
char*p =NULL;
p = strstr(buf, "ID=");
if(p == NULL)
{
sysid = "末知";
}
else
{
p = p+3;
char *q = p;
for(int i =0 ;i < 20 ;i++)
{
if(p[i] == '\n')
{
p[i] = '\0';
break;
}
}
sysid = p;
}
}
return sysid;
}
bool isUbuntu()
{
if(get_system_id() == "ubuntu")
return true;
else
return false;
}
bool isYingHeKyline()
{
if(get_system_id() == "kylin")
return true;
else
return false;
}
bool isZhongbiaoKyline()
{
if(get_system_id() == "neokylin")
return true;
else
return false;
}
bool isNfs()
{
if(get_system_id() == "NFS Desktop")
return true;
else {
return false;
}
}
获得linux系统名称
最新推荐文章于 2024-09-01 10:20:57 发布