summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJerome Soumagne <jsoumagne@hdfgroup.org>2016-04-27 20:35:17 (GMT)
committerJerome Soumagne <jsoumagne@hdfgroup.org>2016-11-29 23:42:33 (GMT)
commita2a663286f9d609029215079f26aed678cf19aff (patch)
tree400d22658862341b3df109f341bd7b31e9949576 /src
parentd8a3f4a5bcb83017c510ef659d9d8da6247cf5a7 (diff)
downloadhdf5-a2a663286f9d609029215079f26aed678cf19aff.zip
hdf5-a2a663286f9d609029215079f26aed678cf19aff.tar.gz
hdf5-a2a663286f9d609029215079f26aed678cf19aff.tar.bz2
Add H5Rcopy to copy an existing reference
Diffstat (limited to 'src')
-rw-r--r--src/H5R.c82
-rw-r--r--src/H5Rpublic.h1
2 files changed, 83 insertions, 0 deletions
diff --git a/src/H5R.c b/src/H5R.c
index d33ce53..7f6915a 100644
--- a/src/H5R.c
+++ b/src/H5R.c
@@ -52,6 +52,7 @@
/********************/
static htri_t H5R__equal(href_t _ref1, href_t _ref2);
+static href_t H5R__copy(href_t _ref);
static ssize_t H5R__get_file_name(href_t ref, char *name, size_t size);
@@ -1037,6 +1038,87 @@ done:
} /* end H5Requal() */
/*-------------------------------------------------------------------------
+ * Function: H5R__copy
+ *
+ * Purpose: Copy a reference
+ *
+ * Return: Success: Reference created
+ * Failure: NULL
+ *
+ *-------------------------------------------------------------------------
+ */
+static href_t
+H5R__copy(href_t _ref)
+{
+ struct href *ref = (struct href *) _ref; /* Reference */
+ struct href *new_ref = NULL;
+ href_t ret_value = NULL;
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ HDassert(ref);
+
+ /* Allocate the space to store the serialized information */
+ if(NULL == (new_ref = (struct href *)H5MM_malloc(sizeof(struct href))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Cannot allocate memory for reference")
+ new_ref->ref_type = ref->ref_type;
+
+ switch (ref->ref_type) {
+ case H5R_OBJECT:
+ new_ref->ref.addr = ref->ref.addr;
+ break;
+ case H5R_REGION:
+ case H5R_ATTR:
+ case H5R_EXT_OBJECT:
+ case H5R_EXT_REGION:
+ case H5R_EXT_ATTR:
+ if (0 == (new_ref->ref.serial.buf_size = ref->ref.serial.buf_size))
+ HGOTO_ERROR(H5E_REFERENCE, H5E_BADVALUE, NULL, "Invalid reference buffer size")
+ if (NULL == (new_ref->ref.serial.buf = H5MM_malloc(new_ref->ref.serial.buf_size)))
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTALLOC, NULL, "Cannot allocate reference buffer")
+ HDmemcpy(new_ref->ref.serial.buf, ref->ref.serial.buf, ref->ref.serial.buf_size);
+ break;
+ default:
+ HDassert("unknown reference type" && 0);
+ HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, NULL, "internal error (unknown reference type)")
+ }
+
+ ret_value = new_ref;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5R__copy() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5Rcopy
+ *
+ * Purpose: Copy a reference
+ *
+ * Return: Success: Reference created
+ * Failure: NULL
+ *
+ *-------------------------------------------------------------------------
+ */
+href_t
+H5Rcopy(href_t ref)
+{
+ href_t ret_value;
+
+ FUNC_ENTER_API(NULL)
+
+ /* Check args */
+ if(!ref)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid reference pointer")
+
+ /* Create reference */
+ if (NULL == (ret_value = H5R__copy(ref)))
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, NULL, "cannot copy reference")
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* end H5Rcopy() */
+
+/*-------------------------------------------------------------------------
* Function: H5R__get_object
*
* Purpose: Given a reference to some object, open that object and return an
diff --git a/src/H5Rpublic.h b/src/H5Rpublic.h
index 5bcf5ef..3077025 100644
--- a/src/H5Rpublic.h
+++ b/src/H5Rpublic.h
@@ -62,6 +62,7 @@ H5_DLL herr_t H5Rdestroy(href_t ref);
H5_DLL H5R_type_t H5Rget_type(href_t ref);
H5_DLL htri_t H5Requal(href_t ref1, href_t ref2);
+H5_DLL href_t H5Rcopy(href_t ref);
H5_DLL hid_t H5Rget_object(hid_t loc_id, hid_t oapl_id, href_t ref);
H5_DLL hid_t H5Rget_region2(hid_t loc_id, href_t ref);