From: Dan Aloni <da-x@gmx.net>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Linux Kernel List <linux-kernel@vger.kernel.org>
Subject: Re: [BK PATCH] One strdup() to rule them all
Date: Mon, 25 Aug 2003 19:34:45 +0300 [thread overview]
Message-ID: <20030825163445.GA9531@callisto.yi.org> (raw)
In-Reply-To: <20030825122532.J10720@devserv.devel.redhat.com>
On Mon, Aug 25, 2003 at 12:25:32PM -0400, Jakub Jelinek wrote:
> On Mon, Aug 25, 2003 at 07:14:35PM +0300, Dan Aloni wrote:
> > diff -Nru a/lib/string.c b/lib/string.c
> > --- a/lib/string.c Mon Aug 25 19:03:26 2003
> > +++ b/lib/string.c Mon Aug 25 19:03:26 2003
> > @@ -582,3 +582,19 @@
> > }
> >
> > #endif
> > +
> > +/**
> > + * strdup - Allocate a copy of a string.
> > + * @s: The string to copy. Must not be NULL.
> > + *
> > + * returns the address of the allocation, or NULL on
> > + * error.
> > + */
> > +char *strdup(const char *s)
> > +{
> > + char *rv = kmalloc(strlen(s)+1, GFP_KERNEL);
> > + if (rv)
> > + strcpy(rv, s);
> > + return rv;
> > +}
> > +EXPORT_SYMBOL(strdup);
>
> Better save strlen(s)+1 in a local size_t variable and use memcpy instead
> of strcpy.
Maybe, but no optimizations like this are needed for a function
such as strdup() which is called relatively rare.
--
Dan Aloni
da-x@gmx.net
next prev parent reply other threads:[~2003-08-25 16:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-25 16:14 [BK PATCH] One strdup() to rule them all Dan Aloni
2003-08-25 16:25 ` Jakub Jelinek
2003-08-25 16:34 ` Dan Aloni [this message]
2003-08-25 17:05 ` Jeff Garzik
2003-08-25 17:23 ` Dan Aloni
2003-08-25 17:49 ` Andries Brouwer
2003-09-11 16:22 ` Jörn Engel
2003-09-12 1:57 ` Rusty Russell
2003-09-12 3:12 ` Jeff Garzik
2003-09-12 4:16 ` Rusty Russell
2003-09-12 8:49 ` Bernd Petrovitsch
2003-08-25 16:37 ` Jörn Engel
2003-08-25 16:55 ` Dan Aloni
2003-08-25 17:02 ` Jörn Engel
2003-08-25 17:04 ` Jeff Garzik
2003-08-25 17:08 ` Jörn Engel
2003-08-25 17:22 ` Jeff Garzik
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=20030825163445.GA9531@callisto.yi.org \
--to=da-x@gmx.net \
--cc=jakub@redhat.com \
--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