summaryrefslogtreecommitdiffstats
path: root/src/H5Gname.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Gname.c')
-rw-r--r--src/H5Gname.c225
1 files changed, 181 insertions, 44 deletions
diff --git a/src/H5Gname.c b/src/H5Gname.c
index c7feb62..62875dc 100644
--- a/src/H5Gname.c
+++ b/src/H5Gname.c
@@ -23,22 +23,36 @@
*
*-------------------------------------------------------------------------
*/
-#define H5F_PACKAGE /*suppress error about including H5Fpkg */
+
+/****************/
+/* Module Setup */
+/****************/
+
#define H5G_PACKAGE /*suppress error about including H5Gpkg */
-/* Packages needed by this file... */
+/***********/
+/* Headers */
+/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Dprivate.h" /* Datasets */
#include "H5Eprivate.h" /* Error handling */
-#include "H5Fpkg.h" /* File access */
+#include "H5Fprivate.h" /* File access */
#include "H5FLprivate.h" /* Free Lists */
#include "H5Gpkg.h" /* Groups */
#include "H5Iprivate.h" /* IDs */
#include "H5Lprivate.h" /* Links */
#include "H5MMprivate.h" /* Memory wrappers */
-/* Private typedefs */
+
+/****************/
+/* Local Macros */
+/****************/
+
+
+/******************/
+/* Local Typedefs */
+/******************/
/* Struct used by change name callback function */
typedef struct H5G_names_t {
@@ -60,14 +74,15 @@ typedef struct H5G_gnba_iter_t {
char *path; /* Name of the object */
} H5G_gnba_iter_t;
-/* Private macros */
+/********************/
+/* Package Typedefs */
+/********************/
-/* Local variables */
-/* Declare extern the PQ free list for the wrapped strings */
-H5FL_BLK_EXTERN(str_buf);
+/********************/
+/* Local Prototypes */
+/********************/
-/* PRIVATE PROTOTYPES */
static htri_t H5G_common_path(const H5RS_str_t *fullpath_r, const H5RS_str_t *prefix_r);
static H5RS_str_t *H5G_build_fullpath(const char *prefix, const char *name);
#ifdef NOT_YET
@@ -77,6 +92,123 @@ static herr_t H5G_name_move_path(H5RS_str_t **path_r_ptr,
const char *full_suffix, const char *src_path, const char *dst_path);
static int H5G_name_replace_cb(void *obj_ptr, hid_t obj_id, void *key);
+
+/*********************/
+/* Package Variables */
+/*********************/
+
+/* Declare extern the PQ free list for the wrapped strings */
+H5FL_BLK_EXTERN(str_buf);
+
+
+/*****************************/
+/* Library Private Variables */
+/*****************************/
+
+
+/*******************/
+/* Local Variables */
+/*******************/
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5G__component
+ *
+ * Purpose: Returns the pointer to the first component of the
+ * specified name by skipping leading slashes. Returns
+ * the size in characters of the component through SIZE_P not
+ * counting leading slashes or the null terminator.
+ *
+ * Return: Success: Ptr into NAME.
+ *
+ * Failure: Ptr to the null terminator of NAME.
+ *
+ * Programmer: Robb Matzke
+ * matzke@llnl.gov
+ * Aug 11 1997
+ *
+ *-------------------------------------------------------------------------
+ */
+const char *
+H5G__component(const char *name, size_t *size_p)
+{
+ FUNC_ENTER_PACKAGE_NOERR
+
+ assert(name);
+
+ while ('/' == *name)
+ name++;
+ if (size_p)
+ *size_p = HDstrcspn(name, "/");
+
+ FUNC_LEAVE_NOAPI(name)
+} /* end H5G__component() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5G_normalize
+ *
+ * Purpose: Returns a pointer to a new string which has duplicate and
+ * trailing slashes removed from it.
+ *
+ * Return: Success: Ptr to normalized name.
+ * Failure: NULL
+ *
+ * Programmer: Quincey Koziol
+ * Saturday, August 16, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+char *
+H5G_normalize(const char *name)
+{
+ char *norm; /* Pointer to the normalized string */
+ size_t s,d; /* Positions within the strings */
+ unsigned last_slash; /* Flag to indicate last character was a slash */
+ char *ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ /* Sanity check */
+ HDassert(name);
+
+ /* Duplicate the name, to return */
+ if(NULL == (norm = H5MM_strdup(name)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for normalized string")
+
+ /* Walk through the characters, omitting duplicated '/'s */
+ s = d = 0;
+ last_slash = 0;
+ while(name[s] != '\0') {
+ if(name[s] == '/')
+ if(last_slash)
+ ;
+ else {
+ norm[d++] = name[s];
+ last_slash = 1;
+ } /* end else */
+ else {
+ norm[d++] = name[s];
+ last_slash = 0;
+ } /* end else */
+ s++;
+ } /* end while */
+
+ /* Terminate normalized string */
+ norm[d] = '\0';
+
+ /* Check for final '/' on normalized name & eliminate it */
+ if(d > 1 && last_slash)
+ norm[d - 1] = '\0';
+
+ /* Set return value */
+ ret_value = norm;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5G_normalize() */
+
/*-------------------------------------------------------------------------
* Function: H5G_common_path
@@ -100,16 +232,16 @@ H5G_common_path(const H5RS_str_t *fullpath_r, const H5RS_str_t *prefix_r)
size_t nchars1,nchars2; /* Number of characters in components */
htri_t ret_value=FALSE; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_common_path)
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
/* Get component of each name */
fullpath=H5RS_get_str(fullpath_r);
assert(fullpath);
- fullpath=H5G_component(fullpath,&nchars1);
+ fullpath=H5G__component(fullpath,&nchars1);
assert(fullpath);
prefix=H5RS_get_str(prefix_r);
assert(prefix);
- prefix=H5G_component(prefix,&nchars2);
+ prefix=H5G__component(prefix,&nchars2);
assert(prefix);
/* Check if we have a real string for each component */
@@ -123,9 +255,9 @@ H5G_common_path(const H5RS_str_t *fullpath_r, const H5RS_str_t *prefix_r)
prefix+=nchars2;
/* Get next component of each name */
- fullpath=H5G_component(fullpath,&nchars1);
+ fullpath=H5G__component(fullpath,&nchars1);
assert(fullpath);
- prefix=H5G_component(prefix,&nchars2);
+ prefix=H5G__component(prefix,&nchars2);
assert(prefix);
} /* end if */
else
@@ -165,7 +297,7 @@ H5G_build_fullpath(const char *prefix, const char *name)
unsigned need_sep; /* Flag to indicate if separator is needed */
H5RS_str_t *ret_value; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5G_build_fullpath)
+ FUNC_ENTER_NOAPI_NOINIT
/* Sanity check */
HDassert(prefix);
@@ -221,7 +353,7 @@ H5G_build_fullpath_refstr_str(H5RS_str_t *prefix_r, const char *name)
const char *prefix; /* Pointer to raw string for path */
H5RS_str_t *ret_value;
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_build_fullpath_refstr_str)
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
HDassert(prefix_r);
HDassert(name);
@@ -259,7 +391,7 @@ H5G_build_fullpath_refstr_refstr(const H5RS_str_t *prefix_r, const H5RS_str_t *n
const char *name; /* Pointer to raw string of name */
H5RS_str_t *ret_value; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_build_fullpath_refstr_refstr)
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
/* Get the pointer to the prefix */
prefix = H5RS_get_str(prefix_r);
@@ -276,7 +408,7 @@ H5G_build_fullpath_refstr_refstr(const H5RS_str_t *prefix_r, const H5RS_str_t *n
/*-------------------------------------------------------------------------
- * Function: H5G_name_init
+ * Function: H5G__name_init
*
* Purpose: Set the initial path for a group hierarchy name
*
@@ -289,9 +421,9 @@ H5G_build_fullpath_refstr_refstr(const H5RS_str_t *prefix_r, const H5RS_str_t *n
*-------------------------------------------------------------------------
*/
herr_t
-H5G_name_init(H5G_name_t *name, const char *path)
+H5G__name_init(H5G_name_t *name, const char *path)
{
- FUNC_ENTER_NOAPI_NOFUNC(H5G_name_init)
+ FUNC_ENTER_PACKAGE
/* Check arguments */
HDassert(name);
@@ -304,7 +436,7 @@ H5G_name_init(H5G_name_t *name, const char *path)
name->obj_hidden = 0;
FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5G_name_init() */
+} /* end H5G__name_init() */
/*-------------------------------------------------------------------------
@@ -321,11 +453,11 @@ H5G_name_init(H5G_name_t *name, const char *path)
*-------------------------------------------------------------------------
*/
herr_t
-H5G_name_set(H5G_name_t *loc, H5G_name_t *obj, const char *name)
+H5G_name_set(const H5G_name_t *loc, H5G_name_t *obj, const char *name)
{
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI(H5G_name_set, FAIL)
+ FUNC_ENTER_NOAPI(FAIL)
HDassert(loc);
HDassert(obj);
@@ -379,7 +511,7 @@ done:
herr_t
H5G_name_copy(H5G_name_t *dst, const H5G_name_t *src, H5_copy_depth_t depth)
{
- FUNC_ENTER_NOAPI_NOFUNC(H5G_name_copy)
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
/* Check arguments */
HDassert(src);
@@ -432,7 +564,7 @@ H5G_get_name(const H5G_loc_t *loc, char *name/*out*/, size_t size,
ssize_t len = 0; /* Length of object's name */
ssize_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5G_get_name, FAIL)
+ FUNC_ENTER_NOAPI(FAIL)
/* Sanity check */
HDassert(loc);
@@ -499,7 +631,7 @@ done:
herr_t
H5G_name_reset(H5G_name_t *name)
{
- FUNC_ENTER_NOAPI_NOFUNC(H5G_name_reset)
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
/* Check arguments */
HDassert(name);
@@ -527,7 +659,7 @@ H5G_name_reset(H5G_name_t *name)
herr_t
H5G_name_free(H5G_name_t *name)
{
- FUNC_ENTER_NOAPI_NOFUNC(H5G_name_free)
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
/* Check args */
HDassert(name);
@@ -568,7 +700,7 @@ H5G_name_move_path(H5RS_str_t **path_r_ptr, const char *full_suffix, const char
size_t full_suffix_len; /* Length of full suffix */
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5G_name_move_path)
+ FUNC_ENTER_NOAPI_NOINIT
/* Check arguments */
HDassert(path_r_ptr && *path_r_ptr);
@@ -670,7 +802,7 @@ H5G_name_replace_cb(void *obj_ptr, hid_t obj_id, void *key)
hbool_t obj_in_child = FALSE; /* Flag to indicate that the object is in the child mount hier. */
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5G_name_replace_cb)
+ FUNC_ENTER_NOAPI_NOINIT
HDassert(obj_ptr);
@@ -719,30 +851,30 @@ H5G_name_replace_cb(void *obj_ptr, hid_t obj_id, void *key)
HGOTO_DONE(SUCCEED) /* No need to look at object, it's path is already invalid */
/* Find the top file in object's mount hier. */
- if(oloc->file->parent) {
+ if(H5F_PARENT(oloc->file)) {
/* Check if object is in child file (for mount & unmount operations) */
- if(names->dst_file && oloc->file->shared == names->dst_file->shared)
+ if(names->dst_file && H5F_SAME_SHARED(oloc->file, names->dst_file))
obj_in_child = TRUE;
/* Find the "top" file in the chain of mounted files */
- top_obj_file = oloc->file->parent;
- while(top_obj_file->parent != NULL) {
+ top_obj_file = H5F_PARENT(oloc->file);
+ while(H5F_PARENT(top_obj_file) != NULL) {
/* Check if object is in child mount hier. (for mount & unmount operations) */
- if(names->dst_file && top_obj_file->shared == names->dst_file->shared)
+ if(names->dst_file && H5F_SAME_SHARED(top_obj_file, names->dst_file))
obj_in_child = TRUE;
- top_obj_file = top_obj_file->parent;
+ top_obj_file = H5F_PARENT(top_obj_file);
} /* end while */
} /* end if */
else
top_obj_file = oloc->file;
/* Check if object is in top of child mount hier. (for mount & unmount operations) */
- if(names->dst_file && top_obj_file->shared == names->dst_file->shared)
+ if(names->dst_file && H5F_SAME_SHARED(top_obj_file, names->dst_file))
obj_in_child = TRUE;
/* Check if the object is in same file mount hier. */
- if(top_obj_file->shared != names->src_file->shared)
+ if(!H5F_SAME_SHARED(top_obj_file, names->src_file))
HGOTO_DONE(SUCCEED) /* No need to look at object, it's path is already invalid */
switch(names->op) {
@@ -938,7 +1070,7 @@ H5G_name_replace(const H5O_link_t *lnk, H5G_names_op_t op, H5F_t *src_file,
{
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI(H5G_name_replace, FAIL)
+ FUNC_ENTER_NOAPI(FAIL)
/* Check arguments */
HDassert(src_file);
@@ -1022,8 +1154,8 @@ H5G_name_replace(const H5O_link_t *lnk, H5G_names_op_t op, H5F_t *src_file,
H5G_names_t names; /* Structure to hold operation information for callback */
/* Find top file in src location's mount hierarchy */
- while(src_file->parent)
- src_file = src_file->parent;
+ while(H5F_PARENT(src_file))
+ src_file = H5F_PARENT(src_file);
/* Set up common information for callback */
names.src_file = src_file;
@@ -1076,7 +1208,7 @@ H5G_get_name_by_addr_cb(hid_t gid, const char *path, const H5L_info_t *linfo,
hbool_t obj_found = FALSE; /* Object at 'path' found */
herr_t ret_value = H5_ITER_CONT; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5G_get_name_by_addr_cb)
+ FUNC_ENTER_NOAPI_NOINIT
/* Sanity check */
HDassert(path);
@@ -1105,7 +1237,8 @@ H5G_get_name_by_addr_cb(hid_t gid, const char *path, const H5L_info_t *linfo,
/* Check for object in same file (handles mounted files) */
/* (re-verify address, in case we traversed a file mount) */
if(udata->loc->addr == obj_loc.oloc->addr && udata->loc->file == obj_loc.oloc->file) {
- udata->path = H5MM_strdup(path);
+ if(NULL == (udata->path = H5MM_strdup(path)))
+ HGOTO_ERROR(H5E_SYM, H5E_CANTALLOC, H5_ITER_ERROR, "can't duplicate path string")
/* We found a match so we return immediately */
HGOTO_DONE(H5_ITER_STOP)
@@ -1145,7 +1278,10 @@ H5G_get_name_by_addr(hid_t file, hid_t lapl_id, hid_t dxpl_id, const H5O_loc_t *
herr_t status; /* Status from iteration */
ssize_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5G_get_name_by_addr, FAIL)
+ /* Portably clear udata struct (before FUNC_ENTER) */
+ HDmemset(&udata, 0, sizeof(udata));
+
+ FUNC_ENTER_NOAPI(FAIL)
/* Construct the link info for the file's root group */
if(H5G_loc(file, &root_loc) < 0)
@@ -1153,7 +1289,8 @@ H5G_get_name_by_addr(hid_t file, hid_t lapl_id, hid_t dxpl_id, const H5O_loc_t *
/* Check for root group being the object looked for */
if(root_loc.oloc->addr == loc->addr && root_loc.oloc->file == loc->file) {
- udata.path = H5MM_strdup("");
+ if(NULL == (udata.path = H5MM_strdup("")))
+ HGOTO_ERROR(H5E_SYM, H5E_CANTALLOC, FAIL, "can't duplicate path string")
found_obj = TRUE;
} /* end if */
else {