diff options
author | Bill Wendling <wendling@ncsa.uiuc.edu> | 2002-03-29 23:01:30 (GMT) |
---|---|---|
committer | Bill Wendling <wendling@ncsa.uiuc.edu> | 2002-03-29 23:01:30 (GMT) |
commit | 5e5889822117f79de83b1e399b73c2cc664db10f (patch) | |
tree | 04b23ec6168bf33b293fa809d625a2f48266f9a0 /tools/lib | |
parent | c6b201b25debf34ff0d49ddf80ece394b8c581d5 (diff) | |
download | hdf5-5e5889822117f79de83b1e399b73c2cc664db10f.zip hdf5-5e5889822117f79de83b1e399b73c2cc664db10f.tar.gz hdf5-5e5889822117f79de83b1e399b73c2cc664db10f.tar.bz2 |
[svn-r5122] Purpose:
Fix and Code Removal
Description:
Back ported fix for the problem with >1024byte object names in the
h5dumper.
Removed the testfiles which were HDF4 specific.
Solution:
Changed the way the object name was being allocated from a static
array size to a dynamically allocated address...
Platforms tested:
Linux
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5tools_utils.c | 186 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.h | 2 |
2 files changed, 99 insertions, 89 deletions
diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index baaebc4..c9ef60d 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -1,6 +1,7 @@ /* - * Copyright (c) 2001 National Center for Supercomputing Applications - * All rights reserved. + * Copyright (c) 2001, 2002 + * National Center for Supercomputing Applications + * All rights reserved. * * Programmer: Bill Wendling <wendling@ncsa.uiuc.edu> * Tuesday, 6. March 2001 @@ -52,13 +53,13 @@ error_msg(const char *progname, const char *fmt, ...) va_list ap; va_start(ap, fmt); - fflush(stdout); + HDfflush(stdout); #ifdef WIN32 - fprintf(stdout, "%s error: ", progname); - vfprintf(stdout, fmt, ap); + HDfprintf(stdout, "%s error: ", progname); + HDvfprintf(stdout, fmt, ap); #else - fprintf(stderr, "%s error: ", progname); - vfprintf(stderr, fmt, ap); + HDfprintf(stderr, "%s error: ", progname); + HDvfprintf(stderr, fmt, ap); #endif va_end(ap); @@ -86,9 +87,14 @@ warn_msg(const char *progname, const char *fmt, ...) va_list ap; va_start(ap, fmt); - fflush(stdout); - fprintf(stderr, "%s warning: ", progname); - vfprintf(stderr, fmt, ap); + HDfflush(stdout); +#ifdef WIN32 + HDfprintf(stdout, "%s warning: ", progname); + HDvfprintf(stdout, fmt, ap); +#else /* WIN32 */ + HDfprintf(stderr, "%s warning: ", progname); + HDvfprintf(stderr, fmt, ap); +#endif /* WIN32 */ va_end(ap); } @@ -122,7 +128,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti /* check for more flag-like tokens */ if (opt_ind >= argc || argv[opt_ind][0] != '-' || argv[opt_ind][1] == '\0') { return EOF; - } else if (strcmp(argv[opt_ind], "--") == 0) { + } else if (HDstrcmp(argv[opt_ind], "--") == 0) { opt_ind++; return EOF; } @@ -134,9 +140,9 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti register int i; for (i = 0; l_opts && l_opts[i].name; i++) { - size_t len = strlen(l_opts[i].name); + size_t len = HDstrlen(l_opts[i].name); - if (strncmp(arg, l_opts[i].name, len) == 0) { + if (HDstrncmp(arg, l_opts[i].name, len) == 0) { /* we've found a matching long command line flag */ opt_opt = l_opts[i].shortval; @@ -147,7 +153,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti opt_arg = argv[++opt_ind]; } else if (l_opts[i].has_arg == require_arg) { if (opt_err) - fprintf(stderr, + HDfprintf(stderr, "%s: option required for \"--%s\" flag\n", argv[0], arg); @@ -156,7 +162,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti } else { if (arg[len] == '=') { if (opt_err) - fprintf(stderr, + HDfprintf(stderr, "%s: no option required for \"%s\" flag\n", argv[0], arg); @@ -173,7 +179,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti if (l_opts[i].name == NULL) { /* exhausted all of the l_opts we have and still didn't match */ if (opt_err) - fprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg); + HDfprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg); opt_opt = '?'; } @@ -188,7 +194,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti if (opt_opt == ':' || (cp = strchr(opts, opt_opt)) == 0) { if (opt_err) - fprintf(stderr, "%s: unknown option \"%c\"\n", + HDfprintf(stderr, "%s: unknown option \"%c\"\n", argv[0], opt_opt); /* if no chars left in this token, move to next token */ @@ -207,7 +213,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti opt_arg = &argv[opt_ind++][sp + 1]; } else if (++opt_ind >= argc) { if (opt_err) - fprintf(stderr, + HDfprintf(stderr, "%s: value expected for option \"%c\"\n", argv[0], opt_opt); @@ -255,7 +261,7 @@ indentation(int x) while (x-- > 0) printf(" "); } else { - fprintf(stderr, "error: the indentation exceeds the number of cols.\n"); + HDfprintf(stderr, "error: the indentation exceeds the number of cols.\n"); exit(1); } } @@ -302,17 +308,18 @@ void init_table(table_t **tbl) { int i; - table_t *table = malloc(sizeof(table_t)); + table_t *table = HDmalloc(sizeof(table_t)); table->size = 20; table->nobjs = 0; - table->objs = malloc(table->size * sizeof(obj_t)); + table->objs = HDmalloc(table->size * sizeof(obj_t)); for (i = 0; i < table->size; i++) { table->objs[i].objno[0] = table->objs[i].objno[1] = 0; table->objs[i].displayed = 0; table->objs[i].recorded = 0; table->objs[i].objflag = 0; + table->objs[i].objname = NULL; } *tbl = table; @@ -334,7 +341,7 @@ void init_prefix(char **prefix, int prefix_len) { assert(prefix_len > 0); - *prefix = calloc((size_t)prefix_len, 1); + *prefix = HDcalloc((size_t)prefix_len, 1); } @@ -417,93 +424,94 @@ find_objs(hid_t group, const char *name, void *op_data) H5Gget_objinfo(group, name, TRUE, &statbuf); - tmp = malloc(strlen(info->prefix) + strlen(name) + 2); - strcpy(tmp, info->prefix); + tmp = HDmalloc(HDstrlen(info->prefix) + HDstrlen(name) + 2); + HDstrcpy(tmp, info->prefix); switch (statbuf.type) { - case H5G_GROUP: - if ((obj = H5Gopen(group, name)) >= 0) { - if (info->prefix_len < (int)(strlen(info->prefix) + strlen(name) + 2)) { - info->prefix_len *= 2; - info->prefix = realloc(info->prefix, - info->prefix_len * sizeof(char)); - } + case H5G_GROUP: + if ((obj = H5Gopen(group, name)) >= 0) { + if (info->prefix_len < (int)(HDstrlen(info->prefix) + HDstrlen(name) + 2)) { + info->prefix_len *= 2; + info->prefix = HDrealloc(info->prefix, + info->prefix_len * sizeof(char)); + } - strcat(strcat(info->prefix,"/"), name); + HDstrcat(HDstrcat(info->prefix,"/"), name); - if (statbuf.nlink > info->threshold) { - if (search_obj(info->group_table, statbuf.objno) == FAIL) { - add_obj(info->group_table, statbuf.objno, info->prefix); - H5Giterate(obj, ".", NULL, find_objs, (void *)info); + if (statbuf.nlink > info->threshold) { + if (search_obj(info->group_table, statbuf.objno) == FAIL) { + add_obj(info->group_table, statbuf.objno, info->prefix); + H5Giterate(obj, ".", NULL, find_objs, (void *)info); + } + } else { + H5Giterate (obj, ".", NULL, find_objs, (void *)info); } - } else { - H5Giterate (obj, ".", NULL, find_objs, (void *)info); - } - strcpy(info->prefix, tmp); - H5Gclose (obj); - } else { - info->status = 1; - } + HDstrcpy(info->prefix, tmp); + H5Gclose (obj); + } else { + info->status = 1; + } - break; + break; - case H5G_DATASET: - strcat(tmp,"/"); - strcat(tmp,name); /* absolute name of the data set */ + case H5G_DATASET: + HDstrcat(tmp,"/"); + HDstrcat(tmp,name); /* absolute name of the data set */ - if (statbuf.nlink > info->threshold && - search_obj(info->dset_table, statbuf.objno) == FAIL) - add_obj(info->dset_table, statbuf.objno, tmp); + if (statbuf.nlink > info->threshold && + search_obj(info->dset_table, statbuf.objno) == FAIL) + add_obj(info->dset_table, statbuf.objno, tmp); - if ((obj = H5Dopen (group, name)) >= 0) { - type = H5Dget_type(obj); + if ((obj = H5Dopen (group, name)) >= 0) { + type = H5Dget_type(obj); - if (H5Tcommitted(type) > 0) { - H5Gget_objinfo(type, ".", TRUE, &statbuf); + if (H5Tcommitted(type) > 0) { + H5Gget_objinfo(type, ".", TRUE, &statbuf); - if (search_obj(info->type_table, statbuf.objno) == FAIL) { - add_obj(info->type_table, statbuf.objno, tmp); - info->type_table->objs[info->type_table->nobjs - 1].objflag = 0; + if (search_obj(info->type_table, statbuf.objno) == FAIL) { + add_obj(info->type_table, statbuf.objno, tmp); + info->type_table->objs[info->type_table->nobjs - 1].objflag = 0; + } } - } - H5Tclose(type); - H5Dclose (obj); - } else { - info->status = 1; - } - - break; + H5Tclose(type); + H5Dclose (obj); + } else { + info->status = 1; + } + + break; - case H5G_TYPE: - strcat(tmp,"/"); - strcat(tmp,name); /* absolute name of the type */ - i = search_obj(info->type_table, statbuf.objno); + case H5G_TYPE: + HDstrcat(tmp,"/"); + HDstrcat(tmp,name); /* absolute name of the type */ + i = search_obj(info->type_table, statbuf.objno); - if (i == FAIL) { - add_obj(info->type_table, statbuf.objno, tmp) ; + if (i == FAIL) { + add_obj(info->type_table, statbuf.objno, tmp) ; - /* named data type */ - info->type_table->objs[info->type_table->nobjs-1].recorded = 1; + /* named data type */ + info->type_table->objs[info->type_table->nobjs-1].recorded = 1; - /* named data type */ - info->type_table->objs[info->type_table->nobjs-1].objflag = 1; - } else { - strcpy (info->type_table->objs[i].objname, tmp); - info->type_table->objs[i].recorded = 1; + /* named data type */ + info->type_table->objs[info->type_table->nobjs-1].objflag = 1; + } else { + HDfree(info->type_table->objs[i].objname); + info->type_table->objs[i].objname = HDstrdup(tmp); + info->type_table->objs[i].recorded = 1; - /* named data type */ - info->type_table->objs[info->type_table->nobjs-1].objflag = 1; - } + /* named data type */ + info->type_table->objs[info->type_table->nobjs-1].objflag = 1; + } - break; + break; - default: - break; + default: + break; } - free(tmp); + HDfree(tmp); return SUCCEED; } @@ -637,18 +645,20 @@ add_obj(table_t *table, unsigned long *objno, char *objname) if (table->nobjs == table->size) { table->size *= 2; - table->objs = realloc(table->objs, table->size * sizeof(obj_t)); + table->objs = HDrealloc(table->objs, table->size * sizeof(obj_t)); for (i = table->nobjs; i < table->size; i++) { table->objs[i].objno[0] = table->objs[i].objno[1] = 0; table->objs[i].displayed = 0; table->objs[i].recorded = 0; table->objs[i].objflag = 0; + table->objs[i].objname = NULL; } } i = table->nobjs++; table->objs[i].objno[0] = objno[0]; table->objs[i].objno[1] = objno[1]; - strcpy(table->objs[i].objname, objname); + HDfree(table->objs[i].objname); + table->objs[i].objname = HDstrdup(objname); } diff --git a/tools/lib/h5tools_utils.h b/tools/lib/h5tools_utils.h index eda8e00b..bb47c94 100644 --- a/tools/lib/h5tools_utils.h +++ b/tools/lib/h5tools_utils.h @@ -69,7 +69,7 @@ extern int get_option(int argc, const char **argv, const char *opt, /*struct taken from the dumper. needed in table struct*/ typedef struct obj_t { unsigned long objno[2]; - char objname[1024]; + char *objname; int displayed; int recorded; int objflag; |