Skip to content

ImplOfOperatingSystem

Zwetan Kjukov edited this page Jan 8, 2016 · 19 revisions

Implementation Of OperatingSystem

There are different way and extend to detect the current Operating System, here we document how we do it.

Basics

From our compilations directives in C/C++
eg. AVMSYSTEM_UNIX, AVMSYSTEM_MAC and AVMSYSTEM_WIN32
see system-selection.h

we define the "platform" in Runtime.platform which can be
either "linux", "macintosh" or "windows"

This is directly related to the Supported Operating System,
if we were adding more systems then we would need to add more platforms.

For example: if we decided to support Symbian
we would use AVMSYSTEM_SYMBIAN to add the platform "symbian"

rules

  • the platform name should be 1 word, no spaces
    reason why we favoured "macintosh" over "mac os x"
  • the platform name should be all lower case
    no camel case, no mix of upper and lower case
  • no number in the platform name
    unless the number is really part of the operating system name
    for ex: "xbox360" would be ok

Advanced

We want more than just the platform name, we want also

  • the name
    the OS name
  • the version
    the OS version
  • the kernel name
    the OS kernel name
  • the kernel release
    the current release level of the OS
  • the kernel version
    the current version level of this release of the OS
  • the vendor
    name of the vendor (commercial)
    or distributor (non-commercial) of this OS
  • the vendor name
    name of the OS provided by the vendor/distributor
  • the vendor version
    version of the OS provided by the vendor/distributor
  • the vendor build
    build number or tag of the OS provided by the vendor/distributor
  • the vendor description
    description of the OS provided by the vendor/distributor
    or empty string if not defined
  • the system codename
    codename of this OS
    or empty string if not known
  • the long description
    the vendor description followed by codename and build number if they exists

here some examples:

  • name
    "Windows 8.1" for "windows"
    "Mac OS X 10.10" for "macintosh"
    "Ubuntu 15.10" for "linux"
  • version
    "6.3" for "Windows 8.1"
    "10.10" for "Mac OS X 10.10"
    "15.10" for "Ubuntu 15.10"
  • kernel names
    TODO
  • kernel releases
    TODO
  • kernel versions
    TODO
  • vendors
    "Microsoft" for "windows"
    "Apple" for "macintosh"
    "Linux" for "linux"
  • vendor names
    "Windows 7" for "Microsoft"
    "Mac OS X" for "Apple"
    "Ubuntu" for "Linux"
  • vendor versions
    "NT 6.3" for "Windows 8.1"
    "10.10.5" for "Mac OS X 10.10"
    "14.04.3" for "Ubuntu 15.10"
  • vendor builds
    "9600" for "Windows 8.1"
    "14F27" for "Mac OS X 10.10.5"
    "" for "Ubuntu 15.10"
  • vendor descriptions
    "Microsoft Windows 7 Home Premium"
    "Apple Mac OS X 10.10.5"
    "Linux Ubuntu 14.04.3 LTS"
  • codenames
    "Vienna" for "Windows 7"
    "Yosemite" for "Mac OS X 10.10"
    "Trusty Tahr" for "Ubuntu 14.04"
  • long descriptions
    "Microsoft Windows 7 Home Premium (Vienna 6.1 build 2600)"
    "Apple Mac OS X 10.10.5 (Yosemite build 14F27)"
    "Linux Ubuntu 14.04.3 LTS (Trusty Tahr)"

About name:
The name is the general name used to describe the Operating System.

  • with the windows platform, you can not just use "Windows"
    "Windows 7", "Windows 8.1" are the common usage
    so that's why the version number or other letters are included
  • with the macintosh platform, you can not just use "Mac OS X"
    "Mac OS X 10.10", "Mac OS X 10.11" are the common usage
    but you will not use the full version for ex: "Mac OS X 10.10.5"
    so even if the version is included we use the short version
  • with the linux platform, you can not just use "Ubuntu"
    "Ubuntu 10.04", "Ubuntu 15.10" are the common usage
    but you will not use the full version for ex: "Ubuntu 10.04.3"
    so even if the version is included we use the short version

About version:
The version is the general string used to distinguish between Operating System of the same class.

