Re: [PATCH] 2.5.47: strdup()

Jeff Garzik (jgarzik@pobox.com)
Sat, 16 Nov 2002 01:25:38 -0500


Olaf Dietsche wrote:

> This *untested* patch adds strdup(). There are about five or six
> different strdup() implementations in various parts of the kernel.
>

> +#ifndef __HAVE_ARCH_STRDUP
> +/**
> + * strdup - allocate memory and duplicate a string
> + */
> +char *strdup(const char *s)
> +{
> + char *p = kmalloc(strlen(s) + 1, GFP_KERNEL);
> + if (p)
> + strcpy(p, s);
> +
> + return p;
> }

Comments:

* arch-specific strdup is unlikely

* IMO safer to create a strndup, and then update all strdup callers to
use strndup...

-
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/