aboutsummaryrefslogtreecommitdiff
path: root/src/open_lib.cpp
diff options
context:
space:
mode:
authorsnowman2 <alansnow21@gmail.com>2019-03-31 23:11:28 -0500
committersnowman2 <alansnow21@gmail.com>2019-04-01 19:47:01 -0500
commite31cd44d2b53a6dae71fd767f41ea5823f0612a9 (patch)
treeb65e5b57fc56e164259dfa0ed61622ec6ffcb742 /src/open_lib.cpp
parent54b21b1e97f149dce43a9199d13e421f24b6984e (diff)
downloadPROJ-e31cd44d2b53a6dae71fd767f41ea5823f0612a9.tar.gz
PROJ-e31cd44d2b53a6dae71fd767f41ea5823f0612a9.zip
paths set by user take priority over PROJ_LIB for search paths
Diffstat (limited to 'src/open_lib.cpp')
-rw-r--r--src/open_lib.cpp51
1 files changed, 20 insertions, 31 deletions
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 );