Files
0ad/source/lib/sysdep/os/win/wposix/wutsname.cpp
T
janwas 6fb5c1b307 lib/ changes required at work:
- allow building regardless of UNICODE setting (e.g. use LoadLibraryW
instead of LoadLibrary)
- export dlopen etc.
- more robust redirection of stdout

This was SVN commit r7427.
2010-04-03 10:46:28 +00:00

70 lines
2.4 KiB
C++

/* Copyright (c) 2010 Wildfire Games
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "precompiled.h"
#include "lib/sysdep/os/win/wposix/wutsname.h"
#include "lib/utf8.h"
#include "lib/sysdep/os/win/wutil.h"
#include "lib/sysdep/os/win/wposix/wposix_internal.h"
int uname(struct utsname* un)
{
static OSVERSIONINFOW vi;
vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
GetVersionExW(&vi);
// OS implementation name
sprintf_s(un->sysname, ARRAY_SIZE(un->sysname), "%ls", wutil_WindowsFamily());
// release info
const wchar_t* vs = vi.szCSDVersion;
int sp;
if(swscanf_s(vs, L"Service Pack %d", &sp) == 1)
sprintf_s(un->release, ARRAY_SIZE(un->release), "SP %d", sp);
// version
sprintf_s(un->version, ARRAY_SIZE(un->version), "%ls.%lu", wutil_WindowsVersionString(), vi.dwBuildNumber & 0xFFFF);
// node name
DWORD buf_size = sizeof(un->nodename);
DWORD last_err = GetLastError();
BOOL ok = GetComputerNameA(un->nodename, &buf_size);
// GetComputerName sets last error even on success - suppress.
if(ok)
SetLastError(last_err);
else
debug_assert(0); // GetComputerName failed
// hardware type
static SYSTEM_INFO si;
GetSystemInfo(&si);
if(si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
strcpy_s(un->machine, ARRAY_SIZE(un->machine), "AMD64");
else
strcpy_s(un->machine, ARRAY_SIZE(un->machine), "IA-32");
return 0;
}