diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5dump/h5dump.c | 23 | ||||
-rw-r--r-- | tools/h5dump/h5dumpgentest.c | 5 | ||||
-rw-r--r-- | tools/h5ls/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tools/h5ls/h5ls.c | 22 | ||||
-rw-r--r-- | tools/h5ls/testh5ls.sh.in | 3 | ||||
-rw-r--r-- | tools/testfiles/tgrp_comments.ddl | 3 | ||||
-rw-r--r-- | tools/testfiles/tgrp_comments.h5 | bin | 14336 -> 13248 bytes | |||
-rw-r--r-- | tools/testfiles/tgrp_comments.ls | 8 |
8 files changed, 61 insertions, 10 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 33750f3..40a37af 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -2646,15 +2646,28 @@ dump_oid(hid_t oid) static void dump_comment(hid_t obj_id) { - char comment[50]; - - comment[0] = '\0'; - H5Oget_comment(obj_id, comment, sizeof(comment)); + size_t buf_size = 0; + char* comment = NULL; + ssize_t cmt_bufsize = -1; + + cmt_bufsize = H5Oget_comment(obj_id, comment, buf_size); + + // if the actual length of the comment is longer than cmt_bufsize, then call + // H5Oget_comment again with the correct value. + // If the call to H5Oget_comment returned an error, skip this block + if (cmt_bufsize >= 0) { + comment = (char *)HDmalloc((size_t)cmt_bufsize++); // new_size including null terminator + if(comment) + cmt_bufsize = H5Oget_comment(obj_id, comment, cmt_bufsize); + } - if(comment[0]) { + if(cmt_bufsize > 0) { + comment[cmt_bufsize] = '\0'; indentation(indent); printf("COMMENT \"%s\"\n", comment); } /* end if */ + if(comment) + HDfree(comment); } /* end dump_comment() */ diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c index 7701651..8401000 100644 --- a/tools/h5dump/h5dumpgentest.c +++ b/tools/h5dump/h5dumpgentest.c @@ -3400,6 +3400,11 @@ gent_group_comments(void) H5Oset_comment_by_name(group, "/g2/g2.1/g2.1.3", "Comment for group /g2/g2.1/g2.1.3", H5P_DEFAULT); H5Gclose(group); + /* /glongcomment */ + group = H5Gcreate2(fid, "/glongcomment", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5Oset_comment_by_name(group, "/glongcomment", "Comment for group /glongcomment with a really, really, really long, long, long comment", H5P_DEFAULT); + H5Gclose(group); + H5Fclose(fid); } diff --git a/tools/h5ls/CMakeLists.txt b/tools/h5ls/CMakeLists.txt index 3039682..7db6c7f 100644 --- a/tools/h5ls/CMakeLists.txt +++ b/tools/h5ls/CMakeLists.txt @@ -62,6 +62,7 @@ IF (BUILD_TESTING) tsoftlinks-5.ls textlinksrc-nodangle-1.ls textlinksrc-nodangle-2.ls + tgrp_comments.ls tsoftlinks-nodangle-1.ls thlinks-nodangle-1.ls tgroup.ls @@ -94,6 +95,7 @@ IF (BUILD_TESTING) textlinksrc.h5 textlinktar.h5 tgroup.h5 + tgrp_comments.h5 thlink.h5 tloop.h5 tnestedcomp.h5 @@ -210,6 +212,8 @@ IF (BUILD_TESTING) textlinksrc-6-old.out.err textlinksrc-7-old.out textlinksrc-7-old.out.err + tgrp_comments.out + tgrp_comments.out.err tsoftlinks-1.out tsoftlinks-1.out.err tsoftlinks-2.out @@ -288,6 +292,9 @@ IF (BUILD_TESTING) ADD_H5_TEST (tgroup-1 1 -w80 -r -g tgroup.h5) ADD_H5_TEST (tgroup-2 0 -w80 -g tgroup.h5/g1) + # test for files with groups that have long comments + ADD_H5_TEST (tgrp_comments 0 -w80 -v -g tgrp_comments.h5/glongcomment) + # test for displaying simple space datasets ADD_H5_TEST (tdset-1 0 -w80 -r -d tdset.h5) diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index b74d525..051821e 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -1785,7 +1785,9 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void /* Show detailed information about the object, beginning with information * which is common to all objects. */ if(verbose_g > 0) { - char comment[50]; + size_t buf_size = 0; + char* comment = NULL; + ssize_t cmt_bufsize = -1; /* Display attributes */ if(obj_type >= 0) @@ -1811,14 +1813,24 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void } /* end if */ /* Object comment */ - comment[0] = '\0'; - H5Oget_comment(obj, comment, sizeof(comment)); - HDstrcpy(comment + sizeof(comment) - 4, "..."); - if(comment[0]) { + cmt_bufsize = H5Oget_comment(obj, comment, buf_size); + + // if the actual length of the comment is longer than cmt_bufsize, then call + // H5Oget_comment again with the correct value. + // If the call to H5Oget_comment returned an error, skip this block + if (cmt_bufsize >= 0) { + comment = (char *)HDmalloc((size_t)cmt_bufsize++); // new_size including null terminator + if(comment) + cmt_bufsize = H5Oget_comment(obj, comment, cmt_bufsize); + } + if(cmt_bufsize > 0) { + comment[cmt_bufsize] = '\0'; printf(" %-10s \"", "Comment:"); display_string(stdout, comment, FALSE); puts("\""); } /* end if */ + if(comment) + HDfree(comment); } /* end if */ /* Detailed list for object */ diff --git a/tools/h5ls/testh5ls.sh.in b/tools/h5ls/testh5ls.sh.in index a996401..3083028 100644 --- a/tools/h5ls/testh5ls.sh.in +++ b/tools/h5ls/testh5ls.sh.in @@ -135,6 +135,9 @@ TOOLTEST tgroup-3.ls 0 -w80 tgroup.h5/g1 TOOLTEST tgroup-1.ls 1 -w80 -r -g tgroup.h5 TOOLTEST tgroup-2.ls 0 -w80 -g tgroup.h5/g1 +# test for files with groups that have long comments +TOOLTEST tgrp_comments.ls 0 -w80 -v -g tgrp_comments.h5/glongcomment + # test for displaying simple space datasets TOOLTEST tdset-1.ls 0 -w80 -r -d tdset.h5 diff --git a/tools/testfiles/tgrp_comments.ddl b/tools/testfiles/tgrp_comments.ddl index 6321b36..460a9f0 100644 --- a/tools/testfiles/tgrp_comments.ddl +++ b/tools/testfiles/tgrp_comments.ddl @@ -42,5 +42,8 @@ GROUP "/" { COMMENT "Comment for group /g3/g3.4" } } + GROUP "glongcomment" { + COMMENT "Comment for group /glongcomment with a really, really, really long, long, long comment" + } } } diff --git a/tools/testfiles/tgrp_comments.h5 b/tools/testfiles/tgrp_comments.h5 Binary files differindex 70c7cce..ddd2eec 100644 --- a/tools/testfiles/tgrp_comments.h5 +++ b/tools/testfiles/tgrp_comments.h5 diff --git a/tools/testfiles/tgrp_comments.ls b/tools/testfiles/tgrp_comments.ls new file mode 100644 index 0000000..e4c7d42 --- /dev/null +++ b/tools/testfiles/tgrp_comments.ls @@ -0,0 +1,8 @@ +############################# + output for 'h5ls -w80 -v -g tgrp_comments.h5/glongcomment' +############################# +Opened "tgrp_comments.h5" with sec2 driver. +glongcomment Group + Location: 1:12424 + Links: 1 + Comment: "Comment for group /glongcomment with a really, really, really long, long, long comment" |