Include <config.h> in all C files; use `#ifdef HAVE_CONFIG_H' rather than `#if'.
[bpt/guile.git] / libguile / win32-uname.c
1 /* Copyright (C) 2001, 2006, 2008 Free Software Foundation, Inc.
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include "libguile/__scm.h"
23
24 #include <windows.h>
25 #include <stdio.h>
26 #include <string.h>
27
28 #include "win32-uname.h"
29
30 /*
31 * Get name and information about current kernel.
32 */
33 int
34 uname (struct utsname *uts)
35 {
36 enum { WinNT, Win95, Win98, WinUnknown };
37 OSVERSIONINFO osver;
38 SYSTEM_INFO sysinfo;
39 DWORD sLength;
40 DWORD os = WinUnknown;
41
42 memset (uts, 0, sizeof (*uts));
43
44 osver.dwOSVersionInfoSize = sizeof (osver);
45 GetVersionEx (&osver);
46 GetSystemInfo (&sysinfo);
47
48 switch (osver.dwPlatformId)
49 {
50 case VER_PLATFORM_WIN32_NT: /* NT, Windows 2000 or Windows XP */
51 if (osver.dwMajorVersion == 4)
52 strcpy (uts->sysname, "Windows NT4x"); /* NT4x */
53 else if (osver.dwMajorVersion <= 3)
54 strcpy (uts->sysname, "Windows NT3x"); /* NT3x */
55 else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion < 1)
56 strcpy (uts->sysname, "Windows 2000"); /* 2k */
57 else if (osver.dwMajorVersion >= 5)
58 strcpy (uts->sysname, "Windows XP"); /* XP */
59 os = WinNT;
60 break;
61
62 case VER_PLATFORM_WIN32_WINDOWS: /* Win95, Win98 or WinME */
63 if ((osver.dwMajorVersion > 4) ||
64 ((osver.dwMajorVersion == 4) && (osver.dwMinorVersion > 0)))
65 {
66 if (osver.dwMinorVersion >= 90)
67 strcpy (uts->sysname, "Windows ME"); /* ME */
68 else
69 strcpy (uts->sysname, "Windows 98"); /* 98 */
70 os = Win98;
71 }
72 else
73 {
74 strcpy (uts->sysname, "Windows 95"); /* 95 */
75 os = Win95;
76 }
77 break;
78
79 case VER_PLATFORM_WIN32s: /* Windows 3.x */
80 strcpy (uts->sysname, "Windows");
81 break;
82 }
83
84 sprintf (uts->version, "%ld.%02ld",
85 osver.dwMajorVersion, osver.dwMinorVersion);
86
87 if (osver.szCSDVersion[0] != '\0' &&
88 (strlen (osver.szCSDVersion) + strlen (uts->version) + 1) <
89 sizeof (uts->version))
90 {
91 strcat (uts->version, " ");
92 strcat (uts->version, osver.szCSDVersion);
93 }
94
95 sprintf (uts->release, "build %ld", osver.dwBuildNumber & 0xFFFF);
96
97 switch (sysinfo.wProcessorArchitecture)
98 {
99 case PROCESSOR_ARCHITECTURE_PPC:
100 strcpy (uts->machine, "ppc");
101 break;
102 case PROCESSOR_ARCHITECTURE_ALPHA:
103 strcpy (uts->machine, "alpha");
104 break;
105 case PROCESSOR_ARCHITECTURE_MIPS:
106 strcpy (uts->machine, "mips");
107 break;
108 case PROCESSOR_ARCHITECTURE_INTEL:
109 /*
110 * dwProcessorType is only valid in Win95 and Win98 and WinME
111 * wProcessorLevel is only valid in WinNT
112 */
113 switch (os)
114 {
115 case Win95:
116 case Win98:
117 switch (sysinfo.dwProcessorType)
118 {
119 case PROCESSOR_INTEL_386:
120 case PROCESSOR_INTEL_486:
121 case PROCESSOR_INTEL_PENTIUM:
122 sprintf (uts->machine, "i%ld", sysinfo.dwProcessorType);
123 break;
124 default:
125 strcpy (uts->machine, "i386");
126 break;
127 }
128 break;
129 case WinNT:
130 sprintf (uts->machine, "i%d86", sysinfo.wProcessorLevel);
131 break;
132 default:
133 strcpy (uts->machine, "unknown");
134 break;
135 }
136 break;
137 default:
138 strcpy (uts->machine, "unknown");
139 break;
140 }
141
142 sLength = sizeof (uts->nodename) - 1;
143 GetComputerName (uts->nodename, &sLength);
144 return 0;
145 }