]> Pileus Git - ~andy/linux/blobdiff - tools/perf/util/string.c
Merge tag 'v3.11-rc5' into perf/core
[~andy/linux] / tools / perf / util / string.c
index 29c7b2cb252192b8cb9d184ef320c32265de832e..f0b0c008c5075005b562a2a5a2e938dd2644ea51 100644 (file)
@@ -387,3 +387,27 @@ void *memdup(const void *src, size_t len)
 
        return p;
 }
+
+/**
+ * str_append - reallocate string and append another
+ * @s: pointer to string pointer
+ * @len: pointer to len (initialized)
+ * @a: string to append.
+ */
+int str_append(char **s, int *len, const char *a)
+{
+       int olen = *s ? strlen(*s) : 0;
+       int nlen = olen + strlen(a) + 1;
+       if (*len < nlen) {
+               *len = *len * 2;
+               if (*len < nlen)
+                       *len = nlen;
+               *s = realloc(*s, *len);
+               if (!*s)
+                       return -ENOMEM;
+               if (olen == 0)
+                       **s = 0;
+       }
+       strcat(*s, a);
+       return 0;
+}