#include "debug.h"
#include "gettext.h"
+#include "support/environment.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/os.h"
#endif
#if defined (USE_WINDOWS_PACKAGING)
+
+/*
+ * MinGW's version of winver.h contains this comment:
+ *
+ * If you need Win32 API features newer the Win95 and WinNT then you must
+ * define WINVER before including windows.h or any other method of including
+ * the windef.h header.
+ *
+ * GetLongPathNameA requires WINVER == 0x0500.
+ *
+ * It doesn't matter if the Windows version is older than this because the
+ * function will compile but will fail at run time. See
+ * http://msdn.microsoft.com/library/en-us/mslu/winprog/microsoft_layer_for_unicode_apis_with_limited_support.asp
+ */
+# if defined(__MINGW32__)
+# define WINVER 0x0500
+# endif
+
# include <windows.h>
# include <shlobj.h> // SHGetFolderPath
string const get_home_dir()
{
#if defined (USE_WINDOWS_PACKAGING)
- string const home_dir = GetEnv("USERPROFILE");
+ string const home_dir = getEnv("USERPROFILE");
#else // Posix-like.
- string const home_dir = GetEnv("HOME");
+ string const home_dir = getEnv("HOME");
#endif
return os::internal_path(home_dir);
// Typical example: C:/TEMP/.
char path[MAX_PATH + 1];
GetTempPath(MAX_PATH, path);
+ GetLongPathName(path, path, MAX_PATH + 1);
return os::internal_path(path);
#else // Posix-like.
return "/tmp";
// Does the grunt work for abs_path_from_binary_name()
string const get_binary_path(string const & exe)
{
- string const exe_path = os::internal_path(exe);
+ // The executable may have been invoked either with or
+ // without the .exe extension.
+ // Ensure that it is present.
+ string const as_internal_path = os::internal_path(exe);
+ string const exe_path = suffixIs(as_internal_path, ".exe") ?
+ as_internal_path : as_internal_path + ".exe";
if (os::is_absolute_path(exe_path))
return exe_path;
// The environment variable @c env_var expands to a (single) file path.
string const extract_env_var_dir(string const & env_var)
{
- string const dir = os::internal_path(GetEnv(env_var));
+ string const dir = os::internal_path(getEnv(env_var));
return dir.empty() ? dir : MakeAbsPath(dir);
}