[PATCH] Simplify strncat.

Paul Eggert eggert@cs.ucla.edu
Fri Dec 19 20:03:00 GMT 2014


On 12/18/2014 06:37 AM, Wilco Dijkstra wrote:
> char *
> STRNCAT (char *s1, const char *s2, size_t n)
> {
>    char *s;
>    n = strnlen (s2, n);
>    s = s1 + strlen (s1);
>    s[n] = '\0';
>    memcpy (s, s2, n);
>    return s1;
> }

I originally wrote it the above way first, but rewrote it to use mempcpy 
because that  made strncat simpler and its executable code smaller, and 
since nobody in their right mind ever uses strncat I figured simpler and 
smaller was better for glibc users overall even if it might be 
unmeasurably slower for the few crazies who actually use strncat.

It's not a big deal either way, of course.  Either version is fine.



More information about the Libc-alpha mailing list