diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2004-06-30 13:45:07 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2004-06-30 13:45:07 (GMT) |
commit | 358b8545dd9e3baa4b63c88a0d28aa8d7afb065b (patch) | |
tree | 50e0eac8be56d523b056778f4d3cac14dd777c28 /src | |
parent | 62f6531f2d3910a53c333047fdd941539eb6908f (diff) | |
download | hdf5-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')
-rw-r--r-- | src/H5F.c | 52 | ||||
-rw-r--r-- | src/H5Fpublic.h | 1 | ||||
-rw-r--r-- | src/H5I.c | 4 | ||||
-rw-r--r-- | src/H5MPprivate.h | 1 |
4 files changed, 57 insertions, 1 deletions
@@ -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() */ + diff --git a/src/H5Fpublic.h b/src/H5Fpublic.h index 911bdff..c372130 100644 --- a/src/H5Fpublic.h +++ b/src/H5Fpublic.h @@ -114,6 +114,7 @@ H5_DLL herr_t H5Fmount(hid_t loc, const char *name, hid_t child, hid_t plist); H5_DLL herr_t H5Funmount(hid_t loc, const char *name); H5_DLL hssize_t H5Fget_freespace(hid_t file_id); H5_DLL haddr_t H5Fget_filesize(hid_t file_id); +H5_DLL ssize_t H5Fget_name(hid_t obj_id, char *name, size_t size); #ifdef __cplusplus } @@ -2022,7 +2022,9 @@ H5I_find_id(hid_t id) * * Purpose: Gets a name of an object from its ID. * - * Return: Success: 0, Failure: -1 + * Return: Success: The length of name. + * + * Failure: -1 * * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu * diff --git a/src/H5MPprivate.h b/src/H5MPprivate.h index 126194e..24d709e 100644 --- a/src/H5MPprivate.h +++ b/src/H5MPprivate.h @@ -131,6 +131,7 @@ #define color_H5Funmount "red" #define color_H5Fget_freespace "red" #define color_H5Fget_filesize "red" +#define color_H5Fget_name "red" #define color_H5Gcreate "red" #define color_H5Gopen "red" |