Windows: use Win32 API to obtain executable name.
cygwin lies about it, stripping the '.exe' suffix.
Needed for #276.
--
MOS_MIGRATED_REVID=114860126
diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc
index c8e2d12..d3ebfed 100644
--- a/src/main/cpp/blaze_util_mingw.cc
+++ b/src/main/cpp/blaze_util_mingw.cc
@@ -44,16 +44,9 @@
string GetSelfPath() {
char buffer[PATH_MAX] = {};
- ssize_t bytes = readlink("/proc/self/exe", buffer, sizeof(buffer));
- if (bytes == sizeof(buffer)) {
- // symlink contents truncated
- bytes = -1;
- errno = ENAMETOOLONG;
+ if (!GetModuleFileName(0, buffer, sizeof(buffer))) {
+ pdie(255, "Error %u getting executable file name\n", GetLastError());
}
- if (bytes == -1) {
- pdie(blaze_exit_code::INTERNAL_ERROR, "error reading /proc/self/exe");
- }
- buffer[bytes] = '\0'; // readlink does not NUL-terminate
return string(buffer);
}