summaryrefslogtreecommitdiffstats
path: root/test/h5test.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@koziol.gov>2020-06-27 14:49:49 (GMT)
committerQuincey Koziol <koziol@koziol.gov>2020-06-27 14:49:49 (GMT)
commitce50e34c58c599f3a52affe8a9b9b9040cb5144d (patch)
tree014b5579a949cc9750a88a1b6f032457e14d9b1c /test/h5test.c
parent7bdab523b3eb8eb5a83c3a6eca622171b88856ab (diff)
parent30776671fb0a27a98b0640aa968f850241a862ce (diff)
downloadhdf5-ce50e34c58c599f3a52affe8a9b9b9040cb5144d.zip
hdf5-ce50e34c58c599f3a52affe8a9b9b9040cb5144d.tar.gz
hdf5-ce50e34c58c599f3a52affe8a9b9b9040cb5144d.tar.bz2
Merge remote-tracking branch 'origin/develop' into monotonic_timer
Diffstat (limited to 'test/h5test.c')
-rw-r--r--test/h5test.c107
1 files changed, 87 insertions, 20 deletions
diff --git a/test/h5test.c b/test/h5test.c
index 9cca100..1b445dd 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -2057,23 +2057,23 @@ h5_get_version_string(H5F_libver_t libver)
int
h5_compare_file_bytes(char *f1name, char *f2name)
{
- FILE *f1ptr = NULL; /* two file pointers */
- FILE *f2ptr = NULL;
- hsize_t f1size = 0; /* size of the files */
- hsize_t f2size = 0;
- char f1char = 0; /* one char from each file */
- char f2char = 0;
- hsize_t ii = 0;
- int ret_value = 0; /* for error handling */
+ FILE *f1ptr = NULL; /* two file pointers */
+ FILE *f2ptr = NULL;
+ off_t f1size = 0; /* size of the files */
+ off_t f2size = 0;
+ char f1char = 0; /* one char from each file */
+ char f2char = 0;
+ off_t ii = 0;
+ int ret_value = 0; /* for error handling */
/* Open files for reading */
- f1ptr = fopen(f1name, "r");
+ f1ptr = HDfopen(f1name, "r");
if (f1ptr == NULL) {
HDfprintf(stderr, "Unable to fopen() %s\n", f1name);
ret_value = -1;
goto done;
}
- f2ptr = fopen(f2name, "r");
+ f2ptr = HDfopen(f2name, "r");
if (f2ptr == NULL) {
HDfprintf(stderr, "Unable to fopen() %s\n", f2name);
ret_value = -1;
@@ -2081,11 +2081,11 @@ h5_compare_file_bytes(char *f1name, char *f2name)
}
/* Get the file sizes and verify that they equal */
- fseek(f1ptr , 0 , SEEK_END);
- f1size = ftell(f1ptr);
+ HDfseek(f1ptr , 0 , SEEK_END);
+ f1size = HDftell(f1ptr);
- fseek(f2ptr , 0 , SEEK_END);
- f2size = ftell(f2ptr);
+ HDfseek(f2ptr , 0 , SEEK_END);
+ f2size = HDftell(f2ptr);
if (f1size != f2size) {
HDfprintf(stderr, "Files differ in size, %llu vs. %llu\n", f1size, f2size);
@@ -2094,11 +2094,11 @@ h5_compare_file_bytes(char *f1name, char *f2name)
}
/* Compare each byte and fail if a difference is found */
- rewind(f1ptr);
- rewind(f2ptr);
+ HDrewind(f1ptr);
+ HDrewind(f2ptr);
for (ii = 0; ii < f1size; ii++) {
- fread(&f1char, 1, 1, f1ptr);
- fread(&f2char, 1, 1, f2ptr);
+ HDfread(&f1char, 1, 1, f1ptr);
+ HDfread(&f2char, 1, 1, f2ptr);
if (f1char != f2char) {
HDfprintf(stderr, "Mismatch @ 0x%llX: 0x%X != 0x%X\n", ii, f1char, f2char);
ret_value = -1;
@@ -2108,10 +2108,10 @@ h5_compare_file_bytes(char *f1name, char *f2name)
done:
if (f1ptr) {
- fclose(f1ptr);
+ HDfclose(f1ptr);
}
if (f2ptr) {
- fclose(f2ptr);
+ HDfclose(f2ptr);
}
return(ret_value);
} /* end h5_compare_file_bytes() */
@@ -2169,3 +2169,70 @@ const char *H5_get_srcdir(void)
return(NULL);
} /* end H5_get_srcdir() */
+/*-------------------------------------------------------------------------
+ * Function: h5_duplicate_file_by_bytes
+ *
+ * Purpose: Duplicate a file byte-for-byte at filename/path 'orig'
+ * to a new (or replaced) file at 'dest'.
+ *
+ * Return: Success: 0, completed successfully
+ * Failure: -1
+ *
+ * Programmer: Jake Smith
+ * 24 June 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+h5_duplicate_file_by_bytes(const char *orig, const char *dest)
+{
+ FILE *orig_ptr = NULL;
+ FILE *dest_ptr = NULL;
+ hsize_t fsize = 0;
+ hsize_t read_size = 0;
+ hsize_t max_buf = 0;
+ void *dup_buf = NULL;
+ int ret_value = 0;
+
+ max_buf = 4096 * sizeof(char);
+
+ orig_ptr = HDfopen(orig, "r");
+ if (NULL == orig_ptr) {
+ ret_value = -1;
+ goto done;
+ }
+
+ HDfseek(orig_ptr , 0 , SEEK_END);
+ fsize = (hsize_t)HDftell(orig_ptr);
+ HDrewind(orig_ptr);
+
+ dest_ptr = HDfopen(dest, "w");
+ if (NULL == dest_ptr) {
+ ret_value = -1;
+ goto done;
+ }
+
+ read_size = MIN(fsize, max_buf);
+ dup_buf = HDmalloc(read_size);
+ if (NULL == dup_buf) {
+ ret_value = -1;
+ goto done;
+ }
+
+ while (read_size > 0) {
+ HDfread(dup_buf, read_size, 1, orig_ptr); /* warning: no error-check */
+ HDfwrite(dup_buf, read_size, 1, dest_ptr);
+ fsize -= read_size;
+ read_size = MIN(fsize, max_buf);
+ }
+
+done:
+ if (orig_ptr != NULL)
+ HDfclose(orig_ptr);
+ if (dest_ptr != NULL)
+ HDfclose(dest_ptr);
+ if (dup_buf != NULL)
+ HDfree(dup_buf);
+ return ret_value;
+} /* end h5_duplicate_file_by_bytes() */
+