aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2019-04-02 20:49:49 +0200
committerGitHub <noreply@github.com>2019-04-02 20:49:49 +0200
commit41fe4d06282f5a5374cd6d19382e0e37c2c277bc (patch)
tree4ff1c99e4af8fb55f395569460fe7e6e2d6a0b69
parent2a0ad3d42c7342ee060791aba01f70f058238dce (diff)
parent996930229a83cf84e465ab20de70eda4745bd097 (diff)
downloadPROJ-41fe4d06282f5a5374cd6d19382e0e37c2c277bc.tar.gz
PROJ-41fe4d06282f5a5374cd6d19382e0e37c2c277bc.zip
Merge pull request #1398 from snowman2/issue_1327
paths set by user take priority over PROJ_LIB for search paths
-rw-r--r--docs/source/usage/environmentvars.rst10
-rw-r--r--src/open_lib.cpp51
2 files changed, 30 insertions, 31 deletions
diff --git a/docs/source/usage/environmentvars.rst b/docs/source/usage/environmentvars.rst
index 478e2eab..c8dfe28e 100644
--- a/docs/source/usage/environmentvars.rst
+++ b/docs/source/usage/environmentvars.rst
@@ -40,6 +40,16 @@ done by setting the variable with no content::
in other locations as well, amongst those are the users home directory,
``/usr/share/proj`` and the current folder.
+ You can also set the location of the resource files using
+ :func:`proj_context_set_search_paths` in the `proj.h` API header.
+
+.. versionchanged:: 6.1.0
+
+ Starting with PROJ version 6.1.0, the paths set by
+ :func:`proj_context_set_search_paths` will have priority over the
+ :envvar:`PROJ_LIB` to allow for mutliple versions of PROJ
+ resource files on your system without conflicting.
+
.. envvar:: PROJ_DEBUG
Set the debug level of PROJ. The default debug level is zero, which results
diff --git a/src/open_lib.cpp b/src/open_lib.cpp
index a00d3d0e..68477996 100644
--- a/src/open_lib.cpp
+++ b/src/open_lib.cpp
@@ -200,9 +200,24 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
else if( ctx->file_finder_legacy != nullptr && (sysname = ctx->file_finder_legacy( name )) != nullptr )
;
- /* or is environment PROJ_LIB defined */
+ /* The user has search paths set */
+ else if( !ctx->search_paths.empty() ) {
+ for( const auto& path: ctx->search_paths ) {
+ try {
+ fname = path;
+ fname += DIR_CHAR;
+ fname += name;
+ sysname = fname.c_str();
+ fid = pj_ctx_fopen(ctx, sysname, mode);
+ } catch( const std::exception& )
+ {
+ }
+ if( fid )
+ break;
+ }
+ }
+ /* if is environment PROJ_LIB defined */
else if ((sysname = getenv("PROJ_LIB")) != nullptr) {
-
auto paths = NS_PROJ::internal::split(std::string(sysname), dirSeparator);
for( const auto& path: paths ) {
fname = path;
@@ -213,15 +228,16 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
if( fid )
break;
}
-
/* or hardcoded path */
} else if ((sysname = proj_lib_name) != nullptr) {
fname = sysname;
fname += DIR_CHAR;
fname += name;
sysname = fname.c_str();
- } else /* just try it bare bones */
+ /* just try it bare bones */
+ } else {
sysname = name;
+ }
if ( fid != nullptr || (fid = pj_ctx_fopen(ctx, sysname, mode)) != nullptr)
{
@@ -233,33 +249,6 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
errno = 0;
}
- /* If none of those work and we have a search path, try it */
- if( !fid && !ctx->search_paths.empty() )
- {
- for( const auto& path: ctx->search_paths ) {
- try {
- fname = path;
- fname += DIR_CHAR;
- fname += name;
- sysname = fname.c_str();
- fid = pj_ctx_fopen(ctx, sysname, mode);
- } catch( const std::exception& )
- {
- }
- if( fid )
- break;
- }
- if (fid)
- {
- if( out_full_filename != nullptr && out_full_filename_size > 0 )
- {
- strncpy(out_full_filename, sysname, out_full_filename_size);
- out_full_filename[out_full_filename_size-1] = '\0';
- }
- errno = 0;
- }
- }
-
if( ctx->last_errno == 0 && errno != 0 )
pj_ctx_set_errno( ctx, errno );