1
/*********************************************************
2
* Copyright (C) 1998 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License as published
6
* by the Free Software Foundation version 2.1 and no later version.
8
* This program is released with an additional exemption that
9
* compiling, linking, and/or using the OpenSSL libraries with this
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
15
* License for more details.
17
* You should have received a copy of the GNU Lesser General Public License
18
* along with this program; if not, write to the Free Software Foundation, Inc.,
19
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
*********************************************************/
33
#include <sys/utsname.h>
41
static Bool hostinfoOSVersionInitialized;
44
static int hostinfoOSVersion[4];
45
static DWORD hostinfoOSPlatform;
47
#if defined(__APPLE__)
48
#define SYS_NMLN _SYS_NAMELEN
50
static int hostinfoOSVersion[3];
51
static char hostinfoOSVersionString[SYS_NMLN];
57
*----------------------------------------------------------------------
59
* HostinfoOSVersionInit --
61
* Compute the OS version information
67
* hostinfoOS* variables are filled in.
69
*----------------------------------------------------------------------
73
HostinfoOSVersionInit(void)
76
OSVERSIONINFOEX infoEx;
78
if (hostinfoOSVersionInitialized) {
82
info.dwOSVersionInfoSize = sizeof (info);
83
if (!GetVersionEx(&info)) {
84
Warning("Unable to get OS version.\n");
87
ASSERT(ARRAYSIZE(hostinfoOSVersion) >= 4);
88
hostinfoOSVersion[0] = info.dwMajorVersion;
89
hostinfoOSVersion[1] = info.dwMinorVersion;
90
hostinfoOSVersion[2] = info.dwBuildNumber & 0xffff;
92
* Get the service pack number. We don't care much about NT4 hosts
93
* so we can use OSVERSIONINFOEX without checking for Windows NT 4.0 SP6
96
infoEx.dwOSVersionInfoSize = sizeof infoEx;
97
if (GetVersionEx((OSVERSIONINFO*)&infoEx)) {
98
hostinfoOSVersion[3] = infoEx.wServicePackMajor;
100
hostinfoOSPlatform = info.dwPlatformId;
102
hostinfoOSVersionInitialized = TRUE;
107
*----------------------------------------------------------------------
109
* Hostinfo_OSIsWinNT --
111
* This is Windows NT or descendant.
114
* TRUE if Windows NT or descendant.
119
*----------------------------------------------------------------------
123
Hostinfo_OSIsWinNT(void)
125
HostinfoOSVersionInit();
126
return hostinfoOSPlatform == VER_PLATFORM_WIN32_NT;
132
*----------------------------------------------------------------------
134
* HostinfoOSVersionInit --
136
* Compute the OS version information
142
* hostinfoOS* variables are filled in.
144
*----------------------------------------------------------------------
148
HostinfoOSVersionInit(void)
151
char extra[SYS_NMLN] = "";
153
if (hostinfoOSVersionInitialized) {
158
Warning("%s unable to get host OS version (uname): %s\n",
159
__FUNCTION__, strerror(errno));
163
Str_Strcpy(hostinfoOSVersionString, u.release, SYS_NMLN);
165
ASSERT(ARRAYSIZE(hostinfoOSVersion) >= 3);
166
if (sscanf(u.release, "%d.%d.%d%s",
167
&hostinfoOSVersion[0], &hostinfoOSVersion[1],
168
&hostinfoOSVersion[2], extra) < 1) {
169
Warning("%s unable to parse host OS version string: %s\n",
170
__FUNCTION__, u.release);
174
hostinfoOSVersionInitialized = TRUE;
179
*----------------------------------------------------------------------
181
* Hostinfo_OSVersionString --
183
* Returns the host version information as returned in the
184
* release field of uname(2)
187
* const char * - pointer to static buffer containing the release
192
*----------------------------------------------------------------------
196
Hostinfo_OSVersionString(void)
198
HostinfoOSVersionInit();
199
return hostinfoOSVersionString;
205
*----------------------------------------------------------------------
207
* Hostinfo_OSVersion --
209
* Host OS release info.
212
* The i-th component of a dotted release string.
213
* 0 if i is greater than the number of components we support.
218
*----------------------------------------------------------------------
222
Hostinfo_OSVersion(int i)
224
HostinfoOSVersionInit();
225
return i < ARRAYSIZE(hostinfoOSVersion) ? hostinfoOSVersion[i] : 0;
230
*----------------------------------------------------------------------
232
* Hostinfo_GetTimeOfDay --
234
* Return the current time of day according to the host. We want
235
* UTC time (seconds since Jan 1, 1970).
238
* Time of day in microseconds.
243
*----------------------------------------------------------------------
247
Hostinfo_GetTimeOfDay(VmTimeType *time)
254
*time = (t.time * 1000000) + t.millitm * 1000;
255
#else // assume POSIX
258
gettimeofday(&tv, NULL);
260
*time = ((int64)tv.tv_sec * 1000000) + tv.tv_usec;