diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-03-25 03:51:41 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-03-25 03:51:41 (GMT) |
commit | 42efc1c2b591e4cd45ec6cb3bdf32044343118d2 (patch) | |
tree | 0ab542871c32246199479e8933ff26286aaf629a /tools/h5jam | |
parent | 3360c3af0c100ac4d3a2fe2865f34661da862ec5 (diff) | |
download | hdf5-42efc1c2b591e4cd45ec6cb3bdf32044343118d2.zip hdf5-42efc1c2b591e4cd45ec6cb3bdf32044343118d2.tar.gz hdf5-42efc1c2b591e4cd45ec6cb3bdf32044343118d2.tar.bz2 |
[svn-r18451] Description:
Bring r18172:18446 from trunk to revise_chunks branch.
Tested on:
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x,
w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-amd64 2.6 (amani) w/Intel compilers, w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
Diffstat (limited to 'tools/h5jam')
-rw-r--r-- | tools/h5jam/h5jamgentest.c | 2 | ||||
-rw-r--r-- | tools/h5jam/h5unjam.c | 59 |
2 files changed, 46 insertions, 15 deletions
diff --git a/tools/h5jam/h5jamgentest.c b/tools/h5jam/h5jamgentest.c index 96d113e..ec79215 100644 --- a/tools/h5jam/h5jamgentest.c +++ b/tools/h5jam/h5jamgentest.c @@ -345,7 +345,7 @@ create_textfile(const char *name, size_t size) HDwrite(fd, buf, size); - free(buf); + free(buf); HDclose(fd); } diff --git a/tools/h5jam/h5unjam.c b/tools/h5jam/h5unjam.c index 3ab2202..5e4d864 100644 --- a/tools/h5jam/h5unjam.c +++ b/tools/h5jam/h5unjam.c @@ -28,10 +28,11 @@ #define TRUE 1 #define FALSE 0 +#define COPY_BUF_SIZE 1024 hsize_t write_pad( int , hsize_t ); hsize_t compute_pad( hsize_t ); -hsize_t copy_to_file( int , int , ssize_t, ssize_t ); +herr_t copy_to_file( int , int , ssize_t, ssize_t ); const char *progname = "h5unjam"; int d_status = EXIT_SUCCESS; @@ -268,13 +269,19 @@ main(int argc, const char *argv[]) /* copy from 0 to 'usize - 1' into ufid */ if (!do_delete) { - copy_to_file( ifid, ufid, 0, (ssize_t) usize); + if(copy_to_file(ifid, ufid, 0, (ssize_t) usize) < 0) { + error_msg(progname, "unable to copy user block to output file \"%s\"\n", ub_file); + exit(EXIT_FAILURE); + } } /* copy from usize to end of file into h5fid, * starting at end of user block if present */ - copy_to_file( ifid, h5fid, (ssize_t) usize, (ssize_t)(fsize - (ssize_t)usize) ); + if(copy_to_file(ifid, h5fid, (ssize_t) usize, (ssize_t)(fsize - (ssize_t)usize)) < 0) { + error_msg(progname, "unable to copy hdf5 data to output file \"%s\"\n", output_file); + exit(EXIT_FAILURE); + } HDclose(ufid); @@ -288,36 +295,60 @@ main(int argc, const char *argv[]) * Copy 'how_much' bytes from the input file to the output file, * starting at byte 'where' in the input file. * - * Returns the size of the output file. + * Returns 0 on success, -1 on failure. */ -hsize_t +herr_t copy_to_file( int infid, int ofid, ssize_t where, ssize_t how_much ) { - char buf[1024]; + static char buf[COPY_BUF_SIZE]; off_t to; off_t from; ssize_t nchars = -1; + ssize_t wnchars = -1; + herr_t ret_value = 0; /* nothing to copy */ if(how_much <= 0) - return(where); + goto done; from = where; to = 0; - while( how_much > 0) { + while(how_much > 0) { + /* Seek to correct position in input file */ HDlseek(infid,from,SEEK_SET); - if (how_much > 512) - nchars = HDread(infid,buf,(unsigned)512); + + /* Read data to buffer */ + if (how_much > COPY_BUF_SIZE) + nchars = HDread(infid,buf,(unsigned)COPY_BUF_SIZE); else nchars = HDread(infid,buf,(unsigned)how_much); + if(nchars < 0) { + ret_value = -1; + goto done; + } /* end if */ + + /* Seek to correct position in output file */ HDlseek(ofid,to,SEEK_SET); - HDwrite(ofid,buf,(unsigned)nchars); + + /* Update positions/size */ how_much -= nchars; from += nchars; to += nchars; - } - return (where + how_much); -} + /* Write nchars bytes to output file */ + wnchars = nchars; + while(nchars > 0) { + wnchars = HDwrite(ofid,buf,(unsigned)nchars); + if(wnchars < 0) { + ret_value = -1; + goto done; + } /* end if */ + nchars -= wnchars; + } /* end while */ + } /* end while */ + +done: + return ret_value; +} /* end copy_to_file */ |