In general we only use the short version version = major . minor used in the name.

About host name:
TODO

About user name:
TODO

About kernel name:
TODO

About kernel release:
TODO

About kernel version:
TODO

About vendor:
The vendor is the name of the vendor or distributor of the Operating System.

As we are supporting only 3 OS we use: "Microsoft", "Apple" and "Linux".

If we were to support others we could add for example: "Solaris", "BSD", etc.

About vendor name:
The vendorName is the name of the Operating System provided by the vendor/distributor.

In general we see it as a "product name"

  • with the windows platform,
    it will always be "Windows"
  • with the macintosh platform,
    it will always be "Mac OS X"
  • with the linux platform,
    it is the name of the Linux distribution
    for example: "Ubuntu", "Debian", "CentOS", "Red Hat", etc.

About vendor version:
The vendorVersion is the version of the Operating System provided by the vendor/distributor.

In general we provide the longest form of the version number

  • for Mac OS X we will return "10.10.5"
    instead of just "10.10"
  • for Linux Ubuntu we will return "14.04.3"
    instead of just "14.04"

Also we will use the vendor notation, for example with Windows we will return "NT 6.3", not just "6.3"

About vendor build:
The vendorBuild is the build number or tag of the Operating System provided by the vendor/distributor.

We provide it only if the vendor usually include it or use it somehow to distinguish between different identical versions.

For example with Windows a build "9200" or "9600" both represent a "Windows 8.1" but the build "9600" in fact indicate a "Windows 8.1 Update 1".

But at the opposite under Linux Ubuntu they do not use build numbers so there we will return an empty string.

About vendor description:
The vendorDescription is the description of the Operating System provided by the vendor/distributor.

It is in general the same as the name but can contain more informations.

For example under Windows

  • name would be "Windows 8.1" and
    vendorDescription would be also "Windows 8.1"
  • name would be "Windows 8.1" and
    vendorDescription would be "Windows 8.1 Update 1"

For example under Linux Ubuntu

  • name would be "Ubuntu 15.10" and
    vendorDescription would be also "Ubuntu 15.10"
  • name would be "Ubuntu 14.04" and
    vendorDescription would be "Ubuntu 14.04.3 LTS"

About codename:
The codename used by the vendor for the Operating System or the empty string if not found or does not exists.

Most OS use a "codename" as a way to quickly distinguish between different versions/releases of the same product.

About long description:
The longDescription is the vendor description followed by codename and build number if they exists.

In general the longest form that could describe this Operating System.

Detection under Windows

TODO

use C:\> ver

Microsoft Windows [Version 6.3.9600]

use $ uname -a with Cygwin
returns CYGWIN_NT-6.3 gamma 2.3.1(0.291/5/3) 2015-11-14 12:44 x86_64 Cygwin

Build version to Windows name

