From: Simon Josefsson Date: Thu, 8 Feb 2007 11:53:10 +0000 (+0000) Subject: Add _gnutls_string_append_printf. X-Git-Tag: gnutls_1_7_6~49 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5114d821df73e199ba8f343c755baabbda2bc3d1;p=thirdparty%2Fgnutls.git Add _gnutls_string_append_printf. --- diff --git a/lib/gnutls_str.c b/lib/gnutls_str.c index cbda764af2..a03f00f4b8 100644 --- a/lib/gnutls_str.c +++ b/lib/gnutls_str.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002, 2004, 2005 Free Software Foundation + * Copyright (C) 2002, 2004, 2005, 2007 Free Software Foundation * * Author: Nikos Mavroyanopoulos * @@ -227,6 +227,29 @@ _gnutls_string_append_data (gnutls_string * dest, const void *data, } } +#include + +int +_gnutls_string_append_printf (gnutls_string * dest, const char *fmt, ...) +{ + va_list args; + int len; + char *str; + + va_start (args, fmt); + len = vasprintf (&str, fmt, args); + va_end (args); + + if (len < 0 || !str) + return -1; + + len = _gnutls_string_append_str (dest, str); + + free (str); + + return len; +} + /* Converts the given string (old) to hex. A buffer must be provided * to hold the new hex string. The new string will be null terminated. * If the buffer does not have enough space to hold the string, a diff --git a/lib/gnutls_str.h b/lib/gnutls_str.h index 3acf071a29..ad7c1159a7 100644 --- a/lib/gnutls_str.h +++ b/lib/gnutls_str.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation + * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation * * Author: Nikos Mavroyanopoulos * @@ -55,6 +55,7 @@ int _gnutls_string_copy_str (gnutls_string * dest, const char *src); int _gnutls_string_append_str (gnutls_string *, const char *str); int _gnutls_string_append_data (gnutls_string *, const void *data, size_t data_size); +int _gnutls_string_append_printf (gnutls_string * dest, const char *fmt, ...); char *_gnutls_bin2hex (const void *old, size_t oldlen, char *buffer, size_t buffer_size);