PostGIS  2.1.10dev-r@@SVN_REVISION@@
static va_dcl int int_vasprintf ( char **  result,
const char *  format,
va_list *  args 
)
static

Definition at line 58 of file vsprintf.c.

Referenced by lw_vasprintf().

62 {
63  const char *p = format;
64  /* Add one to make sure that it is never zero, which might cause malloc
65  to return NULL. */
66  int total_width = strlen (format) + 1;
67  va_list ap;
68 
69  memcpy (&ap, args, sizeof (va_list));
70 
71  while (*p != '\0')
72  {
73  if (*p++ == '%')
74  {
75  while (strchr ("-+ #0", *p))
76  ++p;
77  if (*p == '*')
78  {
79  ++p;
80  total_width += abs (va_arg (ap, int));
81  }
82  else
83  total_width += strtoul (p, (char **) &p, 10);
84  if (*p == '.')
85  {
86  ++p;
87  if (*p == '*')
88  {
89  ++p;
90  total_width += abs (va_arg (ap, int));
91  }
92  else
93  total_width += strtoul (p, (char **) &p, 10);
94  }
95  while (strchr ("hlLjtz", *p))
96  ++p;
97  /* Should be big enough for any format specifier except %s
98  and floats. */
99  total_width += 30;
100  switch (*p)
101  {
102  case 'd':
103  case 'i':
104  case 'o':
105  case 'u':
106  case 'x':
107  case 'X':
108  case 'c':
109  (void) va_arg (ap, int);
110  break;
111  case 'f':
112  {
113  double arg = va_arg (ap, double);
114  if (arg >= 1.0 || arg <= -1.0)
115  /* Since an ieee double can have an exponent of 307, we'll
116  make the buffer wide enough to cover the gross case. */
117  total_width += 307;
118  }
119  break;
120  case 'e':
121  case 'E':
122  case 'g':
123  case 'G':
124  (void) va_arg (ap, double);
125  break;
126  case 's':
127  total_width += strlen (va_arg (ap, char *));
128  break;
129  case 'p':
130  case 'n':
131  (void) va_arg (ap, char *);
132  break;
133  }
134  p++;
135  }
136  }
137 #ifdef TEST
138  global_total_width = total_width;
139 #endif
140  *result = malloc (total_width);
141  if (*result != NULL)
142  return vsprintf (*result, format, *args);
143  else
144  return 0;
145 }
char ** result
Definition: vsprintf.c:52

Here is the caller graph for this function: