aboutsummaryrefslogtreecommitdiff
path: root/src/open_lib.cpp
diff options
context:
space:
mode:
authordalia2 <57895979+dalia2@users.noreply.github.com>2019-12-12 14:25:40 +0000
committerGitHub <noreply@github.com>2019-12-12 14:25:40 +0000
commit1efec9523d21e7948db2d278635c8881409b9cf8 (patch)
tree2ac7fde4db93e75c109d65f2c596275a02a3cc06 /src/open_lib.cpp
parente9d6a0b2993c903c8932b68d2812dc02adb26014 (diff)
parent5b4e60f4f9ec353f79fba01790a3b945c50cab8e (diff)
downloadPROJ-1efec9523d21e7948db2d278635c8881409b9cf8.tar.gz
PROJ-1efec9523d21e7948db2d278635c8881409b9cf8.zip
Merge branch 'master' into update-grid-alternatives.sql-for-Icealnd
Diffstat (limited to 'src/open_lib.cpp')
-rw-r--r--src/open_lib.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/open_lib.cpp b/src/open_lib.cpp
index 7fedb28b..24c31033 100644
--- a/src/open_lib.cpp
+++ b/src/open_lib.cpp
@@ -151,6 +151,51 @@ void pj_set_searchpath ( int count, const char **path )
proj_context_set_search_paths( nullptr, count, const_cast<const char* const*>(path) );
}
+#ifdef _WIN32
+#include <windows.h>
+#include <sys/stat.h>
+static const char *get_path_from_win32_projlib(const char *name, std::string& out) {
+ /* Check if proj.db lieves in a share/proj dir parallel to bin/proj.dll */
+ /* Based in https://stackoverflow.com/questions/9112893/how-to-get-path-to-executable-in-c-running-on-windows */
+
+ DWORD path_size = 1024;
+
+ for (;;) {
+ out.resize(path_size);
+ memset(&out[0], 0, path_size);
+ DWORD result = GetModuleFileNameA(nullptr, &out[0], path_size - 1);
+ DWORD last_error = GetLastError();
+
+ if (result == 0) {
+ return nullptr;
+ }
+ else if (result == path_size - 1) {
+ if (ERROR_INSUFFICIENT_BUFFER != last_error) {
+ return nullptr;
+ }
+ path_size = path_size * 2;
+ }
+ else {
+ break;
+ }
+ }
+ // Now remove the program's name. It was (example) "C:\programs\gmt6\bin\gdal_translate.exe"
+ size_t k = strlen(out.c_str());
+ while (k > 0 && out[--k] != '\\') {}
+ out.resize(k);
+
+ out += "/../share/proj/";
+ out += name;
+
+ struct stat fileInfo;
+ if (stat(out.c_str(), &fileInfo) == 0) // Check if file exists (probably there are simpler ways)
+ return out.c_str();
+ else {
+ return nullptr;
+ }
+}
+#endif
+
/************************************************************************/
/* pj_open_lib_ex() */
/************************************************************************/
@@ -229,6 +274,10 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
if( fid )
break;
}
+#ifdef _WIN32
+ /* check if it lives in a ../share/proj dir of the proj dll */
+ } else if ((sysname = get_path_from_win32_projlib(name, fname)) != nullptr) {
+#endif
/* or hardcoded path */
} else if ((sysname = proj_lib_name) != nullptr) {
fname = sysname;