diff options
author | James Laird <jlaird@hdfgroup.org> | 2006-08-24 00:52:21 (GMT) |
---|---|---|
committer | James Laird <jlaird@hdfgroup.org> | 2006-08-24 00:52:21 (GMT) |
commit | 9edac8a668f823aa7a60a97e4332216619609ba5 (patch) | |
tree | d3ba30d52bdaac0270ea68046cddeac8938765dc /src | |
parent | afb817a0a71058e02625fb67f3935ddd33a48404 (diff) | |
download | hdf5-9edac8a668f823aa7a60a97e4332216619609ba5.zip hdf5-9edac8a668f823aa7a60a97e4332216619609ba5.tar.gz hdf5-9edac8a668f823aa7a60a97e4332216619609ba5.tar.bz2 |
[svn-r12623] Added H5Fget_intent() function to get the "intent" of a file (read/write or
read-only).
Added this to external links, so that external files are opened with the
same intent as the source file.
Added tests.
Diffstat (limited to 'src')
-rw-r--r-- | src/H5F.c | 45 | ||||
-rw-r--r-- | src/H5Fpublic.h | 1 | ||||
-rw-r--r-- | src/H5Lexternal.c | 11 |
3 files changed, 56 insertions, 1 deletions
@@ -2729,6 +2729,51 @@ done: HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close file") FUNC_LEAVE_API(ret_value) } + + +/*------------------------------------------------------------------------- + * Function: H5Fget_intent + * + * Purpose: Public API to retrieve the file's 'intent' flags passed + * during H5Fopen() + * + * Return: Non-negative on success/negative on failure + * + * Programmer: James Laird + * August 23, 2006 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5Fget_intent(hid_t file_id, unsigned *intent_flags) +{ + H5F_t * file = NULL; + herr_t ret_value; + FUNC_ENTER_API(H5Fget_intent, FAIL) + + if (NULL==(file=H5I_object_verify(file_id, H5I_FILE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file") + + /* If no intent flags were passed in, exit quietly */ + if(!intent_flags) + HGOTO_DONE(SUCCEED) + + *intent_flags = H5F_get_intent(file); + + /* HDF5 uses some flags internally that users don't know about. + * Simplify things for them so that they get one of H5F_ACC_RDWR + * or H5F_ACC_RDONLY. + */ + if(*intent_flags & H5F_ACC_RDWR) + *intent_flags = H5F_ACC_RDWR; + else + *intent_flags = H5F_ACC_RDONLY; + +done: + FUNC_LEAVE_API(ret_value) +} /*------------------------------------------------------------------------- diff --git a/src/H5Fpublic.h b/src/H5Fpublic.h index 7243c98..d3ae119 100644 --- a/src/H5Fpublic.h +++ b/src/H5Fpublic.h @@ -114,6 +114,7 @@ H5_DLL herr_t H5Fflush(hid_t object_id, H5F_scope_t scope); H5_DLL herr_t H5Fclose (hid_t file_id); H5_DLL hid_t H5Fget_create_plist (hid_t file_id); H5_DLL hid_t H5Fget_access_plist (hid_t file_id); +H5_DLL herr_t H5Fget_intent(hid_t file_id, unsigned * intent); H5_DLL int H5Fget_obj_count(hid_t file_id, unsigned types); H5_DLL int H5Fget_obj_ids(hid_t file_id, unsigned types, int max_objs, hid_t *obj_id_list); H5_DLL herr_t H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void** file_handle); diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c index 612c4c6..3452c20 100644 --- a/src/H5Lexternal.c +++ b/src/H5Lexternal.c @@ -53,6 +53,7 @@ static hid_t H5L_extern_traverse(const char * link_name, hid_t cur_group, void * char *prefix; size_t fname_len; hbool_t fname_alloc = FALSE; + unsigned intent; hid_t ret_value = -1; file_name = (char *) udata; @@ -79,7 +80,15 @@ static hid_t H5L_extern_traverse(const char * link_name, hid_t cur_group, void * strcat(file_name, udata); } - if((fid = H5Fopen(file_name, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + /* Figure out if we should open with read-write or read-only */ + if((fid = H5Iget_file_id(cur_group)) < 0) + goto error; + if(H5Fget_intent(fid, &intent) < 0) + goto error; + if(H5Fclose(fid) < 0) + goto error; + + if((fid = H5Fopen(file_name, intent, H5P_DEFAULT)) < 0) goto error; ret_value = H5Oopen(fid, obj_name, lapl_id); /* If this fails, our return value will be negative. */ if(H5Fclose(fid) < 0) |