summaryrefslogtreecommitdiffstats
path: root/src/asprintf.h
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2011-09-14 01:39:02 +0200
committerGravatar Martin Szulecki2012-03-19 01:43:00 +0100
commit0df63036c888220ea2d5c122f3c19861b0959167 (patch)
tree05febc2ead4e0b426eda479823b2ae1e254c96f4 /src/asprintf.h
parenta87e507134f674f06b3150b1e588a3707c6f4277 (diff)
downloadlibimobiledevice-0df63036c888220ea2d5c122f3c19861b0959167.tar.gz
libimobiledevice-0df63036c888220ea2d5c122f3c19861b0959167.tar.bz2
Refined asprintf/vasprintf detection and inclusion
Diffstat (limited to 'src/asprintf.h')
-rw-r--r--src/asprintf.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/asprintf.h b/src/asprintf.h
index 6f1250d..3b0072e 100644
--- a/src/asprintf.h
+++ b/src/asprintf.h
@@ -1,15 +1,24 @@
1#ifndef ASPRINTF_H 1#ifndef ASPRINTF_H
2#define ASPRINTF_H 2#define ASPRINTF_H
3#ifndef vasprintf 3
4#ifdef HAVE_CONFIG_H
5#include <config.h>
6#endif
7
8#ifndef HAVE_VASPRINTF
4static inline int vasprintf(char **PTR, const char *TEMPLATE, va_list AP) 9static inline int vasprintf(char **PTR, const char *TEMPLATE, va_list AP)
5{ 10{
6 int res; 11 int res;
7 *PTR = (char*)malloc(512); 12 res = vsnprintf(NULL, 32768, TEMPLATE, AP);
8 res = vsnprintf(*PTR, 512, TEMPLATE, AP); 13 if (res > 0) {
14 *PTR = (char*)malloc(res+1);
15 res = vsnprintf(*PTR, res, TEMPLATE, AP);
16 }
9 return res; 17 return res;
10} 18}
11#endif 19#endif
12#ifndef asprintf 20
21#ifndef HAVE_ASPRINTF
13static inline int asprintf(char **PTR, const char *TEMPLATE, ...) 22static inline int asprintf(char **PTR, const char *TEMPLATE, ...)
14{ 23{
15 int res; 24 int res;
@@ -20,4 +29,5 @@ static inline int asprintf(char **PTR, const char *TEMPLATE, ...)
20 return res; 29 return res;
21} 30}
22#endif 31#endif
23#endif 32
33#endif /* ASPRINTF_H */