"Fossies" - the Fresh Open Source Software Archive

Member "src/Platform/Unix/SystemInfo.cpp" (10 Oct 2018, 1888 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "SystemInfo.cpp" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #include "Platform/SystemException.h"
   14 #include "Platform/SystemInfo.h"
   15 #include <sys/utsname.h>
   16 
   17 namespace VeraCrypt
   18 {
   19     wstring SystemInfo::GetPlatformName ()
   20     {
   21 #ifdef TC_LINUX
   22         return L"Linux";
   23 #elif defined (TC_MACOSX)
   24         return L"Mac OS X";
   25 #elif defined (TC_FREEBSD)
   26         return L"FreeBSD";
   27 #elif defined (TC_SOLARIS)
   28         return L"Solaris";
   29 #else
   30 #   error GetPlatformName() undefined
   31 #endif
   32 
   33     }
   34 
   35     vector <int> SystemInfo::GetVersion ()
   36     {
   37         struct utsname unameData;
   38         throw_sys_if (uname (&unameData) == -1);
   39 
   40         vector <string> versionStrings = StringConverter::Split (unameData.release, ".");
   41         vector <int> version;
   42 
   43         for (size_t i = 0; i < versionStrings.size(); ++i)
   44         {
   45             string s = versionStrings[i];
   46 
   47             size_t p = s.find_first_not_of ("0123456789");
   48             if (p != string::npos)
   49                 s = s.substr (0, p);
   50 
   51             if (s.empty())
   52                 break;
   53 
   54             version.push_back (StringConverter::ToUInt32 (s));
   55         }
   56 
   57         return version;
   58     }
   59 
   60     bool SystemInfo::IsVersionAtLeast (int versionNumber1, int versionNumber2, int versionNumber3)
   61     {
   62         vector <int> osVersionNumbers = GetVersion();
   63 
   64         if (osVersionNumbers.size() < 2)
   65             throw ParameterIncorrect (SRC_POS);
   66 
   67         if (osVersionNumbers.size() < 3)
   68             osVersionNumbers[2] = 0;
   69 
   70         return (osVersionNumbers[0] * 10000000 +  osVersionNumbers[1] * 10000 + osVersionNumbers[2]) >=
   71             (versionNumber1 * 10000000 +  versionNumber2 * 10000 + versionNumber3);
   72     }
   73 }