*** empty log message ***
[bpt/guile.git] / libguile / win32-uname.c
CommitLineData
8dd6dfdc
MV
1/* Copyright (C) 2001 Free Software Foundation, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program 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
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
41
42#include "libguile/__scm.h"
43
44#include <windows.h>
45#include <stdio.h>
46#include <string.h>
47
1dcb9876 48#include "win32-uname.h"
8dd6dfdc
MV
49
50/*
51 * Get name and information about current kernel.
52 */
53int
54uname (struct utsname *uts)
55{
56 enum { WinNT, Win95, Win98, WinUnknown };
57 OSVERSIONINFO osver;
58 SYSTEM_INFO sysinfo;
59 DWORD sLength;
60 DWORD os = WinUnknown;
61
62 memset (uts, 0, sizeof (*uts));
63
64 osver.dwOSVersionInfoSize = sizeof (osver);
65 GetVersionEx (&osver);
66 GetSystemInfo (&sysinfo);
67
68 switch (osver.dwPlatformId)
69 {
70 case VER_PLATFORM_WIN32_NT: /* NT, Windows 2000 or Windows XP */
71 if (osver.dwMajorVersion == 4)
72 strcpy (uts->sysname, "Windows NT4x"); /* NT4x */
73 else if (osver.dwMajorVersion <= 3)
74 strcpy (uts->sysname, "Windows NT3x"); /* NT3x */
75 else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion < 1)
76 strcpy (uts->sysname, "Windows 2000"); /* 2k */
77 else if (osver.dwMajorVersion >= 5)
78 strcpy (uts->sysname, "Windows XP"); /* XP */
79 os = WinNT;
80 break;
81
82 case VER_PLATFORM_WIN32_WINDOWS: /* Win95, Win98 or WinME */
83 if ((osver.dwMajorVersion > 4) ||
84 ((osver.dwMajorVersion == 4) && (osver.dwMinorVersion > 0)))
85 {
86 if (osver.dwMinorVersion >= 90)
87 strcpy (uts->sysname, "Windows ME"); /* ME */
88 else
89 strcpy (uts->sysname, "Windows 98"); /* 98 */
90 os = Win98;
91 }
92 else
93 {
94 strcpy (uts->sysname, "Windows 95"); /* 95 */
95 os = Win95;
96 }
97 break;
98
99 case VER_PLATFORM_WIN32s: /* Windows 3.x */
100 strcpy (uts->sysname, "Windows");
101 break;
102 }
103
104 sprintf (uts->version, "%ld.%02ld",
105 osver.dwMajorVersion, osver.dwMinorVersion);
106
107 if (osver.szCSDVersion[0] != '\0' &&
108 (strlen (osver.szCSDVersion) + strlen (uts->version) + 1) <
109 sizeof (uts->version))
110 {
111 strcat (uts->version, " ");
112 strcat (uts->version, osver.szCSDVersion);
113 }
114
115 sprintf (uts->release, "build %ld", osver.dwBuildNumber & 0xFFFF);
116
117 switch (sysinfo.wProcessorArchitecture)
118 {
119 case PROCESSOR_ARCHITECTURE_PPC:
120 strcpy (uts->machine, "ppc");
121 break;
122 case PROCESSOR_ARCHITECTURE_ALPHA:
123 strcpy (uts->machine, "alpha");
124 break;
125 case PROCESSOR_ARCHITECTURE_MIPS:
126 strcpy (uts->machine, "mips");
127 break;
128 case PROCESSOR_ARCHITECTURE_INTEL:
129 /*
130 * dwProcessorType is only valid in Win95 and Win98 and WinME
131 * wProcessorLevel is only valid in WinNT
132 */
133 switch (os)
134 {
135 case Win95:
136 case Win98:
137 switch (sysinfo.dwProcessorType)
138 {
139 case PROCESSOR_INTEL_386:
140 case PROCESSOR_INTEL_486:
141 case PROCESSOR_INTEL_PENTIUM:
142 sprintf (uts->machine, "i%ld", sysinfo.dwProcessorType);
143 break;
144 default:
145 strcpy (uts->machine, "i386");
146 break;
147 }
148 break;
149 case WinNT:
150 sprintf (uts->machine, "i%d86", sysinfo.wProcessorLevel);
151 break;
152 default:
153 strcpy (uts->machine, "unknown");
154 break;
155 }
156 break;
157 default:
158 strcpy (uts->machine, "unknown");
159 break;
160 }
161
162 sLength = sizeof (uts->nodename) - 1;
163 GetComputerName (uts->nodename, &sLength);
164 return 0;
165}