summaryrefslogtreecommitdiffstats
path: root/hl/src
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2005-02-22 17:14:13 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2005-02-22 17:14:13 (GMT)
commit7ff30cd69523ea8379c1ebbd7efb95eed80a6925 (patch)
treeeba9754de140a9fbd260f4edde637546eb046962 /hl/src
parent643e9a38bd78fcf6c16127731693e6720bc6b22b (diff)
downloadhdf5-7ff30cd69523ea8379c1ebbd7efb95eed80a6925.zip
hdf5-7ff30cd69523ea8379c1ebbd7efb95eed80a6925.tar.gz
hdf5-7ff30cd69523ea8379c1ebbd7efb95eed80a6925.tar.bz2
[svn-r10063] Purpose:
changed the function H5DSget_scale_name to return the size of the name buffer added a test Description: Solution: Platforms tested: linux solaris Misc. update:
Diffstat (limited to 'hl/src')
-rw-r--r--hl/src/H5DS.c99
-rw-r--r--hl/src/H5DS.h11
2 files changed, 84 insertions, 26 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index 5ad4b0c..bc22625 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -10,7 +10,7 @@
* *
****************************************************************************/
-
+#include "H5private.h"
#include "H5DS.h"
#include "H5LT.h"
#include <stdlib.h>
@@ -1329,11 +1329,17 @@ out:
*-------------------------------------------------------------------------
*/
-herr_t H5DSget_scale_name(hid_t did,
- char *buf)
+ssize_t H5DSget_scale_name(hid_t did,
+ char *name,
+ size_t size)
{
- H5I_type_t it; /* ID type */
- int has_name;
+ hid_t aid; /* attribute ID */
+ hid_t tid; /* attribute type ID */
+ hid_t sid; /* space ID */
+ H5I_type_t it; /* ID type */
+ size_t len;
+ int has_name;
+ char *buf=NULL;
/*-------------------------------------------------------------------------
* parameter checking
@@ -1358,14 +1364,72 @@ herr_t H5DSget_scale_name(hid_t did,
if ((has_name = H5LT_find_attribute(did,"NAME"))<0)
return FAIL;
- if (has_name == 1)
+ if (has_name == 0)
+ return FAIL;
+
+/*-------------------------------------------------------------------------
+ * open the attribute
+ *-------------------------------------------------------------------------
+ */
+
+ if ((aid = H5Aopen_name(did,"NAME"))<0)
+ return FAIL;
+
+ /* get space */
+ if ((sid = H5Aget_space(aid))<0)
+ goto out;
+
+ /* get type */
+ if ((tid = H5Aget_type(aid))<0)
+ goto out;
+
+ /* get the size */
+ if ((len = H5Tget_size(tid))<0)
+ goto out;
+
+ /* allocate a temporary buffer */
+ buf = (char*)malloc(len * sizeof(char));
+ if (buf == NULL)
+ goto out;
+
+ /* read */
+ if (H5Aread(aid,tid,buf)<0)
+ goto out;
+
+ /* compute the string length which will fit into the user's buffer, copy all/some of the name */
+ if(name)
{
- /* get the attribute */
- if (H5LT_get_attribute_disk(did,"NAME",buf)<0)
- return FAIL;
+ HDstrncpy(name, buf, MIN(len+1,size));
+ if(len >= size)
+ name[size-1]='\0';
+ } /* end if */
+
+ /* close */
+ if (H5Tclose(tid)<0)
+ goto out;
+ if (H5Aclose(aid)<0)
+ goto out;
+ if (H5Sclose(sid)<0)
+ goto out;
+ if (buf)
+ {
+ free(buf);
+ buf=NULL;
}
- return SUCCESS;
+
+ return (ssize_t) len;
+
+ /* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Aclose(aid);
+ H5Tclose(tid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ if (buf)
+ free(buf);
+ return FAIL;
}
@@ -1618,15 +1682,8 @@ out:
}
-
/*-------------------------------------------------------------------------
- * private functions
- *-------------------------------------------------------------------------
- */
-
-
-/*-------------------------------------------------------------------------
- * Function: H5DS_is_attached
+ * Function: H5DSis_attached
*
* Purpose: Checks if the dataset named DNAME has a pointer in the REFERENCE_LIST
* attribute and the the dataset named DSNAME (scale ) has a pointer in the
@@ -1648,9 +1705,9 @@ out:
*-------------------------------------------------------------------------
*/
-htri_t H5DS_is_attached(hid_t did,
- hid_t dsid,
- unsigned int idx)
+htri_t H5DSis_attached(hid_t did,
+ hid_t dsid,
+ unsigned int idx)
{
int has_dimlist;
int has_reflist;
diff --git a/hl/src/H5DS.h b/hl/src/H5DS.h
index 2bd57d9..4ae47ef 100644
--- a/hl/src/H5DS.h
+++ b/hl/src/H5DS.h
@@ -63,8 +63,9 @@ herr_t H5DSget_label(hid_t did,
char *label,
unsigned int idx);
-herr_t H5DSget_scale_name(hid_t did,
- char *buf);
+ssize_t H5DSget_scale_name(hid_t did,
+ char *name,
+ size_t size);
herr_t H5DSis_scale(hid_t did);
@@ -74,9 +75,9 @@ herr_t H5DSiterate_scales(hid_t did,
H5DS_iterate_t visitor,
void *visitor_data);
-htri_t H5DS_is_attached(hid_t did,
- hid_t dsid,
- unsigned int idx);
+htri_t H5DSis_attached(hid_t did,
+ hid_t dsid,
+ unsigned int idx);
#ifdef __cplusplus