Source
if ((object_id=H5Gopen2(datafile_g, (*target_obj_name?target_obj_name:"/"), H5P_DEFAULT)) < 0){
/* Delete an attribute from a group or dataset.
* If attribute_name is not given (==NULL), extract it from the given
* group or dataset name.
* Return 0 if all okay; otherwise -1.
*/
int
delete_attribute(
const char *attribute_name,
const char *group_name,
const char *dataset_name)
{
hid_t object_id = -1;
int retval = -1; /* assume it will fail */
char *attr_name = NULL; /* local pointer of the attr_name */
char *target_obj_name = NULL; /* local point of the target object name */
object_t attribute_type = No_type;
/* sanity check */
HDassert((group_name || dataset_name));
HDassert(datafile_g>=0);
/* If attribute name is given, assign it to the local attribute name pointer; */
/* else extract it from the group or dataset name. */
if (attribute_name){
attr_name = attribute_name;
/* open the target object */
/* try dataset_name first */
if (dataset_name){
if ((object_id=H5Dopen2(datafile_g, dataset_name, H5P_DEFAULT)) < 0){
fprintf(stderr, "failed to open dataset %s\n", dataset_name);
goto error;
}
attribute_type = Dataset_type; /* delete a dataset attribute */
}else{
if ((object_id=H5Gopen2(datafile_g, group_name, H5P_DEFAULT)) < 0){
fprintf(stderr, "failed to open group %s\n", group_name);
goto error;
}
attribute_type = Group_type; /* delete a group attribute */
}
}else{
/* copy group or dataset name into target_obj_name and then extract attribute name from it. */
if ((target_obj_name = HDstrdup(dataset_name ? dataset_name: group_name)) == NULL){
fprintf(stderr, "strdup failed\n");
goto error;
};
if ((attr_name=HDstrrchr(target_obj_name, '/')) == NULL){
fprintf(stderr, "Cannot extract attribute name from target-object-name %s",