/*------------------------------------------------------------------------- * Function: H5Iget_name * * Purpose: Gets a name of an object from its ID. * * Return: Success: The length of name. * * Failure: -1 * * Programmer: Pedro Vicente, [email protected] * * Date: July 26, 2002 * * Comments: Public function * 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. * If a zero is returned for the name's length, then there is no name * associated with the ID. * * Modifications: * *------------------------------------------------------------------------- */ ssize_t H5Iget_name(hid_t 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 (H5Iget_name, FAIL); H5TRACE3("Zs","ixz",id,name,size); /* get symbol table entry */ if(NULL!=(ent = H5G_loc(id))) { if (ent->user_path_r != NULL && ent->user_path_hidden==0) { len = H5RS_len(ent->user_path_r); if(name) { HDstrncpy(name, H5RS_get_str(ent->user_path_r), MIN(len+1,size)); if(len >= size) name[size-1]='\0'; } /* end if */ } /* end if */ } /* end if */ /* Set return value */ ret_value=(ssize_t)len; done: FUNC_LEAVE_API(ret_value); }
/**************************************************************** ** ** test_refstr_cmp(): Test basic H5RS (ref-counted strings) code. ** Tests comparing ref-counted strings. ** ****************************************************************/ static void test_refstr_cmp(void) { H5RS_str_t *rs1; /* Ref-counted string created */ H5RS_str_t *rs2; /* Ref-counted string created */ int cmp; /* Comparison value */ ssize_t len; /* Length of string */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Comparing Ref-Counted Strings\n")); /* Create first reference counted string */ rs1=H5RS_create("foo"); CHECK(rs1, NULL, "H5RS_create"); /* Create second reference counted string */ rs2=H5RS_create("foo2"); CHECK(rs2, NULL, "H5RS_create"); /* Compare the strings in various ways */ cmp=H5RS_cmp(rs1,rs1); VERIFY(cmp, 0, "H5RS_cmp"); cmp=H5RS_cmp(rs2,rs2); VERIFY(cmp, 0, "H5RS_cmp"); cmp=H5RS_cmp(rs1,rs2); if(cmp>=0) TestErrPrintf("%d: string comparison incorrect!\n",__LINE__); /* Check the lengths of the strings also */ len=H5RS_len(rs1); VERIFY(len, 3, "H5RS_len"); len=H5RS_len(rs2); VERIFY(len, 4, "H5RS_len"); /* Decrement reference count for strings */ ret=H5RS_decr(rs2); CHECK(ret, FAIL, "H5RS_decr"); ret=H5RS_decr(rs1); CHECK(ret, FAIL, "H5RS_decr"); } /* end test_refstr_cmp() */
/*-------------------------------------------------------------------------- NAME H5G_user_path_test PURPOSE Retrieve the user path for an ID USAGE herr_t H5G_user_path_test(obj_id, user_path, user_path_len) hid_t obj_id; IN: ID to check char *user_path; OUT: Pointer to buffer for User path size_t *user_path_len; OUT: Size of user path unsigned *obj_hidden; OUT: Whether object is hidden RETURNS Non-negative on success, negative on failure DESCRIPTION Retrieves the user path for an ID. A zero for the length is returned in the case of no user path. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS DO NOT USE THIS FUNCTION FOR ANYTHING EXCEPT TESTING EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ herr_t H5G_user_path_test(hid_t obj_id, char *user_path, size_t *user_path_len, unsigned *obj_hidden) { void *obj_ptr; /* Pointer to object for ID */ H5G_entry_t *obj_ent; /* Pointer to symbol table entry for obj */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5G_user_path_test, FAIL) /* Sanity check */ HDassert(user_path_len); HDassert(obj_hidden); /* Get pointer to object for ID */ if(NULL == (obj_ptr = H5I_object(obj_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get object for ID") /* Get the symbol table entry */ switch(H5I_get_type(obj_id)) { case H5I_GROUP: obj_ent = H5G_entof((H5G_t *)obj_ptr); break; case H5I_DATASET: obj_ent = H5D_entof((H5D_t *)obj_ptr); break; case H5I_DATATYPE: /* Avoid non-named datatypes */ if(!H5T_is_named((H5T_t *)obj_ptr)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a named datatype") obj_ent = H5T_entof((H5T_t *)obj_ptr); break; default: HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "unknown data object type") } /* end switch */ HDassert(obj_ent); /* Retrieve a copy of the user path and put it into the buffer */ if(obj_ent->user_path_r) { size_t len = H5RS_len(obj_ent->user_path_r); /* Set the user path, if given */ if(user_path) HDstrcpy(user_path, H5RS_get_str(obj_ent->user_path_r)); /* Set the length of the path */ *user_path_len = len; /* Set the user path hidden flag */ *obj_hidden = obj_ent->obj_hidden; } /* end if */ else { *user_path_len = 0; *obj_hidden = 0; } /* end else */ done: FUNC_LEAVE_NOAPI(ret_value) } /* H5G_user_path_test() */