summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5A.c50
-rw-r--r--src/H5Adeprec.c40
-rw-r--r--src/H5Apublic.h4
3 files changed, 80 insertions, 14 deletions
diff --git a/src/H5A.c b/src/H5A.c
index 635893b..742a0e3 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -1642,43 +1642,67 @@ done:
/*--------------------------------------------------------------------------
NAME
- H5Adelete
+ H5Adelete2
PURPOSE
Deletes an attribute from a location
USAGE
herr_t H5Adelete (loc_id, name)
- hid_t loc_id; IN: Object (dataset or group) to have attribute deleted from
- const char *name; IN: Name of attribute to delete
+ hid_t loc_id; IN: Base location for object
+ const char *obj_name; IN: Name of object relative to location
+ const char *attr_name; IN: Name of attribute to delete
+ hid_t lapl_id; IN: Link access property list
RETURNS
Non-negative on success/Negative on failure
DESCRIPTION
- This function removes the named attribute from a dataset or group.
- This function should not be used when attribute IDs are open on 'loc_id'
- as it may cause the internal indexes of the attributes to change and future
- writes to the open attributes to produce incorrect results.
+ This function removes the named attribute from an object.
--------------------------------------------------------------------------*/
herr_t
-H5Adelete(hid_t loc_id, const char *name)
+H5Adelete2(hid_t loc_id, const char *obj_name, const char *attr_name,
+ hid_t lapl_id)
{
H5G_loc_t loc; /* Object location */
+ H5G_loc_t obj_loc; /* Location used to open group */
+ H5G_name_t obj_path; /* Opened object group hier. path */
+ H5O_loc_t obj_oloc; /* Opened object object location */
+ hbool_t loc_found = FALSE; /* Entry at 'obj_name' found */
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_API(H5Adelete, FAIL)
- H5TRACE2("e", "is", loc_id, name);
+ FUNC_ENTER_API(H5Adelete2, FAIL)
/* check arguments */
if(H5I_ATTR == H5I_get_type(loc_id))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
if(H5G_loc(loc_id, &loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
- if(!name || !*name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
+ if(!obj_name || !*obj_name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
+ if(!attr_name || !*attr_name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name")
+ if(H5P_DEFAULT == lapl_id)
+ lapl_id = H5P_LINK_ACCESS_DEFAULT;
+ else
+ if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID")
+
+ /* Set up opened group location to fill in */
+ obj_loc.oloc = &obj_oloc;
+ obj_loc.path = &obj_path;
+ H5G_loc_reset(&obj_loc);
+
+ /* Find the object's location */
+ if(H5G_loc_find(&loc, obj_name, &obj_loc/*out*/, lapl_id, H5AC_ind_dxpl_id) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "object not found")
+ loc_found = TRUE;
/* Delete the attribute from the location */
- if(H5O_attr_remove(loc.oloc, name, H5AC_dxpl_id) < 0)
+ if(H5O_attr_remove(obj_loc.oloc, attr_name, H5AC_dxpl_id) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute")
done:
+ /* Release resources */
+ if(loc_found && H5G_loc_free(&obj_loc) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't free location")
+
FUNC_LEAVE_API(ret_value)
} /* H5Adelete() */
diff --git a/src/H5Adeprec.c b/src/H5Adeprec.c
index d1d7740..0e1d264 100644
--- a/src/H5Adeprec.c
+++ b/src/H5Adeprec.c
@@ -165,3 +165,43 @@ done:
FUNC_LEAVE_API(ret_value)
} /* H5Aget_num_attrs() */
+
+/*--------------------------------------------------------------------------
+ NAME
+ H5Adelete
+ PURPOSE
+ Deletes an attribute from a location
+ USAGE
+ herr_t H5Adelete (loc_id, name)
+ hid_t loc_id; IN: Object (dataset or group) to have attribute deleted from
+ const char *name; IN: Name of attribute to delete
+ RETURNS
+ Non-negative on success/Negative on failure
+ DESCRIPTION
+ This function removes the named attribute from a dataset or group.
+--------------------------------------------------------------------------*/
+herr_t
+H5Adelete(hid_t loc_id, const char *name)
+{
+ H5G_loc_t loc; /* Object location */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_API(H5Adelete, FAIL)
+ H5TRACE2("e", "is", loc_id, name);
+
+ /* check arguments */
+ if(H5I_ATTR == H5I_get_type(loc_id))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
+ if(H5G_loc(loc_id, &loc) < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
+ if(!name || !*name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
+
+ /* Delete the attribute from the location */
+ if(H5O_attr_remove(loc.oloc, name, H5AC_dxpl_id) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute")
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* H5Adelete() */
+
diff --git a/src/H5Apublic.h b/src/H5Apublic.h
index 818fc30..7268c73 100644
--- a/src/H5Apublic.h
+++ b/src/H5Apublic.h
@@ -64,7 +64,8 @@ H5_DLL ssize_t H5Aget_name_by_idx(hid_t loc_id, const char *obj_name,
H5_DLL herr_t H5Arename(hid_t loc_id, const char *old_name, const char *new_name);
H5_DLL herr_t H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op,
void *op_data);
-H5_DLL herr_t H5Adelete(hid_t loc_id, const char *name);
+H5_DLL herr_t H5Adelete2(hid_t loc_id, const char *obj_name,
+ const char *attr_name, hid_t lapl_id);
H5_DLL herr_t H5Adelete_by_idx(hid_t loc_id, const char *obj_name,
H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t lapl_id);
@@ -74,6 +75,7 @@ H5_DLL herr_t H5Adelete_by_idx(hid_t loc_id, const char *obj_name,
* Use of these functions and variables is deprecated.
*/
H5_DLL int H5Aget_num_attrs(hid_t loc_id);
+H5_DLL herr_t H5Adelete(hid_t loc_id, const char *name);
#ifdef __cplusplus
}