win32-uname.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include "libguile/__scm.h"
  21. #include <windows.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "win32-uname.h"
  25. /*
  26. * Get name and information about current kernel.
  27. */
  28. int
  29. uname (struct utsname *uts)
  30. {
  31. enum { WinNT, Win95, Win98, WinUnknown };
  32. OSVERSIONINFO osver;
  33. SYSTEM_INFO sysinfo;
  34. DWORD sLength;
  35. DWORD os = WinUnknown;
  36. memset (uts, 0, sizeof (*uts));
  37. osver.dwOSVersionInfoSize = sizeof (osver);
  38. GetVersionEx (&osver);
  39. GetSystemInfo (&sysinfo);
  40. switch (osver.dwPlatformId)
  41. {
  42. case VER_PLATFORM_WIN32_NT: /* NT, Windows 2000 or Windows XP */
  43. if (osver.dwMajorVersion == 4)
  44. strcpy (uts->sysname, "Windows NT4x"); /* NT4x */
  45. else if (osver.dwMajorVersion <= 3)
  46. strcpy (uts->sysname, "Windows NT3x"); /* NT3x */
  47. else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion < 1)
  48. strcpy (uts->sysname, "Windows 2000"); /* 2k */
  49. else if (osver.dwMajorVersion >= 5)
  50. strcpy (uts->sysname, "Windows XP"); /* XP */
  51. os = WinNT;
  52. break;
  53. case VER_PLATFORM_WIN32_WINDOWS: /* Win95, Win98 or WinME */
  54. if ((osver.dwMajorVersion > 4) ||
  55. ((osver.dwMajorVersion == 4) && (osver.dwMinorVersion > 0)))
  56. {
  57. if (osver.dwMinorVersion >= 90)
  58. strcpy (uts->sysname, "Windows ME"); /* ME */
  59. else
  60. strcpy (uts->sysname, "Windows 98"); /* 98 */
  61. os = Win98;
  62. }
  63. else
  64. {
  65. strcpy (uts->sysname, "Windows 95"); /* 95 */
  66. os = Win95;
  67. }
  68. break;
  69. case VER_PLATFORM_WIN32s: /* Windows 3.x */
  70. strcpy (uts->sysname, "Windows");
  71. break;
  72. }
  73. sprintf (uts->version, "%ld.%02ld",
  74. osver.dwMajorVersion, osver.dwMinorVersion);
  75. if (osver.szCSDVersion[0] != '\0' &&
  76. (strlen (osver.szCSDVersion) + strlen (uts->version) + 1) <
  77. sizeof (uts->version))
  78. {
  79. strcat (uts->version, " ");
  80. strcat (uts->version, osver.szCSDVersion);
  81. }
  82. sprintf (uts->release, "build %ld", osver.dwBuildNumber & 0xFFFF);
  83. switch (sysinfo.wProcessorArchitecture)
  84. {
  85. case PROCESSOR_ARCHITECTURE_PPC:
  86. strcpy (uts->machine, "ppc");
  87. break;
  88. case PROCESSOR_ARCHITECTURE_ALPHA:
  89. strcpy (uts->machine, "alpha");
  90. break;
  91. case PROCESSOR_ARCHITECTURE_MIPS:
  92. strcpy (uts->machine, "mips");
  93. break;
  94. case PROCESSOR_ARCHITECTURE_INTEL:
  95. /*
  96. * dwProcessorType is only valid in Win95 and Win98 and WinME
  97. * wProcessorLevel is only valid in WinNT
  98. */
  99. switch (os)
  100. {
  101. case Win95:
  102. case Win98:
  103. switch (sysinfo.dwProcessorType)
  104. {
  105. case PROCESSOR_INTEL_386:
  106. case PROCESSOR_INTEL_486:
  107. case PROCESSOR_INTEL_PENTIUM:
  108. sprintf (uts->machine, "i%ld", sysinfo.dwProcessorType);
  109. break;
  110. default:
  111. strcpy (uts->machine, "i386");
  112. break;
  113. }
  114. break;
  115. case WinNT:
  116. sprintf (uts->machine, "i%d86", sysinfo.wProcessorLevel);
  117. break;
  118. default:
  119. strcpy (uts->machine, "unknown");
  120. break;
  121. }
  122. break;
  123. default:
  124. strcpy (uts->machine, "unknown");
  125. break;
  126. }
  127. sLength = sizeof (uts->nodename) - 1;
  128. GetComputerName (uts->nodename, &sLength);
  129. return 0;
  130. }