"Fossies" - the Fresh Open Source Software Archive

Member "src/Common/Dictionary.c" (10 Oct 2018, 1853 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 "Dictionary.c" 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 "../Common/Dictionary.h"
   14 #include <windows.h>
   15 #include <map>
   16 #include <string>
   17 
   18 using namespace std;
   19 
   20 static map <string, void *> StringKeyMap;
   21 static map <int, void *> IntKeyMap;
   22 
   23 static void *DataPool = NULL;
   24 static size_t DataPoolSize = 0;
   25 
   26 
   27 void AddDictionaryEntry (char *key, int intKey, void *value)
   28 {
   29     try
   30     {
   31         if (key)
   32             StringKeyMap[key] = value;
   33 
   34         if (intKey != 0)
   35             IntKeyMap[intKey] = value;
   36     }
   37     catch (exception&) {}
   38 }
   39 
   40 
   41 void *GetDictionaryValue (const char *key)
   42 {
   43     map <string, void *>::const_iterator i = StringKeyMap.find (key);
   44 
   45     if (i == StringKeyMap.end())
   46         return NULL;
   47 
   48     return i->second;
   49 }
   50 
   51 
   52 void *GetDictionaryValueByInt (int intKey)
   53 {
   54     map <int, void *>::const_iterator i = IntKeyMap.find (intKey);
   55 
   56     if (i == IntKeyMap.end())
   57         return NULL;
   58 
   59     return i->second;
   60 }
   61 
   62 
   63 void *AddPoolData (void *data, size_t dataSize)
   64 {
   65     if (DataPoolSize + dataSize > DATA_POOL_CAPACITY) return NULL;
   66 
   67     if (DataPool == NULL)
   68     {
   69         DataPool = malloc (DATA_POOL_CAPACITY);
   70         if (DataPool == NULL) return NULL;
   71     }
   72 
   73     memcpy ((BYTE *)DataPool + DataPoolSize, data, dataSize);
   74 
   75     // Ensure 32-bit alignment for next entries
   76     dataSize = (dataSize + 3) & (~(size_t)3);
   77 
   78     DataPoolSize += dataSize;
   79     return (BYTE *)DataPool + DataPoolSize - dataSize;
   80 }
   81 
   82 
   83 void ClearDictionaryPool ()
   84 {
   85     DataPoolSize = 0;
   86     StringKeyMap.clear();
   87     IntKeyMap.clear();
   88 }