summaryrefslogtreecommitdiff
path: root/src/conversion.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/conversion.c')
-rw-r--r--src/conversion.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/conversion.c b/src/conversion.c
index 3df8fe5..6dfabe7 100644
--- a/src/conversion.c
+++ b/src/conversion.c
@@ -31,6 +31,7 @@
#endif
#include <time.h>
#include <errno.h>
+#include <stdarg.h>
#include "gpgme.h"
#include "util.h"
@@ -42,6 +43,61 @@
+static char *
+do_strconcat (const char *s1, va_list arg_ptr)
+{
+ const char *argv[16];
+ size_t argc;
+ size_t needed;
+ char *buffer, *p;
+
+ argc = 0;
+ argv[argc++] = s1;
+ needed = strlen (s1);
+ while (((argv[argc] = va_arg (arg_ptr, const char *))))
+ {
+ needed += strlen (argv[argc]);
+ if (argc >= DIM (argv)-1)
+ {
+ gpg_err_set_errno (EINVAL);
+ return NULL;
+ }
+ argc++;
+ }
+ needed++;
+ buffer = malloc (needed);
+ if (buffer)
+ {
+ for (p = buffer, argc=0; argv[argc]; argc++)
+ p = stpcpy (p, argv[argc]);
+ }
+ return buffer;
+}
+
+
+/* Concatenate the string S1 with all the following strings up to a
+ * NULL. Returns a malloced buffer with the new string or NULL on a
+ malloc error or if too many arguments are given. */
+char *
+_gpgme_strconcat (const char *s1, ...)
+{
+ va_list arg_ptr;
+ char *result;
+
+ if (!s1)
+ result = strdup ("");
+ else
+ {
+ va_start (arg_ptr, s1);
+ result = do_strconcat (s1, arg_ptr);
+ va_end (arg_ptr);
+ }
+ return result;
+}
+
+
+
+
/* Convert two hexadecimal digits from STR to the value they
represent. Returns -1 if one of the characters is not a
hexadecimal digit. */