summaryrefslogtreecommitdiffstats
path: root/src/H5Lexternal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Lexternal.c')
-rw-r--r--src/H5Lexternal.c102
1 files changed, 45 insertions, 57 deletions
diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c
index aae3684..ed3d39a 100644
--- a/src/H5Lexternal.c
+++ b/src/H5Lexternal.c
@@ -157,25 +157,10 @@ done:
* link access property list, appends that prefix to the
* filename being opened.
*
- * Return: ID of the opened object on success/Negative on failure
+ * Return: ID of the opened object on success/H5I_INVALID_HID on failure
*
* Programmer: James Laird
* Monday, July 10, 2006
- * Modifications:
- * Vailin Choi, April 2, 2008
- * Add handling to search for the target file
- * See description in RM: H5Lcreate_external
- *
- * Vailin Choi; Sept. 12th, 2008; bug #1247
- * Retrieve the file access property list identifer that is set
- * for link access property via H5Pget_elink_fapl().
- * If the return value is H5P_DEFAULT, the parent's file access
- * property is used to H5F_open() the target file;
- * Otherwise, the file access property retrieved from H5Pget_elink_fapl()
- * is used to H5F_open() the target file.
- *
- * Vailin Choi; Nov 2010
- * Free memory pointed to by tmp_env_prefix for HDF5_EXT_PREFIX case.
*
*-------------------------------------------------------------------------
*/
@@ -204,18 +189,18 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
char * actual_file_name = NULL; /* Parent file's actual name */
H5P_genplist_t * fa_plist; /* File access property list pointer */
H5F_close_degree_t fc_degree = H5F_CLOSE_WEAK; /* File close degree for target file */
- hid_t ret_value; /* Return value */
+ hid_t ret_value = H5I_INVALID_HID; /* Return value */
- FUNC_ENTER_NOAPI(FAIL)
+ FUNC_ENTER_NOAPI(H5I_INVALID_HID)
/* Sanity checks */
HDassert(p);
/* Check external link version & flags */
if (((*p >> 4) & 0x0F) > H5L_EXT_VERSION)
- HGOTO_ERROR(H5E_LINK, H5E_CANTDECODE, FAIL, "bad version number for external link")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTDECODE, H5I_INVALID_HID, "bad version number for external link")
if ((*p & 0x0F) & ~H5L_EXT_FLAGS_ALL)
- HGOTO_ERROR(H5E_LINK, H5E_CANTDECODE, FAIL, "bad flags for external link")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTDECODE, H5I_INVALID_HID, "bad flags for external link")
p++;
/* Gather some information from the external link's user data */
@@ -225,19 +210,19 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
/* Get the plist structure */
if (NULL == (plist = H5P_object_verify(lapl_id, H5P_LINK_ACCESS)))
- HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
+ HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5I_INVALID_HID, "can't find object for ID")
/* Get the fapl_id set for lapl_id if any */
if (H5P_get(plist, H5L_ACS_ELINK_FAPL_NAME, &fapl_id) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fapl for links")
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't get fapl for links")
/* Get the location for the group holding the external link */
if (H5G_loc(cur_group, &loc) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't get object location")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, H5I_INVALID_HID, "can't get object location")
/* get the access flags set for lapl_id if any */
if (H5P_get(plist, H5L_ACS_ELINK_FLAGS_NAME, &intent) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get elink file access flags")
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't get elink file access flags")
/* get the file access mode flags for the parent file, if they were not set
* on lapl_id */
@@ -245,15 +230,15 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
intent = H5F_INTENT(loc.oloc->file);
if ((fapl_id == H5P_DEFAULT) && ((fapl_id = H5F_get_access_plist(loc.oloc->file, FALSE)) < 0))
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't get parent's file access property list")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, H5I_INVALID_HID, "can't get parent's file access property list")
/* Get callback_info */
if (H5P_get(plist, H5L_ACS_ELINK_CB_NAME, &cb_info) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get elink callback info")
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't get elink callback info")
/* Get file access property list */
if (NULL == (fa_plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS)))
- HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
+ HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5I_INVALID_HID, "can't find object for ID")
/* Make callback if it exists */
if (cb_info.func) {
@@ -265,7 +250,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
/* Query length of parent group name */
if ((group_name_len = H5G_get_name(&loc, NULL, (size_t)0, NULL, lapl_id, H5AC_ind_dxpl_id)) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to retrieve length of group name")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, H5I_INVALID_HID, "unable to retrieve length of group name")
/* Account for null terminator */
group_name_len++;
@@ -273,8 +258,8 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
/* Check if we need to allocate larger buffer */
if ((size_t)group_name_len > sizeof(local_group_name)) {
if (NULL == (parent_group_name = (char *)H5MM_malloc((size_t)group_name_len)))
- HGOTO_ERROR(H5E_LINK, H5E_CANTALLOC, FAIL,
- "can't allocate buffer to hold group name, group_name_len = %Zu", group_name_len)
+ HGOTO_ERROR(H5E_LINK, H5E_CANTALLOC, H5I_INVALID_HID,
+ "can't allocate buffer to hold group name, group_name_len = %zd", group_name_len)
} /* end if */
else
parent_group_name = local_group_name;
@@ -282,21 +267,21 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
/* Get parent group name */
if (H5G_get_name(&loc, parent_group_name, (size_t)group_name_len, NULL, lapl_id, H5AC_ind_dxpl_id) <
0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to retrieve group name")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, H5I_INVALID_HID, "unable to retrieve group name")
/* Make callback */
if ((cb_info.func)(parent_file_name, parent_group_name, file_name, obj_name, &intent, fapl_id,
cb_info.user_data) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CALLBACK, FAIL, "traversal operator failed")
+ HGOTO_ERROR(H5E_LINK, H5E_CALLBACK, H5I_INVALID_HID, "traversal operator failed")
/* Check access flags */
if ((intent & H5F_ACC_TRUNC) || (intent & H5F_ACC_EXCL))
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file open flags")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid file open flags")
} /* end if */
/* Set file close degree for new file to "weak" */
if (H5P_set(fa_plist, H5F_ACS_CLOSE_DEGREE_NAME, &fc_degree) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set file close degree")
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, H5I_INVALID_HID, "can't set file close degree")
/*
* Start searching for the target file
@@ -307,7 +292,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
/* Copy the file name to use */
if (NULL == (temp_file_name = H5MM_strdup(file_name)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5I_INVALID_HID, "memory allocation failed")
temp_file_name_len = HDstrlen(temp_file_name);
/* target file_name is an absolute pathname: see RM for detailed description */
@@ -352,7 +337,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
char *tmp_env_prefix, *saved_env;
if (NULL == (saved_env = tmp_env_prefix = H5MM_strdup(env_prefix)))
- HGOTO_ERROR(H5E_LINK, H5E_NOSPACE, FAIL, "memory allocation failed")
+ HGOTO_ERROR(H5E_LINK, H5E_NOSPACE, H5I_INVALID_HID, "memory allocation failed")
while ((tmp_env_prefix) && (*tmp_env_prefix)) {
char *out_prefix_name;
@@ -361,7 +346,8 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
if (out_prefix_name && (*out_prefix_name)) {
if (H5L_build_name(out_prefix_name, temp_file_name, &full_name /*out*/) < 0) {
saved_env = (char *)H5MM_xfree(saved_env);
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, H5I_INVALID_HID,
+ "can't prepend prefix to filename")
} /* end if */
ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT,
@@ -379,10 +365,10 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
/* try searching from property list */
if (ext_file == NULL) {
if (H5P_get(plist, H5L_ACS_ELINK_PREFIX_NAME, &my_prefix) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get external link prefix")
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't get external link prefix")
if (my_prefix) {
if (H5L_build_name(my_prefix, temp_file_name, &full_name /*out*/) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, H5I_INVALID_HID, "can't prepend prefix to filename")
if (NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT,
fapl_id, H5AC_dxpl_id)))
H5E_clear_stack(NULL);
@@ -396,7 +382,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
if (NULL != (extpath = H5F_EXTPATH(loc.oloc->file))) {
if (H5L_build_name(extpath, temp_file_name, &full_name /*out*/) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, H5I_INVALID_HID, "can't prepend prefix to filename")
if (NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT,
fapl_id, H5AC_dxpl_id)))
H5E_clear_stack(NULL);
@@ -419,12 +405,12 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
/* Copy resolved file name */
if (NULL == (actual_file_name = H5MM_strdup(H5F_ACTUAL_NAME(loc.oloc->file))))
- HGOTO_ERROR(H5E_LINK, H5E_CANTALLOC, FAIL, "can't duplicate resolved file name string")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTALLOC, H5I_INVALID_HID, "can't duplicate resolved file name string")
/* get last component of file_name */
H5_GET_LAST_DELIMITER(actual_file_name, ptr)
if (!ptr)
- HGOTO_ERROR(H5E_LINK, H5E_CANTOPENFILE, FAIL,
+ HGOTO_ERROR(H5E_LINK, H5E_CANTOPENFILE, H5I_INVALID_HID,
"unable to open external file, external link file name = '%s', temp_file_name = '%s'",
file_name, temp_file_name)
@@ -433,12 +419,12 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
/* Build new file name for the external file */
if (H5L_build_name(actual_file_name, temp_file_name, &full_name /*out*/) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, H5I_INVALID_HID, "can't prepend prefix to filename")
/* Try opening with the resolved name */
if (NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT,
fapl_id, H5AC_dxpl_id)))
- HGOTO_ERROR(H5E_LINK, H5E_CANTOPENFILE, FAIL,
+ HGOTO_ERROR(H5E_LINK, H5E_CANTOPENFILE, H5I_INVALID_HID,
"unable to open external file, external link file name = '%s', temp_file_name = '%s'",
file_name, temp_file_name)
full_name = (char *)H5MM_xfree(full_name);
@@ -446,11 +432,11 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
/* Retrieve the "group location" for the file's root group */
if (H5G_root_loc(ext_file, &root_loc) < 0)
- HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "unable to create location for file")
+ HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, H5I_INVALID_HID, "unable to create location for file")
/* Open the object referenced in the external file */
if ((ext_obj = H5O_open_name(&root_loc, obj_name, lapl_id, FALSE)) < 0)
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open object")
+ HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object")
/* Set return value */
ret_value = ext_obj;
@@ -458,9 +444,10 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group, const
done:
/* Release resources */
if (fapl_id > 0 && H5I_dec_ref(fapl_id) < 0)
- HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, FAIL, "unable to close atom for file access property list")
+ HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, H5I_INVALID_HID,
+ "unable to close atom for file access property list")
if (ext_file && H5F_efc_close(loc.oloc->file, ext_file) < 0)
- HDONE_ERROR(H5E_LINK, H5E_CANTCLOSEFILE, FAIL, "problem closing external file")
+ HDONE_ERROR(H5E_LINK, H5E_CANTCLOSEFILE, H5I_INVALID_HID, "problem closing external file")
if (parent_group_name && parent_group_name != local_group_name)
parent_group_name = (char *)H5MM_xfree(parent_group_name);
full_name = (char *)H5MM_xfree(full_name);
@@ -470,7 +457,8 @@ done:
if (ret_value < 0) {
/* Close object if it's open and something failed */
if (ext_obj >= 0 && H5I_dec_ref(ext_obj) < 0)
- HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, FAIL, "unable to close atom for external object")
+ HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, H5I_INVALID_HID,
+ "unable to close atom for external object")
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -479,16 +467,16 @@ done:
/*-------------------------------------------------------------------------
* Function: H5L_extern_query
*
- * Purpose: Default query function for external links. This can
+ * Purpose: Default query function for external links. This can
* be overridden using H5Lregister().
*
* Returns the size of the link's user data. If a buffer of
* is provided, copies at most buf_size bytes of the udata
* into it.
*
- * Return: Size of buffer on success/Negative on failure
+ * Return: Size of buffer on success/Negative on failure
*
- * Programmer: James Laird
+ * Programmer: James Laird
* Monday, July 10, 2006
*
*-------------------------------------------------------------------------
@@ -526,21 +514,21 @@ done:
} /* end H5L_extern_query() */
/*-------------------------------------------------------------------------
- * Function: H5Lcreate_external
+ * Function: H5Lcreate_external
*
- * Purpose: Creates an external link from LINK_NAME to OBJ_NAME.
+ * Purpose: Creates an external link from LINK_NAME to OBJ_NAME.
*
* External links are links to objects in other HDF5 files. They
* are allowed to "dangle" like soft links internal to a file.
* FILE_NAME is the name of the file that OBJ_NAME is is contained
* within. If OBJ_NAME is given as a relative path name, the
* path will be relative to the root group of FILE_NAME.
- * LINK_NAME is interpreted relative to LINK_LOC_ID, which is
+ * LINK_NAME is interpreted relative to LINK_LOC_ID, which is
* either a file ID or a group ID.
*
- * Return: Non-negative on success/Negative on failure
+ * Return: Non-negative on success/Negative on failure
*
- * Programmer: Quincey Koziol
+ * Programmer: Quincey Koziol
* Wednesday, May 18, 2005
*
*-------------------------------------------------------------------------