From: Olaf Dietsche <olaf.dietsche@t-online.de>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: linux-kernel@vger.kernel.org, torvalds@transmeta.com,
trivial@rustcorp.com.au, Neil Brown <neilb@cse.unsw.edu.au>,
dwmw2@redhat.com
Subject: Re: [PATCH] [TRIVIAL] kstrdup
Date: Tue, 14 Jan 2003 12:48:11 +0100 [thread overview]
Message-ID: <87bs2kkl50.fsf@goat.bogus.local> (raw)
In-Reply-To: 20030114025452.656612C385@lists.samba.org
Rusty Russell <rusty@rustcorp.com.au> writes:
> Everyone loves reimplementing strdup.
Really? ;-) SCNR
Please consider this one or parts of it:
<http://groups.google.com/groups?selm=87y97t34hs.fsf%40goat.bogus.local>
Rediffed against 2.5.58 below.
Regards, Olaf.
diff -urN a/include/linux/string.h b/include/linux/string.h
--- a/include/linux/string.h Mon Nov 18 10:33:57 2002
+++ b/include/linux/string.h Tue Jan 14 12:37:29 2003
@@ -7,6 +7,7 @@
#include <linux/types.h> /* for size_t */
#include <linux/stddef.h> /* for NULL */
+#include <linux/gfp.h> /* for GFP_KERNEL */
#ifdef __cplusplus
extern "C" {
@@ -16,6 +17,11 @@
extern char * strsep(char **,const char *);
extern __kernel_size_t strspn(const char *,const char *);
extern __kernel_size_t strcspn(const char *,const char *);
+extern void *kmemdup(const void *, __kernel_size_t, int);
+
+static inline char *kstrdup(const char *s, int flags)
+ { return kmemdup(s, strlen(s) + 1, flags); }
+static inline char *strdup(const char *s) { return kstrdup(s, GFP_KERNEL); }
/*
* Include machine specific inline routines
diff -urN a/kernel/ksyms.c b/kernel/ksyms.c
--- a/kernel/ksyms.c Tue Jan 14 12:31:42 2003
+++ b/kernel/ksyms.c Tue Jan 14 12:33:41 2003
@@ -586,6 +586,7 @@
EXPORT_SYMBOL(strnicmp);
EXPORT_SYMBOL(strspn);
EXPORT_SYMBOL(strsep);
+EXPORT_SYMBOL(kmemdup);
/* software interrupts */
EXPORT_SYMBOL(tasklet_init);
diff -urN a/lib/string.c b/lib/string.c
--- a/lib/string.c Mon Nov 18 10:33:58 2002
+++ b/lib/string.c Tue Jan 14 12:39:55 2003
@@ -22,6 +22,7 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/ctype.h>
+#include <linux/slab.h>
#ifndef __HAVE_ARCH_STRNICMP
/**
@@ -502,6 +503,20 @@
s1++;
}
return NULL;
+}
+#endif
+
+#ifndef __HAVE_ARCH_KMEMDUP
+/**
+ * kmemdup - allocate memory and duplicate a string
+ */
+void *kmemdup(const void *s, __kernel_size_t n, int flags)
+{
+ void *p = kmalloc(n, flags);
+ if (p)
+ memcpy(p, s, n);
+
+ return p;
}
#endif
next prev parent reply other threads:[~2003-01-14 11:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-14 1:55 [PATCH] [TRIVIAL] kstrdup Rusty Russell
2003-01-14 3:19 ` Jeff Garzik
2003-01-15 6:45 ` Rusty Russell
2003-01-14 3:28 ` Valdis.Kletnieks
2003-01-14 3:38 ` Jeff Garzik
2003-01-14 3:53 ` Valdis.Kletnieks
2003-01-14 4:15 ` Jeff Garzik
2003-01-14 5:15 ` Valdis.Kletnieks
2003-01-14 11:48 ` Olaf Dietsche [this message]
2003-01-15 6:55 ` Rusty Russell
2003-01-19 23:37 ` Pavel Machek
2003-01-22 2:04 ` Rusty Russell
2003-01-23 14:02 ` Pavel Machek
2003-01-23 14:21 ` Martin Mares
2003-01-23 14:44 ` Pavel Machek
2003-01-29 4:51 ` Rusty Russell
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=87bs2kkl50.fsf@goat.bogus.local \
--to=olaf.dietsche@t-online.de \
--cc=dwmw2@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=neilb@cse.unsw.edu.au \
--cc=rusty@rustcorp.com.au \
--cc=torvalds@transmeta.com \
--cc=trivial@rustcorp.com.au \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.