fa.openbsd.tech
[Top] [All Lists]

Re: memdup(3)

Subject: Re: memdup(3)
From: Marc Balmer <marc@xxxxxxx>
Date: Mon, 14 Jul 2008 15:16:38 UTC
Newsgroups: fa.openbsd.tech

* Alexey Dobriyan wrote:
> memdup(3) has strdup(3) semantics but without strings.
> 
> Canonical code for duplicating buffer looks like:
> 
>       rpl = malloc(src, len);
>       if (!rpl)
>               ...
>       memcpy(rpl, src, len);
> 
> Mistakes happen and two lengths in snippet above will be different.
> To prevent this memdup(3) was created:
> 
>       rpl = memdup(src, len);
>       if (!rpl)
>               ...
>       ...

I dislike this a lot.   It is not available anywhere else, for a start.


<Prev in Thread] Current Thread [Next in Thread>