tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Theo chiming in on strlcpy



* Christos Zoulas <christos%astron.com@localhost> [2013-12-22 21:07]:
> In article <20131222200544.GA15715%weiss.in-berlin.de@localhost>,
> Holger Weiss  <lists%jhweiss.de@localhost> wrote:
> >    static char *
> >    concat(const char *s1, const char *s2)
> >    {
> >        size_t l1 = strlen(s1);
> >        size_t l2 = strlen(s2);
> >        size_t size;
> >
> >        if (((size = l1 + l2) <= l1 && l2 != 0) || ++size == 0)
> >            abort(); /* Handle `size_t' overflow. */
> >        return strcat(strcpy(xmalloc(size), s1), s2);
> >    }
> >
> > [...]
> 
> Easier:
> 
> static char *
> concat(const char *s1, const char *s2) {
>       char *p;
>       return asprintf(&p, "%s%s", p1, p2) == -1 ? NULL : p;
> }

Easier, but not as portable.

Holger


Home | Main Index | Thread Index | Old Index