@@ -40,20 +40,28 @@ namespace pdal
4040{
4141namespace capi
4242{
43- size_t PDALGetGdalDataPath (char *path, size_t size)
43+ /* *
44+ * Retrieves the value of an environment variable.
45+ *
46+ * @param name The name of the environment variable
47+ * @param[out] path The buffer used to retrieve the value
48+ * @param size The size of the provided buffer
49+ * @return The size of the retrieved value
50+ */
51+ size_t getEnvironmentVariable (const char *name, char *value, size_t size)
4452{
4553 size_t length = 0 ;
4654
47- if (path && size > 0 )
55+ if (value && size > 0 )
4856 {
49- path [0 ] = ' \0 ' ;
50- path [size-1 ] = ' \0 ' ;
57+ value [0 ] = ' \0 ' ;
58+ value [size-1 ] = ' \0 ' ;
5159
5260 char *env = nullptr ;
5361
5462 try
5563 {
56- env = std::getenv (" GDAL_DATA " );
64+ env = std::getenv (name );
5765 }
5866 catch (const std::exception &)
5967 {
@@ -62,42 +70,22 @@ size_t PDALGetGdalDataPath(char *path, size_t size)
6270
6371 if (env)
6472 {
65- std::strncpy (path , env, size - 1 );
73+ std::strncpy (value , env, size - 1 );
6674 length = std::min (std::strlen (env), size - 1 );
6775 }
6876 }
6977
7078 return length;
7179}
7280
73- size_t PDALGetProj4DataPath (char *path, size_t size)
81+ size_t PDALGetGdalDataPath (char *path, size_t size)
7482{
75- size_t length = 0 ;
76-
77- if (path && size > 0 )
78- {
79- path[0 ] = ' \0 ' ;
80- path[size-1 ] = ' \0 ' ;
81-
82- char *env = nullptr ;
83-
84- try
85- {
86- env = std::getenv (" PROJ_LIB" );
87- }
88- catch (const std::exception &)
89- {
90- env = nullptr ;
91- }
92-
93- if (env)
94- {
95- std::strncpy (path, env, size - 1 );
96- length = std::min (std::strlen (env), size - 1 );
97- }
98- }
83+ return getEnvironmentVariable (" GDAL_DATA" , path, size);
84+ }
9985
100- return length;
86+ size_t PDALGetProj4DataPath (char *path, size_t size)
87+ {
88+ return getEnvironmentVariable (" PROJ_LIB" , path, size);
10189}
10290
10391void PDALSetGdalDataPath (const char *path)
0 commit comments