summaryrefslogtreecommitdiffstats
path: root/tools/h5jam
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5jam')
-rw-r--r--tools/h5jam/h5jam.c42
-rw-r--r--tools/h5jam/h5jamgentest.c12
-rw-r--r--tools/h5jam/h5unjam.c12
3 files changed, 35 insertions, 31 deletions
diff --git a/tools/h5jam/h5jam.c b/tools/h5jam/h5jam.c
index 28a62fd..fae7b9e 100644
--- a/tools/h5jam/h5jam.c
+++ b/tools/h5jam/h5jam.c
@@ -19,10 +19,7 @@
/* Name of tool */
#define PROGRAMNAME "h5jam"
-#define TRUE 1
-#define FALSE 0
-
-hsize_t write_pad (int, hsize_t);
+herr_t write_pad(int ofile, hsize_t old_where, hsize_t *new_where);
hsize_t compute_user_block_size (hsize_t);
hsize_t copy_some_to_file (int, int, hsize_t, hsize_t, ssize_t);
void parse_command_line (int, const char *[]);
@@ -313,7 +310,7 @@ main (int argc, const char *argv[])
h5fsize = (hsize_t)sbuf2.st_size;
if (output_file == NULL) {
- ofid = HDopen (input_file, O_WRONLY, 0);
+ ofid = HDopen(input_file, O_WRONLY, 0);
if (ofid < 0) {
error_msg("unable to open output file \"%s\"\n", output_file);
@@ -323,7 +320,7 @@ main (int argc, const char *argv[])
}
}
else {
- ofid = HDopen (output_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ ofid = HDopen(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (ofid < 0) {
error_msg("unable to create output file \"%s\"\n", output_file);
@@ -366,7 +363,13 @@ main (int argc, const char *argv[])
where = copy_some_to_file(ufid, ofid, (hsize_t) 0, startub, (ssize_t) - 1);
/* pad the ub */
- where = write_pad (ofid, where);
+ if(write_pad(ofid, where, &where) < 0) {
+ error_msg("Can't pad file \"%s\"\n", output_file);
+ HDclose (h5fid);
+ HDclose (ufid);
+ HDclose (ofid);
+ leave (EXIT_FAILURE);
+ } /* end if */
if(ub_file)
HDfree(ub_file);
@@ -503,7 +506,7 @@ copy_some_to_file(int infid, int outfid, hsize_t startin, hsize_t startout,
*-------------------------------------------------------------------------
*/
hsize_t
-compute_user_block_size (hsize_t ublock_size)
+compute_user_block_size(hsize_t ublock_size)
{
hsize_t where = 512;
@@ -521,23 +524,30 @@ compute_user_block_size (hsize_t ublock_size)
*
* Returns the size of the padded file.
*/
-hsize_t
-write_pad(int ofile, hsize_t where)
+herr_t
+write_pad(int ofile, hsize_t old_where, hsize_t *new_where)
{
unsigned int i;
char buf[1];
hsize_t psize;
+ if(new_where == NULL)
+ return FAIL;
+
buf[0] = '\0';
- HDlseek(ofile, (off_t) where, SEEK_SET);
+ HDlseek(ofile, (off_t)old_where, SEEK_SET);
- psize = compute_user_block_size (where);
- psize -= where;
+ psize = compute_user_block_size(old_where);
+ psize -= old_where;
for(i = 0; i < psize; i++)
- HDwrite (ofile, buf, 1);
+ if(HDwrite(ofile, buf, 1) < 0)
+ return FAIL;
- return(where + psize); /* the new size of the file. */
-}
+ /* Set the new size of the file. */
+ *new_where = old_where + psize;
+
+ return SUCCEED;
+} /* end write_pad() */
diff --git a/tools/h5jam/h5jamgentest.c b/tools/h5jam/h5jamgentest.c
index e7a1878..c8b0801 100644
--- a/tools/h5jam/h5jamgentest.c
+++ b/tools/h5jam/h5jamgentest.c
@@ -275,10 +275,7 @@ gent_ub(const char * filename, size_t ub_size, size_t ub_fill)
H5Fclose(fid);
/* If a user block is being used, write to it here */
- if(ub_size > 0)
- {
- ssize_t nbytes;
-
+ if(ub_size > 0) {
HDassert(ub_size <= BUF_SIZE);
fd = HDopen(filename, O_RDWR, 0);
@@ -290,8 +287,7 @@ gent_ub(const char * filename, size_t ub_size, size_t ub_fill)
for (u = 0; u < ub_fill; u++)
*bp++ = pattern[u % 10];
- nbytes = HDwrite(fd, buf, ub_size);
- HDassert(nbytes >= 0);
+ HDwrite(fd, buf, ub_size);
HDclose(fd);
}
@@ -304,7 +300,6 @@ create_textfile(const char *name, size_t size)
int fd;
size_t i;
char *bp;
- ssize_t nbytes;
fd = HDcreat(name,0777);
HDassert(fd >= 0);
@@ -316,8 +311,7 @@ create_textfile(const char *name, size_t size)
for(i = 0; i < size; i++)
*bp++ = pattern[i % 10];
- nbytes = HDwrite(fd, buf, size);
- HDassert(nbytes >= 0);
+ HDwrite(fd, buf, size);
HDfree(buf);
diff --git a/tools/h5jam/h5unjam.c b/tools/h5jam/h5unjam.c
index 59e5dae..ffe2aca 100644
--- a/tools/h5jam/h5unjam.c
+++ b/tools/h5jam/h5unjam.c
@@ -19,8 +19,6 @@
/* Name of tool */
#define PROGRAMNAME "h5unjam"
-#define TRUE 1
-#define FALSE 0
#define COPY_BUF_SIZE 1024
hsize_t write_pad( int , hsize_t );
@@ -334,17 +332,19 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-copy_to_file( FILE *infid, FILE *ofid, ssize_t _where, ssize_t how_much )
+copy_to_file( FILE *infid, FILE *ofid, ssize_t _where, ssize_t show_much )
{
static char buf[COPY_BUF_SIZE];
+ size_t how_much;
off_t where = (off_t)_where;
off_t to;
off_t from;
herr_t ret_value = 0;
/* nothing to copy */
- if(how_much <= 0)
+ if(show_much <= 0)
goto done;
+ how_much = (size_t)show_much;
/* rewind */
HDfseek(infid, 0L, 0);
@@ -379,8 +379,8 @@ copy_to_file( FILE *infid, FILE *ofid, ssize_t _where, ssize_t how_much )
/* Update positions/size */
how_much -= bytes_read;
- from += bytes_read;
- to += bytes_read;
+ from += (off_t)bytes_read;
+ to += (off_t)bytes_read;
/* Write nchars bytes to output file */
bytes_wrote = HDfwrite(buf, (size_t)1, bytes_read, ofid);