summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5trav.c
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2008-09-21 18:35:43 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2008-09-21 18:35:43 (GMT)
commit6d28e06f30587202147f6ae31b658a5021adf2a0 (patch)
tree0ec105751d2a26f24039870fb6e44b770917e18e /tools/lib/h5trav.c
parentdcd4c0b04988dbe869a3a479381118844217fa66 (diff)
downloadhdf5-6d28e06f30587202147f6ae31b658a5021adf2a0.zip
hdf5-6d28e06f30587202147f6ae31b658a5021adf2a0.tar.gz
hdf5-6d28e06f30587202147f6ae31b658a5021adf2a0.tar.bz2
[svn-r15668] Purpose: Add feature requested in bug #1282
Description: Adds capability to h5ls to traverse external links when the -r (recursive) option is given. Changes to the way absolute path names are patched in h5trav.c. Changes to the way recursive traversal starting from a non-root group is handled (which also fixes some preexisting issues). Tests added for these cases. Tested: kagiso, smirom, linew (h5committest)
Diffstat (limited to 'tools/lib/h5trav.c')
-rw-r--r--tools/lib/h5trav.c15
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) {