lkml.org 
[lkml]   [2003]   [Aug]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [BK PATCH] One strdup() to rule them all
On Mon, 25 August 2003 19:14:35 +0300, Dan Aloni wrote:
>
> While working on the fix to network devices names and sysctl,
> I fought to urge to create yet another strdup() implementation
> This came up.

Nice one.

> +/**
> + * 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;
> +}

My gut feeling is always afraid when something "must not be NULL",
someone will ignore this and Bad Things (tm) happen. Is strdup ever
used such performance critical code that the extra check would hurt?

Apart from that, well done.

Jörn

--
Eighty percent of success is showing up.
-- Woody Allen
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:48    [W:0.402 / U:0.616 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site