herr_t
ss_attr_modify(ss_attr_t *attr, /* The attribute whose size will be changed. */
hid_t type, /* The new datatype for the attribute, or H5I_INVALID_HID if the type is not
* to be changed. If the datatype is changed but is conversion compatible with
* the previous type then the attribute's data will be converted to the new
* datatype. Otherwise the attribute's data will be initialized to all zero. */
size_t nelmts, /* The new number of elements in the attribute value, or SS_NOSIZE if the
* number of elements is not to be changed. If the number of elements
* decreases then the extra elements are discarded. If the number of elements
* increases then the new elements will be initialized to all zero bytes. */
unsigned flags /* Bit flags such as SS_ALLSAME. */
)
{
SS_ENTER(ss_attr_modify, herr_t);
void *values=NULL;
size_t old_nelmts;
SS_ASSERT_MEM(attr, ss_attr_t);
if (type>0) {
if (NULL==(values=ss_array_get(SS_ATTR_P(attr,value), type, (size_t)0, SS_NOSIZE, NULL))) {
/* Types are not conversion compatible; we'll zero them instead */
SS_STATUS_OK;
}
if (SS_NOSIZE==(old_nelmts=ss_array_nelmts(SS_ATTR_P(attr,value)))) SS_ERROR(FAILED);
if (ss_pers_modified((ss_pers_t*)attr, flags)<0) SS_ERROR(FAILED);
if (ss_array_resize(SS_ATTR_P(attr,value), 0)<0) SS_ERROR(FAILED); /*zero size or else we can't change the type*/
if (ss_array_target(SS_ATTR_P(attr,value), type)<0) SS_ERROR(FAILED);
if (ss_array_resize(SS_ATTR_P(attr,value), old_nelmts)<0) SS_ERROR(FAILED); /*restore original size*/
if (values && ss_array_put(SS_ATTR_P(attr,value), type, (size_t)0, old_nelmts, values)<0) SS_ERROR(FAILED);
values = SS_FREE(values);
}
if (SS_NOSIZE!=nelmts) {
if (ss_array_resize(SS_ATTR_P(attr,value), nelmts)<0) SS_ERROR(FAILED);
}
SS_CLEANUP:
SS_FREE(values);
SS_LEAVE(0);
}