summaryrefslogtreecommitdiffstats
path: root/test/h5test.c
diff options
context:
space:
mode:
authorLarry Knox <lrknox@hdfgroup.org>2009-10-15 22:14:10 (GMT)
committerLarry Knox <lrknox@hdfgroup.org>2009-10-15 22:14:10 (GMT)
commit62521fcb96cbaaa5befc598ebf518d79f2fa7ac3 (patch)
tree26b8fd3df7f5c8b4c8bac81f3d1c2541b46bfa97 /test/h5test.c
parent148828d46a193048e99df253c429bc0ea307de1a (diff)
downloadhdf5-62521fcb96cbaaa5befc598ebf518d79f2fa7ac3.zip
hdf5-62521fcb96cbaaa5befc598ebf518d79f2fa7ac3.tar.gz
hdf5-62521fcb96cbaaa5befc598ebf518d79f2fa7ac3.tar.bz2
[svn-r17656] Added h5_make_local_copy function to address bug 1630, and refactored tests that were discovered to copy data files to avoid writing to data files checked into svn to use the new function.
Tested on amani, jam, and linew with h5committest and on jam with a read only mount of source files on pegdub.
Diffstat (limited to 'test/h5test.c')
-rw-r--r--test/h5test.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/h5test.c b/test/h5test.c
index 03e857f..a5b50d3 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -71,6 +71,9 @@ char *paraprefix = NULL; /* for command line option para-prefix */
MPI_Info h5_io_info_g=MPI_INFO_NULL;/* MPI INFO object for IO */
#endif
+#define FILENAME_BUF_SIZE 1024
+#define READ_BUF_SIZE 4096
+
/*
* These are the letters that are appended to the file name when generating
* names for the split and multi drivers. They are:
@@ -1088,3 +1091,55 @@ getenv_all(MPI_Comm comm, int root, const char* name)
#endif
+/*-------------------------------------------------------------------------
+ * Function: h5_make_local_copy
+ *
+ * Purpose: Make copy of file. Some tests write to data files under that
+ * are under version control. Those tests should make a copy of
+ * the versioned file and write to the copy. This function
+ * prepends srcdir to the name of the file to be copied and uses
+ * the name of the copy as is.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Larry Knox
+ * Monday, October 13, 2009
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hid_t
+h5_make_local_copy(char *origfilename, char *local_copy_name)
+{
+ char filename[FILENAME_BUF_SIZE] = "";
+ int fd_old = (-1), fd_new = (-1); /* File descriptors for copying data */
+ ssize_t nread; /* Number of bytes read in */
+ char buf[READ_BUF_SIZE]; /* Buffer for copying data */
+ char * srcdir = HDgetenv("srcdir"); /* The source directory */
+
+ if(srcdir && ((HDstrlen(srcdir) +
+ HDstrlen(origfilename) + 6) < FILENAME_BUF_SIZE)) {
+ HDstrcpy(filename, srcdir);
+ HDstrcat(filename, "/");
+ }
+ HDstrcat(filename, origfilename);
+
+ /* Copy old file into temporary file */
+ if((fd_old = HDopen(filename, O_RDONLY, 0666)) < 0) return -1;
+ if((fd_new = HDopen(local_copy_name, O_RDWR|O_CREAT|O_TRUNC, 0666))
+ < 0) return -1;
+
+ /* Copy data */
+ while((nread = HDread(fd_old, buf, (size_t)READ_BUF_SIZE)) > 0)
+ HDwrite(fd_new, buf, (size_t)nread);
+
+ /* Close files */
+ if(HDclose(fd_old) < 0) return -1;
+ if(HDclose(fd_new) < 0) return -1;
+
+ return 0;
+}
+