diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5E.c | 18 | ||||
-rw-r--r-- | src/H5config.h.in | 7 | ||||
-rw-r--r-- | src/H5private.h | 1 |
3 files changed, 25 insertions, 1 deletions
@@ -1513,13 +1513,24 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line /* Format the description */ va_start(ap, fmt); +#ifdef H5_HAVE_VASPRINTF + /* Use the vasprintf() routine, since it does what we're trying to do below */ + if(HDvasprintf(&tmp,fmt,ap)<0) + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") +#else /* H5_HAVE_VASPRINTF */ /* Allocate space for the formatted description buffer */ tmp_len=128; if((tmp=H5MM_malloc((size_t)tmp_len))==NULL) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* If the description doesn't fit into the initial buffer size, allocate more space and try again */ - while((desc_len=HDvsnprintf(tmp, (size_t)tmp_len, fmt, ap))>tmp_len) { + while((desc_len=HDvsnprintf(tmp, (size_t)tmp_len, fmt, ap)) +#ifdef H5_VSNPRINTF_WORKS + > +#else /* H5_VSNPRINTF_WORKS */ + >= +#endif /* H5_VSNPRINTF_WORKS */ + (tmp_len-1)) { /* shutdown & restart the va_list */ va_end(ap); va_start(ap, fmt); @@ -1528,10 +1539,15 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line H5MM_xfree(tmp); /* Allocate a description of the appropriate length */ +#ifdef H5_VSNPRINTF_WORKS tmp_len = desc_len+1; +#else /* H5_VSNPRINTF_WORKS */ + tmp_len = 2 * desc_len; +#endif /* H5_VSNPRINTF_WORKS */ if((tmp=H5MM_malloc((size_t)tmp_len))==NULL) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") } /* end while */ +#endif /* H5_HAVE_VASPRINTF */ va_end(ap); diff --git a/src/H5config.h.in b/src/H5config.h.in index 6edc4fd..ab57f34 100644 --- a/src/H5config.h.in +++ b/src/H5config.h.in @@ -366,6 +366,9 @@ /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if you have the `vasprintf' function. */ +#undef HAVE_VASPRINTF + /* Define to 1 if you have the `vsnprintf' function. */ #undef HAVE_VSNPRINTF @@ -553,6 +556,10 @@ correct precision. */ #undef ULLONG_TO_LDOUBLE_PRECISION_WORKS +/* Define if vsnprintf() returns the correct value for formatted strings that + don't fit into size allowed */ +#undef VSNPRINTF_WORKS + /* Define if the HDF5 v1.6 compatibility functions are to be compiled in */ #undef WANT_H5_V1_6_COMPAT diff --git a/src/H5private.h b/src/H5private.h index fe4cbaa..95694c6 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -838,6 +838,7 @@ H5_DLL int64_t HDstrtoll (const char *s, const char **rest, int base); #define HDva_arg(A,T) va_arg(A,T) #define HDva_end(A) va_end(A) #define HDva_start(A,P) va_start(A,P) +#define HDvasprintf(RET,FMT,A) vasprintf(RET,FMT,A) #define HDvfprintf(F,FMT,A) vfprintf(F,FMT,A) #define HDvprintf(FMT,A) vprintf(FMT,A) #define HDvsprintf(S,FMT,A) vsprintf(S,FMT,A) |