libwine: Remove __wine_main_arg* from the public header.
[wine/zf.git] / dlls / kernel32 / version.c
blobcca59416eb4d9e4638cd5c3ab824f3228845cde3
1 /*
2 * Windows and DOS version functions
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Patrik Stridvall
6 * Copyright 1998, 2003 Andreas Mohr
7 * Copyright 1997, 2003 Alexandre Julliard
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.
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.
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
24 #include "config.h"
25 #include "wine/port.h"
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/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(ver);
45 static inline UCHAR version_update_condition(UCHAR *last_condition, UCHAR condition)
47 switch (*last_condition)
49 case 0:
50 *last_condition = condition;
51 break;
52 case VER_EQUAL:
53 if (condition >= VER_EQUAL && condition <= VER_LESS_EQUAL)
55 *last_condition = condition;
56 return condition;
58 break;
59 case VER_GREATER:
60 case VER_GREATER_EQUAL:
61 if (condition >= VER_EQUAL && condition <= VER_GREATER_EQUAL)
62 return condition;
63 break;
64 case VER_LESS:
65 case VER_LESS_EQUAL:
66 if (condition == VER_EQUAL || (condition >= VER_LESS && condition <= VER_LESS_EQUAL))
67 return condition;
68 break;
70 if (!condition) *last_condition |= 0x10;
71 return *last_condition & 0xf;
74 static inline BOOL version_compare_values(ULONG left, ULONG right, UCHAR condition)
76 switch (condition)
78 case VER_EQUAL:
79 if (left != right) return FALSE;
80 break;
81 case VER_GREATER:
82 if (left <= right) return FALSE;
83 break;
84 case VER_GREATER_EQUAL:
85 if (left < right) return FALSE;
86 break;
87 case VER_LESS:
88 if (left >= right) return FALSE;
89 break;
90 case VER_LESS_EQUAL:
91 if (left > right) return FALSE;
92 break;
93 default:
94 return FALSE;
96 return TRUE;
100 /******************************************************************************
101 * VerifyVersionInfoA (KERNEL32.@)
103 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
104 DWORDLONG dwlConditionMask)
106 OSVERSIONINFOEXW verW;
108 verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
109 verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
110 verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
111 verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
112 verW.dwPlatformId = lpVersionInfo->dwPlatformId;
113 verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
114 verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
115 verW.wSuiteMask = lpVersionInfo->wSuiteMask;
116 verW.wProductType = lpVersionInfo->wProductType;
117 verW.wReserved = lpVersionInfo->wReserved;
119 return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
123 /******************************************************************************
124 * VerifyVersionInfoW (KERNEL32.@)
126 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW info, DWORD dwTypeMask,
127 DWORDLONG dwlConditionMask)
129 OSVERSIONINFOEXW ver;
131 TRACE("(%p 0x%x 0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
133 ver.dwOSVersionInfoSize = sizeof(ver);
134 if (!GetVersionExW((OSVERSIONINFOW*)&ver)) return FALSE;
136 if (!dwTypeMask || !dwlConditionMask)
138 SetLastError(ERROR_BAD_ARGUMENTS);
139 return FALSE;
142 if (dwTypeMask & VER_PRODUCT_TYPE)
144 if (!version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07))
145 goto mismatch;
147 if (dwTypeMask & VER_SUITENAME)
148 switch (dwlConditionMask >> 6*3 & 0x07)
150 case VER_AND:
151 if ((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
152 goto mismatch;
153 break;
154 case VER_OR:
155 if (!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
156 goto mismatch;
157 break;
158 default:
159 SetLastError(ERROR_BAD_ARGUMENTS);
160 return FALSE;
162 if (dwTypeMask & VER_PLATFORMID)
164 if (!version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07))
165 goto mismatch;
167 if (dwTypeMask & VER_BUILDNUMBER)
169 if (!version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07))
170 goto mismatch;
173 if (dwTypeMask & (VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR))
175 unsigned char condition, last_condition = 0;
176 BOOL succeeded = TRUE, do_next_check = TRUE;
178 if (dwTypeMask & VER_MAJORVERSION)
180 condition = version_update_condition(&last_condition, dwlConditionMask >> 1*3 & 0x07);
181 succeeded = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
182 do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
183 ((condition >= VER_EQUAL) && (condition <= VER_LESS_EQUAL));
185 if ((dwTypeMask & VER_MINORVERSION) && do_next_check)
187 condition = version_update_condition(&last_condition, dwlConditionMask >> 0*3 & 0x07);
188 succeeded = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
189 do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
190 ((condition >= VER_EQUAL) && (condition <= VER_LESS_EQUAL));
192 if ((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
194 condition = version_update_condition(&last_condition, dwlConditionMask >> 5*3 & 0x07);
195 succeeded = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
196 do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
197 ((condition >= VER_EQUAL) && (condition <= VER_LESS_EQUAL));
199 if ((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
201 condition = version_update_condition(&last_condition, dwlConditionMask >> 4*3 & 0x07);
202 succeeded = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
205 if (!succeeded) goto mismatch;
208 return TRUE;
210 mismatch:
211 SetLastError(ERROR_OLD_WIN_VERSION);
212 return FALSE;
215 /***********************************************************************
216 * TermsrvAppInstallMode (KERNEL32.@)
218 * Find out whether the terminal server is in INSTALL or EXECUTE mode.
220 BOOL WINAPI TermsrvAppInstallMode(void)
222 FIXME("stub\n");
223 return FALSE;
226 /***********************************************************************
227 * SetTermsrvAppInstallMode (KERNEL32.@)
229 * This function is said to switch between the INSTALL (TRUE) or
230 * EXECUTE (FALSE) terminal server modes.
232 * This function always returns zero on WinXP Home so it's probably
233 * safe to return that value in most cases. However, if a terminal
234 * server is running it will probably return something else.
236 DWORD WINAPI SetTermsrvAppInstallMode(BOOL bInstallMode)
238 FIXME("(%d): stub\n", bInstallMode);
239 return 0;
242 /***********************************************************************
243 * GetCurrentPackageId (KERNEL32.@)
245 LONG WINAPI GetCurrentPackageId(UINT32 *len, BYTE *buffer)
247 FIXME("(%p %p): stub\n", len, buffer);
248 return APPMODEL_ERROR_NO_PACKAGE;
251 /***********************************************************************
252 * GetCurrentPackageFamilyName (KERNEL32.@)
254 LONG WINAPI GetCurrentPackageFamilyName(UINT32 *length, PWSTR name)
256 FIXME("(%p %p): stub\n", length, name);
257 return APPMODEL_ERROR_NO_PACKAGE;
260 /***********************************************************************
261 * GetCurrentPackageFullName (KERNEL32.@)
263 LONG WINAPI GetCurrentPackageFullName(UINT32 *length, PWSTR name)
265 FIXME("(%p %p): stub\n", length, name);
266 return APPMODEL_ERROR_NO_PACKAGE;
269 /***********************************************************************
270 * GetPackageFullName (KERNEL32.@)
272 LONG WINAPI GetPackageFullName(HANDLE process, UINT32 *length, PWSTR name)
274 FIXME("(%p %p %p): stub\n", process, length, name);
275 return APPMODEL_ERROR_NO_PACKAGE;