summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_utils.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2017-10-13 21:34:01 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2017-10-13 21:34:01 (GMT)
commitd5c073d406f8d1e1ac3bcb05883bea406c8e9378 (patch)
treef9a8d818c032fa4d5f3cfa0857a799ecfa0cc9a7 /tools/lib/h5tools_utils.c
parentfc12672cdbd162f47293ec9ee2185e3efe1d0405 (diff)
downloadhdf5-d5c073d406f8d1e1ac3bcb05883bea406c8e9378.zip
hdf5-d5c073d406f8d1e1ac3bcb05883bea406c8e9378.tar.gz
hdf5-d5c073d406f8d1e1ac3bcb05883bea406c8e9378.tar.bz2
HDFFV-10296 Update tools lib to use the error handling macros.
Diffstat (limited to 'tools/lib/h5tools_utils.c')
-rw-r--r--tools/lib/h5tools_utils.c231
1 files changed, 65 insertions, 166 deletions
diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c
index 8c435b2..1b5911b 100644
--- a/tools/lib/h5tools_utils.c
+++ b/tools/lib/h5tools_utils.c
@@ -58,15 +58,11 @@ static void add_obj(table_t *table, haddr_t objno, const char *objname, hbool_t
/*-------------------------------------------------------------------------
* Function: parallel_print
*
- * Purpose: wrapper for printf for use in parallel mode.
- *
- * Programmer: Leon Arber
- *
- * Date: December 1, 2004
- *
+ * Purpose: wrapper for printf for use in parallel mode.
*-------------------------------------------------------------------------
*/
-void parallel_print(const char* format, ...)
+void
+parallel_print(const char* format, ...)
{
int bytes_written;
va_list ap;
@@ -103,18 +99,12 @@ void parallel_print(const char* format, ...)
/*-------------------------------------------------------------------------
- * Function: error_msg
+ * Function: error_msg
*
- * Purpose: Print a nicely formatted error message to stderr flushing the
+ * Purpose: Print a nicely formatted error message to stderr flushing the
* stdout stream first.
*
- * Return: Nothing
- *
- * Programmer: Bill Wendling
- * Tuesday, 20. February 2001
- *
- * Modifications:
- *
+ * Return: Nothing
*-------------------------------------------------------------------------
*/
void
@@ -134,18 +124,12 @@ error_msg(const char *fmt, ...)
/*-------------------------------------------------------------------------
- * Function: warn_msg
+ * Function: warn_msg
*
- * Purpose: Print a nicely formatted warning message to stderr flushing
+ * Purpose: Print a nicely formatted warning message to stderr flushing
* the stdout stream first.
*
- * Return: Nothing
- *
- * Programmer: Bill Wendling
- * Tuesday, 20. February 2001
- *
- * Modifications:
- *
+ * Return: Nothing
*-------------------------------------------------------------------------
*/
void
@@ -163,14 +147,11 @@ warn_msg(const char *fmt, ...)
}
/*-------------------------------------------------------------------------
- * Function: help_ref_msg
+ * Function: help_ref_msg
*
- * Purpose: Print a message to refer help page
- *
- * Return: Nothing
- *
- * Modifications:
+ * Purpose: Print a message to refer help page
*
+ * Return: Nothing
*-------------------------------------------------------------------------
*/
void
@@ -182,24 +163,16 @@ help_ref_msg(FILE *output)
/*-------------------------------------------------------------------------
- * Function: get_option
+ * Function: get_option
*
- * Purpose: Determine the command-line options a user specified. We can
- * accept both short and long type command-lines.
+ * Purpose: Determine the command-line options a user specified. We can
+ * accept both short and long type command-lines.
*
* Return: Success: The short valued "name" of the command line
* parameter or EOF if there are no more
* parameters to process.
*
- * Failure: A question mark.
- *
- * Programmer: Bill Wendling
- * Friday, 5. January 2001
- *
- * Modifications: Pedro Vicente
- * October, 27 2008
- * Wilcard "*" argument type
- *
+ * Failure: A question mark.
*-------------------------------------------------------------------------
*/
int
@@ -232,9 +205,8 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
opt_opt = l_opts[i].shortval;
if (l_opts[i].has_arg != no_arg) {
- if (arg[len] == '=') {
+ if (arg[len] == '=')
opt_arg = &arg[len + 1];
- }
else if (l_opts[i].has_arg != optional_arg) {
if (opt_ind < (argc - 1))
if (argv[opt_ind + 1][0] != '-')
@@ -323,16 +295,13 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
opt_ind++;
/* we do have an extra argument, check if not last */
if ( (opt_ind+1) < argc ) {
- if ( argv[opt_ind][0] != '-' ) {
+ if ( argv[opt_ind][0] != '-' )
opt_arg = argv[opt_ind++];
- }
- else {
+ else
opt_arg = NULL;
- }
}
- else {
+ else
opt_arg = NULL;
- }
}
else {
/* set up to look at next char in token, next time */
@@ -351,16 +320,11 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
/*-------------------------------------------------------------------------
- * Function: indentation
+ * Function: indentation
*
- * Purpose: Print spaces for indentation
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
+ * Purpose: Print spaces for indentation
*
+ * Return: void
*-------------------------------------------------------------------------
*/
void
@@ -378,17 +342,12 @@ indentation(unsigned x)
/*-------------------------------------------------------------------------
- * Function: print_version
+ * Function: print_version
*
- * Purpose: Print the program name and the version information which is
- * defined the same as the HDF5 library version.
- *
- * Return: void
- *
- * Programmer: unknown
- *
- * Modifications:
+ * Purpose: Print the program name and the version information which is
+ * defined the same as the HDF5 library version.
*
+ * Return: void
*-------------------------------------------------------------------------
*/
void
@@ -407,11 +366,6 @@ print_version(const char *progname)
* and committed types
*
* Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static void
@@ -434,11 +388,6 @@ init_table(table_t **tbl)
* and committed types
*
* Return: void
- *
- * Programmer: Paul Harten
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
void
@@ -462,11 +411,6 @@ free_table(table_t *table)
* Purpose: display the contents of tables for debugging purposes
*
* Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static void
@@ -488,11 +432,6 @@ dump_table(char* tablename, table_t *table)
* Purpose: display the contents of tables for debugging purposes
*
* Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
void
@@ -513,11 +452,6 @@ dump_tables(find_objs_t *info)
* Return: Success: an integer, the location of the object
*
* Failure: FAIL if object is not found
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
H5_ATTR_PURE obj_t *
@@ -541,11 +475,6 @@ search_obj(table_t *table, haddr_t objno)
* Return: Success: SUCCEED
*
* Failure: FAIL
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -623,11 +552,6 @@ find_objs_cb(const char *name, const H5O_info_t *oinfo, const char *already_seen
* Return: Success: SUCCEED
*
* Failure: FAIL
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
herr_t
@@ -657,11 +581,6 @@ init_objs(hid_t fid, find_objs_t *info, table_t **group_table,
* realloc the table if necessary
*
* Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static void
@@ -695,11 +614,6 @@ add_obj(table_t *table, haddr_t objno, const char *objname, hbool_t record)
*
* Return: a stream description when succeeds.
* NULL if fails.
- *
- * Programmer: Albert Cheng, 2005/8/9
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
FILE *
@@ -723,70 +637,61 @@ tmpfile(void)
*
* Return:
* 2 : given pathname is object
- * 1 : Succed to get link info.
+ * 1 : Succeed to get link info.
* 0 : Detected as a dangling link
* -1 : H5 API failed.
*
* NOTE:
* link_info->trg_path must be freed out of this function
- *
- * Programmer: Jonathan Kim
- *
- * Date: Feb 8, 2010
*-------------------------------------------------------------------------*/
int
-H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_t *link_info,
- hbool_t get_obj_type)
+H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_t *link_info, hbool_t get_obj_type)
{
htri_t l_ret;
H5O_info_t trg_oinfo;
hid_t fapl = H5P_DEFAULT;
hid_t lapl = H5P_DEFAULT;
- int ret = -1; /* init to fail */
+ int ret_value = -1; /* init to fail */
/* init */
link_info->trg_type = H5O_TYPE_UNKNOWN;
/* if path is root, return group type */
- if(!HDstrcmp(linkpath,"/"))
- {
+ if(!HDstrcmp(linkpath,"/")) {
link_info->trg_type = H5O_TYPE_GROUP;
- ret = 2;
- goto out;
+ HGOTO_DONE(2);
}
/* check if link itself exist */
if(H5Lexists(file_id, linkpath, H5P_DEFAULT) <= 0) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: link <%s> doesn't exist \n",linkpath);
- goto out;
+ HGOTO_DONE(FAIL);
} /* end if */
/* get info from link */
if(H5Lget_info(file_id, linkpath, &(link_info->linfo), H5P_DEFAULT) < 0) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to get link info from <%s>\n",linkpath);
- goto out;
+ HGOTO_DONE(FAIL);
} /* end if */
/* given path is hard link (object) */
- if(link_info->linfo.type == H5L_TYPE_HARD) {
- ret = 2;
- goto out;
- } /* end if */
+ if(link_info->linfo.type == H5L_TYPE_HARD)
+ HGOTO_DONE(2);
/* trg_path must be freed out of this function when finished using */
if((link_info->trg_path = (char*)HDcalloc(link_info->linfo.u.val_size, sizeof(char))) == NULL) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to allocate buffer for <%s>\n",linkpath);
- goto out;
+ HGOTO_DONE(FAIL);
} /* end if */
/* get link value */
if(H5Lget_val(file_id, linkpath, (void *)link_info->trg_path, link_info->linfo.u.val_size, H5P_DEFAULT) < 0) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to get link value from <%s>\n",linkpath);
- goto out;
+ HGOTO_DONE(FAIL);
} /* end if */
/*-----------------------------------------------------
@@ -795,13 +700,13 @@ H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_
*/
if(link_info->linfo.type == H5L_TYPE_EXTERNAL) {
if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
- goto out;
+ HGOTO_DONE(FAIL);
if(H5Pset_fapl_sec2(fapl) < 0)
- goto out;
+ HGOTO_DONE(FAIL);
if((lapl = H5Pcreate(H5P_LINK_ACCESS)) < 0)
- goto out;
+ HGOTO_DONE(FAIL);
if(H5Pset_elink_fapl(lapl, fapl) < 0)
- goto out;
+ HGOTO_DONE(FAIL);
} /* end if */
/* Check for retrieving object info */
@@ -814,25 +719,24 @@ H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_
/* detect dangling link */
if(l_ret == FALSE) {
- ret = 0;
- goto out;
- } /* end if */
- /* function failed */
- else if(l_ret < 0)
- goto out;
+ HGOTO_DONE(0);
+ }
+ else if(l_ret < 0) { /* function failed */
+ HGOTO_DONE(FAIL);
+ }
/* get target object info */
if(H5Oget_info_by_name(file_id, linkpath, &trg_oinfo, lapl) < 0) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to get object information for <%s>\n", linkpath);
- goto out;
+ HGOTO_DONE(FAIL);
} /* end if */
/* check unknown type */
if(trg_oinfo.type < H5O_TYPE_GROUP || trg_oinfo.type >=H5O_TYPE_NTYPES) {
if(link_info->opt.msg_mode == 1)
parallel_print("Warning: target object of <%s> is unknown type\n", linkpath);
- goto out;
+ HGOTO_DONE(FAIL);
} /* end if */
/* set target obj type to return */
@@ -844,31 +748,34 @@ H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_
link_info->trg_type = H5O_TYPE_UNKNOWN;
/* succeed */
- ret = 1;
+ ret_value = 1;
-out:
+done:
if(fapl != H5P_DEFAULT)
H5Pclose(fapl);
if(lapl != H5P_DEFAULT)
H5Pclose(lapl);
- return ret;
+ return ret_value;
} /* end H5tools_get_symlink_info() */
/*-------------------------------------------------------------------------
* Audience: Public
- * Chapter: H5Tools Library
+ *
* Purpose: Initialize the name and operation status of the H5 Tools library
+ *
* Description:
* These are utility functions to set/get the program name and operation status.
*-------------------------------------------------------------------------
*/
-void h5tools_setprogname(const char *Progname)
+void
+h5tools_setprogname(const char *Progname)
{
h5tools_progname = Progname;
}
-void h5tools_setstatus(int D_status)
+void
+h5tools_setstatus(int D_status)
{
h5tools_d_status = D_status;
}
@@ -892,25 +799,19 @@ h5tools_getstatus(void)
* This can be called from each tools main() as part of initial act.
* Note: this is more of debugging purpose for now.
*/
-int h5tools_getenv_update_hyperslab_bufsize(void)
+int
+h5tools_getenv_update_hyperslab_bufsize(void)
{
const char *env_str = NULL;
long hyperslab_bufsize_mb;
+ int ret_value = 1;
/* check if environment variable is set for the hyperslab buffer size */
- if (NULL != (env_str = HDgetenv ("H5TOOLS_BUFSIZE")))
- {
+ if (NULL != (env_str = HDgetenv ("H5TOOLS_BUFSIZE"))) {
errno = 0;
hyperslab_bufsize_mb = HDstrtol(env_str, (char**)NULL, 10);
if (errno != 0 || hyperslab_bufsize_mb <= 0)
- {
- /* TODO: later when pubilshed
- HDfprintf(rawerrorstream,"Error: Invalid environment variable \"H5TOOLS_BUFSIZE\" : %s\n", env_str);
- */
-
- goto error;
- }
-
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "hyperslab buffer size failed");
/* convert MB to byte */
H5TOOLS_BUFSIZE = (hsize_t)hyperslab_bufsize_mb * 1024 * 1024;
@@ -918,9 +819,7 @@ int h5tools_getenv_update_hyperslab_bufsize(void)
H5TOOLS_MALLOCSIZE = MAX(H5TOOLS_BUFSIZE, H5TOOLS_MALLOCSIZE);
}
- return (1);
-
-error:
- return (-1);
+done:
+ return ret_value;
}