summaryrefslogtreecommitdiffstats
path: root/src/H5Pdxpl.c
diff options
context:
space:
mode:
authorLeon Arber <larber@ncsa.uiuc.edu>2004-10-26 20:45:52 (GMT)
committerLeon Arber <larber@ncsa.uiuc.edu>2004-10-26 20:45:52 (GMT)
commit74d574632fd5aed6c11902caaa87aa33055bf2ce (patch)
tree546c5886311ec4bf600c44a223dd343adb4be200 /src/H5Pdxpl.c
parent3b63db5f7fb8299ab60a2af8a709e9e33764c11e (diff)
downloadhdf5-74d574632fd5aed6c11902caaa87aa33055bf2ce.zip
hdf5-74d574632fd5aed6c11902caaa87aa33055bf2ce.tar.gz
hdf5-74d574632fd5aed6c11902caaa87aa33055bf2ce.tar.bz2
[svn-r9461] Purpose:
Changed functionality of H5Pget_data_transform Description: H5Pget_data_transform no longer allocates memory for the transform string...it is the user's responsbility to do so. Solution: Made H5Pget_data_transform be more in line with other functions that do similiar things: User now has to allocate memory for the string themselves and specify how much of the string should be copied into the buffer. There is also support for querying the length of the transform string. Platforms tested: sol + eirene + copper Misc. update:
Diffstat (limited to 'src/H5Pdxpl.c')
-rw-r--r--src/H5Pdxpl.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/H5Pdxpl.c b/src/H5Pdxpl.c
index 430c025..5941a19 100644
--- a/src/H5Pdxpl.c
+++ b/src/H5Pdxpl.c
@@ -85,40 +85,65 @@ done:
*
* Purpose:
* Gets data transform expression.
- *
*
* Return: Returns a non-negative value if successful; otherwise returns a negative value.
*
+ * Comments:
+ * If `expression' is non-NULL then write up to `size' bytes into that
+ * buffer and always return the length of the transform name.
+ * Otherwise `size' is ignored and the function does not store the expression,
+ * just returning the number of characters required to store the expression.
+ * If an error occurs then the buffer pointed to by `expression' (NULL or non-NULL)
+ * is unchanged and the function returns a negative value.
+ * If a zero is returned for the name's length, then there is no name
+ * associated with the ID.
*
* Programmer: Leon Arber
* August 27, 2004
*
* Modifications:
- *
+ * October 20, 2004 LA: Changed API to use size and return ssize_t
*-------------------------------------------------------------------------
*/
-herr_t H5Pget_data_transform(hid_t plist_id, char** expression)
+ssize_t H5Pget_data_transform(hid_t plist_id, char* expression /*out*/, size_t size)
{
H5P_genplist_t *plist; /* Property list pointer */
H5Z_data_xform_t *data_xform_prop=NULL; /* New data xform property */
- herr_t ret_value=SUCCEED; /* return value */
+ ssize_t ret_value; /* return value */
+
+ size_t len;
+ char* pexp;
FUNC_ENTER_API(H5Pget_data_transform, FAIL);
- /* Check arguments */
- if (expression == NULL)
- HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "expression cannot be NULL");
-
/* Get the plist structure */
if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_XFER)))
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID");
if(H5P_get(plist, H5D_XFER_XFORM_NAME, &data_xform_prop)<0)
- HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "Error setting data transform expression");
+ HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Error getting data transform expression");
+ if(NULL == data_xform_prop)
+ HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Cannot get a data transform that has not been set");
+
/* Get the data transform string */
- *expression = H5Z_xform_extract_xform_str(data_xform_prop);
+ pexp = H5Z_xform_extract_xform_str(data_xform_prop);
+
+ if(!pexp)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Failed to retrieve transform expression");
+
+ len = HDstrlen(pexp);
+ if(expression)
+ {
+ /* sanity check */
+ if(size > len)
+ size = len;
+
+ HDstrncpy(expression, pexp, size);
+ }
+
+ ret_value = (ssize_t)len;
done:
if(ret_value<0) {