diff options
author | unknown <tomas@poseidon.ndb.mysql.com> | 2004-10-29 13:59:40 +0000 |
---|---|---|
committer | unknown <tomas@poseidon.ndb.mysql.com> | 2004-10-29 13:59:40 +0000 |
commit | 90218123848f26942446af7eabff0363467e3d0d (patch) | |
tree | ddb2532f80fa9c1f39495c90a4a723a5caefbc7c /ndb | |
parent | 731b06f47fcd220dd12324fd7547943e80e68505 (diff) | |
download | mariadb-git-90218123848f26942446af7eabff0363467e3d0d.tar.gz |
added define flag SNPRINTF_RETURN_ZERO to indicate that snprintf returns zero if buffer too small
use flag SNPRINTF_RETURN_ZERO
emulate snprintf behavior by writing to _big_ buffer if set
use my_vsnprintf if HAVE_SNPRINTF is not set and set SNPRINTF_RETURN_ZERO in that case
configure.in:
added define flag to indicate that snprintf returns zero if buffer too small
ndb/src/common/util/basestring_vsnprintf.c:
use flag SNPRINTF_RETURN_ZERO
emulate snprintf behavior by writing to _big_ buffer if set
use my_vsnprintf if HAVE_SNPRINTF is not set and set SNPRINTF_RETURN_ZERO in that case
Diffstat (limited to 'ndb')
-rw-r--r-- | ndb/src/common/util/basestring_vsnprintf.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/ndb/src/common/util/basestring_vsnprintf.c b/ndb/src/common/util/basestring_vsnprintf.c index 10932226d18..87ffb8ad146 100644 --- a/ndb/src/common/util/basestring_vsnprintf.c +++ b/ndb/src/common/util/basestring_vsnprintf.c @@ -18,6 +18,7 @@ #define _XOPEN_SOURCE 500 #include <stdio.h> #include <basestring_vsnprintf.h> +#include <my_config.h> int basestring_snprintf(char *str, size_t size, const char *format, ...) @@ -30,8 +31,27 @@ basestring_snprintf(char *str, size_t size, const char *format, ...) return(ret); } +#ifdef HAVE_SNPRINTF + #define BASESTRING_VSNPRINTF_FUNC(a,b,c,d) vsnprintf(a,b,c,d) +#else + #define SNPRINTF_RETURN_ZERO + #define BASESTRING_VSNPRINTF_FUNC(a,b,c,d) my_vsnprintf(a,b,c,d) + extern int my_vsnprintf(char *str, size_t size, const char *format, va_list ap); +#endif + +#ifdef SNPRINTF_RETURN_ZERO +static char basestring_vsnprintf_buf[16*1024]; +#endif int basestring_vsnprintf(char *str, size_t size, const char *format, va_list ap) { - return(vsnprintf(str, size, format, ap)); + int ret= BASESTRING_VSNPRINTF_FUNC(str, size, format, ap); +#ifdef SNPRINTF_RETURN_ZERO + if (ret == 0 && format != 0 && format[0] != '\0') { + ret= BASESTRING_VSNPRINTF_FUNC(basestring_vsnprintf_buf, + sizeof(basestring_vsnprintf_buf), + format, ap); + } +#endif + return ret; } |