Mercurial > pidgin.yaz
changeset 7767:1f4005fcd872
[gaim-migrate @ 8412]
As Nathan pointed out, a printf'd stringref is probably desirable
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Fri, 05 Dec 2003 17:28:22 +0000 |
parents | 9d6ba1c44cb7 |
children | 4e5c48ea9478 |
files | src/stringref.c src/stringref.h |
diffstat | 2 files changed, 31 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/stringref.c Fri Dec 05 17:09:18 2003 +0000 +++ b/src/stringref.c Fri Dec 05 17:28:22 2003 +0000 @@ -25,6 +25,7 @@ #include "internal.h" #include <string.h> +#include <stdarg.h> #include "stringref.h" @@ -39,6 +40,22 @@ return newref; } +GaimStringref *gaim_stringref_printf(const char *format, ...) +{ + GaimStringref *newref; + va_list ap; + + if (format == NULL) + return NULL; + + va_start(ap, format); + newref = g_malloc(sizeof(GaimStringref) + g_printf_string_upper_bound(format, ap)); + vsprintf(newref->value, format, ap); + va_end(ap); + + return newref; +} + GaimStringref *gaim_stringref_ref(GaimStringref *stringref) { if (stringref == NULL)
--- a/src/stringref.h Fri Dec 05 17:09:18 2003 +0000 +++ b/src/stringref.h Fri Dec 05 17:28:22 2003 +0000 @@ -42,11 +42,24 @@ * @param value This will be the value of the string; it will be * duplicated. * - * @return A newly allocated string reference object. + * @return A newly allocated string reference object with a refcount + * of 1. */ GaimStringref *gaim_stringref_new(const char *value); /** + * Creates an immutable reference-counted string object from a printf + * format specification and arguments. The created object will have a + * reference count of 1. + * + * @param format A printf-style format specification. + * + * @return A newly allocated string reference object with a refcount + * of 1. + */ +GaimStringref *gaim_stringref_printf(const char *format, ...); + +/** * Increase the reference count of the given stringref. * * @param stringref String to be referenced.