summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac9
-rw-r--r--src/asprintf.h20
-rw-r--r--src/debug.c2
-rw-r--r--src/lockdown.c2
4 files changed, 24 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index 98b0008..1bb33fa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,6 +54,15 @@ AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([strcasecmp strdup strerror strndup])
+AC_CHECK_FUNC(asprintf, [have_asprintf="yes"], [have_asprintf="no"])
+if test "x$have_asprintf" = "xyes"; then
+ AC_DEFINE(HAVE_ASPRINTF,1,[define if asprintf is available])
+fi
+AC_CHECK_FUNC(vasprintf, [have_vasprintf="yes"], [have_vasprintf="no"])
+if test "x$have_vasprintf" = "xyes"; then
+ AC_DEFINE(HAVE_VASPRINTF,1,[define if vasprintf is available])
+fi
+
AC_DEFINE(LITTLE_ENDIAN,0,[little endian])
AC_DEFINE(BIG_ENDIAN,1,[big endian])
AC_C_BIGENDIAN([ac_cv_c_bigendian="yes"], [ac_cv_c_bigendian="no"], [], [])
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 @@
#ifndef ASPRINTF_H
#define ASPRINTF_H
-#ifndef vasprintf
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifndef HAVE_VASPRINTF
static inline int vasprintf(char **PTR, const char *TEMPLATE, va_list AP)
{
int res;
- *PTR = (char*)malloc(512);
- res = vsnprintf(*PTR, 512, TEMPLATE, AP);
+ res = vsnprintf(NULL, 32768, TEMPLATE, AP);
+ if (res > 0) {
+ *PTR = (char*)malloc(res+1);
+ res = vsnprintf(*PTR, res, TEMPLATE, AP);
+ }
return res;
}
#endif
-#ifndef asprintf
+
+#ifndef HAVE_ASPRINTF
static inline int asprintf(char **PTR, const char *TEMPLATE, ...)
{
int res;
@@ -20,4 +29,5 @@ static inline int asprintf(char **PTR, const char *TEMPLATE, ...)
return res;
}
#endif
-#endif
+
+#endif /* ASPRINTF_H */
diff --git a/src/debug.c b/src/debug.c
index 49ec7c7..b1c528d 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -35,10 +35,8 @@
#include "libimobiledevice/libimobiledevice.h"
#ifndef STRIP_DEBUG_CODE
-#ifndef HAVE_ASPRINTF
#include "asprintf.h"
#endif
-#endif
int debug_level = 0;
diff --git a/src/lockdown.c b/src/lockdown.c
index e3d557c..0f1e1b2 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -35,9 +35,7 @@
#include "idevice.h"
#include "debug.h"
#include "userpref.h"
-#ifndef HAVE_ASPRINTF
#include "asprintf.h"
-#endif
#define RESULT_SUCCESS 0
#define RESULT_FAILURE 1