This patch creates the kstrdup library function so that it doesn't have to be
reimplemented (or even EXPORT'ed) by every user that needs it.

Signed-off-by: Paulo Marques <[EMAIL PROTECTED]>

--
Paulo Marques - www.grupopie.com
 
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke (1729 - 1797)
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/include/linux/string.h linux-2.6.11-rc2-bk9/include/linux/string.h
--- vanilla-2.6.11-rc2-bk9/include/linux/string.h	2004-12-24 21:34:31.000000000 +0000
+++ linux-2.6.11-rc2-bk9/include/linux/string.h	2005-01-31 19:31:12.000000000 +0000
@@ -88,6 +88,8 @@ extern int memcmp(const void *,const voi
 extern void * memchr(const void *,int,__kernel_size_t);
 #endif

+extern char *kstrdup(const char *s, int gfp);
+
 #ifdef __cplusplus
 }
 #endif
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/lib/string.c linux-2.6.11-rc2-bk9/lib/string.c
--- vanilla-2.6.11-rc2-bk9/lib/string.c	2005-01-31 20:05:37.000000000 +0000
+++ linux-2.6.11-rc2-bk9/lib/string.c	2005-01-31 20:00:31.000000000 +0000
@@ -599,3 +599,23 @@ void *memchr(const void *s, int c, size_
 }
 EXPORT_SYMBOL(memchr);
 #endif
+
+/*
+ * kstrdup - allocate space for and copy an existing string
+ *
+ * @s: the string to duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ */
+char *kstrdup(const char *s, int gfp)
+{
+	int len;
+	char *buf;
+
+	if (!s) return NULL;
+
+	len = strlen(s) + 1;
+	buf = kmalloc(len, gfp);
+	if (buf)
+		memcpy(buf, s, len);
+	return buf;
+}
+
+EXPORT_SYMBOL(kstrdup);

Reply via email to