summaryrefslogtreecommitdiffstats
path: root/src/H5PLpath.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5PLpath.c')
-rw-r--r--src/H5PLpath.c480
1 files changed, 342 insertions, 138 deletions
diff --git a/src/H5PLpath.c b/src/H5PLpath.c
index e270c73..291d259 100644
--- a/src/H5PLpath.c
+++ b/src/H5PLpath.c
@@ -5,7 +5,7 @@
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -30,69 +30,64 @@
/* Module Setup */
/****************/
-#include "H5PLmodule.h" /* This source code file is part of the H5PL module */
-
+#include "H5PLmodule.h" /* This source code file is part of the H5PL module */
/***********/
/* Headers */
/***********/
-#include "H5private.h" /* Generic Functions */
-#include "H5Eprivate.h" /* Error handling */
-#include "H5MMprivate.h" /* Memory management */
-#include "H5PLpkg.h" /* Plugin */
-
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5MMprivate.h" /* Memory management */
+#include "H5PLpkg.h" /* Plugin */
/****************/
/* Local Macros */
/****************/
/* Initial capacity of the path table */
-#define H5PL_INITIAL_PATH_CAPACITY 16
+#define H5PL_INITIAL_PATH_CAPACITY 16
/* The amount to add to the capacity when the table is full */
-#define H5PL_PATH_CAPACITY_ADD 16
-
+#define H5PL_PATH_CAPACITY_ADD 16
/******************/
/* Local Typedefs */
/******************/
-
/********************/
/* Local Prototypes */
/********************/
-static herr_t H5PL__insert_at(const char *path, unsigned int index);
-static herr_t H5PL__make_space_at(unsigned int index);
-static herr_t H5PL__replace_at(const char *path, unsigned int index);
+static herr_t H5PL__insert_at(const char *path, unsigned int idx);
+static herr_t H5PL__make_space_at(unsigned int idx);
+static herr_t H5PL__replace_at(const char *path, unsigned int idx);
static herr_t H5PL__expand_path_table(void);
-static herr_t H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *found, const char *dir, const void **plugin_info);
+static herr_t H5PL__path_table_iterate_process_path(const char *plugin_path, H5PL_iterate_type_t iter_type,
+ H5PL_iterate_t iter_op, void *op_data);
+static herr_t H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *found,
+ const char *dir, const void **plugin_info);
/*********************/
/* Package Variables */
/*********************/
-
/*****************************/
/* Library Private Variables */
/*****************************/
-
/*******************/
/* Local Variables */
/*******************/
/* Stored plugin paths to search */
-static char **H5PL_paths_g = NULL;
+static char **H5PL_paths_g = NULL;
/* The number of stored paths */
-static unsigned H5PL_num_paths_g = 0;
+static unsigned H5PL_num_paths_g = 0;
/* The capacity of the path table */
-static unsigned H5PL_path_capacity_g = H5PL_INITIAL_PATH_CAPACITY;
+static unsigned H5PL_path_capacity_g = H5PL_INITIAL_PATH_CAPACITY;
-
-
/*-------------------------------------------------------------------------
* Function: H5PL__insert_at()
*
@@ -105,12 +100,12 @@ static unsigned H5PL_path_capacity_g = H5PL_INITIAL_PATH_CAPACITY;
*-------------------------------------------------------------------------
*/
static herr_t
-H5PL__insert_at(const char *path, unsigned int index)
+H5PL__insert_at(const char *path, unsigned int idx)
{
- char *path_copy = NULL; /* copy of path string (for storing) */
- herr_t ret_value = SUCCEED; /* Return value */
+ char * path_copy = NULL; /* copy of path string (for storing) */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_STATIC
+ FUNC_ENTER_PACKAGE
/* Check args - Just assert on package functions */
HDassert(path);
@@ -127,24 +122,23 @@ H5PL__insert_at(const char *path, unsigned int index)
#ifdef H5_HAVE_WIN32_API
/* Clean up Microsoft Windows environment variables in the path string */
- if(H5_expand_windows_env_vars(&path_copy))
+ if (H5_expand_windows_env_vars(&path_copy))
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTCONVERT, FAIL, "can't expand environment variable string")
#endif /* H5_HAVE_WIN32_API */
/* If the table entry is in use, make some space */
- if (H5PL_paths_g[index])
- if (H5PL__make_space_at(index) < 0)
+ if (H5PL_paths_g[idx])
+ if (H5PL__make_space_at(idx) < 0)
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "unable to make space in the table for the new entry")
/* Insert the copy of the search path into the table at the specified index */
- H5PL_paths_g[index] = path_copy;
+ H5PL_paths_g[idx] = path_copy;
H5PL_num_paths_g++;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__insert_at() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__make_space_at()
*
@@ -156,26 +150,25 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5PL__make_space_at(unsigned int index)
+H5PL__make_space_at(unsigned int idx)
{
- unsigned u; /* iterator */
- herr_t ret_value = SUCCEED; /* Return value */
+ unsigned u; /* iterator */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_STATIC_NOERR
+ FUNC_ENTER_PACKAGE_NOERR
/* Check args - Just assert on package functions */
- HDassert(index < H5PL_path_capacity_g);
+ HDassert(idx < H5PL_path_capacity_g);
/* Copy the paths back to make a space */
- for (u = H5PL_num_paths_g; u > index; u--)
- H5PL_paths_g[u] = H5PL_paths_g[u-1];
+ for (u = H5PL_num_paths_g; u > idx; u--)
+ H5PL_paths_g[u] = H5PL_paths_g[u - 1];
- H5PL_paths_g[index] = NULL;
+ H5PL_paths_g[idx] = NULL;
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__make_space_at() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__replace_at()
*
@@ -188,42 +181,41 @@ H5PL__make_space_at(unsigned int index)
*-------------------------------------------------------------------------
*/
static herr_t
-H5PL__replace_at(const char *path, unsigned int index)
+H5PL__replace_at(const char *path, unsigned int idx)
{
- char *path_copy = NULL; /* copy of path string (for storing) */
- herr_t ret_value = SUCCEED; /* Return value */
+ char * path_copy = NULL; /* copy of path string (for storing) */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_STATIC
+ FUNC_ENTER_PACKAGE
/* Check args - Just assert on package functions */
HDassert(path);
HDassert(HDstrlen(path));
/* Check that the table entry is in use */
- if (!H5PL_paths_g[index])
- HGOTO_ERROR(H5E_PLUGIN, H5E_CANTFREE, FAIL, "path entry at index %u in the table is NULL", index)
+ if (!H5PL_paths_g[idx])
+ HGOTO_ERROR(H5E_PLUGIN, H5E_CANTFREE, FAIL, "path entry at index %u in the table is NULL", idx)
/* Copy the path for storage so the caller can dispose of theirs */
if (NULL == (path_copy = H5MM_strdup(path)))
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't make internal copy of path")
#ifdef H5_HAVE_WIN32_API
- /* Clean up Microsoft Windows environment variables in the path string */
- if (H5_expand_windows_env_vars(&path_copy))
- HGOTO_ERROR(H5E_PLUGIN, H5E_CANTCONVERT, FAIL, "can't expand environment variable string")
+ /* Clean up Microsoft Windows environment variables in the path string */
+ if (H5_expand_windows_env_vars(&path_copy))
+ HGOTO_ERROR(H5E_PLUGIN, H5E_CANTCONVERT, FAIL, "can't expand environment variable string")
#endif /* H5_HAVE_WIN32_API */
/* Free the existing path entry */
- H5PL_paths_g[index] = (char *)H5MM_xfree(H5PL_paths_g[index]);
+ H5PL_paths_g[idx] = (char *)H5MM_xfree(H5PL_paths_g[idx]);
/* Copy the search path into the table at the specified index */
- H5PL_paths_g[index] = path_copy;
+ H5PL_paths_g[idx] = path_copy;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__replace_at() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__create_path_table
*
@@ -237,18 +229,18 @@ done:
herr_t
H5PL__create_path_table(void)
{
- char *env_var= NULL; /* Path string from environment variable */
- char *paths = NULL; /* Delimited paths string. Either from the
- * environment variable or the default.
- */
- char *next_path = NULL; /* A path tokenized from the paths string */
- char *lasts = NULL; /* Context pointer for strtok_r() call */
- herr_t ret_value = SUCCEED; /* Return value */
+ char *env_var = NULL; /* Path string from environment variable */
+ char *paths = NULL; /* Delimited paths string. Either from the
+ * environment variable or the default.
+ */
+ char * next_path = NULL; /* A path tokenized from the paths string */
+ char * lasts = NULL; /* Context pointer for strtok_r() call */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Allocate memory for the path table */
- H5PL_num_paths_g = 0;
+ H5PL_num_paths_g = 0;
H5PL_path_capacity_g = H5PL_INITIAL_PATH_CAPACITY;
if (NULL == (H5PL_paths_g = (char **)H5MM_calloc((size_t)H5PL_path_capacity_g * sizeof(char *))))
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path table")
@@ -256,7 +248,7 @@ H5PL__create_path_table(void)
/* Retrieve paths from HDF5_PLUGIN_PATH if the user sets it
* or from the default paths if it isn't set.
*/
- env_var = HDgetenv("HDF5_PLUGIN_PATH");
+ env_var = HDgetenv(HDF5_PLUGIN_PATH);
if (NULL == env_var)
paths = H5MM_strdup(H5PL_DEFAULT_PATH);
else
@@ -291,7 +283,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__create_path_table() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__close_path_table
*
@@ -305,8 +296,8 @@ done:
herr_t
H5PL__close_path_table(void)
{
- unsigned u; /* iterator */
- herr_t ret_value = SUCCEED; /* Return value */
+ unsigned u; /* iterator */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE_NOERR
@@ -325,14 +316,13 @@ H5PL__close_path_table(void)
} /* end H5PL__close_path_table() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__get_num_paths
*
* Purpose: Gets the number of plugin paths that have been stored.
*
* Return: Success: The number of paths
- * Failture: Can't fail
+ * Failure: Can't fail
*-------------------------------------------------------------------------
*/
unsigned
@@ -344,7 +334,6 @@ H5PL__get_num_paths(void)
} /* end H5PL__get_num_paths() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__expand_path_table
*
@@ -357,15 +346,16 @@ H5PL__get_num_paths(void)
static herr_t
H5PL__expand_path_table(void)
{
- herr_t ret_value = SUCCEED;
+ herr_t ret_value = SUCCEED;
- FUNC_ENTER_STATIC
+ FUNC_ENTER_PACKAGE
/* Update the capacity */
H5PL_path_capacity_g += H5PL_PATH_CAPACITY_ADD;
/* Resize the array */
- if(NULL == (H5PL_paths_g = (char **)H5MM_realloc(H5PL_paths_g, (size_t)H5PL_path_capacity_g * sizeof(char *))))
+ if (NULL ==
+ (H5PL_paths_g = (char **)H5MM_realloc(H5PL_paths_g, (size_t)H5PL_path_capacity_g * sizeof(char *))))
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "allocating additional memory for path table failed")
/* Initialize the new memory */
@@ -379,7 +369,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__expand_path_table() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__append_path
*
@@ -392,7 +381,7 @@ done:
herr_t
H5PL__append_path(const char *path)
{
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
@@ -408,7 +397,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__append_path() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__prepend_path
*
@@ -421,7 +409,7 @@ done:
herr_t
H5PL__prepend_path(const char *path)
{
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
@@ -437,7 +425,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__prepend_path() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__replace_path
*
@@ -448,26 +435,25 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5PL__replace_path(const char *path, unsigned int index)
+H5PL__replace_path(const char *path, unsigned int idx)
{
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check args - Just assert on package functions */
HDassert(path);
HDassert(HDstrlen(path));
- HDassert(index < H5PL_path_capacity_g);
+ HDassert(idx < H5PL_path_capacity_g);
/* Insert the path at the requested index */
- if (H5PL__replace_at(path, index) < 0)
+ if (H5PL__replace_at(path, idx) < 0)
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTINSERT, FAIL, "unable to replace search path")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__replace_path() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__insert_path
*
@@ -479,26 +465,25 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5PL__insert_path(const char *path, unsigned int index)
+H5PL__insert_path(const char *path, unsigned int idx)
{
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check args - Just assert on package functions */
HDassert(path);
HDassert(HDstrlen(path));
- HDassert(index < H5PL_path_capacity_g);
+ HDassert(idx < H5PL_path_capacity_g);
/* Insert the path at the requested index */
- if (H5PL__insert_at(path, index) < 0)
+ if (H5PL__insert_at(path, idx) < 0)
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTINSERT, FAIL, "unable to insert search path")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__insert_path() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__remove_path
*
@@ -510,27 +495,27 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5PL__remove_path(unsigned int index)
+H5PL__remove_path(unsigned int idx)
{
- unsigned u; /* iterator */
- herr_t ret_value = SUCCEED; /* Return value */
+ unsigned u; /* iterator */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check args - Just assert on package functions */
- HDassert(index < H5PL_path_capacity_g);
+ HDassert(idx < H5PL_path_capacity_g);
/* Check if the path at that index is set */
- if (!H5PL_paths_g[index])
- HGOTO_ERROR(H5E_PLUGIN, H5E_CANTDELETE, FAIL, "search path at index %u is NULL", index)
+ if (!H5PL_paths_g[idx])
+ HGOTO_ERROR(H5E_PLUGIN, H5E_CANTDELETE, FAIL, "search path at index %u is NULL", idx)
/* Delete the path */
H5PL_num_paths_g--;
- H5PL_paths_g[index] = (char *)H5MM_xfree(H5PL_paths_g[index]);
+ H5PL_paths_g[idx] = (char *)H5MM_xfree(H5PL_paths_g[idx]);
/* Shift the paths down to close the gap */
- for (u = index; u < H5PL_num_paths_g; u++)
- H5PL_paths_g[u] = H5PL_paths_g[u+1];
+ for (u = idx; u < H5PL_num_paths_g; u++)
+ H5PL_paths_g[u] = H5PL_paths_g[u + 1];
/* Set the (former) last path to NULL */
H5PL_paths_g[H5PL_num_paths_g] = NULL;
@@ -539,7 +524,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__remove_path() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__get_path
*
@@ -551,22 +535,237 @@ done:
*-------------------------------------------------------------------------
*/
const char *
-H5PL__get_path(unsigned int index)
+H5PL__get_path(unsigned int idx)
{
- char *ret_value = NULL; /* Return value */
+ char *ret_value = NULL; /* Return value */
FUNC_ENTER_PACKAGE
/* Get the path at the requested index */
- if (index >= H5PL_num_paths_g)
- HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "path index %u is out of range in table", index)
+ if (idx >= H5PL_num_paths_g)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "path index %u is out of range in table", idx)
- return H5PL_paths_g[index];
+ return H5PL_paths_g[idx];
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5PL__replace_path() */
+} /* end H5PL__get_path() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5PL__path_table_iterate
+ *
+ * Purpose: Iterates over all the plugins in the plugin path table and
+ * calls the specified callback function on each plugin found.
+ *
+ * Return: H5_ITER_CONT if all plugins are processed successfully
+ * H5_ITER_STOP if short-circuit success occurs while
+ * processing plugins
+ * H5_ITER_ERROR if an error occurs while processing plugins
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5PL__path_table_iterate(H5PL_iterate_type_t iter_type, H5PL_iterate_t iter_op, void *op_data)
+{
+ unsigned int u;
+ herr_t ret_value = H5_ITER_CONT;
+
+ FUNC_ENTER_PACKAGE
+
+ for (u = 0; (u < H5PL_num_paths_g) && (ret_value == H5_ITER_CONT); u++) {
+ if ((ret_value =
+ H5PL__path_table_iterate_process_path(H5PL_paths_g[u], iter_type, iter_op, op_data)) < 0)
+ HGOTO_ERROR(H5E_PLUGIN, H5E_BADITER, H5_ITER_ERROR,
+ "can't iterate over plugins in plugin path '%s'", H5PL_paths_g[u]);
+ }
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value);
+} /* end H5PL__path_table_iterate() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5PL__path_table_iterate_process_path
+ *
+ * Purpose: Iterates over all the plugins within a single plugin path
+ * entry in the plugin path table and calls the specified
+ * callback function on each plugin found. Two function
+ * definitions are for Unix and Windows.
+ *
+ * Return: H5_ITER_CONT if all plugins are processed successfully
+ * H5_ITER_STOP if short-circuit success occurs while
+ * processing plugins
+ * H5_ITER_ERROR if an error occurs while processing plugins
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef H5_HAVE_WIN32_API
+static herr_t
+H5PL__path_table_iterate_process_path(const char *plugin_path, H5PL_iterate_type_t iter_type,
+ H5PL_iterate_t iter_op, void *op_data)
+{
+ H5PL_type_t plugin_type;
+ const void * plugin_info = NULL;
+ hbool_t plugin_loaded;
+ char * path = NULL;
+ DIR * dirp = NULL; /* Directory stream */
+ struct dirent *dp = NULL; /* Directory entry */
+ herr_t ret_value = H5_ITER_CONT;
+
+ FUNC_ENTER_PACKAGE
+
+ HDassert(plugin_path);
+ HDassert(iter_op);
+
+ /* Open the directory - skip the path if the directory can't be opened */
+ if (!(dirp = HDopendir(plugin_path)))
+ HGOTO_DONE(H5_ITER_CONT)
+
+ /* Iterate through all entries in the directory */
+ while (NULL != (dp = HDreaddir(dirp))) {
+ /* The library we are looking for should be called libxxx.so... on Unix
+ * or libxxx.xxx.dylib on Mac.
+ */
+#ifndef __CYGWIN__
+ if (!HDstrncmp(dp->d_name, "lib", (size_t)3) &&
+ (HDstrstr(dp->d_name, ".so") || HDstrstr(dp->d_name, ".dylib"))) {
+#else
+ if (!HDstrncmp(dp->d_name, "cyg", (size_t)3) && HDstrstr(dp->d_name, ".dll")) {
+#endif
+
+ hbool_t plugin_matches;
+ h5_stat_t my_stat;
+ size_t len;
+
+ /* Allocate & initialize the path name */
+ len = HDstrlen(plugin_path) + HDstrlen(H5PL_PATH_SEPARATOR) + HDstrlen(dp->d_name) + 1 /*\0*/ +
+ 4; /* Extra "+4" to quiet GCC warning - 2019/07/05, QAK */
+
+ if (NULL == (path = (char *)H5MM_calloc(len)))
+ HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, H5_ITER_ERROR, "can't allocate memory for path")
+
+ HDsnprintf(path, len, "%s/%s", plugin_path, dp->d_name);
+
+ /* Get info for directory entry */
+ if (HDstat(path, &my_stat) == -1)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, H5_ITER_ERROR, "can't stat file %s -- error was: %s", path,
+ HDstrerror(errno))
+
+ /* If it is a directory, skip it */
+ if (S_ISDIR(my_stat.st_mode))
+ continue;
+
+ /* Attempt to open the dynamic library */
+ plugin_type = H5PL_TYPE_ERROR;
+ plugin_info = NULL;
+ plugin_loaded = FALSE;
+ if (H5PL__open(path, H5PL_TYPE_NONE, NULL, &plugin_loaded, &plugin_type, &plugin_info) < 0)
+ HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, H5_ITER_ERROR, "failed to open plugin '%s'", path);
+
+ /* Determine if we should process this plugin */
+ plugin_matches = (iter_type == H5PL_ITER_TYPE_ALL) ||
+ ((iter_type == H5PL_ITER_TYPE_FILTER) && (plugin_type == H5PL_TYPE_FILTER)) ||
+ ((iter_type == H5PL_ITER_TYPE_VOL) && (plugin_type == H5PL_TYPE_VOL)) ||
+ ((iter_type == H5PL_ITER_TYPE_VFD) && (plugin_type == H5PL_TYPE_VFD));
+
+ /* If the plugin was successfully loaded, call supplied callback function on plugin */
+ if (plugin_loaded && plugin_matches && (ret_value = iter_op(plugin_type, plugin_info, op_data)))
+ break;
+
+ path = (char *)H5MM_xfree(path);
+ } /* end if */
+ } /* end while */
+
+ if (ret_value < 0)
+ HERROR(H5E_PLUGIN, H5E_CALLBACK, "callback operator function returned failure");
+
+done:
+ if (dirp)
+ if (HDclosedir(dirp) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CLOSEERROR, H5_ITER_ERROR, "can't close directory: %s",
+ HDstrerror(errno))
+
+ path = (char *)H5MM_xfree(path);
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5PL__path_table_iterate_process_path() */
+#else /* H5_HAVE_WIN32_API */
+static herr_t
+H5PL__path_table_iterate_process_path(const char *plugin_path, H5PL_iterate_type_t iter_type,
+ H5PL_iterate_t iter_op, void *op_data)
+{
+ WIN32_FIND_DATAA fdFile;
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ H5PL_type_t plugin_type;
+ const void * plugin_info = NULL;
+ hbool_t plugin_loaded;
+ char * path = NULL;
+ char service[2048];
+ herr_t ret_value = H5_ITER_CONT;
+
+ FUNC_ENTER_PACKAGE
+
+ /* Check args - Just assert on package functions */
+ HDassert(plugin_path);
+ HDassert(iter_op);
+
+ /* Specify a file mask. *.* = We want everything! -
+ * skip the path if the directory can't be opened */
+ HDsnprintf(service, sizeof(service), "%s\\*.dll", plugin_path);
+ if ((hFind = FindFirstFileA(service, &fdFile)) == INVALID_HANDLE_VALUE)
+ HGOTO_DONE(H5_ITER_CONT)
+
+ /* Loop over all the files */
+ do {
+ /* Ignore '.' and '..' */
+ if (HDstrcmp(fdFile.cFileName, ".") != 0 && HDstrcmp(fdFile.cFileName, "..") != 0) {
+ hbool_t plugin_matches;
+ size_t len;
+
+ /* Allocate & initialize the path name */
+ len = HDstrlen(plugin_path) + HDstrlen(H5PL_PATH_SEPARATOR) + HDstrlen(fdFile.cFileName) + 1;
+
+ if (NULL == (path = (char *)H5MM_calloc(len)))
+ HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, H5_ITER_ERROR, "can't allocate memory for path")
+
+ HDsnprintf(path, len, "%s\\%s", plugin_path, fdFile.cFileName);
+
+ /* Ignore directories */
+ if (fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ continue;
+
+ /* Attempt to open the dynamic library */
+ plugin_type = H5PL_TYPE_ERROR;
+ plugin_info = NULL;
+ plugin_loaded = FALSE;
+ if (H5PL__open(path, H5PL_TYPE_NONE, NULL, &plugin_loaded, &plugin_type, &plugin_info) < 0)
+ HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, H5_ITER_ERROR, "failed to open plugin '%s'", path);
+
+ /* Determine if we should process this plugin */
+ plugin_matches = (iter_type == H5PL_ITER_TYPE_ALL) ||
+ ((iter_type == H5PL_ITER_TYPE_FILTER) && (plugin_type == H5PL_TYPE_FILTER)) ||
+ ((iter_type == H5PL_ITER_TYPE_VOL) && (plugin_type == H5PL_TYPE_VOL)) ||
+ ((iter_type == H5PL_ITER_TYPE_VFD) && (plugin_type == H5PL_TYPE_VFD));
+
+ /* If the plugin was successfully loaded, call supplied callback function on plugin */
+ if (plugin_loaded && plugin_matches && (ret_value = iter_op(plugin_type, plugin_info, op_data)))
+ break;
+
+ path = (char *)H5MM_xfree(path);
+ }
+ } while (FindNextFileA(hFind, &fdFile));
+
+ if (ret_value < 0)
+ HERROR(H5E_PLUGIN, H5E_CALLBACK, "callback operator function returned failure");
+
+done:
+ if (hFind != INVALID_HANDLE_VALUE)
+ FindClose(hFind);
+
+ path = (char *)H5MM_xfree(path);
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5PL__path_table_iterate_process_path() */
+#endif /* H5_HAVE_WIN32_API */
-
/*-------------------------------------------------------------------------
* Function: H5PL__find_plugin_in_path_table
*
@@ -580,10 +779,11 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5PL__find_plugin_in_path_table(const H5PL_search_params_t *search_params, hbool_t *found, const void **plugin_info)
+H5PL__find_plugin_in_path_table(const H5PL_search_params_t *search_params, hbool_t *found,
+ const void **plugin_info)
{
- unsigned int u; /* iterator */
- herr_t ret_value = SUCCEED;
+ unsigned int u; /* iterator */
+ herr_t ret_value = SUCCEED;
FUNC_ENTER_PACKAGE
@@ -593,7 +793,7 @@ H5PL__find_plugin_in_path_table(const H5PL_search_params_t *search_params, hbool
HDassert(plugin_info);
/* Initialize output parameters */
- *found = FALSE;
+ *found = FALSE;
*plugin_info = NULL;
/* Loop over the paths in the table, checking for an appropriate plugin */
@@ -601,7 +801,8 @@ H5PL__find_plugin_in_path_table(const H5PL_search_params_t *search_params, hbool
/* Search for the plugin in this path */
if (H5PL__find_plugin_in_path(search_params, found, H5PL_paths_g[u], plugin_info) < 0)
- HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in path %s encountered an error", H5PL_paths_g[u])
+ HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in path %s encountered an error",
+ H5PL_paths_g[u])
/* Break out if found */
if (*found) {
@@ -615,7 +816,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__find_plugin_in_path_table() */
-
/*-------------------------------------------------------------------------
* Function: H5PL__find_plugin_in_path
*
@@ -633,14 +833,15 @@ done:
*/
#ifndef H5_HAVE_WIN32_API
static herr_t
-H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *found, const char *dir, const void **plugin_info)
+H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *found, const char *dir,
+ const void **plugin_info)
{
- char *path = NULL;
- DIR *dirp = NULL; /* Directory stream */
- struct dirent *dp = NULL; /* Directory entry */
+ char * path = NULL;
+ DIR * dirp = NULL; /* Directory stream */
+ struct dirent *dp = NULL; /* Directory entry */
herr_t ret_value = SUCCEED;
- FUNC_ENTER_STATIC
+ FUNC_ENTER_PACKAGE
/* Check args - Just assert on package functions */
HDassert(search_params);
@@ -663,17 +864,17 @@ H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *fo
*/
#ifndef __CYGWIN__
if (!HDstrncmp(dp->d_name, "lib", (size_t)3) &&
- (HDstrstr(dp->d_name, ".so") || HDstrstr(dp->d_name, ".dylib"))) {
+ (HDstrstr(dp->d_name, ".so") || HDstrstr(dp->d_name, ".dylib"))) {
#else
- if (!HDstrncmp(dp->d_name, "cyg", (size_t)3) &&
- HDstrstr(dp->d_name, ".dll") ) {
+ if (!HDstrncmp(dp->d_name, "cyg", (size_t)3) && HDstrstr(dp->d_name, ".dll")) {
#endif
- h5_stat_t my_stat;
- size_t len;
+ h5_stat_t my_stat;
+ size_t len;
/* Allocate & initialize the path name */
- len = HDstrlen(dir) + HDstrlen(H5PL_PATH_SEPARATOR) + HDstrlen(dp->d_name) + 1 /*\0*/ + 4; /* Extra "+4" to quiet GCC warning - 2019/07/05, QAK */
+ len = HDstrlen(dir) + HDstrlen(H5PL_PATH_SEPARATOR) + HDstrlen(dp->d_name) + 1 /*\0*/ +
+ 4; /* Extra "+4" to quiet GCC warning - 2019/07/05, QAK */
if (NULL == (path = (char *)H5MM_calloc(len)))
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path")
@@ -682,21 +883,24 @@ H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *fo
/* Get info for directory entry */
if (HDstat(path, &my_stat) == -1)
- HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't stat file %s -- error was: %s", path, HDstrerror(errno))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't stat file %s -- error was: %s", path,
+ HDstrerror(errno))
/* If it is a directory, skip it */
- if (S_ISDIR(my_stat.st_mode))
+ if (S_ISDIR(my_stat.st_mode)) {
+ path = (char *)H5MM_xfree(path);
continue;
+ }
- /* attempt to open the dynamic library as a filter library */
- if (H5PL__open(path, search_params->type, search_params->key, found, plugin_info) < 0)
+ /* attempt to open the dynamic library */
+ if (H5PL__open(path, search_params->type, search_params->key, found, NULL, plugin_info) < 0)
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in directory failed")
if (*found)
HGOTO_DONE(SUCCEED)
path = (char *)H5MM_xfree(path);
} /* end if */
- } /* end while */
+ } /* end while */
done:
if (dirp)
@@ -707,17 +911,18 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__find_plugin_in_path() */
-#else /* H5_HAVE_WIN32_API */
+#else /* H5_HAVE_WIN32_API */
static herr_t
-H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *found, const char *dir, const void **plugin_info)
+H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *found, const char *dir,
+ const void **plugin_info)
{
- WIN32_FIND_DATAA fdFile;
- HANDLE hFind = INVALID_HANDLE_VALUE;
- char *path = NULL;
- char service[2048];
- herr_t ret_value = SUCCEED;
+ WIN32_FIND_DATAA fdFile;
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ char * path = NULL;
+ char service[2048];
+ herr_t ret_value = SUCCEED;
- FUNC_ENTER_STATIC
+ FUNC_ENTER_PACKAGE
/* Check args - Just assert on package functions */
HDassert(search_params);
@@ -729,7 +934,7 @@ H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *fo
*found = FALSE;
/* Specify a file mask. *.* = We want everything! */
- HDsprintf(service, "%s\\*.dll", dir);
+ HDsnprintf(service, sizeof(service), "%s\\*.dll", dir);
if ((hFind = FindFirstFileA(service, &fdFile)) == INVALID_HANDLE_VALUE)
HGOTO_ERROR(H5E_PLUGIN, H5E_OPENERROR, FAIL, "can't open directory")
@@ -740,7 +945,7 @@ H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *fo
/* XXX: Probably just continue here and move the code below over one tab */
- size_t len;
+ size_t len;
/* Allocate & initialize the path name */
len = HDstrlen(dir) + HDstrlen(H5PL_PATH_SEPARATOR) + HDstrlen(fdFile.cFileName) + 1;
@@ -754,8 +959,8 @@ H5PL__find_plugin_in_path(const H5PL_search_params_t *search_params, hbool_t *fo
if (fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
continue;
- /* attempt to open the dynamic library as a filter library */
- if (H5PL__open(path, search_params->type, search_params->key, found, plugin_info) < 0)
+ /* attempt to open the dynamic library */
+ if (H5PL__open(path, search_params->type, search_params->key, found, NULL, plugin_info) < 0)
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in directory failed")
if (*found)
HGOTO_DONE(SUCCEED)
@@ -773,4 +978,3 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5PL__find_plugin_in_path() */
#endif /* H5_HAVE_WIN32_API */
-