summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5G.c52
1 files changed, 36 insertions, 16 deletions
diff --git a/src/H5G.c b/src/H5G.c
index 2331ce4..21974ef 100644
--- a/src/H5G.c
+++ b/src/H5G.c
@@ -101,6 +101,8 @@ static herr_t H5G_init_interface(void);
static H5G_typeinfo_t *H5G_type_g = NULL; /*object typing info */
static size_t H5G_ntypes_g = 0; /*entries in type table */
static size_t H5G_atypes_g = 0; /*entries allocated */
+static char *H5G_comp_g = NULL; /*component buffer */
+static size_t H5G_comp_alloc_g = 0; /*sizeof component buffer */
/* Declare a free list to manage the H5G_t struct */
H5FL_DEFINE(H5G_t);
@@ -660,7 +662,7 @@ H5Gget_comment(hid_t loc_id, const char *name, size_t bufsize, char *buf)
if ((retval=H5G_get_comment(loc, name, bufsize, buf))<0) {
HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL,
- "unable to set comment value");
+ "unable to get comment value");
}
FUNC_LEAVE(retval);
@@ -727,7 +729,8 @@ H5G_init_interface(void)
* Monday, January 5, 1998
*
* Modifications:
- *
+ * Robb Matzke, 2002-03-28
+ * Free the global component buffer.
*-------------------------------------------------------------------------
*/
int
@@ -750,6 +753,10 @@ H5G_term_interface(void)
/* Destroy the group object id group */
H5I_destroy_group(H5I_GROUP);
+ /* Free the global component buffer */
+ H5G_comp_g = H5MM_xfree(H5G_comp_g);
+ H5G_comp_alloc_g = 0;
+
/* Mark closed */
interface_initialize_g = 0;
n = 1; /*H5I*/
@@ -984,7 +991,16 @@ H5G_basename(const char *name, size_t *size_p)
* Aug 11 1997
*
* Modifications:
- *
+ * Robb Matzke, 2002-03-28
+ * The component name buffer on the stack has been replaced by
+ * a dynamically allocated buffer on the heap in order to
+ * remove limitations on the length of a name component.
+ * There are two reasons that the buffer pointer is global:
+ * (1) We want to be able to reuse the buffer without
+ * allocating and freeing it each time this function is
+ * called.
+ * (2) We need to be able to free it from H5G_term_interface()
+ * when the library terminates.
*-------------------------------------------------------------------------
*/
static herr_t
@@ -995,7 +1011,6 @@ H5G_namei(H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/,
H5G_entry_t _grp_ent; /*entry for current group */
H5G_entry_t _obj_ent; /*entry found */
size_t nchars; /*component name length */
- char comp[1024]; /*component name buffer */
int _nlinks = H5G_NLINKS;
const char *s = NULL;
@@ -1031,17 +1046,22 @@ H5G_namei(H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/,
* Copy the component name into a null-terminated buffer so
* we can pass it down to the other symbol table functions.
*/
- if (nchars+1 > sizeof(comp)) {
- HRETURN_ERROR (H5E_SYM, H5E_COMPLEN, FAIL,
- "component is too long");
- }
- HDmemcpy(comp, name, nchars);
- comp[nchars] = '\0';
+ if (nchars+1 > H5G_comp_alloc_g) {
+ H5G_comp_alloc_g = MAX3(1024, 2*H5G_comp_alloc_g, nchars+1);
+ H5G_comp_g = H5MM_realloc(H5G_comp_g, H5G_comp_alloc_g);
+ if (!H5G_comp_g) {
+ H5G_comp_alloc_g = 0;
+ HRETURN_ERROR(H5E_SYM, H5E_NOSPACE, FAIL,
+ "unable to allocate component buffer");
+ }
+ }
+ HDmemcpy(H5G_comp_g, name, nchars);
+ H5G_comp_g[nchars] = '\0';
/*
* The special name `.' is a no-op.
*/
- if ('.' == comp[0] && !comp[1]) {
+ if ('.' == H5G_comp_g[0] && !H5G_comp_g[1]) {
name += nchars;
continue;
}
@@ -1053,7 +1073,7 @@ H5G_namei(H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/,
HDmemset(obj_ent, 0, sizeof(H5G_entry_t));
obj_ent->header = HADDR_UNDEF;
- if (H5G_stab_find(grp_ent, comp, obj_ent/*out*/)<0) {
+ if (H5G_stab_find(grp_ent, H5G_comp_g, obj_ent/*out*/)<0) {
/*
* Component was not found in the current symbol table, possibly
* because GRP_ENT isn't a symbol table.
@@ -2044,7 +2064,7 @@ H5G_get_objinfo (H5G_entry_t *loc, const char *name, hbool_t follow_link,
if (H5G_CACHED_SLINK==obj_ent.type) {
/* Named object is a symbolic link */
if (NULL==H5O_read (&grp_ent, H5O_STAB, 0, &stab_mesg) ||
- NULL==(s=H5HL_peek (grp_ent.file, stab_mesg.heap_addr,
+ NULL==(s=H5HL_peek (grp_ent.file, stab_mesg.heap_addr,
obj_ent.cache.slink.lval_offset))) {
HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
"unable to read symbolic link value");
@@ -2069,15 +2089,15 @@ H5G_get_objinfo (H5G_entry_t *loc, const char *name, hbool_t follow_link,
if (NULL==H5O_read(&obj_ent, H5O_MTIME, 0, &(statbuf->mtime))) {
H5E_clear();
statbuf->mtime = 0;
- } /* end if */
+ }
statbuf->type = H5G_get_type(&obj_ent);
H5E_clear(); /*clear errors resulting from checking type*/
- } /* end else */
+ }
/* Common code to retrieve the file's fileno */
if(H5F_get_fileno(obj_ent.file,statbuf->fileno)<0)
HRETURN_ERROR (H5E_FILE, H5E_BADVALUE, FAIL, "unable to read fileno");
- } /* end if */
+ }
FUNC_LEAVE (SUCCEED);
}