public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Paulo Marques <pmarques@grupopie.com>
Cc: Matt Domsch <Matt_Domsch@dell.com>, Greg KH <greg@kroah.com>,
	Christoph Hellwig <hch@infradead.org>,
	lkml - Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@osdl.org>
Subject: Re: [PATCH 2.6.11-rc2] modules: add version and srcversion to sysfs
Date: Thu, 27 Jan 2005 13:10:28 +1100	[thread overview]
Message-ID: <1106791829.24855.5.camel@localhost.localdomain> (raw)
In-Reply-To: <41F7A9F6.20804@grupopie.com>

On Wed, 2005-01-26 at 14:32 +0000, Paulo Marques wrote:
> Matt Domsch wrote:
> > [...]
> >  
> > +static char *strdup(const char *str)
...
> Actually, I've just grep'ed the entire tree and there are about 7 
> similar implementations all over the place:

Wow, I'd never noticed.  Linus, please apply 8)

Rusty.
Name: kstrdup
Author: Neil Brown, Rusty Russell and Robert Love
Status: Trivial

Everyone loves reimplementing strdup.  Give them a kstrdup.

Index: linux-2.6.11-rc2-bk4-Misc/include/linux/string.h
===================================================================
--- linux-2.6.11-rc2-bk4-Misc.orig/include/linux/string.h	2004-05-10 15:13:54.000000000 +1000
+++ linux-2.6.11-rc2-bk4-Misc/include/linux/string.h	2005-01-27 13:08:30.042035568 +1100
@@ -88,6 +88,8 @@
 extern void * memchr(const void *,int,__kernel_size_t);
 #endif
 
+extern char *kstrdup(const char *s, int gfp);
+
 #ifdef __cplusplus
 }
 #endif
Index: linux-2.6.11-rc2-bk4-Misc/lib/string.c
===================================================================
--- linux-2.6.11-rc2-bk4-Misc.orig/lib/string.c	2005-01-27 11:26:15.000000000 +1100
+++ linux-2.6.11-rc2-bk4-Misc/lib/string.c	2005-01-27 13:08:30.080029792 +1100
@@ -23,6 +23,7 @@
 #include <linux/string.h>
 #include <linux/ctype.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 
 #ifndef __HAVE_ARCH_STRNICMP
 /**
@@ -599,3 +600,19 @@
 }
 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)
+{
+	char *buf = kmalloc(strlen(s)+1, gfp);
+	if (buf)
+		strcpy(buf, s);
+	return buf;
+}
+
+EXPORT_SYMBOL(kstrdup);

-- 
A bad analogy is like a leaky screwdriver -- Richard Braakman


      reply	other threads:[~2005-01-27  2:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20050119171357.GA16136@lst.de>
     [not found] ` <20050119172106.GB32702@kroah.com>
     [not found]   ` <20050119213924.GG5508@us.ibm.com>
     [not found]     ` <20050119224016.GA5086@kroah.com>
     [not found]       ` <20050119230350.GA23553@infradead.org>
     [not found]         ` <20050119230855.GA5646@kroah.com>
     [not found]           ` <20050119231559.GA10404@lists.us.dell.com>
     [not found]             ` <20050119234219.GA6294@kroah.com>
2005-01-26  6:05               ` [PATCH 2.6.11-rc2] modules: add version and srcversion to sysfs Matt Domsch
2005-01-26  9:22                 ` Andreas Gruenbacher
2005-01-26 14:09                   ` Matt Domsch
2005-01-26 16:38                     ` Andreas Gruenbacher
2005-01-27 17:03                       ` Matt Domsch
2005-01-27 17:41                       ` Bill Davidsen
2005-01-26 14:32                 ` Paulo Marques
2005-01-27  2:10                   ` Rusty Russell [this message]

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=1106791829.24855.5.camel@localhost.localdomain \
    --to=rusty@rustcorp.com.au \
    --cc=Matt_Domsch@dell.com \
    --cc=greg@kroah.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmarques@grupopie.com \
    --cc=torvalds@osdl.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