diff src/util.c @ 2956:b68c648618a3

[gaim-migrate @ 2969] I Love Rock & Roll.... committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Sun, 17 Feb 2002 18:08:12 +0000
parents cd23279122ed
children a7e03c5d2205
line wrap: on
line diff
--- a/src/util.c	Wed Feb 13 15:23:13 2002 +0000
+++ b/src/util.c	Sun Feb 17 18:08:12 2002 +0000
@@ -912,6 +912,33 @@
 }
 
 
+/*
+ * Like strncpy_withhtml (above), but malloc()'s the necessary space
+ *
+ * The caller is responsible for freeing the space pointed to by the
+ * return value.
+ */
+
+gchar *strdup_withhtml(const gchar *src)
+{
+	char *sp, *dest;
+	gulong destsize;
+
+	/*
+	 * All we need do is multiply the number of newlines by 3 (the
+	 * additional length of "<BR>" over "\n"), account for the
+	 * terminator, malloc the space and call strncpy_withhtml.
+	 */
+	for(destsize = 0, sp = src; (sp = strchr(sp, '\n')) != NULL; ++sp, ++destsize)
+		;
+	destsize *= 3;
+	destsize += strlen(src) + 1;
+	dest = g_malloc(destsize);
+	strncpy_withhtml(dest, src, destsize);
+
+	return(dest);
+}
+
 void away_on_login(char *mesg)
 {
 	GSList *awy = away_messages;