Small fix.
[wine.git] / misc / version.c
blob45c14863e9e80571ac9a051f48f795d15ad60838
1 /*
2 * Windows version functions
4 * Copyright 1997 Alexandre Julliard
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998 Patrik Stridvall
7 */
9 #include <string.h>
10 #include "windows.h"
11 #include "winbase.h"
12 #include "process.h"
13 #include "options.h"
14 #include "debug.h"
15 #include "ole.h"
16 #include "winversion.h"
18 typedef struct
20 LONG getVersion16;
21 LONG getVersion32;
22 OSVERSIONINFO32A getVersionEx;
23 } VERSION_DATA;
26 /* FIXME: compare values below with original and fix */
27 static const VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
29 /* WIN31 */
31 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
32 MAKELONG( 0x0a03, 0x8000 ),
34 sizeof(OSVERSIONINFO32A), 3, 10, 0,
35 VER_PLATFORM_WIN32s, "Win32s 1.3"
38 /* WIN95 */
40 0x07005F03,
41 0xC0000004,
43 sizeof(OSVERSIONINFO32A), 4, 0, 0x40003B6,
44 VER_PLATFORM_WIN32_WINDOWS, "Win95"
47 /* NT351 */
49 0x05000A03,
50 0x04213303,
52 sizeof(OSVERSIONINFO32A), 3, 51, 0x421,
53 VER_PLATFORM_WIN32_NT, "Service Pack 2"
56 /* NT40 */
58 0x05000A03,
59 0x05650004,
61 sizeof(OSVERSIONINFO32A), 4, 0, 0x565,
62 VER_PLATFORM_WIN32_NT, "Service Pack 3"
67 static const char *VersionNames[NB_WINDOWS_VERSIONS] =
69 "win31",
70 "win95",
71 "nt351",
72 "nt40"
75 /* the current version has not been autodetected but forced via cmdline */
76 static BOOL32 versionForced = FALSE;
77 static WINDOWS_VERSION defaultVersion = WIN31;
80 /**********************************************************************
81 * VERSION_ParseVersion
83 void VERSION_ParseVersion( char *arg )
85 int i;
86 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
88 if (!strcmp( VersionNames[i], arg ))
90 defaultVersion = (WINDOWS_VERSION)i;
91 versionForced = TRUE;
92 return;
95 MSG("Invalid winver value '%s' specified.\n", arg );
96 MSG("Valid versions are:" );
97 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
98 MSG(" '%s'%c", VersionNames[i],
99 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
103 /**********************************************************************
104 * VERSION_GetVersion
106 WINDOWS_VERSION VERSION_GetVersion(void)
108 LPIMAGE_NT_HEADERS peheader;
110 if (versionForced) /* user has overridden any sensible checks */
111 return defaultVersion;
112 if (!PROCESS_Current()->exe_modref)
114 /* HACK: if we have loaded a PE image into this address space,
115 * we are probably using thunks, so Win95 is our best bet
117 if (PROCESS_Current()->modref_list) return WIN95;
118 return WIN31; /* FIXME: hmm, look at DDB.version ? */
120 peheader = PE_HEADER(PROCESS_Current()->exe_modref->module);
121 if (peheader->OptionalHeader.MajorSubsystemVersion == 4)
122 /* FIXME: NT4 has the same majorversion; add a check here for it. */
123 return WIN95;
124 if (peheader->OptionalHeader.MajorSubsystemVersion == 3)
126 /* Win3.10 */
127 if (peheader->OptionalHeader.MinorSubsystemVersion <= 11) return WIN31;
128 /* NT 3.51 */
129 if (peheader->OptionalHeader.MinorSubsystemVersion == 50) return NT351;
130 if (peheader->OptionalHeader.MinorSubsystemVersion == 51) return NT351;
132 ERR(ver,"unknown subsystem version: %04x.%04x, please report.\n",
133 peheader->OptionalHeader.MajorSubsystemVersion,
134 peheader->OptionalHeader.MinorSubsystemVersion );
135 return defaultVersion;
139 /**********************************************************************
140 * VERSION_GetVersionName
142 char *VERSION_GetVersionName()
144 WINDOWS_VERSION ver = VERSION_GetVersion();
145 switch(ver)
147 case WIN31:
148 return "Windows 3.1";
149 case WIN95:
150 return "Windows 95";
151 case NT351:
152 return "Windows NT 3.51";
153 case NT40:
154 return "Windows NT 4.0";
155 default:
156 FIXME(ver,"Windows version %d not named",ver);
157 return "Windows <Unknown>";
161 /***********************************************************************
162 * GetVersion16 (KERNEL.3)
164 LONG WINAPI GetVersion16(void)
166 WINDOWS_VERSION ver = VERSION_GetVersion();
167 return VersionData[ver].getVersion16;
171 /***********************************************************************
172 * GetVersion32 (KERNEL32.427)
174 LONG WINAPI GetVersion32(void)
176 WINDOWS_VERSION ver = VERSION_GetVersion();
177 return VersionData[ver].getVersion32;
181 /***********************************************************************
182 * GetVersionEx16 (KERNEL.149)
184 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
186 WINDOWS_VERSION ver = VERSION_GetVersion();
187 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
189 WARN(ver,"wrong OSVERSIONINFO size from app");
190 return FALSE;
192 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
193 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
194 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
195 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
196 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
197 return TRUE;
201 /***********************************************************************
202 * GetVersionEx32A (KERNEL32.428)
204 BOOL32 WINAPI GetVersionEx32A(OSVERSIONINFO32A *v)
206 WINDOWS_VERSION ver = VERSION_GetVersion();
207 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO32A))
209 WARN(ver,"wrong OSVERSIONINFO size from app");
210 return FALSE;
212 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
213 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
214 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
215 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
216 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
217 return TRUE;
221 /***********************************************************************
222 * GetVersionEx32W (KERNEL32.429)
224 BOOL32 WINAPI GetVersionEx32W(OSVERSIONINFO32W *v)
226 WINDOWS_VERSION ver = VERSION_GetVersion();
228 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
230 WARN(ver,"wrong OSVERSIONINFO size from app");
231 return FALSE;
233 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
234 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
235 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
236 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
237 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
238 return TRUE;
242 /***********************************************************************
243 * GetWinFlags (KERNEL.132)
245 DWORD WINAPI GetWinFlags(void)
247 static const long cpuflags[5] =
248 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
249 SYSTEM_INFO si;
250 OSVERSIONINFO32A ovi;
251 DWORD result;
253 GetSystemInfo(&si);
255 /* There doesn't seem to be any Pentium flag. */
256 result = cpuflags[MIN (si.wProcessorLevel, 4)];
258 switch(Options.mode)
260 case MODE_STANDARD:
261 result |= WF_STANDARD | WF_PMODE | WF_80x87;
262 break;
264 case MODE_ENHANCED:
265 result |= WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
266 break;
268 default:
269 ERR(ver, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
270 break;
272 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
273 ovi.dwOSVersionInfoSize = sizeof(ovi);
274 GetVersionEx32A(&ovi);
275 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
276 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
277 return result;
281 /***********************************************************************
282 * GetWinDebugInfo (KERNEL.355)
284 BOOL16 WINAPI GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT16 flags)
286 FIXME(ver, "(%8lx,%d): stub returning 0\n",
287 (unsigned long)lpwdi, flags);
288 /* 0 means not in debugging mode/version */
289 /* Can this type of debugging be used in wine ? */
290 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
291 return 0;
295 /***********************************************************************
296 * SetWinDebugInfo (KERNEL.356)
298 BOOL16 WINAPI SetWinDebugInfo(WINDEBUGINFO *lpwdi)
300 FIXME(ver, "(%8lx): stub returning 0\n", (unsigned long)lpwdi);
301 /* 0 means not in debugging mode/version */
302 /* Can this type of debugging be used in wine ? */
303 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
304 return 0;
308 /***********************************************************************
309 * DebugFillBuffer (KERNEL.329)
311 * TODO:
312 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
314 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
316 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
319 /***********************************************************************
320 * DiagQuery (KERNEL.339)
322 * returns TRUE if Win called with "/b" (bootlog.txt)
324 BOOL16 WINAPI DiagQuery()
326 /* perhaps implement a Wine "/b" command line flag sometime ? */
327 return FALSE;
330 /***********************************************************************
331 * DiagOutput (KERNEL.340)
333 * writes a debug string into <windir>\bootlog.txt
335 void WINAPI DiagOutput(LPCSTR str)
337 /* FIXME */
338 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
341 /***********************************************************************
342 * OaBuildVersion [OLEAUT32.170]
344 UINT32 WINAPI OaBuildVersion()
346 WINDOWS_VERSION ver = VERSION_GetVersion();
348 switch(VersionData[ver].getVersion32)
350 case 0x80000a03: /* Win 3.1 */
351 return 0x140fd1; /* from Win32s 1.1e */
352 case 0xc0000004: /* Win 95 */
353 return 0x0a0bd3;
354 case 0x04213303: /* NT 3.51 */
355 return 0x0; /* FIXME */
356 case 0x05650004: /* NT 4.0 */
357 return 0x141016;
358 default:
359 return 0x0;