mirror of
https://github.com/HDFGroup/hdf5.git
synced 2024-11-27 02:10:55 +08:00
[svn-r12533] Standardized the way path prefixes are passed to external links using a
LAPL. Now there are H5Pget and H5Pset functions for "elink_prefixes".
This commit is contained in:
parent
b1e0516dd0
commit
b5724779d0
@ -50,6 +50,7 @@ static hid_t H5L_extern_traverse(const char * link_name, hid_t cur_group, void *
|
||||
hid_t fid;
|
||||
char *file_name;
|
||||
char *obj_name;
|
||||
char *prefix;
|
||||
size_t fname_len;
|
||||
htri_t result;
|
||||
hbool_t fname_alloc = FALSE;
|
||||
@ -60,25 +61,22 @@ static hid_t H5L_extern_traverse(const char * link_name, hid_t cur_group, void *
|
||||
obj_name = ((char *) udata) + fname_len + 1;
|
||||
|
||||
/* See if the external link prefix property is set */
|
||||
if((result = H5Pexist(lapl_id, H5L_ELINK_PREFIX_PROP)) < 0)
|
||||
if(H5Pget_elink_prefix(lapl_id, &prefix) < 0)
|
||||
goto error;
|
||||
|
||||
/* If so, prepend it to the filename */
|
||||
if(result > 0)
|
||||
if(prefix != NULL)
|
||||
{
|
||||
size_t buf_size;
|
||||
|
||||
if(H5Pget_size(lapl_id, H5L_ELINK_PREFIX_PROP, &buf_size) < 0)
|
||||
goto error;
|
||||
buf_size = HDstrlen(prefix);
|
||||
|
||||
/* Allocate a buffer to hold the filename plus prefix */
|
||||
file_name = malloc(buf_size + fname_len + 1);
|
||||
fname_alloc = TRUE;
|
||||
|
||||
if(H5Pget(lapl_id, H5L_ELINK_PREFIX_PROP, file_name) < 0)
|
||||
goto error;
|
||||
|
||||
/* Add the external link's filename to the prefix supplied */
|
||||
strcpy(file_name, prefix);
|
||||
strcat(file_name, udata);
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,10 @@
|
||||
#define H5L_NLINKS_SIZE sizeof(size_t)
|
||||
#define H5L_NLINKS_DEF 16 /*max symlinks to follow per lookup */
|
||||
|
||||
#define H5L_ELINK_PREFIX_NAME "external link prefix"
|
||||
#define H5L_ELINK_PREFIX_SIZE sizeof(char *)
|
||||
#define H5L_ELINK_PREFIX_DEF NULL /*default is no prefix */
|
||||
|
||||
/* Functions that understand link messages */
|
||||
/* forward reference for later use */
|
||||
struct H5HL_t; /* defined in H5HLprivate.h */
|
||||
|
@ -243,6 +243,7 @@ H5P_init_interface(void)
|
||||
*/
|
||||
H5P_genclass_t *lacc_class; /* Pointer to link access property list class created */
|
||||
size_t nlinks = H5L_NLINKS_DEF;
|
||||
char * elink_prefix = H5L_ELINK_PREFIX_DEF;
|
||||
/* Group creation property class variables. In sequence, they are,
|
||||
* - Creation property list class to modify
|
||||
* - Default value for "group info"
|
||||
@ -344,6 +345,10 @@ H5P_init_interface(void)
|
||||
if(H5P_register(lacc_class, H5L_NLINKS_NAME, H5L_NLINKS_SIZE,
|
||||
&nlinks, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0)
|
||||
HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class")
|
||||
/* Register property for external link prefix */
|
||||
if(H5P_register(lacc_class, H5L_ELINK_PREFIX_NAME, H5L_ELINK_PREFIX_SIZE,
|
||||
&elink_prefix, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0)
|
||||
HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class")
|
||||
} /* end if */
|
||||
|
||||
/* Register the group creation and group access property classes */
|
||||
|
@ -75,8 +75,6 @@ done:
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: H5Pget_nlinks
|
||||
*
|
||||
* Purpose: Get the number of soft or UD traversals allowed when using
|
||||
* this property list.
|
||||
* Purpose: Gets the number of soft or user-defined links that can be
|
||||
* traversed before a failure occurs.
|
||||
*
|
||||
@ -115,3 +113,83 @@ done:
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: H5Pset_elink_prefix
|
||||
*
|
||||
* Purpose: Set a prefix to be applied to the path of any external links
|
||||
* traversed. The prefix is appended to the filename stored
|
||||
* in the external link.
|
||||
*
|
||||
* The prefix is supplied by giving a pointer to a user-
|
||||
* allocated buffer. This buffer should not be freed
|
||||
* until this property list has been closed.
|
||||
*
|
||||
* Return: Non-negative on success/Negative on failure
|
||||
*
|
||||
* Programmer: James Laird
|
||||
* Thursday, August 3, 2006
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
herr_t
|
||||
H5Pset_elink_prefix(hid_t plist_id, const char *prefix)
|
||||
{
|
||||
H5P_genplist_t *plist; /* Property list pointer */
|
||||
herr_t ret_value = SUCCEED; /* Return value */
|
||||
|
||||
FUNC_ENTER_API(H5Pset_elink_prefix, FAIL)
|
||||
H5TRACE2("e","iz",plist_id,nlinks);
|
||||
|
||||
/* Get the plist structure */
|
||||
if(NULL == (plist = H5P_object_verify(plist_id, H5P_LINK_ACCESS)))
|
||||
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
|
||||
|
||||
/* Set prefix */
|
||||
if(H5P_set(plist, H5L_ELINK_PREFIX_NAME, &prefix) < 0)
|
||||
HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set prefix info")
|
||||
|
||||
done:
|
||||
FUNC_LEAVE_API(ret_value)
|
||||
} /* end H5Pset_elink_prefix() */
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: H5Pget_elink_prefix
|
||||
*
|
||||
* Purpose: Gets the prefix to be applied to any external link
|
||||
* traversals made using this property list.
|
||||
*
|
||||
* If the pointer is not NULL, it points to a user-allocated
|
||||
* buffer.
|
||||
*
|
||||
* Return: Non-negative on success/Negative on failure
|
||||
*
|
||||
* Programmer: James Laird
|
||||
* Thursday, August 3, 2006
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
herr_t
|
||||
H5Pget_elink_prefix(hid_t plist_id, char **prefix)
|
||||
{
|
||||
H5P_genplist_t *plist; /* Property list pointer */
|
||||
herr_t ret_value = SUCCEED; /* Return value */
|
||||
|
||||
FUNC_ENTER_API(H5Pget_elink_prefix, FAIL)
|
||||
H5TRACE2("e","i*z",plist_id,nlinks);
|
||||
|
||||
if(!prefix)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid pointer passed in");
|
||||
|
||||
/* Get the plist structure */
|
||||
if(NULL == (plist = H5P_object_verify(plist_id, H5P_LINK_ACCESS)))
|
||||
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
|
||||
|
||||
/* Get the current prefix */
|
||||
if(H5P_get(plist, H5L_ELINK_PREFIX_NAME, prefix) < 0)
|
||||
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get external link prefix")
|
||||
|
||||
done:
|
||||
FUNC_LEAVE_API(ret_value)
|
||||
}
|
||||
|
||||
|
@ -3187,11 +3187,9 @@ ext_link_endian(hid_t fapl)
|
||||
|
||||
/* Create a link access property list with the path to the srcdir */
|
||||
if((lapl_id = H5Pcreate(H5P_LINK_ACCESS)) < 0) TEST_ERROR;
|
||||
if(H5Pinsert(lapl_id, H5L_ELINK_PREFIX_PROP, strlen(pathbuf) + 1, pathbuf,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL) < 0) TEST_ERROR;
|
||||
if(H5Pset_elink_prefix(lapl_id, pathbuf) < 0) TEST_ERROR;
|
||||
|
||||
if(HDstrlen(pathbuf) + HDstrlen(LE_FILENAME) >= sizeof(namebuf)) TEST_ERROR;
|
||||
|
||||
HDstrcpy(namebuf, pathbuf);
|
||||
HDstrcat(namebuf, LE_FILENAME);
|
||||
|
||||
@ -3208,7 +3206,6 @@ ext_link_endian(hid_t fapl)
|
||||
if(H5Fclose(fid) < 0) TEST_ERROR;
|
||||
|
||||
if(HDstrlen(pathbuf) + HDstrlen(BE_FILENAME) >= sizeof(namebuf)) TEST_ERROR;
|
||||
|
||||
HDstrcpy(namebuf, pathbuf);
|
||||
HDstrcat(namebuf, BE_FILENAME);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user