Skip to content

Instantly share code, notes, and snippets.

@jzrake
Created June 30, 2012 21:44
Show Gist options
  • Select an option

  • Save jzrake/3025642 to your computer and use it in GitHub Desktop.

Select an option

Save jzrake/3025642 to your computer and use it in GitHub Desktop.
HDF5 safe, recursive H5Lexists
int H5Lexists_safe(hid_t base, const char *path)
// -----------------------------------------------------------------------------
// The HDF5 specification only allows H5Lexists to be called on an immediate
// child of the current object. However, you may wish to see whether a whole
// relative path exists, returning false if any of the intermediate links are
// not present. This function does that.
// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Exists
// -----------------------------------------------------------------------------
{
#if (COW_HDF5)
hid_t last = base, next;
char *pch;
char pathc[2048];
strcpy(pathc, path);
pch = strtok(pathc, "/");
while (pch != NULL) {
int exists = H5Lexists(last, pch, H5P_DEFAULT);
if (!exists) {
if (last != base) H5Gclose(last);
return 0;
}
else {
next = H5Gopen(last, pch, H5P_DEFAULT);
if (last != base) H5Gclose(last);
last = next;
}
pch = strtok(NULL, "/");
}
if (last != base) H5Gclose(last);
return 1;
#endif
}
@jaabell

jaabell commented Mar 25, 2014

Copy link
Copy Markdown

Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment