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 distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
11
* License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
*********************************************************/
29
#include <sys/utsname.h>
37
static Bool hostinfoOSVersionInitialized;
40
static int hostinfoOSVersion[4];
41
static DWORD hostinfoOSPlatform;
43
#if defined(__APPLE__)
44
#define SYS_NMLN _SYS_NAMELEN
46
static int hostinfoOSVersion[3];
47
static char hostinfoOSVersionString[SYS_NMLN];
53
*----------------------------------------------------------------------
55
* HostinfoOSVersionInit --
57
* Compute the OS version information
63
* hostinfoOS* variables are filled in.
65
*----------------------------------------------------------------------
69
HostinfoOSVersionInit(void)
72
OSVERSIONINFOEX infoEx;
74
if (hostinfoOSVersionInitialized) {
78
info.dwOSVersionInfoSize = sizeof (info);
79
if (!GetVersionEx(&info)) {
80
Warning("Unable to get OS version.\n");
83
ASSERT(ARRAYSIZE(hostinfoOSVersion) >= 4);
84
hostinfoOSVersion[0] = info.dwMajorVersion;
85
hostinfoOSVersion[1] = info.dwMinorVersion;
86
hostinfoOSVersion[2] = info.dwBuildNumber & 0xffff;
88
* Get the service pack number. We don't care much about NT4 hosts
89
* so we can use OSVERSIONINFOEX without checking for Windows NT 4.0 SP6
92
infoEx.dwOSVersionInfoSize = sizeof infoEx;
93
if (GetVersionEx((OSVERSIONINFO*)&infoEx)) {
94
hostinfoOSVersion[3] = infoEx.wServicePackMajor;
96
hostinfoOSPlatform = info.dwPlatformId;
98
hostinfoOSVersionInitialized = TRUE;
103
*----------------------------------------------------------------------
105
* Hostinfo_OSIsWinNT --
107
* This is Windows NT or descendant.
110
* TRUE if Windows NT or descendant.
115
*----------------------------------------------------------------------
119
Hostinfo_OSIsWinNT(void)
121
HostinfoOSVersionInit();
122
return hostinfoOSPlatform == VER_PLATFORM_WIN32_NT;
128
*----------------------------------------------------------------------
130
* HostinfoOSVersionInit --
132
* Compute the OS version information
138
* hostinfoOS* variables are filled in.
140
*----------------------------------------------------------------------
144
HostinfoOSVersionInit(void)
147
char extra[SYS_NMLN] = "";
149
if (hostinfoOSVersionInitialized) {
154
Warning("%s unable to get host OS version (uname): %s\n",
155
__FUNCTION__, strerror(errno));
159
Str_Strcpy(hostinfoOSVersionString, u.release, SYS_NMLN);
161
ASSERT(ARRAYSIZE(hostinfoOSVersion) >= 3);
162
if (sscanf(u.release, "%d.%d.%d%s",
163
&hostinfoOSVersion[0], &hostinfoOSVersion[1],
164
&hostinfoOSVersion[2], extra) < 1) {
165
Warning("%s unable to parse host OS version string: %s\n",
166
__FUNCTION__, u.release);
170
hostinfoOSVersionInitialized = TRUE;
175
*----------------------------------------------------------------------
177
* Hostinfo_OSVersionString --
179
* Returns the host version information as returned in the
180
* release field of uname(2)
183
* const char * - pointer to static buffer containing the release
188
*----------------------------------------------------------------------
192
Hostinfo_OSVersionString(void)
194
HostinfoOSVersionInit();
195
return hostinfoOSVersionString;
201
*----------------------------------------------------------------------
203
* Hostinfo_OSVersion --
205
* Host OS release info.
208
* The i-th component of a dotted release string.
209
* 0 if i is greater than the number of components we support.
214
*----------------------------------------------------------------------
218
Hostinfo_OSVersion(int i)
220
HostinfoOSVersionInit();
221
return i < ARRAYSIZE(hostinfoOSVersion) ? hostinfoOSVersion[i] : 0;
226
*----------------------------------------------------------------------
228
* Hostinfo_GetTimeOfDay --
230
* Return the current time of day according to the host. We want
231
* UTC time (seconds since Jan 1, 1970).
234
* Time of day in microseconds.
239
*----------------------------------------------------------------------
243
Hostinfo_GetTimeOfDay(VmTimeType *time)
250
*time = (t.time * 1000000) + t.millitm * 1000;
251
#else // assume POSIX
254
gettimeofday(&tv, NULL);
256
*time = ((int64)tv.tv_sec * 1000000) + tv.tv_usec;