summaryrefslogtreecommitdiffstats
path: root/tools/h5copy/h5copy.c
diff options
context:
space:
mode:
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)