From b5724779d0b10f610de10bf2ab88d62202160272 Mon Sep 17 00:00:00 2001 From: James Laird Date: Thu, 3 Aug 2006 17:35:58 -0500 Subject: [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". --- src/H5Lexternal.c | 12 ++++---- src/H5Lprivate.h | 4 +++ src/H5P.c | 5 ++++ src/H5Plapl.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- test/links.c | 5 +--- 5 files changed, 95 insertions(+), 13 deletions(-) diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c index 5609658..312028a 100644 --- a/src/H5Lexternal.c +++ b/src/H5Lexternal.c @@ -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); } diff --git a/src/H5Lprivate.h b/src/H5Lprivate.h index d5cc7d8..bfe3949 100644 --- a/src/H5Lprivate.h +++ b/src/H5Lprivate.h @@ -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 */ diff --git a/src/H5P.c b/src/H5P.c index 3aa66ce..144ce72 100644 --- a/src/H5P.c +++ b/src/H5P.c @@ -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 */ diff --git a/src/H5Plapl.c b/src/H5Plapl.c index cfe6b50..4a80cc2 100644 --- a/src/H5Plapl.c +++ b/src/H5Plapl.c @@ -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) +} + diff --git a/test/links.c b/test/links.c index 27449c8..0ecbf5e 100644 --- a/test/links.c +++ b/test/links.c @@ -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); -- cgit v0.12