summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-11-13 09:06:41 +0100
committerGravatar Nikias Bassen2019-11-13 09:06:41 +0100
commitaf91dc6376946daffd5c9ece916d9f33af828890 (patch)
treec87414ff6bb7d9a29a0eef52532087ff9f268469 /common
parent7dbc17f2c763a7b18bc1a867f39918c26bb5e9e5 (diff)
downloadlibimobiledevice-af91dc6376946daffd5c9ece916d9f33af828890.tar.gz
libimobiledevice-af91dc6376946daffd5c9ece916d9f33af828890.tar.bz2
debugserver: Improved memory handling in debugserver_client_send_command() and debugserver_client_receive_response()
Diffstat (limited to 'common')
-rw-r--r--common/utils.c49
-rw-r--r--common/utils.h6
2 files changed, 53 insertions, 2 deletions
diff --git a/common/utils.c b/common/utils.c
index 4a45d95..7f66ec2 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -1,7 +1,10 @@
/*
* utils.c
- * Miscellaneous utilities for string manipulation
+ * Miscellaneous utilities for string manipulation,
+ * file I/O and plist helper.
*
+ * Copyright (c) 2014-2019 Nikias Bassen, All Rights Reserved.
+ * Copyright (c) 2013-2014 Martin Szulecki, All Rights Reserved.
* Copyright (c) 2013 Federico Mena Quintero
*
* This library is free software; you can redistribute it and/or
@@ -111,6 +114,50 @@ char *string_concat(const char *str, ...)
return result;
}
+char *string_append(char* str, ...)
+{
+ size_t len = 0;
+ size_t slen;
+ va_list args;
+ char *s;
+ char *result;
+ char *dest;
+
+ /* Compute final length */
+
+ if (str) {
+ len = strlen(str);
+ }
+ slen = len;
+ len++; /* plus 1 for the null terminator */
+
+ va_start(args, str);
+ s = va_arg(args, char *);
+ while (s) {
+ len += strlen(s);
+ s = va_arg(args, char*);
+ }
+ va_end(args);
+
+ result = realloc(str, len);
+ if (!result)
+ return NULL; /* errno remains set */
+
+ dest = result + slen;
+
+ /* Concat additional strings */
+
+ va_start(args, str);
+ s = va_arg(args, char *);
+ while (s) {
+ dest = stpcpy(dest, s);
+ s = va_arg(args, char *);
+ }
+ va_end(args);
+
+ return result;
+}
+
char *string_build_path(const char *elem, ...)
{
if (!elem)
diff --git a/common/utils.h b/common/utils.h
index 8426bc0..2c3acec 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -1,7 +1,10 @@
/*
* utils.h
- * Miscellaneous utilities for string manipulation
+ * Miscellaneous utilities for string manipulation,
+ * file I/O and plist helper.
*
+ * Copyright (c) 2014-2019 Nikias Bassen, All Rights Reserved.
+ * Copyright (c) 2013-2014 Martin Szulecki, All Rights Reserved.
* Copyright (c) 2013 Federico Mena Quintero
*
* This library is free software; you can redistribute it and/or
@@ -39,6 +42,7 @@
char *stpcpy(char *s1, const char *s2);
#endif
char *string_concat(const char *str, ...);
+char *string_append(char *str, ...);
char *string_build_path(const char *elem, ...);
char *string_format_size(uint64_t size);
char *string_toupper(char *str);