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__
29 /* Mingw headers don't have latest processor codes. */
30 #ifndef PROCESSOR_AMD_X8664
31 # define PROCESSOR_AMD_X8664 8664
35 uname (struct utsname *buf)
37 OSVERSIONINFO version;
39 const char *super_version;
41 /* Fill in nodename. */
42 if (gethostname (buf->nodename, sizeof (buf->nodename)) < 0)
43 strcpy (buf->nodename, "localhost");
45 /* Determine major-major Windows version. */
46 version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
47 have_version = GetVersionEx (&version);
50 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
52 /* Windows NT or newer. */
55 else if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
57 /* Windows 95/98/ME. */
58 switch (version.dwMinorVersion)
80 /* Fill in sysname. */
82 /* Returns a string compatible with the MSYS uname.exe program,
83 so that no further changes are needed to GNU config.guess.
85 $ ./uname.exe -s => MINGW32_NT-5.1
88 sprintf (buf->sysname, "MINGW32_%s-%u.%u", super_version,
89 (unsigned int) version.dwMajorVersion,
90 (unsigned int) version.dwMinorVersion);
92 strcpy (buf->sysname, "MINGW32");
95 sprintf (buf->sysname, "Windows%s", super_version);
97 strcpy (buf->sysname, "Windows");
100 /* Fill in release, version. */
101 /* The MSYS uname.exe programs uses strings from a modified Cygwin runtime:
102 $ ./uname.exe -r => 1.0.11(0.46/3/2)
103 $ ./uname.exe -v => 2008-08-25 23:40
104 There is no point in imitating this behaviour. */
107 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
109 /* Windows NT or newer. */
110 if (version.dwMajorVersion <= 4)
111 sprintf (buf->release, "Windows NT %u.%u",
112 (unsigned int) version.dwMajorVersion,
113 (unsigned int) version.dwMinorVersion);
114 else if (version.dwMajorVersion == 5)
115 switch (version.dwMinorVersion)
118 strcpy (buf->release, "Windows 2000");
121 strcpy (buf->release, "Windows XP");
124 strcpy (buf->release, "Windows Server 2003");
127 strcpy (buf->release, "Windows");
130 else if (version.dwMajorVersion == 6)
132 OSVERSIONINFOEX versionex;
134 versionex.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
135 if (GetVersionEx ((OSVERSIONINFO *) &versionex)
136 && versionex.wProductType != VER_NT_WORKSTATION)
137 strcpy (buf->release, "Windows Server 2008");
139 switch (version.dwMinorVersion)
142 strcpy (buf->release, "Windows Vista");
145 default: /* versions not yet known */
146 strcpy (buf->release, "Windows 7");
151 strcpy (buf->release, "Windows");
155 /* Windows 95/98/ME. */
156 sprintf (buf->release, "Windows %s", super_version);
158 strcpy (buf->version, version.szCSDVersion);
162 strcpy (buf->release, "Windows");
163 strcpy (buf->version, "");
166 /* Fill in machine. */
170 GetSystemInfo (&info);
171 /* Check for Windows NT, since the info.wProcessorLevel is
172 garbage on Windows 95. */
173 if (have_version && version.dwPlatformId == VER_PLATFORM_WIN32_NT)
175 /* Windows NT or newer. */
176 switch (info.wProcessorArchitecture)
178 case PROCESSOR_ARCHITECTURE_AMD64:
179 strcpy (buf->machine, "x86_64");
181 case PROCESSOR_ARCHITECTURE_IA64:
182 strcpy (buf->machine, "ia64");
184 case PROCESSOR_ARCHITECTURE_INTEL:
185 strcpy (buf->machine, "i386");
186 if (info.wProcessorLevel >= 3)
188 '0' + (info.wProcessorLevel <= 6 ? info.wProcessorLevel : 6);
191 strcpy (buf->machine, "unknown");
197 /* Windows 95/98/ME. */
198 switch (info.dwProcessorType)
200 case PROCESSOR_AMD_X8664:
201 strcpy (buf->machine, "x86_64");
203 case PROCESSOR_INTEL_IA64:
204 strcpy (buf->machine, "ia64");
207 if (info.dwProcessorType % 100 == 86)
208 sprintf (buf->machine, "i%u",
209 (unsigned int) info.dwProcessorType);
211 strcpy (buf->machine, "unknown");