Created
June 30, 2012 21:44
-
-
Save jzrake/3025642 to your computer and use it in GitHub Desktop.
HDF5 safe, recursive H5Lexists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this!