~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/common/util/basestring_vsnprintf.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifdef __sgi
 
17
/* define on IRIX to get posix compliant vsnprintf */
 
18
#define _XOPEN_SOURCE 500
 
19
#endif
 
20
#include <stdio.h>
 
21
#include <basestring_vsnprintf.h>
 
22
#include <my_config.h>
 
23
 
 
24
#ifdef _WINDOWS
 
25
#define SNPRINTF_RETURN_TRUNC
 
26
#define snprintf _snprintf
 
27
#define vsnprintf _vsnprintf
 
28
#endif
 
29
 
 
30
int
 
31
basestring_snprintf(char *str, size_t size, const char *format, ...)
 
32
{
 
33
  int ret;
 
34
  va_list ap;
 
35
  va_start(ap, format);
 
36
  ret= basestring_vsnprintf(str, size, format, ap);
 
37
  va_end(ap);
 
38
  return(ret);
 
39
}
 
40
 
 
41
#ifdef SNPRINTF_RETURN_TRUNC
 
42
static char basestring_vsnprintf_buf[16*1024];
 
43
#endif
 
44
int
 
45
basestring_vsnprintf(char *str, size_t size, const char *format, va_list ap)
 
46
{
 
47
  if (size == 0)
 
48
  {
 
49
#ifdef SNPRINTF_RETURN_TRUNC
 
50
    return vsnprintf(basestring_vsnprintf_buf,
 
51
                     sizeof(basestring_vsnprintf_buf),
 
52
                     format, ap);
 
53
#else
 
54
    char buf[1];
 
55
    return vsnprintf(buf, 1, format, ap);
 
56
#endif
 
57
  }
 
58
  {
 
59
    int ret= vsnprintf(str, size, format, ap);
 
60
#ifdef SNPRINTF_RETURN_TRUNC
 
61
    if (ret == size-1 || ret == -1)
 
62
    {
 
63
      ret= vsnprintf(basestring_vsnprintf_buf,
 
64
                     sizeof(basestring_vsnprintf_buf),
 
65
                     format, ap);
 
66
    }
 
67
#endif
 
68
    return ret;
 
69
  }
 
70
}