name release version build ver output operating system
Windows 10 NT 10.0 NT 10.0.10586 10.0.10586 Windows 10 Fall Update
Windows 10 NT 10.0 NT 10.0.10565 10.0.10565 Windows 10 Insider Preview
Windows 10 NT 10.0 NT 10.0.10525 10.0.10525 Windows 10 Insider Preview
Windows 10 NT 10.0 NT 10.0.10240 10.0.10240 Windows 10 RTM
Windows 10 NT 10.0 NT 10.0.10166 10.0.10166 Windows 10 Insider Preview
Windows 10 NT 10.0 NT 10.0.10049 10.0.10049 Windows 10 Technical Preview 6
Windows 10 NT 10.0 NT 10.0.10041 10.0.10041 Windows 10 Technical Preview 5
Windows 10 NT 10.0 NT 10.0.9926 10.0.9926 Windows 10 Technical Preview 4
Windows 10 NT 10.0 NT 6.4.9879 6.4.9879 Windows 10 Technical Preview 3
Windows 10 NT 10.0 NT 6.4.9860 6.4.9860 Windows 10 Technical Preview 2
Windows 10 NT 10.0 NT 6.4.9841 6.4.9841 Windows 10 Technical Preview 1
Windows 8.1 NT 6.3 NT 6.3.9600 6.3.9600 Windows 8.1 Update 1 Windows Server 2012 R2
Windows 8.1 NT 6.3 NT 6.3.9200 6.3.9200 Windows 8.1 Windows Server 2012
Windows 8 NT 6.2 NT 6.2.9200 6.2.9200 Windows 8 Windows Server 2012
Windows Server 2012 NT 6.2 NT 6.2.8102 6.2.8102 Windows Server 2012 Developer Preview
Windows Home Server 2011 NT 6.1 NT 6.1.8400 6.1.8400 Windows Home Server 2011
Windows 7 NT 6.1 NT 6.1.7601 6.1.7601 Windows 7 SP1 Windows Server 2008 R2 SP1
Windows 7 NT 6.1 NT 6.1.7600 6.1.7600 Windows 7 Windows Server 2008 R2
Windows Vista NT 6.0 NT 6.0.6002 6.0.6002 Windows Vista SP2 Windows Server 2008 SP2
Windows Vista NT 6.0 NT 6.0.6001 6.0.6001 Windows Vista SP1 Windows Server 2008 SP1
Windows Vista NT 6.0 NT 6.0.6000 6.0.6000 Windows Vista
Windows XP Professional x64 NT 5.2 NT 5.2.3790 5.2.3790 Windows XP Professional x64 Edition Windows Server 2003 Windows Server 2003 SP1 Windows Home Server
Windows XP NT 5.1 NT 5.1.2600 5.1.2600 Windows XP Windows XP SP1 Windows XP SP2 Windows XP SP3
Windows 2000 Professional NT 5.0 NT 5.0.2195 5.0.2195 Windows 2000 Professional
Windows 2000 NT 5.0 NT 5.00.2195 5.00.2195 Windows 2000
Windows ME NT 4.9 NT 4.90.3000 4.90.3000 Windows ME
Windows 98 SE NT 4.1 NT 4.10.2222 4.10.2222 Windows 98 SE
Windows 98 NT 4.1 NT 4.10.1998 4.10.1998 Windows 98

see

Detection under Mac OS X

Parsing the SystemVersion.plist file

$ cat /System/Library/CoreServices/SystemVersion.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>ProductBuildVersion</key>
	<string>14F27</string>
	<key>ProductCopyright</key>
	<string>1983-2015 Apple Inc.</string>
	<key>ProductName</key>
	<string>Mac OS X</string>
	<key>ProductUserVisibleVersion</key>
	<string>10.10.5</string>
	<key>ProductVersion</key>
	<string>10.10.5</string>
</dict>
</plist>

use $ sw_vers

ProductName:	Mac OS X
ProductVersion:	10.10.5
BuildVersion:	14F27

use $ sysctl kern.osrelease
returns kern.osrelease: 14.5.0

use $ sysctl kern.osversion
returns kern.osversion: 14F27

use $ uname -a returns Darwin alpha.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

Darwin version to OS X release

Darwin version OS X version codename
15.x.x 10.11.x El Capitan
14.x.x 10.10.x Yosemite
13.x.x 10.9.x Mavericks
12.x.x 10.8.x Mountain Lion
11.x.x 10.7.x Lion
10.x.x 10.6.x Snow Leopard
9.x.x 10.5.x Leopard
8.x.x 10.4.x Tiger
7.x.x 10.3.x Panther
6.x.x 10.2.x Jaguar
5.x.x 10.1.x Puma

see

Detection under Linux

Parsing the release files, here some examples with Ubuntu

