2 Copyright (C) 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include <sys/utsname.h>
22 /* This file provides an implementation only for the native Windows API. */
23 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
31 /* Mingw headers don't have all the platform codes. */
32 #ifndef VER_PLATFORM_WIN32_CE
33 # define VER_PLATFORM_WIN32_CE 3
36 /* Some headers don't have all the processor architecture codes. */
37 #ifndef PROCESSOR_ARCHITECTURE_AMD64
38 # define PROCESSOR_ARCHITECTURE_AMD64 9
40 #ifndef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
41 # define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 10
44 /* Mingw headers don't have the latest processor codes. */
45 #ifndef PROCESSOR_AMD_X8664
46 # define PROCESSOR_AMD_X8664 8664
50 uname (struct utsname *buf)
52 OSVERSIONINFO version;
53 OSVERSIONINFOEX versionex;
54 BOOL have_versionex; /* indicates whether versionex is filled */
55 const char *super_version;
57 /* Preparation: Fill version and, if possible, also versionex.
58 But try to call GetVersionEx only once in the common case. */
59 versionex.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
60 have_versionex = GetVersionEx (&versionex);
63 /* We know that OSVERSIONINFO is a subset of OSVERSIONINFOEX. */
64 memcpy (&version, &versionex, sizeof (OSVERSIONINFO));
68 version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
69 if (!GetVersionEx (&version))
73 /* Fill in nodename. */
74 if (gethostname (buf->nodename, sizeof (buf->nodename)) < 0)
75 strcpy (buf->nodename, "localhost");
77 /* Determine major-major Windows version. */
78 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
80 /* Windows NT or newer. */
83 else if (version.dwPlatformId == VER_PLATFORM_WIN32_CE)
85 /* Windows CE or Embedded CE. */
88 else if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
90 /* Windows 95/98/ME. */
91 switch (version.dwMinorVersion)
100 super_version = "ME";
110 /* Fill in sysname. */
112 /* Returns a string compatible with the MSYS uname.exe program,
113 so that no further changes are needed to GNU config.guess.
115 $ ./uname.exe -s => MINGW32_NT-5.1
117 sprintf (buf->sysname, "MINGW32_%s-%u.%u", super_version,
118 (unsigned int) version.dwMajorVersion,
119 (unsigned int) version.dwMinorVersion);
121 sprintf (buf->sysname, "Windows%s", super_version);
124 /* Fill in release, version. */
125 /* The MSYS uname.exe programs uses strings from a modified Cygwin runtime:
126 $ ./uname.exe -r => 1.0.11(0.46/3/2)
127 $ ./uname.exe -v => 2008-08-25 23:40
128 There is no point in imitating this behaviour. */
129 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
131 /* Windows NT or newer. */
132 if (version.dwMajorVersion <= 4)
133 sprintf (buf->release, "Windows NT %u.%u",
134 (unsigned int) version.dwMajorVersion,
135 (unsigned int) version.dwMinorVersion);
136 else if (version.dwMajorVersion == 5)
137 switch (version.dwMinorVersion)
140 strcpy (buf->release, "Windows 2000");
143 strcpy (buf->release, "Windows XP");
146 strcpy (buf->release, "Windows Server 2003");
149 strcpy (buf->release, "Windows");
152 else if (version.dwMajorVersion == 6)
154 if (have_versionex && versionex.wProductType != VER_NT_WORKSTATION)
155 strcpy (buf->release, "Windows Server 2008");
157 switch (version.dwMinorVersion)
160 strcpy (buf->release, "Windows Vista");
163 default: /* versions not yet known */
164 strcpy (buf->release, "Windows 7");
169 strcpy (buf->release, "Windows");
171 else if (version.dwPlatformId == VER_PLATFORM_WIN32_CE)
173 /* Windows CE or Embedded CE. */
174 sprintf (buf->release, "Windows CE %u.%u",
175 (unsigned int) version.dwMajorVersion,
176 (unsigned int) version.dwMinorVersion);
180 /* Windows 95/98/ME. */
181 sprintf (buf->release, "Windows %s", super_version);
183 strcpy (buf->version, version.szCSDVersion);
185 /* Fill in machine. */
189 GetSystemInfo (&info);
190 /* Check for Windows NT or CE, since the info.wProcessorLevel is
191 garbage on Windows 95. */
192 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT
193 || version.dwPlatformId == VER_PLATFORM_WIN32_CE)
195 /* Windows NT or newer, or Windows CE or Embedded CE. */
196 switch (info.wProcessorArchitecture)
198 case PROCESSOR_ARCHITECTURE_AMD64:
199 strcpy (buf->machine, "x86_64");
201 case PROCESSOR_ARCHITECTURE_IA64:
202 strcpy (buf->machine, "ia64");
204 case PROCESSOR_ARCHITECTURE_INTEL:
205 strcpy (buf->machine, "i386");
206 if (info.wProcessorLevel >= 3)
208 '0' + (info.wProcessorLevel <= 6 ? info.wProcessorLevel : 6);
210 case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
211 strcpy (buf->machine, "i686");
213 case PROCESSOR_ARCHITECTURE_MIPS:
214 strcpy (buf->machine, "mips");
216 case PROCESSOR_ARCHITECTURE_ALPHA:
217 case PROCESSOR_ARCHITECTURE_ALPHA64:
218 strcpy (buf->machine, "alpha");
220 case PROCESSOR_ARCHITECTURE_PPC:
221 strcpy (buf->machine, "powerpc");
223 case PROCESSOR_ARCHITECTURE_SHX:
224 strcpy (buf->machine, "sh");
226 case PROCESSOR_ARCHITECTURE_ARM:
227 strcpy (buf->machine, "arm");
230 strcpy (buf->machine, "unknown");
236 /* Windows 95/98/ME. */
237 switch (info.dwProcessorType)
239 case PROCESSOR_AMD_X8664:
240 strcpy (buf->machine, "x86_64");
242 case PROCESSOR_INTEL_IA64:
243 strcpy (buf->machine, "ia64");
246 if (info.dwProcessorType % 100 == 86)
247 sprintf (buf->machine, "i%u",
248 (unsigned int) info.dwProcessorType);
250 strcpy (buf->machine, "unknown");