summaryrefslogtreecommitdiffstats
path: root/tools/h5copy/h5copy.c
diff options
context:
space:
mode:
authorJonathan Kim <jkm@hdfgroup.org>2011-03-08 20:17:17 (GMT)
committerJonathan Kim <jkm@hdfgroup.org>2011-03-08 20:17:17 (GMT)
commit8245bf15728bb73ee4290cb70e08a63ada205657 (patch)
tree3bc66984ad197509630fb361de5f66f629a506d1 /tools/h5copy/h5copy.c
parent9d115d89f2297f3c6e1ae6c3ca35be4b1a9a8cc9 (diff)
downloadhdf5-8245bf15728bb73ee4290cb70e08a63ada205657.zip
hdf5-8245bf15728bb73ee4290cb70e08a63ada205657.tar.gz
hdf5-8245bf15728bb73ee4290cb70e08a63ada205657.tar.bz2
[svn-r20203] Purpose:
Fix Bug 2120 - h5copy: improve to copy an object into same HDF file Description: Before the fix users can't copy an object (dataset or group) with different name if input file (-i) and output file (-o) is same. This feature would be useful to clone any object with different name and reuse contents. Tested: jam (linux32-LE), amani (linux64-LE), heiwa (linuxppc64-BE), tejeda (mac32-LE), linew (solaris-BE), Cmake (jam)
Diffstat (limited to 'tools/h5copy/h5copy.c')
-rw-r--r--tools/h5copy/h5copy.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/tools/h5copy/h5copy.c b/tools/h5copy/h5copy.c
index 3760d6f..fb8bb81 100644
--- a/tools/h5copy/h5copy.c
+++ b/tools/h5copy/h5copy.c
@@ -319,6 +319,14 @@ main (int argc, const char *argv[])
leave(EXIT_FAILURE);
}
+ /*-------------------------------------------------------------------------
+ * open output file
+ *-------------------------------------------------------------------------*/
+
+ /* Attempt to open an existing HDF5 file first. Need to open the dst file
+ before the src file just in case that the dst and src are the same file
+ */
+ fid_dst = h5tools_fopen(fname_dst, H5F_ACC_RDWR, H5P_DEFAULT, NULL, NULL, 0);
/*-------------------------------------------------------------------------
* open input file
@@ -337,13 +345,11 @@ main (int argc, const char *argv[])
leave(EXIT_FAILURE);
}
+
/*-------------------------------------------------------------------------
- * open output file
+ * create an output file when failed to open it
*-------------------------------------------------------------------------*/
- /* Attempt to open an existing HDF5 file first */
- fid_dst = h5tools_fopen(fname_dst, H5F_ACC_RDWR, H5P_DEFAULT, NULL, NULL, 0);
-
/* If we couldn't open an existing file, try creating file */
/* (use "EXCL" instead of "TRUNC", so we don't blow away existing non-HDF5 file) */
if(fid_dst < 0)