summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2019-06-29 09:38:14 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2019-06-29 09:38:14 (GMT)
commitf250815151df8da8a93c0ff781a3cf134f1c6cbd (patch)
treeaea82df0c2ef0e68c0752020b221e65e9a56e709
parent13d951d37205bcd48723330a898e5d67c5e1ecb2 (diff)
downloadhdf5-f250815151df8da8a93c0ff781a3cf134f1c6cbd.zip
hdf5-f250815151df8da8a93c0ff781a3cf134f1c6cbd.tar.gz
hdf5-f250815151df8da8a93c0ff781a3cf134f1c6cbd.tar.bz2
Cleaned up misc warnings.
-rw-r--r--src/H5FDlog.c12
-rw-r--r--src/H5FSsection.c2
-rw-r--r--src/H5Pfapl.c2
-rw-r--r--test/fheap.c67
-rw-r--r--test/ohdr.c2
-rw-r--r--test/twriteorder.c384
6 files changed, 249 insertions, 220 deletions
diff --git a/src/H5FDlog.c b/src/H5FDlog.c
index 06a0e61..ac5667f 100644
--- a/src/H5FDlog.c
+++ b/src/H5FDlog.c
@@ -331,16 +331,22 @@ H5Pset_fapl_log(hid_t fapl_id, const char *logfile, unsigned long long flags, si
HDmemset(&fa, 0, sizeof(H5FD_log_fapl_t));
- /* This shallow copy is correct! The string will be properly
- * copied deep down in the H5P code.
+ /* Duplicate the log file string
+ * A little wasteful, since this string will just be copied later, but
+ * passing it in as a pointer sets off a chain of impossible-to-resolve
+ * const cast warnings.
*/
- fa.logfile = (char *)logfile;
+ if(logfile != NULL && NULL == (fa.logfile = H5MM_xstrdup(logfile)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to copy log file name")
fa.flags = flags;
fa.buf_size = buf_size;
ret_value = H5P_set_driver(plist, H5FD_LOG, &fa);
done:
+ if(fa.logfile)
+ H5MM_free(fa.logfile);
+
FUNC_LEAVE_API(ret_value)
} /* end H5Pset_fapl_log() */
diff --git a/src/H5FSsection.c b/src/H5FSsection.c
index d15e299..9f86aea 100644
--- a/src/H5FSsection.c
+++ b/src/H5FSsection.c
@@ -2539,7 +2539,7 @@ H5FS_vfd_alloc_hdr_and_section_info_if_needed(H5F_t *f, H5FS_t *fspace,
/* Allocate space for the free space header */
if(HADDR_UNDEF == (fspace->addr = H5MF_alloc(f, H5FD_MEM_FSPACE_HDR, hdr_alloc_size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "file allocation failed for free space header")
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for free space header")
/* Cache the new free space header (pinned) */
if(H5AC_insert_entry(f, H5AC_FSPACE_HDR, fspace->addr, fspace, H5AC__PIN_ENTRY_FLAG) < 0)
diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c
index 585e913..8bb2b12 100644
--- a/src/H5Pfapl.c
+++ b/src/H5Pfapl.c
@@ -4892,7 +4892,7 @@ H5P_set_vol(H5P_genplist_t *plist, hid_t vol_id, const void *vol_info)
/* Prepare the VOL connector property */
vol_prop.connector_id = vol_id;
- vol_prop.connector_info = vol_info;
+ vol_prop.connector_info = (void *)vol_info;
/* Set the connector ID & info property */
if(H5P_set(plist, H5F_ACS_VOL_CONN_NAME, &vol_prop) < 0)
diff --git a/test/fheap.c b/test/fheap.c
index 557fd37..91a1df5 100644
--- a/test/fheap.c
+++ b/test/fheap.c
@@ -683,6 +683,7 @@ open_heap(char *filename, hid_t fapl, const H5HF_create_t *cparam,
/* Close (empty) heap */
if(H5HF_close(*fh) < 0)
FAIL_STACK_ERROR
+ *fh = NULL;
} /* end if */
/* Close file */
@@ -759,6 +760,7 @@ reopen_heap(H5F_t *f, H5HF_t **fh, haddr_t fh_addr,
/* Close (empty) heap */
if(H5HF_close(*fh) < 0)
FAIL_STACK_ERROR
+ *fh = NULL;
/* Re-open heap */
if(NULL == (*fh = H5HF_open(f, fh_addr)))
@@ -766,10 +768,10 @@ reopen_heap(H5F_t *f, H5HF_t **fh, haddr_t fh_addr,
} /* end if */
/* Success */
- return(0);
+ return 0;
error:
- return(-1);
+ return -1;
} /* end reopen_heap() */
@@ -1904,8 +1906,9 @@ test_create(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
TEST_ERROR
/* Close the fractal heap */
- if((fh = H5HF_close(fh)) < 0)
+ if(H5HF_close(fh) < 0)
FAIL_STACK_ERROR
+ fh = NULL;
/* Delete heap */
if(H5HF_delete(f, fh_addr) < 0)
@@ -1926,15 +1929,15 @@ test_create(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
/* All tests passed */
PASSED()
- return(0);
+ return 0;
error:
H5E_BEGIN_TRY {
if(fh)
H5HF_close(fh);
- H5Fclose(file);
+ H5Fclose(file);
} H5E_END_TRY;
- return(1);
+ return 1;
} /* test_create() */
@@ -2020,6 +2023,7 @@ test_reopen(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
/* Close the fractal heap */
if(H5HF_close(fh) < 0)
FAIL_STACK_ERROR
+ fh = NULL;
/* Check for closing & re-opening the file */
if(tparam->reopen_heap) {
@@ -2083,7 +2087,7 @@ error:
H5E_BEGIN_TRY {
if(fh)
H5HF_close(fh);
- H5Fclose(file);
+ H5Fclose(file);
} H5E_END_TRY;
return(1);
} /* test_reopen() */
@@ -2250,7 +2254,7 @@ test_open_twice(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
/* All tests passed */
PASSED()
- return(0);
+ return 0;
error:
H5E_BEGIN_TRY {
@@ -2258,11 +2262,11 @@ error:
H5HF_close(fh);
if(fh2)
H5HF_close(fh2);
- H5Fclose(file);
- H5Fclose(file2);
+ H5Fclose(file);
+ H5Fclose(file2);
} H5E_END_TRY;
- return(1);
+ return 1;
} /* test_open_twice() */
@@ -2366,6 +2370,7 @@ test_delete_open(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
if(fh2) {
/* Close opened heap */
H5HF_close(fh2);
+ fh2 = NULL;
/* Indicate error */
TEST_ERROR
@@ -2403,6 +2408,7 @@ test_delete_open(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
if(fh) {
/* Close opened heap */
H5HF_close(fh);
+ fh = NULL;
/* Indicate error */
TEST_ERROR
@@ -2423,7 +2429,7 @@ test_delete_open(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
/* All tests passed */
PASSED()
- return(0);
+ return 0;
error:
H5E_BEGIN_TRY {
@@ -2431,9 +2437,9 @@ error:
H5HF_close(fh);
if(fh2)
H5HF_close(fh2);
- H5Fclose(file);
+ H5Fclose(file);
} H5E_END_TRY;
- return(1);
+ return 1;
} /* test_delete_open() */
@@ -2769,15 +2775,15 @@ test_id_limits(hid_t fapl, H5HF_create_t *cparam, hid_t fcpl)
/* All tests passed */
PASSED()
- return(0);
+ return 0;
error:
H5E_BEGIN_TRY {
if(fh)
H5HF_close(fh);
- H5Fclose(file);
+ H5Fclose(file);
} H5E_END_TRY;
- return(1);
+ return 1;
} /* test_id_limits() */
@@ -2878,6 +2884,7 @@ test_filtered_create(hid_t fapl, H5HF_create_t *cparam, hid_t fcpl)
/* Close the fractal heap */
if(H5HF_close(fh) < 0)
FAIL_STACK_ERROR
+ fh = NULL;
/* Close the file */
@@ -2891,15 +2898,15 @@ test_filtered_create(hid_t fapl, H5HF_create_t *cparam, hid_t fcpl)
/* All tests passed */
PASSED()
- return(0);
+ return 0;
error:
H5E_BEGIN_TRY {
if(fh)
H5HF_close(fh);
- H5Fclose(file);
+ H5Fclose(file);
} H5E_END_TRY;
- return(1);
+ return 1;
} /* test_filtered_create() */
@@ -3022,7 +3029,7 @@ test_size(hid_t fapl, H5HF_create_t *cparam, hid_t fcpl)
/* Close the fractal heap */
if(H5HF_close(fh) < 0)
FAIL_STACK_ERROR
-
+ fh = NULL;
/* Close the file */
if(H5Fclose(file) < 0)
@@ -3031,7 +3038,7 @@ test_size(hid_t fapl, H5HF_create_t *cparam, hid_t fcpl)
/* All tests passed */
PASSED()
- return(0);
+ return 0;
error:
H5E_BEGIN_TRY {
@@ -3039,7 +3046,7 @@ error:
H5HF_close(fh);
H5Fclose(file);
} H5E_END_TRY;
- return(1);
+ return 1;
} /* test_size() */
@@ -6643,8 +6650,9 @@ test_man_remove_one(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tpara
FAIL_STACK_ERROR
/* Close the fractal heap */
- if((fh = H5HF_close(fh)) < 0)
+ if((H5HF_close(fh)) < 0)
TEST_ERROR
+ fh = NULL;
/* Close the file */
if(H5Fclose(file) < 0)
@@ -6834,8 +6842,9 @@ test_man_remove_two(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tpara
FAIL_STACK_ERROR
/* Close the fractal heap */
- if((fh = H5HF_close(fh)) < 0)
+ if((H5HF_close(fh)) < 0)
TEST_ERROR
+ fh = NULL;
/* Close the file */
if(H5Fclose(file) < 0)
@@ -7001,7 +7010,7 @@ test_man_remove_one_larger(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t
FAIL_STACK_ERROR
/* Close the fractal heap */
- if((fh = H5HF_close(fh)) < 0)
+ if(H5HF_close(fh) < 0)
FAIL_STACK_ERROR
/* Close the file */
@@ -7239,8 +7248,9 @@ test_man_remove_two_larger(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t
FAIL_STACK_ERROR
/* Close the fractal heap */
- if((fh = H5HF_close(fh)) < 0)
+ if(H5HF_close(fh) < 0)
TEST_ERROR
+ fh = NULL;
/* Close the file */
if(H5Fclose(file) < 0)
@@ -7541,8 +7551,9 @@ test_man_remove_three_larger(hid_t fapl, H5HF_create_t *cparam, fheap_test_param
FAIL_STACK_ERROR
/* Close the fractal heap */
- if((fh = H5HF_close(fh)) < 0)
+ if(H5HF_close(fh) < 0)
TEST_ERROR
+ fh = NULL;
/* Close the file */
if(H5Fclose(file) < 0)
diff --git a/test/ohdr.c b/test/ohdr.c
index d15e43b..facedd5 100644
--- a/test/ohdr.c
+++ b/test/ohdr.c
@@ -809,7 +809,7 @@ oh_compare(hid_t did1, hid_t did2)
* Conduct additions side-by-side with a standard datataset and one with
* minimized dataset object headers.
*/
-#define ATTR_NAME_MAX 16
+#define ATTR_NAME_MAX 64
#define ATTR_SHORT "first"
#define ATTR_LONG "second"
#define N_ATTRS 64
diff --git a/test/twriteorder.c b/test/twriteorder.c
index 4c86636..60ee384 100644
--- a/test/twriteorder.c
+++ b/test/twriteorder.c
@@ -25,7 +25,6 @@
* get the same data the write has written.
*
* Created: Albert Cheng, 2013/8/28.
-* Modified:
*************************************************************/
/***********************************************************
@@ -69,18 +68,18 @@
#ifdef H5_HAVE_FORK
#define DATAFILE "twriteorder.dat"
-/* #define READERS_MAX 10 */ /* max number of readers */
-#define BLOCKSIZE_DFT 1024 /* 1KB */
-#define PARTITION_DFT 2048 /* 2KB */
-#define NLINKEDBLOCKS_DFT 512 /* default 512 */
-#define SIZE_BLKADDR 4 /* expected sizeof blkaddr */
-#define Hgoto_error(val) {ret_value=val; goto done;}
+/* #define READERS_MAX 10 */ /* max number of readers */
+#define BLOCKSIZE_DFT 1024 /* 1KB */
+#define PARTITION_DFT 2048 /* 2KB */
+#define NLINKEDBLOCKS_DFT 512 /* default 512 */
+#define SIZE_BLKADDR 4 /* expected sizeof blkaddr */
+#define Hgoto_error(val) {ret_value=val; goto done;}
/* type declarations */
typedef enum part_t {
- UC_READWRITE =0, /* both writer and reader */
- UC_WRITER, /* writer only */
- UC_READER /* reader only */
+ UC_READWRITE = 0, /* both writer and reader */
+ UC_WRITER, /* writer only */
+ UC_READER /* reader only */
} part_t;
/* prototypes */
@@ -92,9 +91,9 @@ int setup_parameters(int argc, char * const argv[]);
int parse_option(int argc, char * const argv[]);
/* Global Variable definitions */
-const char *progname_g="twriteorder"; /* program name */
-int write_fd_g;
-int blocksize_g, part_size_g, nlinkedblock_g;
+const char *progname_g="twriteorder"; /* program name */
+int write_fd_g;
+int blocksize_g, part_size_g, nlinkedblock_g;
part_t launch_g;
/* Function definitions */
@@ -103,15 +102,15 @@ part_t launch_g;
void
usage(const char *prog)
{
- fprintf(stderr, "usage: %s [OPTIONS]\n", prog);
- fprintf(stderr, " OPTIONS\n");
- fprintf(stderr, " -h Print a usage message and exit\n");
- fprintf(stderr, " -l w|r launch writer or reader only. [default: launch both]\n");
- fprintf(stderr, " -b N Block size [default: %d]\n", BLOCKSIZE_DFT);
- fprintf(stderr, " -p N Partition size [default: %d]\n", PARTITION_DFT);
- fprintf(stderr, " -n N Number of linked blocks [default: %d]\n", NLINKEDBLOCKS_DFT);
- fprintf(stderr, " where N is an integer value\n");
- fprintf(stderr, "\n");
+ HDfprintf(stderr, "usage: %s [OPTIONS]\n", prog);
+ HDfprintf(stderr, " OPTIONS\n");
+ HDfprintf(stderr, " -h Print a usage message and exit\n");
+ HDfprintf(stderr, " -l w|r launch writer or reader only. [default: launch both]\n");
+ HDfprintf(stderr, " -b N Block size [default: %d]\n", BLOCKSIZE_DFT);
+ HDfprintf(stderr, " -p N Partition size [default: %d]\n", PARTITION_DFT);
+ HDfprintf(stderr, " -n N Number of linked blocks [default: %d]\n", NLINKEDBLOCKS_DFT);
+ HDfprintf(stderr, " where N is an integer value\n");
+ HDfprintf(stderr, "\n");
}
/* Setup test parameters by parsing command line options.
@@ -127,73 +126,73 @@ parse_option(int argc, char * const argv[])
/* suppress getopt from printing error */
opterr = 0;
- while (1){
- c = getopt (argc, argv, cmd_options);
- if (-1 == c)
- break;
- switch (c) {
- case 'h':
- usage(progname_g);
- exit(0);
- break;
- case 'b': /* number of planes to write/read */
- if ((blocksize_g = atoi(optarg)) <= 0){
- fprintf(stderr, "bad blocksize %s, must be a positive integer\n", optarg);
- usage(progname_g);
- Hgoto_error(-1);
- };
- break;
- case 'n': /* number of planes to write/read */
- if ((nlinkedblock_g = atoi(optarg)) < 2){
- fprintf(stderr, "bad number of linked blocks %s, must be greater than 1.\n", optarg);
- usage(progname_g);
- Hgoto_error(-1);
- };
- break;
- case 'p': /* number of planes to write/read */
- if ((part_size_g = atoi(optarg)) <= 0){
- fprintf(stderr, "bad partition size %s, must be a positive integer\n", optarg);
- usage(progname_g);
- Hgoto_error(-1);
- };
- break;
- case 'l': /* launch reader or writer only */
- switch (*optarg) {
- case 'r': /* reader only */
- launch_g = UC_READER;
- break;
- case 'w': /* writer only */
- launch_g = UC_WRITER;
- break;
- default:
- fprintf(stderr, "launch value(%c) should be w or r only.\n", *optarg);
- usage(progname_g);
- Hgoto_error(-1);
- break;
- }
- printf("launch = %d\n", launch_g);
- break;
- case '?':
- fprintf(stderr, "getopt returned '%c'.\n", c);
- usage(progname_g);
- Hgoto_error(-1);
- default:
- fprintf(stderr, "getopt returned unexpected value.\n");
- fprintf(stderr, "Unexpected value is %d\n", c);
- Hgoto_error(-1);
- }
- }
+ while (1) {
+ c = getopt (argc, argv, cmd_options);
+ if (-1 == c)
+ break;
+
+ switch (c) {
+ case 'h':
+ usage(progname_g);
+ HDexit(0);
+ break;
+ case 'b': /* number of planes to write/read */
+ if ((blocksize_g = atoi(optarg)) <= 0) {
+ HDfprintf(stderr, "bad blocksize %s, must be a positive integer\n", optarg);
+ usage(progname_g);
+ Hgoto_error(-1);
+ };
+ break;
+ case 'n': /* number of planes to write/read */
+ if ((nlinkedblock_g = atoi(optarg)) < 2) {
+ HDfprintf(stderr, "bad number of linked blocks %s, must be greater than 1.\n", optarg);
+ usage(progname_g);
+ Hgoto_error(-1);
+ };
+ break;
+ case 'p': /* number of planes to write/read */
+ if ((part_size_g = atoi(optarg)) <= 0) {
+ HDfprintf(stderr, "bad partition size %s, must be a positive integer\n", optarg);
+ usage(progname_g);
+ Hgoto_error(-1);
+ };
+ break;
+ case 'l': /* launch reader or writer only */
+ switch (*optarg) {
+ case 'r': /* reader only */
+ launch_g = UC_READER;
+ break;
+ case 'w': /* writer only */
+ launch_g = UC_WRITER;
+ break;
+ default:
+ HDfprintf(stderr, "launch value(%c) should be w or r only.\n", *optarg);
+ usage(progname_g);
+ Hgoto_error(-1);
+ break;
+ } /* end inner switch */
+ HDprintf("launch = %d\n", launch_g);
+ break;
+ case '?':
+ HDfprintf(stderr, "getopt returned '%c'.\n", c);
+ usage(progname_g);
+ Hgoto_error(-1);
+ default:
+ HDfprintf(stderr, "getopt returned unexpected value.\n");
+ HDfprintf(stderr, "Unexpected value is %d\n", c);
+ Hgoto_error(-1);
+ } /* end outer switch */
+ } /* end while */
/* verify partition size must be >= blocksize */
if (part_size_g < blocksize_g ){
- fprintf(stderr, "Blocksize %d should not be bigger than partition size %d\n",
- blocksize_g, part_size_g);
- Hgoto_error(-1);
+ HDfprintf(stderr, "Blocksize %d should not be bigger than partition size %d\n", blocksize_g, part_size_g);
+ Hgoto_error(-1);
}
done:
/* All done. */
- return(ret_value);
+ return ret_value;
}
/* Setup parameters for the test case.
@@ -209,15 +208,16 @@ int setup_parameters(int argc, char * const argv[])
/* parse options */
if (parse_option(argc, argv) < 0){
- return(-1);
+ return -1;
}
/* show parameters and return */
- printf("blocksize = %ld\n", (long)blocksize_g);
- printf("part_size = %ld\n", (long)part_size_g);
- printf("nlinkedblock = %ld\n", (long)nlinkedblock_g);
- printf("launch = %d\n", launch_g);
- return(0);
+ HDprintf("blocksize = %ld\n", (long)blocksize_g);
+ HDprintf("part_size = %ld\n", (long)part_size_g);
+ HDprintf("nlinkedblock = %ld\n", (long)nlinkedblock_g);
+ HDprintf("launch = %d\n", launch_g);
+
+ return 0;
}
/* Create the test file with initial "empty" file, that is,
@@ -227,19 +227,19 @@ int setup_parameters(int argc, char * const argv[])
*/
int create_wo_file(void)
{
- int blkaddr=0; /* blkaddress of next linked block */
- int ret_code;
+ int blkaddr = 0; /* blkaddress of next linked block */
+ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */
/* Create the data file */
if ((write_fd_g = HDopen(DATAFILE, O_RDWR|O_TRUNC|O_CREAT, H5_POSIX_CREATE_MODE_RW)) < 0) {
HDprintf("WRITER: error from open\n");
return -1;
}
- blkaddr=0;
+ blkaddr = 0;
/* write it to partition 0 */
- if ((ret_code=HDwrite(write_fd_g, &blkaddr, (size_t)SIZE_BLKADDR)) != SIZE_BLKADDR){
- printf("blkaddr write failed\n");
- return -1;
+ if ((bytes_wrote = HDwrite(write_fd_g, &blkaddr, (size_t)SIZE_BLKADDR)) != SIZE_BLKADDR){
+ HDprintf("blkaddr write failed\n");
+ return -1;
}
/* File initialized, return success */
@@ -252,38 +252,45 @@ int write_wo_file(void)
int blkaddr_old=0;
int i;
char buffer[BLOCKSIZE_DFT];
- int ret_code;
+ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */
/* write block 1, 2, ... */
- for (i=1; i<nlinkedblock_g; i++){
- /* calculate where to write this block */
- blkaddr = i*part_size_g + i;
- /* store old block address in byte 0-3 */
- HDmemcpy(&buffer[0], &blkaddr_old, sizeof(blkaddr_old));
- /* fill the rest with the lowest byte of i */
- HDmemset(&buffer[4], i & 0xff, (size_t) (BLOCKSIZE_DFT-4));
- /* write the block */
+ for (i = 1; i < nlinkedblock_g; i++) {
+
+ /* calculate where to write this block */
+ blkaddr = i * part_size_g + i;
+
+ /* store old block address in byte 0-3 */
+ HDmemcpy(&buffer[0], &blkaddr_old, sizeof(blkaddr_old));
+
+ /* fill the rest with the lowest byte of i */
+ HDmemset(&buffer[4], i & 0xff, (size_t) (BLOCKSIZE_DFT-4));
+
+ /* write the block */
#ifdef DEBUG
- printf("writing block at %d\n", blkaddr);
+ HDprintf("writing block at %d\n", blkaddr);
#endif
- HDlseek(write_fd_g, (HDoff_t)blkaddr, SEEK_SET);
- if ((ret_code=HDwrite(write_fd_g, buffer, (size_t)blocksize_g)) != blocksize_g){
- printf("blkaddr write failed in partition %d\n", i);
- return -1;
- }
- blkaddr_old = blkaddr;
- }
+ HDlseek(write_fd_g, (HDoff_t)blkaddr, SEEK_SET);
+ if ((bytes_wrote = HDwrite(write_fd_g, buffer, (size_t)blocksize_g)) != blocksize_g){
+ HDprintf("blkaddr write failed in partition %d\n", i);
+ return -1;
+ }
+
+ blkaddr_old = blkaddr;
+
+ } /* end for */
+
/* write the last blkaddr in partition 0 */
HDlseek(write_fd_g, (HDoff_t)0, SEEK_SET);
- if ((ret_code=HDwrite(write_fd_g, &blkaddr_old, (size_t)sizeof(blkaddr_old))) != sizeof(blkaddr_old)){
- printf("blkaddr write failed in partition %d\n", 0);
- return -1;
+ if ((bytes_wrote = HDwrite(write_fd_g, &blkaddr_old, (size_t)sizeof(blkaddr_old))) != sizeof(blkaddr_old)){
+ HDprintf("blkaddr write failed in partition %d\n", 0);
+ return -1;
}
/* all writes done. return succeess. */
#ifdef DEBUG
- printf("wrote %d blocks\n", nlinkedblock_g);
+ HDprintf("wrote %d blocks\n", nlinkedblock_g);
#endif
return 0;
}
@@ -291,9 +298,9 @@ int write_wo_file(void)
int read_wo_file(void)
{
int read_fd;
- int blkaddr=0;
- int ret_code;
- int linkedblocks_read=0;
+ int blkaddr = 0;
+ h5_posix_io_ret_t bytes_read = -1; /* # of bytes actually read */
+ int linkedblocks_read = 0;
char buffer[BLOCKSIZE_DFT];
/* Open the data file */
@@ -301,36 +308,38 @@ int read_wo_file(void)
HDprintf("READER: error from open\n");
return -1;
}
+
/* keep reading the initial block address until it is non-zero before proceeding. */
- while (blkaddr == 0){
- HDlseek(read_fd, (HDoff_t)0, SEEK_SET);
- if ((ret_code=HDread(read_fd, &blkaddr, (size_t)sizeof(blkaddr))) != sizeof(blkaddr)){
- printf("blkaddr read failed in partition %d\n", 0);
- return -1;
- }
+ while (blkaddr == 0) {
+ HDlseek(read_fd, (HDoff_t)0, SEEK_SET);
+ if ((bytes_read = HDread(read_fd, &blkaddr, (size_t)sizeof(blkaddr))) != sizeof(blkaddr)) {
+ HDprintf("blkaddr read failed in partition %d\n", 0);
+ return -1;
+ }
}
linkedblocks_read++;
/* got a non-zero blkaddr. Proceed down the linked blocks. */
#ifdef DEBUG
- printf("got initial block address=%d\n", blkaddr);
+ HDprintf("got initial block address=%d\n", blkaddr);
#endif
- while (blkaddr != 0){
- HDlseek(read_fd, (HDoff_t)blkaddr, SEEK_SET);
- if ((ret_code=HDread(read_fd, buffer, (size_t)blocksize_g)) != blocksize_g){
- printf("blkaddr read failed in partition %d\n", 0);
- return -1;
- }
- linkedblocks_read++;
- /* retrieve the block address in byte 0-3 */
- HDmemcpy(&blkaddr, &buffer[0], sizeof(blkaddr));
+ while (blkaddr != 0) {
+ HDlseek(read_fd, (HDoff_t)blkaddr, SEEK_SET);
+ if ((bytes_read = HDread(read_fd, buffer, (size_t)blocksize_g)) != blocksize_g){
+ HDprintf("blkaddr read failed in partition %d\n", 0);
+ return -1;
+ }
+ linkedblocks_read++;
+
+ /* retrieve the block address in byte 0-3 */
+ HDmemcpy(&blkaddr, &buffer[0], sizeof(blkaddr));
#ifdef DEBUG
- printf("got next block address=%d\n", blkaddr);
+ HDprintf("got next block address=%d\n", blkaddr);
#endif
}
#ifdef DEBUG
- printf("read %d blocks\n", linkedblocks_read);
+ HDprintf("read %d blocks\n", linkedblocks_read);
#endif
return 0;
}
@@ -351,13 +360,13 @@ main(int argc, char *argv[])
pid_t childpid=0;
int child_ret_value;
pid_t mypid, tmppid;
- int child_status;
+ int child_status;
int child_wait_option=0;
int ret_value = 0;
/* initialization */
if (setup_parameters(argc, argv) < 0){
- Hgoto_error(1);
+ Hgoto_error(1);
}
/* ==============================================================*/
@@ -368,41 +377,43 @@ main(int argc, char *argv[])
/* ============*/
/* Create file */
/* ============*/
- if (launch_g != UC_READER){
- printf("Creating skeleton data file for test...\n");
- if (create_wo_file() < 0){
- fprintf(stderr, "***encounter error\n");
- Hgoto_error(1);
- }else
- printf("File created.\n");
+ if (launch_g != UC_READER) {
+ HDprintf("Creating skeleton data file for test...\n");
+ if (create_wo_file() < 0) {
+ HDfprintf(stderr, "***encounter error\n");
+ Hgoto_error(1);
+ }
+ else
+ HDprintf("File created.\n");
}
/* flush output before possible fork */
HDfflush(stdout);
- if (launch_g==UC_READWRITE){
- /* fork process */
- if((childpid = fork()) < 0) {
- perror("fork");
- Hgoto_error(1);
- };
+ if (launch_g==UC_READWRITE) {
+ /* fork process */
+ if((childpid = HDfork()) < 0) {
+ HDperror("fork");
+ Hgoto_error(1);
+ };
};
mypid = getpid();
/* ============= */
/* launch reader */
/* ============= */
- if (launch_g != UC_WRITER){
- /* child process launch the reader */
- if(0 == childpid) {
- printf("%d: launch reader process\n", mypid);
- if (read_wo_file() < 0){
- fprintf(stderr, "read_wo_file encountered error\n");
- exit(1);
- }
- /* Reader is done. Clean up by removing the data file */
- HDremove(DATAFILE);
- exit(0);
- }
+ if (launch_g != UC_WRITER) {
+ /* child process launch the reader */
+ if(0 == childpid) {
+ HDprintf("%d: launch reader process\n", mypid);
+ if (read_wo_file() < 0) {
+ HDfprintf(stderr, "read_wo_file encountered error\n");
+ HDexit(1);
+ }
+
+ /* Reader is done. Clean up by removing the data file */
+ HDremove(DATAFILE);
+ HDexit(0);
+ }
}
/* ============= */
@@ -410,42 +421,43 @@ main(int argc, char *argv[])
/* ============= */
/* this process continues to launch the writer */
#ifdef DEBUG
- printf("%d: continue as the writer process\n", mypid);
+ HDprintf("%d: continue as the writer process\n", mypid);
#endif
- if (write_wo_file() < 0){
- fprintf(stderr, "write_wo_file encountered error\n");
- Hgoto_error(1);
+ if (write_wo_file() < 0) {
+ HDfprintf(stderr, "write_wo_file encountered error\n");
+ Hgoto_error(1);
}
/* ================================================ */
/* If readwrite, collect exit code of child process */
/* ================================================ */
- if (launch_g == UC_READWRITE){
- if ((tmppid = waitpid(childpid, &child_status, child_wait_option)) < 0){
- perror("waitpid");
- Hgoto_error(1);
- }
- if (WIFEXITED(child_status)){
- if ((child_ret_value=WEXITSTATUS(child_status)) != 0){
- printf("%d: child process exited with non-zero code (%d)\n",
- mypid, child_ret_value);
- Hgoto_error(2);
- }
- } else {
- printf("%d: child process terminated abnormally\n", mypid);
- Hgoto_error(2);
- }
+ if (launch_g == UC_READWRITE) {
+ if ((tmppid = waitpid(childpid, &child_status, child_wait_option)) < 0) {
+ HDperror("waitpid");
+ Hgoto_error(1);
+ }
+ if (WIFEXITED(child_status)) {
+ if ((child_ret_value=WEXITSTATUS(child_status)) != 0) {
+ HDprintf("%d: child process exited with non-zero code (%d)\n", mypid, child_ret_value);
+ Hgoto_error(2);
+ }
+ }
+ else {
+ HDprintf("%d: child process terminated abnormally\n", mypid);
+ Hgoto_error(2);
+ }
}
done:
/* Print result and exit */
if (ret_value != 0){
- printf("Error(s) encountered\n");
- }else{
- printf("All passed\n");
+ HDprintf("Error(s) encountered\n");
+ }
+ else {
+ HDprintf("All passed\n");
}
- return(ret_value);
+ return ret_value;
}
#else /* H5_HAVE_FORK */