Commit 90218123 authored by unknown's avatar unknown
Browse files

added define flag SNPRINTF_RETURN_ZERO to indicate that snprintf returns...

    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
parent 731b06f4
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1142,8 +1142,8 @@ dnl Is this the right match for DEC OSF on alpha?
      fi
      echo "Adding defines for OSF1"
      # gethostbyname_r is deprecated and doesn't work ok on OSF1
      CFLAGS="$CFLAGS -DUNDEF_HAVE_GETHOSTBYNAME_R"
      CXXFLAGS="$CXXFLAGS -DUNDEF_HAVE_GETHOSTBYNAME_R"
      CFLAGS="$CFLAGS -DUNDEF_HAVE_GETHOSTBYNAME_R -DSNPRINTF_RETURN_ZERO"
      CXXFLAGS="$CXXFLAGS -DUNDEF_HAVE_GETHOSTBYNAME_R -DSNPRINTF_RETURN_ZERO"
      # fix to handle include of <stdint.h> correctly on OSF1 with cxx compiler
      CXXFLAGS="$CXXFLAGS -I/usr/include/cxx -I/usr/include/cxx_cname -I/usr/include -I/usr/include.dtk"
    ;;
+21 −1
Original line number Diff line number Diff line
@@ -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;
}