1 #include "../git-compat-util.h"
4 inline void utf16_to_utf8(char *dst
, const wchar_t *src
, size_t len
)
6 if (!WideCharToMultiByte(CP_UTF8
, 0, src
, len
, dst
, len
, NULL
, NULL
))
7 die("failed to convert from UTF-16 to UTF-8: %d", GetLastError());
10 const char *msvc_get_exec_path()
12 static char *exe_path
;
15 wchar_t *wpath
= NULL
;
16 size_t wlen
= MAX_PATH
/ 4;
22 wpath
= xrealloc(wpath
, wlen
* sizeof(wchar_t));
23 len
= GetModuleFileNameW(NULL
, wpath
, wlen
);
25 } while (len
== wlen
);
27 path
= xmalloc((len
+ 1) * sizeof(wchar_t));
28 utf16_to_utf8(path
, wpath
, len
+ 1);
31 len
= (strrchr(path
, '\\') - path
);
32 assert(len
!= ((char*) NULL
- path
));
34 exe_path
= xrealloc(path
, len
+ 1);
40 const char *msvc_get_etc_gitconfig()
42 static char *etc_path
;
45 static const char etc
[] = "/etc/gitconfig";
46 const char *epath
= msvc_get_exec_path();
48 size_t len
= strlen(epath
);
50 path
= xmalloc(len
+ sizeof(etc
));
51 memcpy(path
, epath
, len
);
52 memcpy(path
+ len
, etc
, sizeof(etc
));
59 const char *msvc_get_man_path()
61 static char *man_path
;
64 static const char man
[] = "/man";
65 const char *epath
= msvc_get_exec_path();
67 size_t len
= strlen(epath
);
69 path
= xmalloc(len
+ sizeof(man
));
70 memcpy(path
, epath
, len
);
71 memcpy(path
+ len
, man
, sizeof(man
));
78 const char *msvc_get_info_path()
80 static char *info_path
;
83 static const char info
[] = "/info";
84 const char *epath
= msvc_get_exec_path();
86 size_t len
= strlen(epath
);
88 path
= xmalloc(len
+ sizeof(info
));
89 memcpy(path
, epath
, len
);
90 memcpy(path
+ len
, info
, sizeof(info
));
97 const char *msvc_get_html_path()
99 static char *html_path
;
102 static const char html
[] = "/html";
103 const char *epath
= msvc_get_exec_path();
105 size_t len
= strlen(epath
);
107 path
= xmalloc(len
+ sizeof(html
));
108 memcpy(path
, epath
, len
);
109 memcpy(path
+ len
, html
, sizeof(html
));
116 const char *msvc_get_template_path()
118 static char *template_path
;
120 if (!template_path
) {
121 static const char template[] = "/template";
122 const char *epath
= msvc_get_exec_path();
124 size_t len
= strlen(epath
);
126 path
= xmalloc(len
+ sizeof(template));
127 memcpy(path
, epath
, len
);
128 memcpy(path
+ len
, template, sizeof(template));
129 template_path
= path
;
132 return template_path
;