Commit 277c84e2 authored by unknown's avatar unknown

some platforms provide posix snprintf via special defined, these defines...

some platforms provide posix snprintf via special defined, these defines however cause problems elsewhere
so this is a way to only have to do this define in one file


parent 8a1488cd
......@@ -177,6 +177,12 @@ public:
* Trim string from <i>delim</i>
*/
static char* trim(char * src, const char * delim);
/**
* snprintf on some platforms need special treatment
*/
static int snprintf(char *str, size_t size, const char *format, ...);
static int vsnprintf(char *str, size_t size, const char *format, va_list ap);
private:
char* m_chr;
unsigned m_len;
......
......@@ -18,6 +18,10 @@
#include <ndb_global.h>
#include <BaseString.hpp>
extern "C"
int
basestring_vsnprintf(char *str, size_t size, const char *format, va_list ap);
BaseString::BaseString()
{
m_chr = new char[1];
......@@ -127,14 +131,14 @@ BaseString::assfmt(const char *fmt, ...)
* when called as vsnprintf(NULL, 0, ...).
*/
va_start(ap, fmt);
l = vsnprintf(buf, sizeof(buf), fmt, ap) + 1;
l = basestring_vsnprintf(buf, sizeof(buf), fmt, ap) + 1;
va_end(ap);
if(l > (int)m_len) {
delete[] m_chr;
m_chr = new char[l];
}
va_start(ap, fmt);
vsnprintf(m_chr, l, fmt, ap);
basestring_vsnprintf(m_chr, l, fmt, ap);
va_end(ap);
m_len = strlen(m_chr);
return *this;
......@@ -152,11 +156,11 @@ BaseString::appfmt(const char *fmt, ...)
* when called as vsnprintf(NULL, 0, ...).
*/
va_start(ap, fmt);
l = vsnprintf(buf, sizeof(buf), fmt, ap) + 1;
l = basestring_vsnprintf(buf, sizeof(buf), fmt, ap) + 1;
va_end(ap);
char *tmp = new char[l];
va_start(ap, fmt);
vsnprintf(tmp, l, fmt, ap);
basestring_vsnprintf(tmp, l, fmt, ap);
va_end(ap);
append(tmp);
delete[] tmp;
......@@ -335,6 +339,22 @@ BaseString::trim(char * str, const char * delim){
return str;
}
int
BaseString::vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
return(basestring_vsnprintf(str, size, format, ap));
}
int
BaseString::snprintf(char *str, size_t size, const char *format, ...)
{
va_list ap;
va_start(ap, format);
int ret= basestring_vsnprintf(str, size, format, ap);
va_end(ap);
return(ret);
}
#ifdef TEST_BASE_STRING
......
......@@ -9,7 +9,7 @@ libgeneral_la_SOURCES = \
NdbSqlUtil.cpp new.cpp \
uucode.c random.c getarg.c version.c \
strdup.c strlcat.c strlcpy.c \
ConfigValues.cpp ndb_init.c
ConfigValues.cpp ndb_init.c basestring_vsnprintf.c
include $(top_srcdir)/ndb/config/common.mk.am
include $(top_srcdir)/ndb/config/type_util.mk.am
......
// define on IRIX to get posix complian vsnprintf
#define _XOPEN_SOURCE 500
#include <stdio.h>
int
basestring_vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
return(vsnprintf(str, size, format, ap));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment