mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "" <pmarques@grupopie.com>
To: Andrew Morton <akpm@osdl.org>
Cc: "" <linux-kernel@vger.kernel.org>
Subject: [PATCH 2.6] 1/7 create kstrdup library function
Date: Tue,  1 Feb 2005 03:28:21 +0000	[thread overview]
Message-ID: <1107228501.41fef755e66e8@webmail.grupopie.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]


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 <pmarques@grupopie.com>

--
Paulo Marques - www.grupopie.com
 
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke (1729 - 1797)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch1 --]
[-- Type: text/x-diff; name="patch1", Size: 1233 bytes --]

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	other threads:[~2005-02-01  3:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-01  3:28 pmarques [this message]
2005-02-01 16:44 ` Pekka Enberg
2005-02-01 17:00   ` Paulo Marques
2005-02-02  7:23     ` Pekka Enberg
2005-02-02 12:17       ` Paulo Marques
2005-02-02 12:29         ` Pekka J Enberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1107228501.41fef755e66e8@webmail.grupopie.com \
    --to=pmarques@grupopie.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®