summaryrefslogtreecommitdiffstats
path: root/src/H5F.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2004-06-30 13:45:07 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2004-06-30 13:45:07 (GMT)
commit358b8545dd9e3baa4b63c88a0d28aa8d7afb065b (patch)
tree50e0eac8be56d523b056778f4d3cac14dd777c28 /src/H5F.c
parent62f6531f2d3910a53c333047fdd941539eb6908f (diff)
downloadhdf5-358b8545dd9e3baa4b63c88a0d28aa8d7afb065b.zip
hdf5-358b8545dd9e3baa4b63c88a0d28aa8d7afb065b.tar.gz
hdf5-358b8545dd9e3baa4b63c88a0d28aa8d7afb065b.tar.bz2
[svn-r8765] Purpose: New feature and its test.
Description: Added new API H5Fget_name and new test program called filename.c. This function returns the name of the file by object ID(file, group, dataset, named datatype, and attribute) which belongs to the file. Platforms tested: h5committest and fuss. Misc. update: MANIFEST and RELEASE.txt
Diffstat (limited to 'src/H5F.c')
-rw-r--r--src/H5F.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/H5F.c b/src/H5F.c
index 72c1265..2dc7880 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -4743,3 +4743,55 @@ H5Fget_filesize(hid_t file_id)
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Fget_filesize() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5Fget_name
+ *
+ * Purpose: Gets the name of the file to which object OBJ_ID belongs.
+ * If `name' is non-NULL then write up to `size' bytes into that
+ * buffer and always return the length of the entry name.
+ * Otherwise `size' is ignored and the function does not store the name,
+ * just returning the number of characters required to store the name.
+ * If an error occurs then the buffer pointed to by `name' (NULL or non-NULL)
+ * is unchanged and the function returns a negative value.
+ *
+ * Return: Success: The length of the file name
+ * Failure: Negative
+ *
+ * Programmer: Raymond Lu
+ * June 29, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+ssize_t
+H5Fget_name(hid_t obj_id, char *name/*out*/, size_t size)
+{
+ H5G_entry_t *ent; /*symbol table entry */
+ size_t len=0;
+ ssize_t ret_value;
+
+ FUNC_ENTER_API (H5Fget_name, FAIL);
+ H5TRACE3("Zs","ixz",obj_id,name,size);
+
+ /* get symbol table entry */
+ if((ent = H5G_loc(obj_id))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object ID")
+
+ len = HDstrlen(ent->file->name);
+
+ if(name) {
+ HDstrncpy(name, ent->file->name, MIN(len+1,size));
+ if(len >= size)
+ name[size-1]='\0';
+ } /* end if */
+
+ /* Set return value */
+ ret_value=(ssize_t)len;
+
+done:
+ FUNC_LEAVE_API(ret_value);
+} /* end H5Fget_name() */
+