static VALUE
etc_uname(VALUE obj)
{
OSVERSIONINFOW v;
SYSTEM_INFO s;
const char *sysname, *mach;
VALUE result, release, version;
VALUE vbuf, nodename = Qnil;
DWORD len = 0;
WCHAR *buf;
v.dwOSVersionInfoSize = sizeof(v);
if (!GetVersionExW(&v))
rb_sys_fail("GetVersionEx");
result = rb_hash_new();
switch (v.dwPlatformId) {
case VER_PLATFORM_WIN32s:
sysname = "Win32s";
break;
case VER_PLATFORM_WIN32_NT:
sysname = "Windows_NT";
break;
case VER_PLATFORM_WIN32_WINDOWS:
default:
sysname = "Windows";
break;
}
rb_hash_aset(result, ID2SYM(rb_intern("sysname")), rb_str_new_cstr(sysname));
release = rb_sprintf("%lu.%lu.%lu", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
rb_hash_aset(result, ID2SYM(rb_intern("release")), release);
version = rb_sprintf("%s Version %"PRIsVALUE": %"PRIsVALUE, sysname, release,
rb_w32_conv_from_wchar(v.szCSDVersion, rb_utf8_encoding()));
rb_hash_aset(result, ID2SYM(rb_intern("version")), version);
GET_COMPUTER_NAME(NULL, &len);
buf = ALLOCV_N(WCHAR, vbuf, len);
if (GET_COMPUTER_NAME(buf, &len)) {
nodename = rb_w32_conv_from_wchar(buf, rb_utf8_encoding());
}
ALLOCV_END(vbuf);
if (NIL_P(nodename)) nodename = rb_str_new(0, 0);
rb_hash_aset(result, ID2SYM(rb_intern("nodename")), nodename);
GetSystemInfo(&s);
switch (s.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_AMD64:
mach = "x64";
break;
case PROCESSOR_ARCHITECTURE_ARM:
mach = "ARM";
break;
case PROCESSOR_ARCHITECTURE_IA64:
mach = "IA64";
break;
case PROCESSOR_ARCHITECTURE_INTEL:
mach = "x86";
break;
default:
mach = "unknown";
break;
}
rb_hash_aset(result, ID2SYM(rb_intern("machine")), rb_str_new_cstr(mach));
struct utsname u;
int ret;
VALUE result;
ret = uname(&u);
if (ret == -1)
rb_sys_fail("uname");
result = rb_hash_new();
rb_hash_aset(result, ID2SYM(rb_intern("sysname")), rb_str_new_cstr(u.sysname));
rb_hash_aset(result, ID2SYM(rb_intern("nodename")), rb_str_new_cstr(u.nodename));
rb_hash_aset(result, ID2SYM(rb_intern("release")), rb_str_new_cstr(u.release));
rb_hash_aset(result, ID2SYM(rb_intern("version")), rb_str_new_cstr(u.version));
rb_hash_aset(result, ID2SYM(rb_intern("machine")), rb_str_new_cstr(u.machine));
return result;
}