EDIT:: I do not refer my question to utsname.h. Instead, I'm looking to get the distribution version e.g.: Ubuntu 20.04.1. (Just the numbers).
I'm creating a function in C which return the build version on each OS. I already have it working on MS-Windows and macOS; However, I couldn't find anything to make it work on Linux(Ubuntu). Here is the code of my function with already works fine on MS-W and macOS.
struct OS_VERSION_LAT {
double osMayor, osMenor, osBuild;
};
typedef struct OS_VERSION_LAT Struct;
Struct buscar_os_version() { // Search the build version on each OS
Struct os_v;
#ifdef WIN32
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
os_v.osMayor = osvi.dwMajorVersion;
os_v.osMenor = osvi.dwMinorVersion;
os_v.osBuild = osvi.dwBuildNumber;
#elif __APPLE__
char cmd[64];
for (int i=0; i<=3; i++){
sprintf(cmd, "sw_vers -productVersion | awk -F '.' '{print $%d}'", i);
FILE* stdoutFile = popen(cmd, "r");
int resp = 0;
if (stdoutFile) {
char buff[16];
char *stdout = fgets(buff, sizeof(buff), stdoutFile);
pclose(stdoutFile);
sscanf(stdout, "%d", &resp);
}
switch(i) {
case 1:
os_v.osMayor = resp;
case 2:
os_v.osMenor = resp;
case 3:
os_v.osBuild = resp;
break;
}
}
#else
#endif
return os_v;
}