From: Olaf Dietsche <olaf.dietsche#list.linux-kernel@t-online.de>
To: Andrew Morton <akpm@digeo.com>
Cc: linux-kernel@vger.kernel.org, trivial@rustcorp.com.au
Subject: Re: [PATCH] 2.5.47: strdup()
Date: Sat, 16 Nov 2002 16:42:55 +0100 [thread overview]
Message-ID: <87y97t34hs.fsf@goat.bogus.local> (raw)
In-Reply-To: 3DD5E65A.59243812@digeo.com
Andrew Morton <akpm@digeo.com> writes:
> Olaf Dietsche wrote:
>>
>> +char *strdup(const char *s)
>> +{
>> + char *p = kmalloc(strlen(s) + 1, GFP_KERNEL);
>> + if (p)
>> + strcpy(p, s);
>> +
>> + return p;
>> }
>
> It's best to not assume GFP_KERNEL in there. Make the caller
> pass in the required allocation mode.
Ok, here is my next try, trying to include your and the other
suggestions. As before, it compiles, but is untested.
Regards, Olaf.
diff -urN a/include/linux/string.h b/include/linux/string.h
--- a/include/linux/string.h Sat Oct 5 18:42:33 2002
+++ b/include/linux/string.h Sat Nov 16 16:23:40 2002
@@ -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" {
@@ -15,7 +16,11 @@
extern char * strpbrk(const char *,const char *);
extern char * strsep(char **,const char *);
extern __kernel_size_t strspn(const char *,const char *);
+extern void *kmemdup(const void *, 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 Nov 12 17:56:02 2002
+++ b/kernel/ksyms.c Sat Nov 16 16:26:37 2002
@@ -576,6 +576,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 Sat Oct 5 18:42:33 2002
+++ b/lib/string.c Sat Nov 16 16:22:46 2002
@@ -22,6 +22,7 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/ctype.h>
+#include <linux/slab.h>
#ifndef __HAVE_ARCH_STRNICMP
/**
@@ -479,6 +480,20 @@
s1++;
}
return NULL;
+}
+#endif
+
+#ifndef __HAVE_ARCH_KMEMDUP
+/**
+ * kmemdup - allocate memory and duplicate a string
+ */
+void *kmemdup(const void *s, 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:[~2002-11-16 15:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-16 6:21 [PATCH] 2.5.47: strdup() Olaf Dietsche
2002-11-16 6:25 ` Jeff Garzik
2002-11-16 6:31 ` Andrew Morton
2002-11-16 15:42 ` Olaf Dietsche [this message]
2002-11-17 23:32 ` Werner Almesberger
2002-11-18 2:43 ` Olaf Dietsche
2002-11-16 6:41 ` William Lee Irwin III
2002-11-17 0:08 ` Chris Wedgwood
2002-11-17 1:37 ` Olaf Dietsche
2002-11-17 4:40 ` Chris Wedgwood
-- strict thread matches above, loose matches on Subject: below --
2002-11-16 8:48 Peter Kjellerstedt
2002-11-16 15:53 ` Olaf Dietsche
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=87y97t34hs.fsf@goat.bogus.local \
--to=olaf.dietsche#list.linux-kernel@t-online.de \
--cc=akpm@digeo.com \
--cc=linux-kernel@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox