summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>1999-03-23 21:48:57 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>1999-03-23 21:48:57 (GMT)
commit7fac298167389228750877573437df8c81884d7c (patch)
tree8bb1d86e0d136da52e432f74d21bcdba5d44eb5c
parent6cfb1f932022adb1adbea575f25584b4d7ec6574 (diff)
downloadhdf5-7fac298167389228750877573437df8c81884d7c.zip
hdf5-7fac298167389228750877573437df8c81884d7c.tar.gz
hdf5-7fac298167389228750877573437df8c81884d7c.tar.bz2
[svn-r1161] Modified H5Aread to fill the user's buffer with zero's (the fill value for
uninitialized attributes) if they read the attribute before any data is written to it or it's stored on disk.
-rw-r--r--src/H5A.c66
1 files changed, 36 insertions, 30 deletions
diff --git a/src/H5A.c b/src/H5A.c
index d5168d6..9ef6df5 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -754,7 +754,7 @@ H5Aread(hid_t attr_id, hid_t type_id, void *buf)
ERRORS
DESCRIPTION
- This function read a complete attribute to disk.
+ This function reads a complete attribute from disk.
--------------------------------------------------------------------------*/
static herr_t
H5A_read(H5A_t *attr, const H5T_t *mem_type, void *buf)
@@ -781,39 +781,45 @@ H5A_read(H5A_t *attr, const H5T_t *mem_type, void *buf)
src_type_size = H5T_get_size(attr->dt);
dst_type_size = H5T_get_size(mem_type);
- /* Get the maximum buffer size needed and allocate it */
- buf_size = nelmts*MAX(src_type_size,dst_type_size);
- if (NULL==(tconv_buf = H5MM_malloc (buf_size))) {
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
-
- /* Copy the attribute data into the buffer for conversion */
- HDmemcpy(tconv_buf,attr->data,src_type_size*nelmts);
+ /* Check if the attribute has any data yet, if not, fill with zeroes */
+ if(attr->ent_opened && !attr->initialized) {
+ HDmemset(buf,0,dst_type_size*nelmts);
+ } /* end if */
+ else { /* Attribute exists and has a value */
+ /* Get the maximum buffer size needed and allocate it */
+ buf_size = nelmts*MAX(src_type_size,dst_type_size);
+ if (NULL==(tconv_buf = H5MM_malloc (buf_size))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
- /* Convert memory buffer into disk buffer */
- /* Set up type conversion function */
- if (NULL == (tpath = H5T_path_find(attr->dt, mem_type, NULL, NULL))) {
- HGOTO_ERROR(H5E_ATTR, H5E_UNSUPPORTED, FAIL,
- "unable to convert between src and dest data types");
- } else if (!H5T_IS_NOOP(tpath)) {
- if ((src_id = H5I_register(H5I_DATATYPE,
- H5T_copy(attr->dt, H5T_COPY_ALL)))<0 ||
- (dst_id = H5I_register(H5I_DATATYPE,
- H5T_copy(mem_type, H5T_COPY_ALL)))<0) {
- HGOTO_ERROR(H5E_ATTR, H5E_CANTREGISTER, FAIL,
- "unable to register types for conversion");
+ /* Copy the attribute data into the buffer for conversion */
+ HDmemcpy(tconv_buf,attr->data,src_type_size*nelmts);
+
+ /* Convert memory buffer into disk buffer */
+ /* Set up type conversion function */
+ if (NULL == (tpath = H5T_path_find(attr->dt, mem_type, NULL, NULL))) {
+ HGOTO_ERROR(H5E_ATTR, H5E_UNSUPPORTED, FAIL,
+ "unable to convert between src and dest data types");
+ } else if (!H5T_IS_NOOP(tpath)) {
+ if ((src_id = H5I_register(H5I_DATATYPE,
+ H5T_copy(attr->dt, H5T_COPY_ALL)))<0 ||
+ (dst_id = H5I_register(H5I_DATATYPE,
+ H5T_copy(mem_type, H5T_COPY_ALL)))<0) {
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTREGISTER, FAIL,
+ "unable to register types for conversion");
+ }
}
- }
- /* Perform data type conversion. */
- if (H5T_convert(tpath, src_id, dst_id, nelmts, tconv_buf, NULL)<0) {
- HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL,
- "data type conversion failed");
- }
+ /* Perform data type conversion. */
+ if (H5T_convert(tpath, src_id, dst_id, nelmts, tconv_buf, NULL)<0) {
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL,
+ "data type conversion failed");
+ }
- /* Copy the converted data into the user's buffer */
- HDmemcpy(buf,tconv_buf,dst_type_size*nelmts);
+ /* Copy the converted data into the user's buffer */
+ HDmemcpy(buf,tconv_buf,dst_type_size*nelmts);
+ } /* end else */
ret_value=SUCCEED;