diff --git a/lib/uname.c b/lib/uname.c index a2c4497..4e79ba1 100644 --- a/lib/uname.c +++ b/lib/uname.c @@ -57,7 +57,7 @@ uname (struct utsname *buf) /* Preparation: Fill version and, if possible, also versionex. But try to call GetVersionEx only once in the common case. */ versionex.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX); - have_versionex = GetVersionEx (&versionex); + have_versionex = GetVersionEx ((OSVERSIONINFO *) &versionex); if (have_versionex) { /* We know that OSVERSIONINFO is a subset of OSVERSIONINFOEX. */ @@ -136,11 +136,16 @@ uname (struct utsname *buf) unsigned int server_offset; const char *name; }; + + /* Storing the workstation and server version names in a single + stream does not waste memory when they are the same. These + macros abstract the representation. VERSION1 is used if + version.wProductType does not matter, VERSION2 if it does. */ #define VERSION1(major, minor, name) \ { major, minor, 0, name } #define VERSION2(major, minor, workstation, server) \ { major, minor, sizeof workstation, workstation "\0" server } - const struct windows_version versions[] = + static const struct windows_version versions[] = { VERSION2 (3, -1, "Windows NT Workstation", "Windows NT Server"), VERSION2 (4, -1, "Windows NT Workstation", "Windows NT Server"), @@ -151,18 +156,16 @@ uname (struct utsname *buf) VERSION2 (6, 1, "Windows 7", "Windows Server 2008 R2"), VERSION2 (-1, -1, "Windows", "Windows Server") }; - const struct windows_version *v; const char *base; - unsigned int i; + const struct windows_version *v = versions; - for (i = 0; i < sizeof (versions) / sizeof (versions[0]); i++) - { - v = &versions[i]; - if ((v->major == version.dwMajorVersion || v->major == -1) - && (v->minor == version.dwMinorVersion || v->minor == -1)) - break; - } - if (have_versionex && version.wProductType != VER_NT_WORKSTATION) + /* Find a version that matches ours. The last element is a + wildcard that always ends the loop. */ + while ((v->major != version.dwMajorVersion && v->major != -1) + || (v->minor != version.dwMinorVersion && v->minor != -1)) + v++; + + if (have_versionex && versionex.wProductType != VER_NT_WORKSTATION) base = v->name + v->server_offset; else base = v->name;