I know I can check my OS name with this simple command: lsb_release -ds
. But I also know, that its not portable on all platforms where I need it. I tried struct utsname info;
and uname(&info)
and it works great but gives me only "base" name - "Linux".
Is there any portable (C) way of getting full OS name? Portable between Centos, Debian, Fedora, OpenSUSE, RedHat, Ubuntu at least? Cheers
CentOS vs Ubuntu – Main Differences The biggest difference between the two Linux distributions is that Ubuntu is based on the Debian architecture while CentOS is forked from Red Hat Enterprise Linux. In Ubuntu, you can download DEB packages using the apt-get package manager.
Here is the C code that says the name of the OS. You can also edit the code for other various purpose, by using the same logic.
#include<stdio.h>
int main()
{
FILE *fp;
char buffer[50] = " ";
fp = popen("lsb_release -ds", "r");
fgets(buffer, 50, fp);
pclose(fp);
printf("Name of the OS is : %s",buffer);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With