/* * Class: hdf_hdf5lib_H5 * Method: H5Oget_comment * Signature: (J)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Oget_1comment (JNIEnv *env, jclass clss, jlong loc_id) { jstring str = NULL; ssize_t buf_size; ssize_t status = -1; char *oComment = NULL; UNUSED(clss); /* Get the length of the comment */ if ((buf_size = H5Oget_comment((hid_t)loc_id, NULL, 0)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (buf_size) { if (NULL == (oComment = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) H5_JNI_FATAL_ERROR(ENVONLY, "H5Oget_comment: failed to allocate object comment buffer"); if ((status = H5Oget_comment((hid_t)loc_id, oComment, (size_t)buf_size + 1)) < 0) H5_LIBRARY_ERROR(ENVONLY); oComment[buf_size] = '\0'; if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, oComment))) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } done: if (oComment) HDfree(oComment); return (jstring)str; } /* end Java_hdf_hdf5lib_H5_H5Oget_1comment */
// Constructors }}} // Comments {{{ string Object::getComment() const { // {{{ size_t comment_size = assertSuccess( "getting object comment length", H5Oget_comment(getId(),NULL,0) ); if(comment_size == 0) return string(); scoped_array<char> buffer(new char[comment_size+1]); assertSuccess( "getting object comment", H5Oget_comment(getId(),buffer.get(),comment_size+1) ); return string(buffer.get()); } // }}}
/* * Class: hdf_hdf5lib_H5 * Method: H5Oget_comment * Signature: (J)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Oget_1comment (JNIEnv *env, jclass clss, jlong loc_id) { char *oComment; ssize_t buf_size; ssize_t status; jstring str = NULL; /* get the length of the comment */ buf_size = H5Oget_comment((hid_t)loc_id, NULL, 0); if (buf_size < 0) { h5badArgument( env, "H5Oget_comment: buf_size < 0"); } /* end if */ else if (buf_size > 0) { buf_size++; /* add extra space for the null terminator */ oComment = (char *)HDmalloc(sizeof(char) * (size_t)buf_size); if (oComment == NULL) { /* exception -- out of memory */ h5outOfMemory( env, "H5Oget_comment: malloc failed"); } /* end if */ else { status = H5Oget_comment((hid_t)loc_id, oComment, (size_t)buf_size); if (status < 0) { h5libraryError(env); } /* end if */ else { /* may throw OutOfMemoryError */ str = ENVPTR->NewStringUTF(ENVPAR oComment); if (str == NULL) { h5JNIFatalError( env, "H5Oget_comment: return string not allocated"); } /* end if */ } /* end else */ HDfree(oComment); } } /* end else if */ return (jstring)str; } /* end Java_hdf_hdf5lib_H5_H5Oget_1comment */
/****if* H5Of/h5oget_comment_c * NAME * h5oget_comment_c * PURPOSE * Calls H5Oget_comment * INPUTS * object_id - Identifier for the target object. * bufsize - Anticipated required size of the comment buffer. * OUTPUTS * comment - The comment. * * RETURNS * 0 on success, -1 on failure * AUTHOR * M. Scot Breitenfeld * June 24, 2012 * SOURCE */ int_f nh5oget_comment_c (hid_t_f *object_id, _fcd comment, size_t_f *commentsize, hssize_t_f *bufsize) /******/ { char *c_comment = NULL; /* Buffer to hold C string */ int_f ret_value = 0; /* Return value */ size_t c_commentsize; c_commentsize = (size_t)*commentsize + 1; /* * Allocate buffer to hold comment name */ if(NULL == (c_comment = (char *)HDmalloc(c_commentsize))) HGOTO_DONE(FAIL); /* * Call H5Oget_comment function. */ if((*bufsize = (hssize_t_f)H5Oget_comment((hid_t)*object_id, c_comment, (size_t)*commentsize)) < 0) HGOTO_DONE(FAIL); /* * Convert C name to FORTRAN and place it in the given buffer */ if(c_comment) HD5packFstring(c_comment, _fcdtocp(comment), c_commentsize - 1); return ret_value; done: if(c_comment) HDfree(c_comment); return ret_value; }