diff options
Diffstat (limited to 'tools/lib/h5trav.c')
-rw-r--r-- | tools/lib/h5trav.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index bb8014d..69b4512 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -40,6 +40,8 @@ typedef struct { trav_addr_t *seen; /* List of addresses seen already */ const trav_visitor_t *visitor; /* Information for visiting each link/object */ hbool_t is_absolute; /* Whether the traversal has absolute paths */ + const char *base_grp_name; /* Name of the group that serves as the base + * for iteration */ } trav_ud_traverse_t; typedef struct { @@ -146,9 +148,15 @@ traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo, /* Create the full path name for the link */ if(udata->is_absolute) { - new_name = HDmalloc(HDstrlen(path) + 2); - *new_name = '/'; - HDstrcpy(new_name + 1, path); + size_t base_len = HDstrlen(udata->base_grp_name); + size_t add_slash = base_len ? ((udata->base_grp_name)[base_len-1] != '/') : 1; + + if(NULL == (new_name = HDmalloc(base_len + add_slash + HDstrlen(path) + 1))) + return(H5_ITER_ERROR); + HDstrcpy(new_name, udata->base_grp_name); + if (add_slash) + new_name[base_len] = '/'; + HDstrcpy(new_name + base_len + add_slash, path); full_name = new_name; } /* end if */ else @@ -242,6 +250,7 @@ traverse(hid_t file_id, const char *grp_name, hbool_t visit_start, udata.seen = &seen; udata.visitor = visitor; udata.is_absolute = (*grp_name == '/'); + udata.base_grp_name = grp_name; /* Check for iteration of links vs. visiting all links recursively */ if(recurse) { |