-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathhostinformation.cpp
42 lines (33 loc) · 1.25 KB
/
hostinformation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "common.h"
#include "hostinformation.h"
namespace
{
host_runtime_contract* s_hostContract = nullptr;
}
void HostInformation::SetContract(_In_ host_runtime_contract* hostContract)
{
_ASSERTE(s_hostContract == nullptr);
s_hostContract = hostContract;
}
bool HostInformation::GetProperty(_In_z_ const char* name, SString& value)
{
if (s_hostContract == nullptr || s_hostContract->get_runtime_property == nullptr)
return false;
size_t len = MAX_PATH + 1;
char* dest = value.OpenUTF8Buffer(static_cast<COUNT_T>(len));
size_t lenActual = s_hostContract->get_runtime_property(name, dest, len, s_hostContract->context);
value.CloseBuffer();
// Doesn't exist or failed to get property
if (lenActual == (size_t)-1 || lenActual == 0)
return false;
if (lenActual <= len)
return true;
// Buffer was not large enough
len = lenActual;
dest = value.OpenUTF8Buffer(static_cast<COUNT_T>(len));
lenActual = s_hostContract->get_runtime_property(name, dest, len, s_hostContract->context);
value.CloseBuffer();
return lenActual > 0 && lenActual <= len;
}