herr_t
ss_prop_set(ss_prop_t *prop, /* property list to be modified */
const char *name, /* optional name of property to be modified */
hid_t type, /* optional datatype for supplied value */
const void *value /* optional new property value */
)
{
SS_ENTER(ss_prop_set, herr_t);
hid_t stored_type=-1; /* datatype stored in the property list */
void *convbuf=NULL; /* temporary buffer for data conversion */
void *dest=NULL; /* value's destination in the property list */
if (!prop->modifiable) SS_ERROR(PERM);
if ((stored_type=ss_prop_type(prop, name))<0) SS_ERROR(FAILED);
if (NULL==(dest=ss_prop_buffer(prop, name))) SS_ERROR(FAILED);
/* Store new value. If a conversion is necessary we must allocate a temporary buffer for it because we don't want to
* modify the caller's memory nor do we want to change the property value until we're sure the conversion worked. */
if (value) {
if (type<=0 || H5Tequal(type, stored_type)>0) {
memcpy(dest, value, H5Tget_size(stored_type));
} else {
size_t buf_size = MAX(H5Tget_size(type), H5Tget_size(stored_type));
if (NULL==(convbuf = malloc(buf_size))) SS_ERROR(RESOURCE);
memcpy(convbuf, value, H5Tget_size(type));
if (H5Tconvert(type, stored_type, 1, convbuf, NULL, H5P_DEFAULT)<0) SS_ERROR(HDF5);
memcpy(dest, convbuf, H5Tget_size(stored_type));
convbuf = SS_FREE(convbuf);
}
} else {
memset(dest, 0, H5Tget_size(stored_type));
}
H5Tclose(stored_type);
stored_type=-1;
SS_CLEANUP:
if (stored_type>0) H5Tclose(stored_type);
SS_FREE(convbuf);
SS_LEAVE(0);
}