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__
30 /* Mingw headers don't have latest processor codes. */
31 #ifndef PROCESSOR_AMD_X8664
32 # define PROCESSOR_AMD_X8664 8664
36 uname (struct utsname *buf)
38 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 if (!GetVersionEx (&version))
49 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
51 /* Windows NT or newer. */
54 else if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
56 /* Windows 95/98/ME. */
57 switch (version.dwMinorVersion)
76 /* Fill in sysname. */
78 /* Returns a string compatible with the MSYS uname.exe program,
79 so that no further changes are needed to GNU config.guess.
81 $ ./uname.exe -s => MINGW32_NT-5.1
83 sprintf (buf->sysname, "MINGW32_%s-%u.%u", super_version,
84 (unsigned int) version.dwMajorVersion,
85 (unsigned int) version.dwMinorVersion);
87 sprintf (buf->sysname, "Windows%s", super_version);
90 /* Fill in release, version. */
91 /* The MSYS uname.exe programs uses strings from a modified Cygwin runtime:
92 $ ./uname.exe -r => 1.0.11(0.46/3/2)
93 $ ./uname.exe -v => 2008-08-25 23:40
94 There is no point in imitating this behaviour. */
95 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
97 /* Windows NT or newer. */
98 if (version.dwMajorVersion <= 4)
99 sprintf (buf->release, "Windows NT %u.%u",
100 (unsigned int) version.dwMajorVersion,
101 (unsigned int) version.dwMinorVersion);
102 else if (version.dwMajorVersion == 5)
103 switch (version.dwMinorVersion)
106 strcpy (buf->release, "Windows 2000");
109 strcpy (buf->release, "Windows XP");
112 strcpy (buf->release, "Windows Server 2003");
115 strcpy (buf->release, "Windows");
118 else if (version.dwMajorVersion == 6)
120 OSVERSIONINFOEX versionex;
122 versionex.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
123 if (GetVersionEx ((OSVERSIONINFO *) &versionex)
124 && versionex.wProductType != VER_NT_WORKSTATION)
125 strcpy (buf->release, "Windows Server 2008");
127 switch (version.dwMinorVersion)
130 strcpy (buf->release, "Windows Vista");
133 default: /* versions not yet known */
134 strcpy (buf->release, "Windows 7");
139 strcpy (buf->release, "Windows");
143 /* Windows 95/98/ME. */
144 sprintf (buf->release, "Windows %s", super_version);
146 strcpy (buf->version, version.szCSDVersion);
148 /* Fill in machine. */
152 GetSystemInfo (&info);
153 /* Check for Windows NT, since the info.wProcessorLevel is
154 garbage on Windows 95. */
155 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
157 /* Windows NT or newer. */
158 switch (info.wProcessorArchitecture)
160 case PROCESSOR_ARCHITECTURE_AMD64:
161 strcpy (buf->machine, "x86_64");
163 case PROCESSOR_ARCHITECTURE_IA64:
164 strcpy (buf->machine, "ia64");
166 case PROCESSOR_ARCHITECTURE_INTEL:
167 strcpy (buf->machine, "i386");
168 if (info.wProcessorLevel >= 3)
170 '0' + (info.wProcessorLevel <= 6 ? info.wProcessorLevel : 6);
173 strcpy (buf->machine, "unknown");
179 /* Windows 95/98/ME. */
180 switch (info.dwProcessorType)
182 case PROCESSOR_AMD_X8664:
183 strcpy (buf->machine, "x86_64");
185 case PROCESSOR_INTEL_IA64:
186 strcpy (buf->machine, "ia64");
189 if (info.dwProcessorType % 100 == 86)
190 sprintf (buf->machine, "i%u",
191 (unsigned int) info.dwProcessorType);
193 strcpy (buf->machine, "unknown");