kernel32/tests: Use skip when functions are not available.
[wine] / dlls / kernel32 / version.c
1 /*
2  * Windows and DOS version functions
3  *
4  * Copyright 1997 Marcus Meissner
5  * Copyright 1998 Patrik Stridvall
6  * Copyright 1998, 2003 Andreas Mohr
7  * Copyright 1997, 2003 Alexandre Julliard
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include "config.h"
25 #include "wine/port.h"
26
27 #include <string.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "winternl.h"
38 #include "winerror.h"
39 #include "wine/winbase16.h"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(ver);
44
45
46 /***********************************************************************
47  *         GetVersion   (KERNEL.3)
48  */
49 DWORD WINAPI GetVersion16(void)
50 {
51     static WORD dosver, winver;
52
53     if (!dosver)  /* not determined yet */
54     {
55         RTL_OSVERSIONINFOEXW info;
56
57         info.dwOSVersionInfoSize = sizeof(info);
58         if (RtlGetVersion( &info ) != STATUS_SUCCESS) return 0;
59
60         if (info.dwMajorVersion <= 3)
61             winver = MAKEWORD( info.dwMajorVersion, info.dwMinorVersion );
62         else
63             winver = MAKEWORD( 3, 95 );
64
65         switch(info.dwPlatformId)
66         {
67         case VER_PLATFORM_WIN32s:
68             switch(MAKELONG( info.dwMinorVersion, info.dwMajorVersion ))
69             {
70             case 0x0200:
71                 dosver = 0x0303;  /* DOS 3.3 for Windows 2.0 */
72                 break;
73             case 0x0300:
74                 dosver = 0x0500;  /* DOS 5.0 for Windows 3.0 */
75                 break;
76             default:
77                 dosver = 0x0616;  /* DOS 6.22 for Windows 3.1 and later */
78                 break;
79             }
80             break;
81         case VER_PLATFORM_WIN32_WINDOWS:
82             /* DOS 8.0 for WinME, 7.0 for Win95/98 */
83             if (info.dwMinorVersion >= 90) dosver = 0x0800;
84             else dosver = 0x0700;
85             break;
86         case VER_PLATFORM_WIN32_NT:
87             dosver = 0x0500;  /* always DOS 5.0 for NT */
88             break;
89         }
90         TRACE( "DOS %d.%02d Win %d.%02d\n",
91                HIBYTE(dosver), LOBYTE(dosver), LOBYTE(winver), HIBYTE(winver) );
92     }
93     return MAKELONG( winver, dosver );
94 }
95
96
97 /***********************************************************************
98  *         GetVersion   (KERNEL32.@)
99  *
100  * Win31   0x80000a03
101  * Win95   0xc0000004
102  * Win98   0xc0000a04
103  * WinME   0xc0005a04
104  * NT351   0x04213303
105  * NT4     0x05650004
106  * Win2000 0x08930005
107  * WinXP   0x0a280105
108  */
109 DWORD WINAPI GetVersion(void)
110 {
111     DWORD result = MAKELONG( MAKEWORD( NtCurrentTeb()->Peb->OSMajorVersion,
112                                        NtCurrentTeb()->Peb->OSMinorVersion ),
113                              (NtCurrentTeb()->Peb->OSPlatformId ^ 2) << 14 );
114     if (NtCurrentTeb()->Peb->OSPlatformId == VER_PLATFORM_WIN32_NT)
115         result |= LOWORD(NtCurrentTeb()->Peb->OSBuildNumber) << 16;
116     return result;
117 }
118
119
120 /***********************************************************************
121  *         GetVersionEx   (KERNEL.149)
122  */
123 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
124 {
125     OSVERSIONINFOA info;
126
127     if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
128     {
129         WARN("wrong OSVERSIONINFO size from app\n");
130         return FALSE;
131     }
132
133     info.dwOSVersionInfoSize = sizeof(info);
134     if (!GetVersionExA( &info )) return FALSE;
135
136     v->dwMajorVersion = info.dwMajorVersion;
137     v->dwMinorVersion = info.dwMinorVersion;
138     v->dwBuildNumber  = info.dwBuildNumber;
139     v->dwPlatformId   = info.dwPlatformId;
140     strcpy( v->szCSDVersion, info.szCSDVersion );
141     return TRUE;
142 }
143
144
145 /***********************************************************************
146  *         GetVersionExA   (KERNEL32.@)
147  */
148 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
149 {
150     RTL_OSVERSIONINFOEXW infoW;
151
152     if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
153         v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
154     {
155         WARN("wrong OSVERSIONINFO size from app (got: %d)\n",
156                         v->dwOSVersionInfoSize );
157         return FALSE;
158     }
159
160     infoW.dwOSVersionInfoSize = sizeof(infoW);
161     if (RtlGetVersion( &infoW ) != STATUS_SUCCESS) return FALSE;
162
163     v->dwMajorVersion = infoW.dwMajorVersion;
164     v->dwMinorVersion = infoW.dwMinorVersion;
165     v->dwBuildNumber  = infoW.dwBuildNumber;
166     v->dwPlatformId   = infoW.dwPlatformId;
167     WideCharToMultiByte( CP_ACP, 0, infoW.szCSDVersion, -1,
168                          v->szCSDVersion, sizeof(v->szCSDVersion), NULL, NULL );
169
170     if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))
171     {
172         LPOSVERSIONINFOEXA vex = (LPOSVERSIONINFOEXA) v;
173         vex->wServicePackMajor = infoW.wServicePackMajor;
174         vex->wServicePackMinor = infoW.wServicePackMinor;
175         vex->wSuiteMask        = infoW.wSuiteMask;
176         vex->wProductType      = infoW.wProductType;
177     }
178     return TRUE;
179 }
180
181
182 /***********************************************************************
183  *         GetVersionExW   (KERNEL32.@)
184  */
185 BOOL WINAPI GetVersionExW( OSVERSIONINFOW *info )
186 {
187     if (info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
188         info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
189     {
190         WARN("wrong OSVERSIONINFO size from app (got: %d)\n",
191                         info->dwOSVersionInfoSize);
192         return FALSE;
193     }
194     return (RtlGetVersion( (RTL_OSVERSIONINFOEXW *)info ) == STATUS_SUCCESS);
195 }
196
197
198 /******************************************************************************
199  *        VerifyVersionInfoA   (KERNEL32.@)
200  */
201 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
202                                 DWORDLONG dwlConditionMask)
203 {
204     OSVERSIONINFOEXW verW;
205
206     verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
207     verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
208     verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
209     verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
210     verW.dwPlatformId = lpVersionInfo->dwPlatformId;
211     verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
212     verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
213     verW.wSuiteMask = lpVersionInfo->wSuiteMask;
214     verW.wProductType = lpVersionInfo->wProductType;
215     verW.wReserved = lpVersionInfo->wReserved;
216
217     return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
218 }
219
220
221 /******************************************************************************
222  *        VerifyVersionInfoW   (KERNEL32.@)
223  */
224 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
225                                 DWORDLONG dwlConditionMask)
226 {
227     switch(RtlVerifyVersionInfo( lpVersionInfo, dwTypeMask, dwlConditionMask ))
228     {
229     case STATUS_INVALID_PARAMETER:
230         SetLastError( ERROR_BAD_ARGUMENTS );
231         return FALSE;
232     case STATUS_REVISION_MISMATCH:
233         SetLastError( ERROR_OLD_WIN_VERSION );
234         return FALSE;
235     }
236     return TRUE;
237 }
238
239
240 /***********************************************************************
241  *          GetWinFlags   (KERNEL.132)
242  */
243 DWORD WINAPI GetWinFlags16(void)
244 {
245   static const long cpuflags[5] =
246     { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
247   SYSTEM_INFO si;
248   OSVERSIONINFOA ovi;
249   DWORD result;
250
251   GetSystemInfo(&si);
252
253   /* There doesn't seem to be any Pentium flag.  */
254   result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
255   if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
256   ovi.dwOSVersionInfoSize = sizeof(ovi);
257   GetVersionExA(&ovi);
258   if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
259       result |= WF_WIN32WOW; /* undocumented WF_WINNT */
260   return result;
261 }
262
263
264 #if 0
265 /* Not used at this time. This is here for documentation only */
266
267 /* WINDEBUGINFO flags values */
268 #define WDI_OPTIONS         0x0001
269 #define WDI_FILTER          0x0002
270 #define WDI_ALLOCBREAK      0x0004
271
272 /* dwOptions values */
273 #define DBO_CHECKHEAP       0x0001
274 #define DBO_BUFFERFILL      0x0004
275 #define DBO_DISABLEGPTRAPPING 0x0010
276 #define DBO_CHECKFREE       0x0020
277
278 #define DBO_SILENT          0x8000
279
280 #define DBO_TRACEBREAK      0x2000
281 #define DBO_WARNINGBREAK    0x1000
282 #define DBO_NOERRORBREAK    0x0800
283 #define DBO_NOFATALBREAK    0x0400
284 #define DBO_INT3BREAK       0x0100
285
286 /* DebugOutput flags values */
287 #define DBF_TRACE           0x0000
288 #define DBF_WARNING         0x4000
289 #define DBF_ERROR           0x8000
290 #define DBF_FATAL           0xc000
291
292 /* dwFilter values */
293 #define DBF_KERNEL          0x1000
294 #define DBF_KRN_MEMMAN      0x0001
295 #define DBF_KRN_LOADMODULE  0x0002
296 #define DBF_KRN_SEGMENTLOAD 0x0004
297 #define DBF_USER            0x0800
298 #define DBF_GDI             0x0400
299 #define DBF_MMSYSTEM        0x0040
300 #define DBF_PENWIN          0x0020
301 #define DBF_APPLICATION     0x0008
302 #define DBF_DRIVER          0x0010
303
304 #endif /* NOLOGERROR */
305
306
307 /***********************************************************************
308  *          GetWinDebugInfo   (KERNEL.355)
309  */
310 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
311 {
312     FIXME("(%8lx,%d): stub returning 0\n",
313           (unsigned long)lpwdi, flags);
314     /* 0 means not in debugging mode/version */
315     /* Can this type of debugging be used in wine ? */
316     /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
317     return 0;
318 }
319
320
321 /***********************************************************************
322  *          SetWinDebugInfo   (KERNEL.356)
323  */
324 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
325 {
326     FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
327     /* 0 means not in debugging mode/version */
328     /* Can this type of debugging be used in wine ? */
329     /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
330     return 0;
331 }
332
333
334 /***********************************************************************
335  *           K329                    (KERNEL.329)
336  *
337  * TODO:
338  * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
339  */
340 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
341 {
342         memset(lpBuffer, DBGFILL_BUFFER, wBytes);
343 }
344
345 /***********************************************************************
346  *           DiagQuery                          (KERNEL.339)
347  *
348  * returns TRUE if Win called with "/b" (bootlog.txt)
349  */
350 BOOL16 WINAPI DiagQuery16(void)
351 {
352         /* perhaps implement a Wine "/b" command line flag sometime ? */
353         return FALSE;
354 }
355
356 /***********************************************************************
357  *           DiagOutput                         (KERNEL.340)
358  *
359  * writes a debug string into <windir>\bootlog.txt
360  */
361 void WINAPI DiagOutput16(LPCSTR str)
362 {
363         /* FIXME */
364         TRACE("DIAGOUTPUT:%s\n", debugstr_a(str));
365 }
366
367 /***********************************************************************
368  *           TermsrvAppInstallMode       (KERNEL32.@)
369  *
370  * Find out whether the terminal server is in INSTALL or EXECUTE mode.
371  */
372 BOOL WINAPI TermsrvAppInstallMode(void)
373 {
374     FIXME("stub\n");
375     return FALSE;
376 }
377
378 /***********************************************************************
379  *           SetTermsrvAppInstallMode       (KERNEL32.@)
380  *
381  * This function is said to switch between the INSTALL (TRUE) or
382  * EXECUTE (FALSE) terminal server modes.
383  *
384  * This function always returns zero on WinXP Home so it's probably
385  * safe to return that value in most cases. However, if a terminal
386  * server is running it will probably return something else.
387  */
388 DWORD WINAPI SetTermsrvAppInstallMode(BOOL bInstallMode)
389 {
390     FIXME("(%d): stub\n", bInstallMode);
391     return 0;
392 }