win32-uname.c 4.1 KB

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