From 4e1695576c49988a9d23c8f2a3d00601cb447593 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 31 Jul 2013 11:22:40 -0500 Subject: [svn-r23953] Update stream handling to allow binary mode - due to unjam fix. Tested: local linux --- tools/h5dump/h5dump.c | 2 +- tools/lib/h5tools.c | 71 +++++++++++++++++++++++++++++++++++++++++---------- tools/lib/h5tools.h | 6 ++--- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 8e60bf7..36192e0 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -1020,7 +1020,7 @@ parse_start: break; case 'O': - if (h5tools_set_output_file(opt_arg) < 0) { + if (h5tools_set_output_file(opt_arg, 0) < 0) { usage(h5tools_getprogname()); goto error; } diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 2e48889..d229eec 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -287,9 +287,18 @@ h5tools_set_attr_output_file(const char *fname, int is_bin) /* First check if filename is string "NULL" */ if (fname != NULL) { - if ((f = HDfopen(fname, "w")) != NULL) { - rawattrstream = f; - retvalue = SUCCEED; + /* binary output */ + if (is_bin) { + if ((f = HDfopen(fname, "wb")) != NULL) { + rawattrstream = f; + retvalue = SUCCEED; + } + } + else { + if ((f = HDfopen(fname, "w")) != NULL) { + rawattrstream = f; + retvalue = SUCCEED; + } } } else { @@ -312,7 +321,7 @@ h5tools_set_attr_output_file(const char *fname, int is_bin) *------------------------------------------------------------------------- */ int -h5tools_set_input_file(const char *fname) +h5tools_set_input_file(const char *fname, int is_bin) { int retvalue = FAIL; FILE *f; /* temporary holding place for the stream pointer @@ -326,9 +335,18 @@ h5tools_set_input_file(const char *fname) } /* First check if filename is string "NULL" */ if (fname != NULL) { - if ((f = HDfopen(fname, "r")) != NULL) { - rawinstream = f; - retvalue = SUCCEED; + /* binary output */ + if (is_bin) { + if ((f = HDfopen(fname, "rb")) != NULL) { + rawinstream = f; + retvalue = SUCCEED; + } + } + else { + if ((f = HDfopen(fname, "r")) != NULL) { + rawinstream = f; + retvalue = SUCCEED; + } } } else { @@ -351,7 +369,7 @@ h5tools_set_input_file(const char *fname) *------------------------------------------------------------------------- */ int -h5tools_set_output_file(const char *fname) +h5tools_set_output_file(const char *fname, int is_bin) { int retvalue = FAIL; FILE *f; /* temporary holding place for the stream pointer @@ -365,9 +383,18 @@ h5tools_set_output_file(const char *fname) } /* First check if filename is string "NULL" */ if (fname != NULL) { - if ((f = HDfopen(fname, "w")) != NULL) { - rawoutstream = f; - retvalue = SUCCEED; + /* binary output */ + if (is_bin) { + if ((f = HDfopen(fname, "wb")) != NULL) { + rawoutstream = f; + retvalue = SUCCEED; + } + } + else { + if ((f = HDfopen(fname, "w")) != NULL) { + rawoutstream = f; + retvalue = SUCCEED; + } } } else { @@ -390,7 +417,7 @@ h5tools_set_output_file(const char *fname) *------------------------------------------------------------------------- */ int -h5tools_set_error_file(const char *fname) +h5tools_set_error_file(const char *fname, int is_bin) { int retvalue = FAIL; FILE *f; /* temporary holding place for the stream pointer @@ -403,8 +430,24 @@ h5tools_set_error_file(const char *fname) rawerrorstream = NULL; } - if ((f = HDfopen(fname, "w")) != NULL) { - rawerrorstream = f; + /* First check if filename is string "NULL" */ + if (fname != NULL) { + /* binary output */ + if (is_bin) { + if ((f = HDfopen(fname, "wb")) != NULL) { + rawerrorstream = f; + retvalue = SUCCEED; + } + } + else { + if ((f = HDfopen(fname, "w")) != NULL) { + rawerrorstream = f; + retvalue = SUCCEED; + } + } + } + else { + rawerrorstream = NULL; retvalue = SUCCEED; } diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index 5f834c5..ea6a44f 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -552,9 +552,9 @@ H5TOOLS_DLL void h5tools_init(void); H5TOOLS_DLL void h5tools_close(void); H5TOOLS_DLL int h5tools_set_data_output_file(const char *fname, int is_bin); H5TOOLS_DLL int h5tools_set_attr_output_file(const char *fname, int is_bin); -H5TOOLS_DLL int h5tools_set_input_file(const char *fname); -H5TOOLS_DLL int h5tools_set_output_file(const char *fname); -H5TOOLS_DLL int h5tools_set_error_file(const char *fname); +H5TOOLS_DLL int h5tools_set_input_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_output_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_error_file(const char *fname, int is_bin); H5TOOLS_DLL hid_t h5tools_fopen(const char *fname, unsigned flags, hid_t fapl, const char *driver, char *drivername, size_t drivername_len); H5TOOLS_DLL hid_t h5tools_get_native_type(hid_t type); -- cgit v0.12