forked from uncrustify/uncrustify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompat_win32.cpp
More file actions
60 lines (52 loc) · 1.02 KB
/
compat_win32.cpp
File metadata and controls
60 lines (52 loc) · 1.02 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @file compat_win32.cpp
* Compatibility functions for win32
*
* @author Ben Gardner
* @license GPL v2+
*/
#ifdef WIN32
#include "windows_compat.h"
#include <string>
#include <cstdio>
bool unc_getenv(const char *name, std::string& str)
{
DWORD len = GetEnvironmentVariableA(name, NULL, 0);
char *buf;
if (len == 0)
{
if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
{
return false;
}
}
buf = (char *)malloc(len);
if (buf)
{
len = GetEnvironmentVariableA(name, buf, len);
}
buf[len] = 0;
str = buf;
printf("%s: name=%s len=%d value=%s\n", __func__, name, (int)len, str.c_str());
free(buf);
return true;
}
bool unc_homedir(std::string& home)
{
if (unc_getenv("HOME", home))
{
return true;
}
if (unc_getenv("USERPROFILE", home))
{
return true;
}
std::string hd, hp;
if (unc_getenv("HOMEDRIVE", hd) && unc_getenv("HOMEPATH", hp))
{
home = hd + hp;
return true;
}
return false;
}
#endif /* ifdef WIN32 */