$ cat /etc/*release

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"
NAME="Ubuntu"
VERSION="14.04.3 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.3 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

$ cat /etc/lsb-release

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"

$ cat /etc/os-release

NAME="Ubuntu"
VERSION="14.04.3 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.3 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

use $ uname -a
returns Linux beta 4.2.0-22-generic #27-Ubuntu SMP Thu Dec 17 22:57:08 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Linux distributions release information files

Linux Distro supported? release file
Debian yes /etc/debian_version, /etc/debian_release
Ubuntu yes /etc/lsb-release
Red Hat yes? /etc/redhat-release, /etc/redhat_version
CentOS yes? /etc/centos-release
Gentoo ??? /etc/gentoo-release
Slackware ??? /etc/slackware-version, /etc/slackware-release
Novell SUSE ??? /etc/SUSE-release
SUSE ??? /etc/SuSE-release, /etc/novell-release
Arch ??? /etc/arch-release
Fedora ??? /etc/fedora-release
Mandrake ??? /etc/mandrake-release
Yellow dog ??? /etc/yellowdog-release
UnitedLinux ??? /etc/UnitedLinux-release

see

Parsing Versions string

In general an Operating System will present a version number as
version = major . minor . release . build
with major and minor being mandatory
and release amd/or build being optional

We use this regex

var re:RegExp = /\bv?(?P<major>[0-9]+)\.(?P<minor>[0-9]+)(?:\.(?P<release>[0-9]+))?(?:\.(?P<build>[0-9]+))?\b/;

which parse the following

  • Microsoft Windows [Version 6.3.9600]
  • NT 10.0
  • 10.0.10565
  • CYGWIN_NT-6.3
  • gamma 2.3.1(0.291/5/3)
    (keep 2.3.1, ignore (0.291/5/3))
  • Mac OS X 10.5
  • Mac OS X 10.10.5
  • Darwin 14.5.0
  • Ubuntu 14.04.3 LTS
  • Ubuntu 15.10
  • Linux beta 4.2.0-22-generic
    (keep 4.2.0, ignore 22)
  • etc.

For more about version parsing see Redtamarin Version.

uname

Comparaison of available options

option description Windows Mac OS X Linux
-a all yes yes yes
-s kernel name yes yes yes
-r kernel release yes yes yes
-v kernel version yes yes yes
-o operating system yes no yes
-m machine yes yes yes
-p processor yes yes yes
-i hardware platform yes no yes
-n node name yes yes yes
option Windows Mac OS X Linux example output
-s x CYGWIN_NT-6.3
-s x Darwin
-s x Linux
-r x 2.3.1(0.291/5/3)
-r x 14.5.0
-r x 4.2.0-22-generic
-v x 2015-11-14 12:44
-v x Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64
-v x #27-Ubuntu SMP Thu Dec 17 22:57:08 UTC 2015
-o x Cygwin
-o N/A
-o x GNU/Linux
-m x x86_64
-m x x86_64
-m x x86_64
-p x unknown
-p x i386
-p x x86_64
-i x unknown
-i N/A
-i x x86_64
-n x gamma
-n x alpha.local
-n x beta

We can also use a native C/C++ implementation
using uname() and utsname

Windows

#ifndef _UTSNAME_LENGTH
  #define _UTSNAME_LENGTH 255
#endif

#ifndef _UTSNAME_NODENAME_LENGTH
  #define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH
#endif

struct utsname
{
  char sysname[_UTSNAME_LENGTH];            // Name of the operating system
  char nodename[_UTSNAME_NODENAME_LENGTH];  // Name of this node on the network
  char release[_UTSNAME_LENGTH];            // Current release level
  char version[_UTSNAME_LENGTH];            // Current version level of this release
  char machine[_UTSNAME_LENGTH];            // Name of the hardware type the system is running on
};

#ifndef VER_SUITE_WH_SERVER
  #define VER_SUITE_WH_SERVER     0x00008000
#endif

#ifndef PRODUCT_PROFESSIONAL
  #define PRODUCT_PROFESSIONAL    0x00000030
#endif

extern int uname (struct utsname *uts);
int uname(struct utsname *uts)
{
    enum
    {
        Win95,
        Win98,
        WinNT,
        WinUnknown
    };
    
    typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
    
    OSVERSIONINFOEX osver;
    SYSTEM_INFO sysinfo;
    PGPI pGPI;
    DWORD nodelen;
    DWORD os = WinUnknown;
    DWORD dwType;
    
    VMPI_memset(uts, 0, sizeof(*uts));
    
    osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    GetVersionEx((OSVERSIONINFO *) &osver);
    GetSystemInfo(&sysinfo);
    
    VMPI_strcpy(uts->sysname, "Win32"); //we always want to be WIN32
    
    // Test for the specific product, and we create the version, eg: {windows_type} {suite_mask} {product_info} {service_pack}
    switch( osver.dwPlatformId )
    {
        case VER_PLATFORM_WIN32_NT:
        if(osver.dwMajorVersion == 3) {
            if(osver.dwMinorVersion == 51) {
                VMPI_strcpy(uts->version, "Windows NT 3.51");
            }
            else {
                VMPI_strcpy(uts->version, "Windows NT 3x");
            }
        }
        else if(osver.dwMajorVersion == 4) {
            if(osver.dwMinorVersion == 0) {
                VMPI_strcpy(uts->version, "Windows NT 4");
            }
            else {
                VMPI_strcpy(uts->version, "Windows NT 4x");
            }
        }
        else if((osver.dwMajorVersion == 5) && (osver.dwMinorVersion == 0)) {
            VMPI_strcpy(uts->version, "Windows 2000 ");
            if(osver.wProductType == VER_NT_WORKSTATION) {
                VMPI_strcat(uts->version, "Professional");
            }
            else if(osver.wSuiteMask & VER_SUITE_DATACENTER) {
                VMPI_strcat(uts->version, "Datacenter Server");
            }
            else if(osver.wSuiteMask & VER_SUITE_ENTERPRISE) {
                VMPI_strcat(uts->version, "Advanced Server");
            }
            else {
                VMPI_strcat(uts->version, "Server");
            }
        }
        else if((osver.dwMajorVersion == 5) && (osver.dwMinorVersion == 1)) {
            VMPI_strcpy(uts->version, "Windows XP ");
            if(GetSystemMetrics(SM_MEDIACENTER)) {
                VMPI_strcat(uts->version, "Media Center Edition");
            }
            else if(GetSystemMetrics(SM_STARTER)) {
                VMPI_strcat(uts->version, "Starter Edition");
            }
            else if(GetSystemMetrics(SM_TABLETPC)) {
                VMPI_strcat(uts->version, "Tablet PC Edition");
            }
            else if(osver.wSuiteMask & VER_SUITE_PERSONAL) {
                VMPI_strcat(uts->version, "Home Edition");
            }
            else {
                VMPI_strcat(uts->version, "Professional");
            }
        }
        else if((osver.dwMajorVersion == 5) && (osver.dwMinorVersion == 2)) {
            if(GetSystemMetrics(SM_SERVERR2)) {
                VMPI_strcpy(uts->version, "Windows Server 2003 R2, ");
            }
            else if(osver.wSuiteMask & VER_SUITE_STORAGE_SERVER) {
                VMPI_strcpy(uts->version, "Windows Storage Server 2003");
            }
            else if(osver.wSuiteMask & VER_SUITE_WH_SERVER) {
                VMPI_strcpy(uts->version, "Windows Home Server");
            }
            else if((osver.wProductType == VER_NT_WORKSTATION) && (sysinfo.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)) {
                VMPI_strcpy(uts->version, "Windows XP Professional x64 Edition");
            }
            else {
                VMPI_strcpy(uts->version, "Windows Server 2003, ");
            }
            
            if(osver.wProductType != VER_NT_WORKSTATION) {
                if(sysinfo.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64) {
                    if(osver.wSuiteMask & VER_SUITE_DATACENTER) {
                        VMPI_strcat(uts->version, "Datacenter Edition for Itanium-based Systems");
                    }
                    else if(osver.wSuiteMask & VER_SUITE_ENTERPRISE) {
                        VMPI_strcat(uts->version, "Enterprise Edition for Itanium-based Systems");
                    }
                }
                else if(sysinfo.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) {
                    if(osver.wSuiteMask & VER_SUITE_DATACENTER) {
                        VMPI_strcat(uts->version, "Datacenter x64 Edition");
                    }
                    else if(osver.wSuiteMask & VER_SUITE_ENTERPRISE) {
                        VMPI_strcat(uts->version, "Enterprise x64 Edition");
                    }
                    else {
                        VMPI_strcat(uts->version, "Standard x64 Edition");
                    }
                }
                else {
                    if(osver.wSuiteMask & VER_SUITE_COMPUTE_SERVER) {
                        VMPI_strcat(uts->version, "Compute Cluster Edition");
                    }
                    else if(osver.wSuiteMask & VER_SUITE_DATACENTER) {
                        VMPI_strcat(uts->version, "Datacenter Edition");
                    }
                    else if(osver.wSuiteMask & VER_SUITE_ENTERPRISE) {
                        VMPI_strcat(uts->version, "Enterprise Edition");
                    }
                    else if(osver.wSuiteMask & VER_SUITE_BLADE) {
                        VMPI_strcat(uts->version, "Web Edition");
                    }
                    else {
                        VMPI_strcat(uts->version, "Standard Edition");
                    }
                }
            }
        }
        else if(osver.dwMajorVersion == 6) {
            if(osver.dwMinorVersion == 0) {
                if(osver.wProductType == VER_NT_WORKSTATION) {
                    VMPI_strcpy(uts->version, "Windows Vista ");
                }
                else {
                    VMPI_strcpy(uts->version, "Windows Server 2008 ");
                }
            }
            
            if(osver.dwMinorVersion == 1) {
                if(osver.wProductType == VER_NT_WORKSTATION) {
                    VMPI_strcpy(uts->version, "Windows 7 ");
                }
                else {
                    VMPI_strcpy(uts->version, "Windows Server 2008 R2 ");
                }
            }
            
            pGPI = (PGPI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");
            pGPI(osver.dwMajorVersion, osver.dwMinorVersion, 0, 0, &dwType);
            
            switch( dwType )
            {
                case PRODUCT_ULTIMATE:
                VMPI_strcat(uts->version, "Ultimate Edition");
                break;
                
                case PRODUCT_PROFESSIONAL:
                VMPI_strcat(uts->version, "Professional");
                break;
                
                case PRODUCT_HOME_PREMIUM:
                VMPI_strcat(uts->version, "Home Premium Edition");
                break;
                
                case PRODUCT_HOME_BASIC:
                VMPI_strcat(uts->version, "Home Basic Edition");
                break;
                
                case PRODUCT_ENTERPRISE:
                VMPI_strcat(uts->version, "Enterprise Edition");
                break;
                
                case PRODUCT_BUSINESS:
                VMPI_strcat(uts->version, "Business Edition");
                break;
                
                case PRODUCT_STARTER:
                VMPI_strcat(uts->version, "Starter Edition");
                break;
                
                case PRODUCT_CLUSTER_SERVER:
                VMPI_strcat(uts->version, "Cluster Server Edition");
                break;
                
                case PRODUCT_DATACENTER_SERVER:
                VMPI_strcat(uts->version, "Datacenter Edition");
                break;
                
                case PRODUCT_DATACENTER_SERVER_CORE:
                VMPI_strcat(uts->version, "Datacenter Edition (core installation)");
                break;
                
                case PRODUCT_ENTERPRISE_SERVER:
                VMPI_strcat(uts->version, "Enterprise Edition");
                break;
                
                case PRODUCT_ENTERPRISE_SERVER_CORE:
                VMPI_strcat(uts->version, "Enterprise Edition (core installation)");
                break;
                
                case PRODUCT_ENTERPRISE_SERVER_IA64:
                VMPI_strcat(uts->version, "Enterprise Edition for Itanium-based Systems");
                break;
                
                case PRODUCT_SMALLBUSINESS_SERVER:
                VMPI_strcat(uts->version, "Small Business Server");
                break;
                
                case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
                VMPI_strcat(uts->version, "Small Business Server Premium Edition");
                break;
                
                case PRODUCT_STANDARD_SERVER:
                VMPI_strcat(uts->version, "Standard Edition");
                break;
                
                case PRODUCT_STANDARD_SERVER_CORE:
                VMPI_strcat(uts->version, "Standard Edition (core installation)");
                break;
                
                case PRODUCT_WEB_SERVER:
                VMPI_strcat(uts->version, "Web Server Edition");
                break;
            }
        }
        os = WinNT;
        break;
        
        case VER_PLATFORM_WIN32_WINDOWS:
        if((osver.dwMajorVersion == 4) && (osver.dwMinorVersion >= 10)) {
            if(osver.dwMinorVersion >= 90) {
                VMPI_strcpy(uts->version, "Windows ME");
            }
            else if((osver.dwMinorVersion == 10) && (osver.dwBuildNumber >= 2183)) {
                VMPI_strcpy(uts->version, "Windows 98 Second Edition");
            }
            else if(osver.dwMinorVersion == 10) {
                VMPI_strcpy(uts->version, "Windows 98");
            }
            os = Win98;
        }
        else {
            if((osver.dwMinorVersion < 10) && (osver.dwBuildNumber > 1080)) {
                VMPI_strcpy(uts->version, "Windows 95 OEM Service Release 2");
            }
            else if(osver.dwMinorVersion == 0) {
                VMPI_strcpy(uts->version, "Windows 95");
            }
            os = Win95;
        }
        break;
        
        /*
        case VER_PLATFORM_WIN32_CE:
        VMPI_sprintf(uts->version, "Windows CE %ld.%02ld", osver.dwMajorVersion, osver.dwMinorVersion);
        break;
        */
        
        case VER_PLATFORM_WIN32s:
        VMPI_strcpy(uts->version, "Windows");
        break;
    }
    
    // Include service pack (if any).
    if(osver.wServicePackMajor > 0) {
        VMPI_strcat(uts->version, " ");
        VMPI_strcat(uts->version, osver.szCSDVersion); //ex: "Service Pack 3"
    }
    
    // We create the release, eg: {major}.{minor} build {build}
    VMPI_sprintf(uts->release, "%ld.%ld build %ld", osver.dwMajorVersion, osver.dwMinorVersion, osver.dwBuildNumber & 0xFFFF);
    
    // We create the machine, from the processor infos
    switch( sysinfo.wProcessorArchitecture )
    {
        case PROCESSOR_ARCHITECTURE_PPC:
        VMPI_strcpy(uts->machine, "ppc");
        break;
        
        case PROCESSOR_ARCHITECTURE_ALPHA:
        VMPI_strcpy(uts->machine, "alpha");
        break;
        
        case PROCESSOR_ARCHITECTURE_MIPS:
        VMPI_strcpy(uts->machine, "mips");
        break;
        
        case PROCESSOR_ARCHITECTURE_INTEL:
        switch( os )
        {
            case Win95:
            case Win98:
            switch( sysinfo.dwProcessorType )
            {
                case PROCESSOR_INTEL_386:
                case PROCESSOR_INTEL_486:
                case PROCESSOR_INTEL_PENTIUM:
                VMPI_sprintf(uts->machine, "i%ld", sysinfo.dwProcessorType);
                break;
                
                default:
                VMPI_strcpy(uts->machine, "i386");
                break;
            }
            break;
            
            case WinNT:
            VMPI_sprintf(uts->machine, "i%d86", sysinfo.wProcessorLevel);
            break;
        }
        break;
        
        default:
        VMPI_strcpy(uts->machine, "unknown");
        break;
    }
    
    // We create the nodename.
    nodelen = sizeof(uts->nodename) - 1;
    GetComputerName(uts->nodename, &nodelen);
    
    return 0;
}

This was working fine for redtamarin 0.3.2, we removed it in v0.4
but things have changed since Windows 8.1 and we need an alternative

see

Macintosh / Linux

eg. call int uname(struct utsname *);

basic example

#include <sys/utsname.h>

//OperatingSystem.getName()
void VMPI_getOperatingSystemName(char *name)
{
    utsname info;
    const char *osname;
    
    if( uname(&info) < 0 ) {
        osname = "";
    }
    else {
        osname = info.sysname;
    }
    
    VMPI_strcpy( name, osname );
}

Ideally in AS3 we would want something like

import C.sys.utsname.*;

var uts:utsname = uname();

trace( uts.sysname );
trace( uts.nodename );
trace( uts.release );
trace( uts.version );
trace( uts.machine );

see

sysctl / sysctlbyname

TODO

Mac OS X

#include <errno.h>
#include <sys/sysctl.h>

char str[256];
size_t size = sizeof(str);
int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
Clone this wiki locally