Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wutsname.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2010 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #include "precompiled.h"
25 
26 #include "lib/sysdep/os/win/wutil.h" // WinScopedPreserveLastError
27 #include "lib/sysdep/os/win/wversion.h" // wversion_Family
28 
29 
30 int uname(struct utsname* un)
31 {
32  OSVERSIONINFOW vi = { sizeof(OSVERSIONINFOW) };
33  GetVersionExW(&vi);
34 
35  // OS implementation name
36  sprintf_s(un->sysname, ARRAY_SIZE(un->sysname), "%ls", wversion_Family());
37 
38  // release info
39  const wchar_t* vs = vi.szCSDVersion;
40  int sp;
41  if(swscanf_s(vs, L"Service Pack %d", &sp) == 1)
42  sprintf_s(un->release, ARRAY_SIZE(un->release), "SP %d", sp);
43  else
44  un->release[0] = '\0';
45 
46  // version
47  sprintf_s(un->version, ARRAY_SIZE(un->version), "%ls.%lu", wversion_String(), vi.dwBuildNumber & 0xFFFF);
48 
49  // node name
50  {
51  WinScopedPreserveLastError s; // GetComputerName
52  DWORD bufSize = sizeof(un->nodename);
53  WARN_IF_FALSE(GetComputerNameA(un->nodename, &bufSize));
54  }
55 
56  // hardware type
57  SYSTEM_INFO si;
58  GetSystemInfo(&si);
59  if(si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
60  strcpy_s(un->machine, ARRAY_SIZE(un->machine), "x64");
61  else
62  strcpy_s(un->machine, ARRAY_SIZE(un->machine), "x86");
63 
64  return 0;
65 }
#define swscanf_s
Definition: secure_crt.h:119
some WinAPI functions SetLastError(0) on success, which is bad because it can hide previous errors...
Definition: wutil.h:119
char version[16]
Definition: wutsname.h:35
char nodename[16]
Definition: wutsname.h:33
int sprintf_s(char *buf, size_t max_chars, const char *fmt,...) PRINTF_ARGS(3)
#define ARRAY_SIZE(name)
char machine[9]
Definition: wutsname.h:36
char release[9]
Definition: wutsname.h:34
const wchar_t * wversion_Family()
Definition: wversion.cpp:36
unsigned long DWORD
Definition: wgl.h:56
char sysname[9]
Definition: wutsname.h:32
const wchar_t * wversion_String()
Definition: wversion.cpp:59
int uname(struct utsname *un)
Definition: wutsname.cpp:30
#define WARN_IF_FALSE(expression)
Definition: status.h:360
int strcpy_s(char *dst, size_t max_dst_chars, const char *src)