1 |
schoenebeck |
3199 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
|
|
* * |
5 |
|
|
* Copyright (C) 2003-2017 by Christian Schoenebeck * |
6 |
|
|
* <cuse@users.sourceforge.net> * |
7 |
|
|
* * |
8 |
|
|
* This library is free software; you can redistribute it and/or modify * |
9 |
|
|
* it under the terms of the GNU General Public License as published by * |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
11 |
|
|
* (at your option) any later version. * |
12 |
|
|
* * |
13 |
|
|
* This library is distributed in the hope that it will be useful, * |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
|
|
* GNU General Public License for more details. * |
17 |
|
|
* * |
18 |
|
|
* You should have received a copy of the GNU General Public License * |
19 |
|
|
* along with this library; if not, write to the Free Software * |
20 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
|
|
* MA 02111-1307 USA * |
22 |
|
|
***************************************************************************/ |
23 |
|
|
|
24 |
|
|
#include "helper.h" |
25 |
|
|
|
26 |
|
|
#if !HAVE_VASPRINTF && defined(WIN32) |
27 |
|
|
|
28 |
|
|
#include <stdio.h> |
29 |
|
|
#include <stdlib.h> |
30 |
|
|
#include <stdint.h> |
31 |
|
|
#include <string.h> |
32 |
|
|
|
33 |
|
|
// vasprintf() does not exist on older windows versions |
34 |
|
|
int vasprintf(char** ret, const char* format, va_list arg) { |
35 |
|
|
*ret = NULL; |
36 |
|
|
const int len = _vscprintf(format, arg); // counts without \0 delimiter |
37 |
|
|
if (len < 0) |
38 |
|
|
return -1; |
39 |
|
|
const size_t size = ((size_t) len) + 1; |
40 |
|
|
char* buf = malloc(size); |
41 |
|
|
if (!buf) |
42 |
|
|
return -1; |
43 |
|
|
memset(buf, 0, size); |
44 |
|
|
int res = _vsprintf_s(buf, size, format, arg); |
45 |
|
|
if (res < 0) { |
46 |
|
|
free(buf); |
47 |
|
|
return -1; |
48 |
|
|
} |
49 |
|
|
*ret = buf; |
50 |
|
|
return res; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
#endif // !HAVE_VASPRINTF && defined(WIN32) |