Wanderer/Info: fix compilation
[AROS.git] / tools / flexcat / src / vasprintf.c
blob36b018f9122ce65d320eb81b653e1526906ad834
1 /*
2 * $Id$
4 * Copyright (C) 1993-1999 by Jochen Wiedmann and Marcin Orlowski
5 * Copyright (C) 2002-2010 by the FlexCat Open Source Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #ifndef VA_COPY
28 #if defined(__MORPHOS__)
29 #define VA_COPY(dest, src) __va_copy(dest, src)
30 #elif defined(__AROS__)
31 #define VA_COPY(dest, src) va_copy(dest, src)
32 #else
33 #define VA_COPY(dest, src) (dest) = (src)
34 #endif
35 #endif
37 int vasprintf(char **ptr, const char * format, va_list ap)
39 int ret;
40 va_list ap2;
42 *ptr = NULL;
44 VA_COPY(ap2, ap);
45 ret = vsnprintf(NULL, 0, format, ap2);
46 if(ret <= 0)
47 return ret;
49 *ptr = (char *)malloc(ret+1);
50 if(*ptr == NULL)
51 return -1;
53 VA_COPY(ap2, ap);
54 ret = vsnprintf(*ptr, ret+1, format, ap2);
56 return ret;