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, 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.

Jakub
-
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.092 / U:3.288 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site