mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 13:02:28 +01:00
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
This commit is contained in:
parent
95aad4450e
commit
8224ef80e4
4 changed files with 40 additions and 5 deletions
|
@ -177,6 +177,12 @@ public:
|
||||||
* Trim string from <i>delim</i>
|
* Trim string from <i>delim</i>
|
||||||
*/
|
*/
|
||||||
static char* trim(char * src, const char * delim);
|
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:
|
private:
|
||||||
char* m_chr;
|
char* m_chr;
|
||||||
unsigned m_len;
|
unsigned m_len;
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
#include <ndb_global.h>
|
#include <ndb_global.h>
|
||||||
#include <BaseString.hpp>
|
#include <BaseString.hpp>
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
int
|
||||||
|
basestring_vsnprintf(char *str, size_t size, const char *format, va_list ap);
|
||||||
|
|
||||||
BaseString::BaseString()
|
BaseString::BaseString()
|
||||||
{
|
{
|
||||||
m_chr = new char[1];
|
m_chr = new char[1];
|
||||||
|
@ -127,14 +131,14 @@ BaseString::assfmt(const char *fmt, ...)
|
||||||
* when called as vsnprintf(NULL, 0, ...).
|
* when called as vsnprintf(NULL, 0, ...).
|
||||||
*/
|
*/
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
l = vsnprintf(buf, sizeof(buf), fmt, ap) + 1;
|
l = basestring_vsnprintf(buf, sizeof(buf), fmt, ap) + 1;
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
if(l > (int)m_len) {
|
if(l > (int)m_len) {
|
||||||
delete[] m_chr;
|
delete[] m_chr;
|
||||||
m_chr = new char[l];
|
m_chr = new char[l];
|
||||||
}
|
}
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vsnprintf(m_chr, l, fmt, ap);
|
basestring_vsnprintf(m_chr, l, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
m_len = strlen(m_chr);
|
m_len = strlen(m_chr);
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -152,11 +156,11 @@ BaseString::appfmt(const char *fmt, ...)
|
||||||
* when called as vsnprintf(NULL, 0, ...).
|
* when called as vsnprintf(NULL, 0, ...).
|
||||||
*/
|
*/
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
l = vsnprintf(buf, sizeof(buf), fmt, ap) + 1;
|
l = basestring_vsnprintf(buf, sizeof(buf), fmt, ap) + 1;
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
char *tmp = new char[l];
|
char *tmp = new char[l];
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vsnprintf(tmp, l, fmt, ap);
|
basestring_vsnprintf(tmp, l, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
append(tmp);
|
append(tmp);
|
||||||
delete[] tmp;
|
delete[] tmp;
|
||||||
|
@ -335,6 +339,22 @@ BaseString::trim(char * str, const char * delim){
|
||||||
return str;
|
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
|
#ifdef TEST_BASE_STRING
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ libgeneral_la_SOURCES = \
|
||||||
NdbSqlUtil.cpp new.cpp \
|
NdbSqlUtil.cpp new.cpp \
|
||||||
uucode.c random.c getarg.c version.c \
|
uucode.c random.c getarg.c version.c \
|
||||||
strdup.c strlcat.c strlcpy.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/common.mk.am
|
||||||
include $(top_srcdir)/ndb/config/type_util.mk.am
|
include $(top_srcdir)/ndb/config/type_util.mk.am
|
||||||
|
|
9
ndb/src/common/util/basestring_vsnprintf.c
Normal file
9
ndb/src/common/util/basestring_vsnprintf.c
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// 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));
|
||||||
|
}
|
Loading…
Reference in a new issue