~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/ThirdParty/ANGLE/src/common/system_utils_win32.cpp

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
 
3
// Use of this source code is governed by a BSD-style license that can be
 
4
// found in the LICENSE file.
 
5
//
 
6
// system_utils_win32.cpp: Implementation of OS-specific functions for Windows.
 
7
 
 
8
#include "system_utils.h"
 
9
 
 
10
#include <windows.h>
 
11
#include <array>
 
12
 
 
13
namespace angle
 
14
{
 
15
bool UnsetEnvironmentVar(const char *variableName)
 
16
{
 
17
    return (SetEnvironmentVariableA(variableName, nullptr) == TRUE);
 
18
}
 
19
 
 
20
bool SetEnvironmentVar(const char *variableName, const char *value)
 
21
{
 
22
    return (SetEnvironmentVariableA(variableName, value) == TRUE);
 
23
}
 
24
 
 
25
std::string GetEnvironmentVar(const char *variableName)
 
26
{
 
27
    std::array<char, MAX_PATH> oldValue;
 
28
    DWORD result =
 
29
        GetEnvironmentVariableA(variableName, oldValue.data(), static_cast<DWORD>(oldValue.size()));
 
30
    if (result == 0)
 
31
    {
 
32
        return std::string();
 
33
    }
 
34
    else
 
35
    {
 
36
        return std::string(oldValue.data());
 
37
    }
 
38
}
 
39
 
 
40
class Win32Library : public Library
 
41
{
 
42
  public:
 
43
    Win32Library(const char *libraryName, SearchType searchType)
 
44
    {
 
45
        char buffer[MAX_PATH];
 
46
        int ret = snprintf(buffer, MAX_PATH, "%s.%s", libraryName, GetSharedLibraryExtension());
 
47
        if (ret > 0 && ret < MAX_PATH)
 
48
        {
 
49
            switch (searchType)
 
50
            {
 
51
                case SearchType::ApplicationDir:
 
52
                    mModule = LoadLibraryA(buffer);
 
53
                    break;
 
54
                case SearchType::SystemDir:
 
55
                    mModule = LoadLibraryExA(buffer, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
 
56
                    break;
 
57
            }
 
58
        }
 
59
    }
 
60
 
 
61
    ~Win32Library() override
 
62
    {
 
63
        if (mModule)
 
64
        {
 
65
            FreeLibrary(mModule);
 
66
        }
 
67
    }
 
68
 
 
69
    void *getSymbol(const char *symbolName) override
 
70
    {
 
71
        if (!mModule)
 
72
        {
 
73
            return nullptr;
 
74
        }
 
75
 
 
76
        return reinterpret_cast<void *>(GetProcAddress(mModule, symbolName));
 
77
    }
 
78
 
 
79
    void *getNative() const override { return reinterpret_cast<void *>(mModule); }
 
80
 
 
81
  private:
 
82
    HMODULE mModule = nullptr;
 
83
};
 
84
 
 
85
Library *OpenSharedLibrary(const char *libraryName, SearchType searchType)
 
86
{
 
87
    return new Win32Library(libraryName, searchType);
 
88
}
 
89
}  // namespace angle