From 13a982acc327899b022d0116275c8ac6645a8592 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 1 Aug 2016 12:10:49 -0500 Subject: [svn-r30234] HDFFV-9706: Add windows env var expansion --- src/H5PL.c | 86 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/src/H5PL.c b/src/H5PL.c index d691eb5..4c3555b 100644 --- a/src/H5PL.c +++ b/src/H5PL.c @@ -17,7 +17,7 @@ /****************/ /* Interface initialization */ -#define H5_INTERFACE_INIT_FUNC H5PL__init_interface +#define H5_INTERFACE_INIT_FUNC H5PL__init_interface /***********/ @@ -37,7 +37,7 @@ #define H5PL_MAX_PATH_NUM 16 /****************************/ -/* Macros for supporting +/* Macros for supporting * both Windows and Unix */ /****************************/ /* Windows support @@ -271,7 +271,7 @@ int H5PL_term_interface(void) { int i = 0; - + FUNC_ENTER_NOAPI_NOINIT_NOERR if(H5_interface_initialize_g) { @@ -323,14 +323,17 @@ H5PL_load(H5PL_type_t type, int id) FUNC_ENTER_NOAPI(NULL) - switch (type) { - case H5PL_TYPE_FILTER: - if((H5PL_plugin_g & H5PL_FILTER_PLUGIN) == 0) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id) - break; - default: - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin '%d' is not valid", id) - } + switch(type) { + case H5PL_TYPE_FILTER: + if((H5PL_plugin_g & H5PL_FILTER_PLUGIN) == 0) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id) + break; + + case H5PL_TYPE_ERROR: + case H5PL_TYPE_NONE: + default: + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin '%d' is not valid", id) + } /* end switch */ /* Initialize the location paths for dynamic libraries, if they aren't * already set up. @@ -345,12 +348,12 @@ H5PL_load(H5PL_type_t type, int id) /* If not found, iterate through the path table to find the right dynamic library */ if(!found) { - size_t i; /* Local index variable */ + size_t i; /* Local index variable */ for(i = 0; i < H5PL_num_paths_g; i++) { if((found = H5PL__find(type, id, H5PL_path_table_g[i], &plugin_info)) < 0) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, NULL, "search in paths failed") - + /* Break out if found */ if(found) { HDassert(plugin_info); @@ -401,6 +404,19 @@ H5PL__init_path_table(void) if(NULL == dl_path) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") +#ifdef H5_HAVE_WIN32_API + else { /* Expand windows env var*/ + long bufCharCount; + char tempbuf[EXPAND_BUFFER_SIZE]; + if((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, EXPAND_BUFFER_SIZE)) > EXPAND_BUFFER_SIZE) + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") + if(bufCharCount == 0) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") + dl_path = (char *)H5MM_xfree(dl_path); + dl_path = H5MM_strdup(tempbuf); + } +#endif H5_HAVE_WIN32_API + /* Put paths in the path table. They are separated by ":" */ dir = HDstrtok(dl_path, H5PL_PATH_SEPARATOR); while(dir) { @@ -427,11 +443,11 @@ done: * Function: H5PL__find * * Purpose: Given a path, this function opens the directory and envokes - * another function to go through all files to find the right - * plugin library. Two function definitions are for Unix and + * another function to go through all files to find the right + * plugin library. Two function definitions are for Unix and * Windows. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * negative on failure * @@ -451,17 +467,17 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info) FUNC_ENTER_STATIC - /* Open the directory */ + /* Open the directory */ if(!(dirp = HDopendir(dir))) - HGOTO_ERROR(H5E_PLUGIN, H5E_OPENERROR, FAIL, "can't open directory") + HGOTO_ERROR(H5E_PLUGIN, H5E_OPENERROR, FAIL, "can't open directory: %s", dir) /* Iterates through all entries in the directory to find the right plugin library */ while(NULL != (dp = HDreaddir(dirp))) { - /* The library we are looking for should be called libxxx.so... on Unix + /* 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) && + 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) && @@ -482,7 +498,7 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info) if(HDstat(pathname, &my_stat) == -1) HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't stat file: %s", HDstrerror(errno)) - /* If it is a directory, skip it */ + /* If it is a directory, skip it */ if(S_ISDIR(my_stat.st_mode)) continue; @@ -493,17 +509,18 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info) /* Indicate success */ HGOTO_DONE(TRUE) } /* end if */ - else + else { HDassert(pathname); pathname = (char *)H5MM_xfree(pathname); + } } /* end if */ } /* end while */ done: - if(dirp) + if(dirp) if(HDclosedir(dirp) < 0) HDONE_ERROR(H5E_FILE, H5E_CLOSEERROR, FAIL, "can't close directory: %s", HDstrerror(errno)) - if(pathname) + if(pathname) pathname = (char *)H5MM_xfree(pathname); FUNC_LEAVE_NOAPI(ret_value) @@ -549,16 +566,17 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info) /* Indicate success */ HGOTO_DONE(TRUE) } /* end if */ - else + else { HDassert(pathname); pathname = (char *)H5MM_xfree(pathname); + } } /* end if */ } while(FindNextFileA(hFind, &fdFile)); /* Find the next file. */ done: - if(hFind) + if(hFind) FindClose(hFind); - if(pathname) + if(pathname) pathname = (char *)H5MM_xfree(pathname); FUNC_LEAVE_NOAPI(ret_value) @@ -570,10 +588,10 @@ done: * Function: H5PL__open * * Purpose: Iterates through all files to find the right plugin library. - * It loads the dynamic plugin library and keeps it on the list + * It loads the dynamic plugin library and keeps it on the list * of loaded libraries. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * negative on failure * @@ -639,7 +657,7 @@ H5PL__open(H5PL_type_t pl_type, char *libname, int pl_id, const void **pl_info) /* Set the plugin info to return */ *pl_info = (const void *)plugin_info; - + /* Indicate success */ ret_value = TRUE; } /* end if */ @@ -660,7 +678,7 @@ done: * Purpose: Search in the list of already opened dynamic libraries * to see if the one we are looking for is already opened. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * Negative on failure * @@ -705,7 +723,7 @@ done: /*------------------------------------------------------------------------- * Function: H5PL__close * - * Purpose: Closes the handle for dynamic library + * Purpose: Closes the handle for dynamic library * * Return: Non-negative on success/Negative on failure * @@ -720,6 +738,6 @@ H5PL__close(H5PL_HANDLE handle) FUNC_ENTER_STATIC_NOERR H5PL_CLOSE_LIB(handle); - + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5PL__close() */ -- cgit v0.12