p/version.c: osrelease for Cygwin

On Cygwin systems use a different file and format to get the
OS version.

Thanks to procps Cygwin maintainer Achim!

Signed-off-by: Craig Small <csmall@dropbear.xyz>
This commit is contained in:
Craig Small 2022-04-11 17:30:25 +10:00
parent cb5fa94982
commit 4939a1da8d

View File

@ -25,7 +25,13 @@
#include "misc.h" #include "misc.h"
#include "procps-private.h" #include "procps-private.h"
#ifdef __CYGWIN__
#define PROCFS_OSRELEASE "/proc/version"
#define PROCFS_OSPATTERN "%*s version %u.%u.%u"
#else
#define PROCFS_OSRELEASE "/proc/sys/kernel/osrelease" #define PROCFS_OSRELEASE "/proc/sys/kernel/osrelease"
#define PROCFS_OSPATTERN "%u.%u.%u"
#endif
/* /*
* procps_linux_version * procps_linux_version
@ -55,7 +61,7 @@ PROCPS_EXPORT int procps_linux_version(void)
return -EIO; return -EIO;
} }
fclose(fp); fclose(fp);
version_string_depth = sscanf(buf, "%u.%u.%u", &x, &y, &z); version_string_depth = sscanf(buf, PROCFS_OSPATTERN, &x, &y, &z);
if ((version_string_depth < 2) || /* Non-standard for all known kernels */ if ((version_string_depth < 2) || /* Non-standard for all known kernels */
((version_string_depth < 3) && (x < 3))) /* Non-standard for 2.x.x kernels */ ((version_string_depth < 3) && (x < 3))) /* Non-standard for 2.x.x kernels */
return -ERANGE; return -ERANGE;